Sean's Note

2015年12月30日 星期三

Default highlight behavior of ListView when clicking item

如果 adapter 裡的 view item 都不能觸發點擊事件的話:
android:clickable="false"
android:focusable="false"
點選每一行就會有 default(透明灰的) 的 highlight,
如果有設  setOnItemLongClickListener,就會有長按的效果。
反之,如果有 CheckBox 或 EditText,其屬性又沒有設成 false 的話,
就不會有 default 的效果。

2015年11月12日 星期四

How to check ProGuard obfuscation has worked?

用 Android Studio build 完 APK 檔之後,
在 C:\{Project}\{Application Project}\build\outputs\mapping\release 下會生成四個檔案:
  • dump.txt
    描述了 APK 檔裡所有 class 檔案的架構。
  • mapping.txt
    class, method, field 混淆前後的名稱。 
  • seeds.txt
    沒有被混淆的  class, method, field 名稱。 
  • usage.txt
    被 ProGuard 拿掉的 class, method, field。

How to use proguard for library project(module)?

發現如果在 application project 跟 library project 裡都有定義

buildTypes {
      release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
}

就會有一堆 cannot find symbol class 的 errors。
解決的方法有兩種:
  1. 把 library project 的 proguard-rules.pro 裡的定義都搬到 application project 的 proguard-rules.pro,再把 library project 的 minifyEnabled 設為 false。
  2. 另一種就是把 library project 的 proguardFiles 改成 consumerProguardFiles 就行了 (minifyEnabled 也不須設定,minifyEnabled 是對應 proguardFiles 的)。
consumerProguardFiles 的定義是:
ProGuard rule files to be included in the published AAR.
These proguard rule files will then be used by any application project that consumes the AAR (if ProGuard is enabled).
This allows AAR to specify shrinking or obfuscation exclude rules.
This is only valid for Library project. This is ignored in Application project.

Ref:
  1. http://stackoverflow.com/questions/30820915/android-studio-proguard-handling-in-multi-library-projects
  2. http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html


2015年11月5日 星期四

How to access data/data folder in Android device without root?

透過 adb 指令可以備份資料到當前的目錄下:
adb backup -noapk com.your.packagename
裝置上就會跳出一個視窗問你要不要備份,並輸入密碼,建議是不要輸入密碼會比較方便。
另外,備份的檔案為壓縮過 .ab 檔,必須還得用 tool Android Backup Extractor 解開,
然後再輸入以下指令解壓縮:
java -jar abe.jar unpack backup.ab backup.tar <password>
解完就可以看到 Preference 的 XML 檔案和 DB,
其他 Private Folder 的內容好像看不到。

2015年10月29日 星期四

Material Design

What is material?

Android 從 5.0 開始,引進了 Material Design 的概念,Material 即為物質之意,
而 Material 所處的環境是一個 3D 的空間。利用光和影 (Light and shadow) 的效果,
可以使 UI 元件看起來更為立體 (圖1)。

圖1. 圖片來源: Google Design

Material properties

Google 對 Material 的屬性提出了幾點規定:
  1. Material 應保持著 1dp 的厚度(高度)。
  2. Material 的陰影效果(Shadow) 應隨其高度而反映。
  3. Input events 不能橫跨 material 與 material 之間。
  4. 兩個 material 不能在同一高度上重疊。
  5. Material 可以改變其大小與形狀 (x, y 軸),但僅限於在原本的高度(z 軸)上。
  6. Material 不能被對摺 (fold)。
  7. 高度上的改變,通常是與使用者的互動所造成的。
  8. 更多詳見 Material properties

Elevation and shadows

Google 也對不同的 UI 元件定義的不同的高度。詳見 Elevation and shadows


2015年10月28日 星期三

A tool for reverse engineering Android apk files

由於 APK 檔裡的 AndroidManifest 已經組譯過,看到的是亂碼,
可以用第三方的工具來反組譯,就看的到了~
http://ibotpeaches.github.io/Apktool/