2011年11月16日 星期三

[操作] Android Emulator

- Emulator Image的Project如何新增?
到build/target/product/full_base.mk 新增自己的Package

- 如何丟apk抽換/system/app下的apk
調整emulator的image大小, 避免Out of Memory問題
emulator -avd NAME -partition-size 512

設定 partition可寫入 , 避免 Read-only的問題
adb remount

ICS注意要將apk與odex一同丟入emulator中

[技術] How to install a untrusted root certificate to android emulator

很玄的文章 , 應該有用途 , 記錄下來
http://www.virgo81.net/70

2011年11月15日 星期二

[主機] Ubuntu

Ubuntu預設將root關閉 , 可透過下列方式設定root密碼

sudo passwd root

2011年11月10日 星期四

[原始碼] Android Contacts

Contacts Clound
http://gigaom.com/mobile/how-to-use-the-cloud-to-move-contacts-between-phones/


Android Contact数据模型之EntityDelta
http://www.cnblogs.com/yyq-quan/archive/2011/09/01/2162332.html
http://www.cnblogs.com/yyq-quan/archive/2011/09/01/2162343.html
添加联系人的界面如何去得到用户在文本框里输入的文字? http://www.iteye.com/problems/57473


Entity
包含下列三個元素 , 對應到Contacts的資料表分別為:
Top Level
- Content Value <==> 特定RawContacts Table資料的各欄位資料
SubValue
- Uri <==> 對應到RawContacts的所有Data Table的URI
- Content Value <==> 對應到RawContacts的所有Data Table 欄位資料

ContentValues getEntityValues() <==> 取得特定RawsContacts Table的所有欄位資料
ArrayList<Entity.NamedContentValues> getSubValues() <==> 取得對應RawContacts Table id的
Data Table 資料的欄位

Entity.NamedContentValues

保存下列兩個欄位 , 用來描述特定Contacts Data欄位的內容
- URI (Data欄位的Uri)
- Cotent Value

2011年11月8日 星期二

[技術] Ordered Broadcasts

http://blog.csdn.net/ruijc/article/details/6210024

在Not-ordered模式,系统的Broadcasts是同时发布出来,所有receiver都可以得到该事件信息,互相并不影响。即,一个receiver不能影响其它receivers是否能获得该事件信息。上面电池的 ACTION_BATTERY_LOW 就是属于not-ordered事件。

在ordered模式
,broadcasts是通过优先设置传达给不同receivers的,优先度在AndroidManifest文件中通过android:priority的intent-filter设置控制的。某个receiver可以通过BroadcastReceiver取消broadcast,取消后,比它优先度底的receivers将不再能得到该broadcast。一个典型的例子是,ACTION_NEW_OUTGOING_CALL。

[Fragment] 技術用法

設定TagetFragment
final SelectAccountDialogFragment dialog = new SelectAccountDialogFragment();
 dialog.setTargetFragment(this, 0);
呼叫TargetFragment的function

final Listener target = (Listener) getTargetFragment();
 target.onAccountChosen(accountAdapter.getItem(which));

2011年11月7日 星期一

[技術] R.drawable找不到ID的問題

1.圖檔必須是32 Bit , 不然adpt會編譯失敗..<==超機車 
單純只是搞錯目錄 , android 預設使用mdpi的目錄 , 一直修改hdip , 蠢斃了
使用openRawResource的做法

InputStream ins = getResources().openRawResource(R.raw.my_db_file);
int size = ins.available();
// Read the entire resource into a local byte buffer.
byte[] buffer = new byte[size];
ins.read(buffer);
ins.close();
FileOutputStream fos = new FileOutputStream("mycopy.db");
fos.write(buffer);
fos.close();
http://stackoverflow.com/questions/939170/resources-openrawresource-issue-android
http://blog.csdn.net/aomandeshangxiao/article/details/6654386

2011年11月6日 星期日

[技術] 判斷特定AP的Intent是否存在

http://developer.android.com/resources/articles/can-i-use-this-intent.html

public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
            packageManager.queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}
