2011年7月31日 星期日

[Android] Animation

動畫做法可分以下幾種方式:

* Tweened animation:
  • 通過對 view 不斷做圖像變換(平移、縮放、旋轉)產生動畫效果。
  • 預先在 .java or .xml 中定義一組動畫動作,此組動作可有變換類型、觸發時間、持續時間等,啟動後,便會執行這一連串的動作。
  • 動畫的執行速度由 interpolator 控制,ex: LinearInterpolator、 Accelerateinterpolator、DecelerateInterpolator。
  • 圖形變化是通過鏡射矩陣達成,每種變換都是一次矩陣運算。
  • 在 Android 中,Canvas 類中包含當前矩陣,使用 Canvas.drawBitmap (bmp, x, y, Paint) 繪製時,android 會先把 bmp 做一次矩陣運算,然後將運算的结果顯示在 Canvas 上。
  • 所以只需不断修改 Canvas 的矩陣並更新畫面,View 就會不停的做圖形變化而呈現動畫。


* frame-by-frame animation:順序播放事先做好的圖像,跟電影類似

* LayoutTransition: container 有新增/remove item 時會 animation



* android:duration="@android:integer/config_longAnimTime"
config_longAnimTime is just slightly less than a half second, and is long enough for most purposes.

* alpha:透明度效果
Translate:畫面轉換位置移動動畫效果

* z axis: 距離螢幕的距離
-z: zoomIn
+z: zoomOut

* y axis:
+y: right (逆時鐘)
-y: left (順時鐘)

* angle
-angle: 逆時鐘
+angle: 順時鐘
- -> + : 順時鐘
- -> - : 逆時鐘
+ -> + : 順時鐘
+ -> - : 逆時鐘

* action
onScroll: 拿
onFling: 丟


* Reference
- 分析android动画模块
Android中渐变动画演示(Tween Animation) - Android Studio - 青藤园
- anddev.org • View topic - Splash Fade, Activity Animations, overridePendingTransition

[Android] Multiple screens layout size unit

Resolution is the actual number of pixels available in the display.

Density is how many pixels appear within a constant area of the display, and size is the amount of physical space available for displaying your interface.


* sp (scale-independent pixel)
  • To define text sizes.
  • Depends on a user setting and the system scales the size the same as it does for dp.

* dp
  • To remove the size/density calculations from the picture and should use dp for layout dimensions 
  • Because that the system(Android famework) can adjust dp units for screen density.


* Reference
- Supporting Multiple Screens | Android Developers
- Android Developers Blog: New Tools For Managing Screen Sizes

2011年7月23日 星期六

[Proguard] build project exception

# Proguard returned with error code 1. See console
# proguard.ParseException: Unknown option 'projects\fetnet-appstore-2.0\trunk\android\fetnet_appstore_storeclient_v3\proguard\dump.txt' in argument number 9
# at proguard.ConfigurationParse


Solution:
Android SDK and project path cannot have "space".

[Android] Device screen size

Mobile screen size depend on LCD size

xLarge: 七吋(不含)以上


* Reference
- Android Developers Blog: New Tools For Managing Screen Sizes

[Eclipse] Debug Mode shortcut

F6: next step

F5: go to method

F7: go out method

F8: next breakpoint(?)

[Resource] Draw 9-patch

* android SDK 中所提供的工具,位於 (SDK path)\tools\draw9patch.bat

* 讓圖片可以放大(變長或變寬)並且不會失真。

* 工具中:
圖片旁邊會有 1 px 的空白,在想放大的邊點選這 1 px 的空白。

Zoom:只是單純讓你放大圖片,比較好操作,不會對最終檔案有影響!
Patch scale:只是讓你看圖片最終變長、變寬以後的樣子。在你儲存前都可以修改!

做法可參考Draw 9-patch

* 調整好的檔案 檔名應儲存為 fileName.9.png

* 在 SDK 2.3 版使用此工具時會出現 NoClassDefFoundError,請見[Android]draw9patch 的 NoClassDefFoundError 解決方法


* Reference
- Draw 9-patch
- NinePatch
- Draw 9-patch **
- [Android]draw9patch 的 NoClassDefFoundError 解決方法
- Draw 9-patch Tutorial **
- android 工具 Draw 9-patch 详解 **
- Android学习系列(4)--App自适应draw9patch不失真背景 ***
- android draw 9-path使用总结
- android 9patch ****

2011年7月18日 星期一

[Android] gravity and layout_gravity

android:gravity
  1. 針對定義元素中的子元素的位置。
  2. ex: 可設定 button 中 text 的位置。

android:layout_gravity
  1. 定義元素自己對於其父元素的相對位置。

Update on 2012/03/25

若要使用 layout_gravity,該元件的 layout_width / layout_height 必須是 wrap_content 才有用。


* Reference
- [Android] layout_gravity 和 gravity 的區別 **
- 【Android】界面布局之 LinearLayout(线性布局) - hgyin212314的专栏 - CSDN博客
- 用android LinearLayout和RelativeLayout实现精确布局 - - ITeye技术网站
- Java Artisan: Android Layout Managers - LinearLayout

2011年7月11日 星期一

[Resource] Android resource syntax

@
- 引用已定義好的資源或是android所提供的資源
- ex: @string, @android:string, @+id (表示新增新的id)...etc

?
- 引用style中的資源,引用属性 (?)
- 表示引用的資源是在當前主題定義過的 (?)
A style attribute resource allows you to reference the value of an attribute in the currently-applied theme. Referencing a style attribute allows you to customize the look of UI elements by styling them to match standard variations supplied by the current theme, instead of supplying a hard-coded value. Referencing a style attribute essentially says, "use the style that is defined by this attribute, in the current theme."

* Notice the use of the at-symbol (@) and the question-mark (?) to reference resources. The at-symbol indicates that we're referencing a resource previously defined elsewhere (which may be from this project or from the Android framework). The question-mark indicates that we're referencing a resource value in the currently loaded theme. This is done by referring to a specific by its name value.


* Reference
- 1 2 3
- Android Styles & Themes(下)——Theme | mo-Android
- Android - Applying Styles and Themes

2011年7月7日 星期四

[Coding] Coding Note

  • 思索程式架構
  • error handler:
  1. 印出錯誤訊息
  2. 對回傳值多加附註
  3. 多一參數 讓開發者可以選擇自己的 default value

2011年7月5日 星期二

[Encoding] Dos and Unix format

修改設定檔時不可在 Dos Format 下修改, 不然在 Unix 環境上執行會發生錯誤

否則要記得轉換編碼

[Regular Expression] ?: non-captured group

?:  non-captured group


(xxx)(yyyy)\1\2

(xxx): 第一組

(yyyy): 第二組


若加上 ?:

(?:xxxx)(yyy)\1

如此 (xxxx) 不算一組 (yyyy) 則為第一組

節省空間(不cache在memory)

[Spring] Base concept

如果要使用 ApplicationContext

就會太依賴 Spring

所以才有IoC(?)

乾脆讓Spring可以injection 給我們