2014年8月18日 星期一

Respect View.isInEditMode()

Android 的 layout renderer 並沒有聰明到可以自動去取消每一個 runtime 的程式碼

所以很多時候 onFinishLayout() 裡,onAttachToWindow() 裡
常會有一些 runtime 才會拿得到的東西
這會造成 layout renderer 直接死給你看

解法很簡單
用 isInEditMode() 去把這些 renderer 無法處理的東西包起來
(或者是直接 early return)

或者是之前講的這個...要在 renderer 裡顯示沒有的東西 View.isInEditMode()

很遺憾的是...連 Google 自己都不鳥這個 =__=

2014年8月4日 星期一

early return

看到 BSP 裡不知道在修啥 bug, 把 aosp 原來的 code wrap 了一個 null check 本來可以寫成 early return 結果硬要用 if-else 包起來

private int getWidgetPosition(int id) {
    if (mAppWidgetContainer != null) {
                 // 原來的 code
    } else {
        return -1;
    }
}

一般的 git show or diff 跑出洋洋灑灑的一大片無意義的的畫面 雖然可以下參數避掉, 不過一般還是會用 raw diff 看有沒有多的垃圾

整排indent 的結果 造成整個 diff 多了十行 每次看到這種 code 一整個想翻桌

2014年6月12日 星期四

MacOS skype input lag

自從不知道哪個版本後 Skype 沒事打字就會頓 之前試過只留 main log 再蓋回去有效 可是過陣子又會爛 剛生氣又找了一下,發現這個方法 感覺有效...也沒有之前那麼麻煩
  • Quit Skype
  • rm -rf ~/Library/Caches/com.skype.skype
http://community.skype.com/t5/Mac/Skype-increasing-lagging-and-using-too-much-CPU/td-p/2011405

Fuck you Microsoft

2014年1月8日 星期三

不小心 git commit --amend 了別人的 patch

環境

2d14654 HEAD@{0}: commit (amend): Other's patch
428555b HEAD@{1}: commit: Other's patch
bd33767 HEAD@{2}: commit: Previous one

先把 HEAD 退回到原來的 patch, 記得確定把你的 working directory 搞乾淨

$ git reset --hard HEAD~1
HEAD is now at bd33767 Previous one

$ git cherry-pick 428555b
....

把 amend 到別人 patch 的內容 diff 出來,重新 apply, apply 的參數 - (dash) 表示是從 STDIN 讀入

$ git diff 428555b 2d14654 | git apply -

這時打 git status 就可以發現當初的修改回來 unstage 的狀態了, 重新 git commit

$ git commit

完成

2013年11月26日 星期二

Nexus 5 w/ AOSP

Tested in KRT16M / KOT49H

Steps

Follow the steps here

http://source.android.com/source/building.html

  • unlock device
  • get source code Version

    • KRT16M | android-4.4_r1
    • KOT49H | android-4.4.2_r1
  • get nexus driver

  • fix what's missing in nexus driver

    link
    yes, pull the binary from stock ROM first If you didn't do that, your SIM cannot be used

  • (optional) get /system/media/bootanimation.zip Because AOSP android doesn't have nexus animation

  • (ADD: 2013/11/29 16:55) add Network Location Provider for GMS
    link
    Fixed Wireless GPS issues. Changed "config_locationProviderPackageNames" from "com.google.android.location" to "com.google.android.gms" in frameworks/base/core/res/res/values/config.xml

  • start to build

      $ source build/envsetup.sh  
      $ lunch  
          => Press AOSP hammerhead userdebug  
      $ make clobber  
      $ make -j 4  
    
  • flash custom recovery (CWM or TWRP)

  • flash everything other than recovery

  • fastboot reboot bootloader

  • Press VOL-UP than power button to enter recovery mode
    Choose Advanced -> sideload mode, if you are using TWRP

      $ adb sideload gapps
          gapps link http://forum.xda-developers.com/showthread.php?t=2397942
      $ adb sideload stock_boot_animation or 
          adb push bootanimation.zip into /system/media/bootanimation.zip
    
  • do a factory reset

  • (ADD: 2013/12/19 16:07)
    fix green line issue in camcorder KOT49H (KRT16M has this issue?)
    Replace /system/lib/libmmcamera_interface.so by stock one
    link

Have fun!

2013年11月12日 星期二

WeakReference listener in API

在找 OnSharedPreferenceChangeListener 範例抄時找到這個

SharedPreferences keeps listeners in a WeakHashMap. This means that you cannot use an anonymous inner class as a listener, as it will become the target of garbage collection as soon as you leave the current scope.

SharedPreferences.onSharedPreferenceChangeListener not being called consistently

靠... 這很容易踩到啊 =_=

2013年11月2日 星期六