public boolean onPrepareOptionsMenu(Menu menu) {
    final boolean scanAvailable = isIntentAvailable(this,
        "com.google.zxing.client.android.SCAN");

    MenuItem item;
    item = menu.findItem(R.id.menu_item_add);
    item.setEnabled(scanAvailable);

    return super.onPrepareOptionsMenu(menu);
}

[技術] QR Code

PHP產生QR Code
http://phpqrcode.sourceforge.net/

Google Chart QR Code
http://jishus.org/?p=326
http://www.dotblogs.com.tw/shadow/archive/2011/02/24/21557.aspx

Goolge產生出的 QR Code存到檔案中
http://stackoverflow.com/questions/3693058/php-save-image-file

Android 手機產生QR Code
http://www.qrme.co.uk/qr-code-news/3-newsflash/138-qr-code-android-code.html

Android/Java BarCode Library
http://code.google.com/p/zxing/

使用BarCode下載Market Application做法
http://wiki.cheyingwu.tw/Android/Barcode-Download-Apps

[技術] Listener

Listener的做法
1.在自己的Class中定義介面

 public interface ProviderStatusListener {
        public void onProviderStatusChange();
    }
2.在自己的Class中產生實體
private ProviderStatusListener mListener;

mListener = listener;

3.在別人的Class中implement介面
implement ProviderStatusListener
@Override
    public void onProviderStatusChange() {
        updateFragmentVisibility();
    }

[技術] Android Account

變動時監聽方式
1.Class要implements OnAccountsUpdateListener
2.Class要實做onAccountsUpdated
3.註冊Listener
AccountManager.get(context).addOnAccountsUpdatedListener(this, null, false);

取得系統的Account List
Account[] accounts = AccountManager.get(context).getAccounts();
        int newAccountsLength = accounts.length;
        Account[] newAccounts = new Account[newAccountsLength];
        for (int i = 0; i < accounts.length; i++) {
        Account mAccount = new Account(accounts[i].name, accounts[i].type);
        newAccounts[i] = mAccount;
        }

[技術] CountDownLatch

同步記數器 , Wait and Lock的概念
http://www.cnblogs.com/whgw/archive/2011/09/29/2195827.html

2011年11月5日 星期六

[PHP] 程式程式技巧

計算重複數字的技巧

$str=’123456145′;
for ($i=0;$i<strlen($str);$i++){
 if(strstr($str,$str[$i])){
  $arr[$str[$i]]++;//将重复的值作为数组arr的键名,重复的次数作为值
 }
}
foreach ($arr as $key=>$value){
 echo $key.”出现了”.$value.”次<br>”;
}
本文来源于吴旭晓的个人博客 http://www.wuxuxiao.com/ , 原文地址:http://www.wuxuxiao.com/news/newsview.html?id=300

2011年11月4日 星期五

[JNI] C Code WTF String 轉 char *

node是WTFString , 透過utf8()轉成Cstring,再透過data轉成char * , 天那!
DBG_NAV_LOGD("text content=%s", node->textContent(false).utf8(true).data());

2011年11月3日 星期四

[網頁] PHP MAIL

信件主題若是中文會是亂碼
http://www.macsoho.net/blog/?p=143

這樣改
$subject = "客戶 ".$name." 要求代客尋車";
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";

2011年11月2日 星期三

[技術] Sensor

有關 Sensor的文章與範例
http://mylifewithandroid.blogspot.com/2010/03/sensors.html

Monitor Sensor in Background
http://mylifewithandroid.blogspot.com/2010/04/monitoring-sensors-in-background.html

Android API Demo羅盤的範例程式
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html

[問題] 攔截撥號動作 , 並Show出自己的畫面

https://market.android.com/details?id=com.perracolabs.tcc&feature=search_result
怎麼做的?使用NEW_OUTGOING_CALL的Broadcast Intent
http://groups.google.com/group/android-developers/browse_thread/thread/50cb37b9ae682648/e93ac551486f9e3a
所有Intent
http://developer.android.com/reference/android/content/Intent.html
為甚麼第一個呼叫的一定是自己?

監聽Camera/Media/Phone Key的做法
http://iamnotok.googlecode.com/svn-history/r6/trunk/android/src/com/google/imnotok/PatternTrackingService.java

[技術] Activity Stack

