2012年8月27日 星期一

[Java] Serialize

  • 以字串型態傳遞物件。
  • 不能跨平台。
  • 像物件的 version control id。
  • 當物件屬性改變此 id 就會改變。
  • 當 B side 接收到 Serialize id,會根據此 id 去 new 相對應的物件將值設定進去。

[Spring] enum type attribute

// 如果物件中有 enum type 的屬性。
public class User {
    private MyEnumType name;

    ...... 
}

<%-- 
    JSP 中 form 欄位的 value 必須放入 MyEnumType 才能對回物件。
    使用 List options
--%>
.....

2012年8月26日 星期日

[Spring] Type not matched when String is "" and is tried to convert to date

ERROR MESSAGE
Type not matched when String is "" and is tried to convert to date


Solution

因為 form 中的 date 為 "" (空字串) 因為要轉成 Date 時會出錯。

@InitBinder
protected void initializeBinder (WebDataBinder binder)  {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd" );
    dateFormat.setLenient(false);
    CustomDateEditor dateEditor = new CustomDateEditor(dateFormat, true);

    binder.registerCustomEditor(Date. class, dateEditor);
    binder.registerCustomEditor(ModelEntity.class, customPropertyEditor);
}

2012年8月25日 星期六

[JPA] @ModelAttribute("xxx")

// entity: request 中的值對設定到物件中。
@RequestMapping(...)
public void methodName(@ModelAttribute("model") EntityType entity) {}



---- Update on 2013/08/25 ----

// @ModelAttribute("xxx") 會建立 EntityType 的物件,並且將此物件放入 request.
@ModelAttribute("model")
public Object prepare(...) {
    Object model = new EntityType();
    return model;
}


[Android] MSISDN, ICCID, IMEI, IMSI

下列值在以下情況會被改變或是取不到正確值:
  • ICCID
    • 換了 SIM card
  • IMEI
    • 山寨機
  • ANDROID_ID
    • 恢復原廠設定


Related
MSISDN, ICCID, IMEI, IMSI

[ORM] Date and Timestamp

DB 中時間的 type 有:
  • Date
  • Timestamp

對應到 java 中的 type 皆是宣告為 Date

DB 都是收到相同的值 然後再依欄位 type 決定存入的值

例如若是 date 會被 truncate 掉 millisecond 後再存入

[Animation] Property Animation (>= 11)

Supported from API Level 11.

Property Animation
  • A property animation changes a property's (a field in an object) value over a specified length of time.
  • 以某項 attribute 進行動畫。ex: x-axis 使物件橫向移動。
  • 分為兩部份:
    • 計算產生動畫的值。
    • 設定動畫值於物件的 property 中。

  • The view animation system
    • View animation 是藉由重繪 view 來顯示動畫,而此動作是由每個 view 自己的 container 來做(because the View itself had no properties to manipulate)。
    • 雖然結果可以看到 view 出現在不同位置,但實際上沒有改變到 view object 的任何 property,所以關於 view object 的設定卻還停留在原位 (ex: 點擊原始位置才會觸發 view 的事件)。
  • The property animation system
    • Property animation 則是改善了這個問題,因為它是改變 view object 的 property 來顯示動畫。
    • 而當 view object 的 property 改變,會自動呼叫 invalidate() 。

TypeEvaluator
  • 決定如何去計算進行動畫的 attribute 的值。
  • An interface that allows you to create your own evaluator.
  • If you are animating an object property that is not an int, float, or color, you must implement the TypeEvaluator interface to specify how to compute the object property's animated values.
  • You can also specify a custom TypeEvaluator for int, float, and color values as well, if you want to process those types differently than the default behavior.

ValueAnimator
  • Keeps track of your animation's timing.
  • How long the animation has been running.
  • The current value of the property that it is animating.
  • 管理 object 動畫中的 attribute 在動畫過程中的值,包含資訊:
    • 是否重複動畫。
    • 接收更新動作通知的 listeners。
    • 使用客制化的 evaluator。
  • 但 ValueAnimator 並不會將計算後的值設給 property,因此要使用 listeners 接收計算後的值再自行去更新,例如需實作 ValueAnimator.AnimatorUpdateListener

ObjectAnimator
  • A subclass of ValueAnimator.
  • 可以設定發生動畫的物件以及決定動畫內容的 property。
  • 此 class 會更新 property 的值,所以大部份使用此 class 比較方便,不需自行處理更新這部份動作。

AnimatorSet
  • 設定動畫效果於一群 view,他們能一起變化、有序的或是延遲的。
  • Provides a mechanism to group animations together so that they run in relation to one another. You can set animations to play together, sequentially, or after a specified delay.


* Reference
- Property Animation | Android Developers