ad block on android

plurka 廣告設計得太爛,不要怪我對你不義啊

記錄一下

adb shell mount -o rw,remount /system 
adb push hosts.for.mobile.txt /etc/hosts
adb reboot

refs: xda

2013年10月25日 星期五

Mac OS Mavericks broken list

ant 不見了

xcode-select --install 後還是不在, 用 Mac Ports 吧

$ sudo ports install apache-ant

Genymotion 1.3.0 broken

啟動後的 navigation bar 跟 orietation 一整個亂七八糟
解法: 升級到 1.3.1

http://stackoverflow.com/questions/19561669/error-on-loading-genymotion-device-on-os-x-mavericks

iMovie

更新到 10.0 後, 9.0.9 被搬到 /Application/iMovie 9.0.9 下面
iWork 也是還存在
應該可以砍了吧 = ="

電源按鈕行為改變了

以前按一下電源鈕會跑出電源選單,現在只會直接睡著
解法: 長按 1.5 秒

http://support.apple.com/kb/HT5869?viewlocale=en_US

iWork / iLife 可以免費升級

因為我一直以為只對 Keynote 有需求,所以我當初只買了 Keynote
Pages / Numbers 在試用期過後就放著讓他可以開檔案
結果這次搞一搞他就變正式版了 wwwww

http://share.inside.com.tw/posts/2899

MacPorts 壞了

gnutar 找不到
暫時解法:

sudo ln -s /usr/bin/tar /usr/bin/gnutar

不過 darwin12 != darwin13 只能等官方修吧 QQ

http://trac.macports.org/wiki/MavericksProblems  

update 10/28: mac ports 修好了, 等各 ports 陸續更新...

陸續更新...

2013年9月17日 星期二

一些 git / gerrit / ssh 設定

git / gerrit

alias

常用的指令例如 status 可以減化成短指令

~/.gitconfig

[alias]  
    ci = commit  
    st = status  
    co = checkout  
    l = log --stat=140,100  
    br = branch  
    p = cherry-pick  
    r = rebase  
    f = fetch  
    up = pull --rebase  

指令就變為

$ git st

自動產生 Change-Id

單獨 git clone 下來的 git repository 不會有 commit-msg hook
所以 push 到 gerrit 時,不會有 Change-Id
沒有 Change-Id 的話,重複 push 不會在同一個 patch 裡繼續疊加
所以 commit-msg hook 是必需要用的
(除非要手動從 gerrit 上 copy 下來...何苦呢...)

如果手邊有 BSP

    $ find . -name commit-msg \<BSP_ROOT>/.repo

把他 copy 到 .git/hooks/ 裡

gerrit server

    $ scp -p -P 29418 \<SERVER>:hooks/commit-msg .git/hooks/

template

每次 git repository commit 時,如果要填寫固定格式
可以先將文字檔存下來,就不會每次都要打一次

per repository

進 git repository 寫一個文字檔 .gittemplate

$ git config commit.template=.gittemplate

global

放在 ~/.gitconfig 裡指定

[commit]  
    template = ~/.gittemplate

手動 push 到指定的 branch

$ git push ssh://\<SERVER>:29418/\<PATH> HEAD:refs/for/\<BRANCH>

PATH 可以使用

$ git config -l | grep url remote.origin.url=ssh://\<SERVER>:29418/here/is/my/branch

在此可以知道路徑是 here/is/my/branch

BRANCH

$ git branch -a
...
remotes/origin/aosp/jb-release
...

在裡面找需要的 branch, 不需要包 remotes/origin
所以這邊需要 aosp/jb-release

$ git push ssh://mickey.acer.com.tw:29418/here/is/my/branch HEAD:refs/for/aosp/jb-release

ssh

設定 gerrit

為了不要每次下指令都指定 user name 也就是

$ repo init -u ssh://my.id@\<SERVER>...... 

~/.ssh/config

Host \<SERVER>
Port 29418
User XXXX.YYY

跟 Gerrit 裡 Settings -> Profile -> Username 一樣

2013年9月16日 星期一

BuildConfig in BSP

BuildConfig 在 Eclipse 裡會自動生成 不過如果這份 source code 同時要在 BSP 裡使用就會有問題 先找到一個很醜的解法
wrapper!
public class L {
    private static boolean BUILDCONFIG_DEBUG = false;
    static {
        try {
            Class<?> c = Class.forName("com.helloworld.BuildConfig");
            Field field = c.getField("DEBUG");
            BUILDCONFIG_DEBUG = field.getBoolean(null);
        } catch (NoSuchFieldException e) {
        } catch (ClassNotFoundException e) {
        } catch (IllegalArgumentException e) {
        } catch (IllegalAccessException e) {
        }
    }
}