觀看Activity Stack工具
adb shell dumpsys activity

Android应用程序在新的进程中启动新的Activity的方法和过程分析
http://blog.csdn.net/Luoshengyang/article/details/6720261
解开Android应用程序组件Activity的"singleTask"之谜
http://blog.csdn.net/luoshengyang/article/details/6714543

[Linux] 指令操作

http://www.liiyl.com/index.php/archives/504
列出系統磁區個別的使用容量
df -Th

列出是否有未使用的磁碟空間
fdisk -l

掛載
mount /dev/sdb1 /opt
自動掛載
/ect/fstab
使用UUID方式掛載
blkid -s UUID
範例如下 , 將UUID填到fstab中
/dev/sdb1: UUID="543de266-c8ac-49d0-a0d1-80185415f9f8"
http://blog.xuite.net/chingwei/blog/30943022

重新開機
shutdown
shutdown -h now
reboot

改變檔案或目錄的使用者和群組
chown 使用者:群組 檔案

link
ln -s /use/bin bin

基本指令:
http://linux.vbird.org/linux_basic/redhat6.1/linux_06command.php

2011年11月1日 星期二

[工具] git 好難用

Repository的觀念


http://www.study-area.org/cyril/opentools/opentools/x657.html
Repository就是倉庫,儲存櫃子的意思,在這邊指的就是存放source code的 倉庫

http://www.josephj.com/entry.php?id=308
 Git 跟我過去所用的 CVS、Perforce、SVN 在架構上非常不一樣!之前我用的都是一台 Server 做 Repository,且所有的動作 (Update/Commit/Add...) 都得跟它做連線;而 Git 的 Client 本身就是 Repositiory,每次的 Commit 都是在 Local 做。問題是... 這樣的架構,該如何做到多人同時開發呢?原來 Git 的每個 Repository 都可透過 Publish / Pull Request 的動作讓其他人做 Merge。簡單來說,CVS / SVN 是以 Trunk 為主、Branch 為輔,而 Git 的主要架構就是以 Branch / Merge 為核心

[技術] Thread 和 Handle Thread使用時機

[技術] Parcelable 可IPC的物件實作方式

實作方式:

public class MyParcelable implements Parcelable {
     private int mData;

     public int describeContents() {
         return 0;
     }

     public void writeToParcel(Parcel out, int flags) {
         out.writeInt(mData);
     }

     public static final Parcelable.Creator<MyParcelable> CREATOR
             = new Parcelable.Creator<MyParcelable>() {
         public MyParcelable createFromParcel(Parcel in) {
             return new MyParcelable(in);
         }

         public MyParcelable[] newArray(int size) {
             return new MyParcelable[size];
         }
     };
   
     private MyParcelable(Parcel in) {
         mData = in.readInt();
     }
 }

[圖形] 如何做到刮刮樂的效果

http://stackoverflow.com/questions/5848722/android-scratch-card-app

https://market.android.com/details?id=com.wxj.fingerpaint4kid&hl=zh_TW

Market上已經有的ap
https://market.android.com/details?id=ginlemon.scratchdemo&feature=search_result

Jquery網頁版本:
http://www.senamion.com/blog/jScratchcard.html

相關討論
http://stackoverflow.com/questions/3007750/create-masking-effect-over-a-view

[資訊] Mock是甚麼?常常在Test Function中看到

英文翻譯是"模仿"

http://caterpillar.onlyfun.net/Gossip/JUnit/MockObject.html

Dummy 物件 是一種用來隔離真實環境,使受測程式不受其它物件或外在環境影響的方式。Dummy物件之所以為Dummy,就是它通常沒有複雜的行為,只單純傳回必要的值或物件,供受測程式可以運行。

相較而言,Mock物件就複雜了一些,Mock物件的作用與Dummy物件類似,
隔離真實環境,使受測程式不受其它物件或外在環境影響,所不同的是,Mock物件模擬了真實物件的行為,真實物件被操作後應有什麼狀態變化,Mock物件就會模擬類似的變化。

[怪事] Activity硬體加速參數會影響某些View顯示

Activity manifest硬體加速參數 , 和網路上的Open Source Color Picker會有buffer的效果