2015年8月23日 星期日

Implementation of Undo/Redo on Android



    最近公司的產品拼貼趣想做Undo(上一步)和Redo(下一步)的功能,因為使用者常常不小心就把拼好的作品誤移,然後又很難移回來,其中一個發想就是參考Photoshop可以做Undo/Redo(還有其他發想例如把某個Layer鎖住的功能),聽起來對現在的code非常有挑戰,但還是花了一個下午做出第一版Prototype(只支援Undo),看起來會動只是畫面會狂閃;後來iOS的同事才跟我介紹他們實作的方式 - UndoManager

    秀了幾行code給我看後,感覺這個設計架構根本就超好,結果Android內建沒有這套實作,結果它藏在Android Framework裡,而且命名規則也很iOS(每一個Command叫做Operation),感覺是給內部UI Widget用的功能。

    解決這類型問題也有常用的Design Pattern,在SO找到這篇推薦Command Pattern,有空再來消化這個Pattern的其他應用方式。


2015年8月22日 星期六

Android Vision library

   Google Play Service 7.8 introduces the android vision library. that can easy to implement the function of face detection and barcode reader. the best part of it is that supports android 2.2 devices. you can checkout the sample code here.

Random idea: the traditional digital camera support smile mode. that means you can take photo by your smile face. now you can do the same thing on the android app. or you can trigger it by a wink

 

Solving the confliction on Android BuildToolsVersion 23 with RenderScript v8 library

If you using renderscript support library, and you try to upgrade the android tools version to 23.0.0. you will get the issue likes when compile your project :

UNEXPECTED TOP-LEVEL EXCEPTION:com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)

it cause the renderscirpt support library includes the annotation library's source code. you can solve this issue by adding a few of code in build.gradle

configurations {
    all*.exclude group: 'com.android.support', module: 'support-annotations'
}

reference : http://stackoverflow.com/questions/32051938/getting-multiple-dex-error-when-using-render-script-support-lib/32090710#32090710

2015年8月1日 星期六

Feedback : Upgrade Android M Preview 2

   最近大膽地將自己的Nexus 6升級到Android M的Preview版本,正所謂第一次將Preview版本用在自己手機就上手,反正也是前陣子才從iPhone換成Android,該遺失的資料也早該丟光光了,正所謂沒什麼很失去的時候,人就會變得特別有勇氣。

以上是用起來的後果:

1. Google Now Launcher瘋狂閃退:只要你用adb裝一次apk它就一定閃退給你看
2. Line已不舉:不知道它用了哪個API來檢查網路狀況,升級過後你永遠沒辦法登入Line的帳號,它只會不停的跟你說: "Please make sure that you have network connectivity and try again",這也表示Line的所有遊戲都GG了
3. 如果你是開發Camera App,可以特別把Camera的permission關掉,當你Call Camera.open()時就會拿不到Camera,請做好error handling,以我們的App(SelfieGrid)來說,雖然不會crash,但就剩黑畫面

如果還有其他後果歡迎與我分享


TabLayout will get empty Tab after upgrade design library to 22.2.1

  Google introduces the design library for making material design easier. so we reimplement the tab component by TabLayout. it's work perfectly in 22.2.0. but we get problem after upgrade the version to 22.2.1. the tab doesn't show up anymore(issue track).

  it's work on some place, but some one isn't. we couldn't figure out what is the right way to handle this. so we decide to rollback the version to 22.2.0.