2011年10月31日

Anroid: 簡易Yes/No AlertDialog 對話盒

當程式需要和使用者作簡單的即時互動時,一個簡單的對話盒通常就能滿足所需.
底下是簡單好用的對話盒,可以回應Yes/No按鈕

2011年10月29日

Android: 產生MD5

檔案的MD5碼可用來檢查檔案是否有毀損或異動,
底下的作法,在讀取檔案的同時,進行MD5計算, 省時又方便!

Android: 解壓縮檔zip

當程式從網站下載檔案時,為了節省頻寬,通常會對檔案進行壓縮.
Java本身就有處理Zip/Unzip的API.見底下程式碼:

Android: TTS Engine 範例 RobotSpeakTtsService.java | Android Developers

RobotSpeakTtsService.java | Android Developers:
Android v4.0提供製作TTS engine的API,棒吧!

2011年10月20日

Android: ColorPickerDialog 選不到黑色

原來在Android的原始Demo程式中修改mColors的設定,加入黑色即可。
一口氣加了3個黑色!(別再跟我說選不到了吧:-)
mColors = new int[] {
    0xFFff0000,0xFFff00ff,0xFF000000,0xFF0000ff,0xFF00ffff,
    0xFF000000,0xFF00ff00,0xFFffff00, 0xFF000000,0xFFff0000
};
注意頭尾值必須一致,才不會顏色突然斷掉。 想要白色也沒問題,只要加入0xFFFFFFFF即可!

Android: Android Beam (NFC近場通訊)

翻譯自Android Developer

    Android Beam基於NFC (Near Field Communication 近場通訊) 技術,只需讓兩隻NFC啟動的裝置靠近,使用者就能立刻分享使用中app的資訊。當裝置在作用範圍內(幾公分),系統會建立NFC連結並顯示一個分享使用介面。只需觸摸螢幕就能分享他們在其他裝置看到的任何東西 (見底下示範影片)。

2011年10月19日

Android: 設定Paint.setTextSize() 的大小單位

若不用底下的方法設定大小,則不同解析度的裝置, 其畫出來的字體大小會差異極大!
float dips = 16.0f;
// Convert the dips to pixels
final float scale = getResources().getDisplayMetrics().density;
int ps = (int) (dips * scale + 0.5f);
Paint imagePaint = new Paint();
imagePaint.setTextSize(ps);

Android: EditText和EditTextPreference輸入格式

在AndroidManifest.xml中指定EditText和EditTextPreference的輸入格式,,
可以節省很多不必要的檢查動作!
//文字
android:inputType=
"none"
"text"
"textCapCharacters"
"textCapWords"
"textCapSentences"

2011年10月17日

Android: WebView 設定背景background

//設定透明色
webView.setBackgroundColor(0);   
//或在AndroidManifest.xml中指定也可以
webView.setBackgroundResource(R.drawable.yourImage); 
//或產生一個drawable的物件 webView.setBackgroundResource(d);

2011年10月13日

Java: 文數字排序

出自 Kushal's Java Blog | Software Engineering Blog » Blog » Alphanumeric String Sorting In Java (Implementation):

用Java的基本字串排序,來排序底下字串,
名詞11 名詞1 名詞3 名詞10 名詞2 
變成
名詞1 名詞10 名詞11 名詞2 名詞3


用上面的Alphanumeric String Sorting可以得到我們想要的
名詞1 名詞2 名詞3 名詞10 名詞11 


2011年10月12日

Java: Split分割字串

看起來很簡單又好用的函數,竟讓我冒了一身冷汗,花了一會兒才知道自己錯在哪裡?
第一次用"@"切字串,矇到了ok。
第二次用"^"切字串,出不來;嚇了一跳。
第三次用"$"切字串,還是出不來;差點昏倒 :-(
連忙Google看是怎麼回事?
原來其分隔參數是Regular Expression正則表示式,所以底下那些符號都必須用 \ 避開。
剛好 \ 也在其中所以必須用兩個 \\
例如用"^"切字串,必須寫成 TestString.split("\\^");
^ $ * + ? { }.[ ] ( ) \ | \d \D \w \W \s \S

2011年10月11日

Android: meta-data 使用

出處:android meta-data 使用详解 - - ITeye技术网站:

應用程式可以放些資料在AndroidManifest.xml中的宣告<activity> <activity-alias> <service> <receiver>四个元素中。Meta-data在Activity之間用來判斷某些事物時很有用。
<meta-data android:name="zoo" android:value="@string/kangaroo" />
程式中取得的方式
ActivityInfo ai = activity.getPackageManager().getActivityInfo(componentName, PackageManager.GET_META_DATA); 
String zoo = ai.metaData.getString("zoo"); 
Toast.makeText(this, "meta:"+zoo, 1).show();

2011年10月4日

被胡蜂螫了

不知如何形容那一陣陣的刺痛,只說得出好痛.
周末10/1全家和學校其他家庭一起去南澳溯溪,途中一隻蜂突然飛入車中,
靠窗小朋友抱頭躲著,我這自作聰明的大人,見狀急忙用手去揮趕...
沒錯,就被螫在大拇指上還停在上面不肯走哩,我急忙用左手捏起它,往窗外扔去.
是中午烤肉時煙燻大拇指太香了是嗎 :-)

2011年10月1日

連結:C2DM Android上雲端發訊息

Android Cloud to Device Messaging Framework - Google Projects for Android:
節錄自上述網址

Introduction

Here are the primary characteristics of Android Cloud to Device Messaging (C2DM):
  • It allows third-party application servers to send lightweight messages to their Android applications. The messaging service is not designed for sending a lot of user content via the messages. Rather, it should be used to tell the application that there is new data on the server, so that the application can fetch it.
  • C2DM makes no guarantees about delivery or the order of messages. So, for example, while you might use this feature to tell an instant messaging application that the user has new messages, you probably would not use it to pass the actual messages.
  • An application on an Android device doesn’t need to be running to receive messages. The system will wake up the application via Intent broadcast when the the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
  • It does not provide any built-in user interface or other handling for message data. C2DM simply passes raw message data received straight to the application, which has full control of how to handle it. For example, the application might post a notification, display a custom user interface, or silently sync data.
  • It requires devices running Android 2.2 or higher that also have the Market application installed. However, you are not limited to deploying your applications through Market.
  • It uses an existing connection for Google services. This requires users to set up their Google account on their mobile devices.

2011年9月29日

Android: 從Content Resolver取得Media (II)

Android Developer: Content Provider
底下節錄翻譯自上面:
//Use ContentUris to produce the base URI for the contact with _ID= 23.
Uri myPerson = ContentUris.withAppendedId(People.CONTENT_URI, 23);
// Alternatively, use the Uri method to produce the base URI.
// It takes a string rather than an integer.
Uri myPerson = Uri.withAppendedPath(People.CONTENT_URI, "23");
// Then query for this specific record:
Cursor cur = managedQuery(myPerson, null, null, null, null);

Android: 從Content Resolver取得Media (I)

底下節自Android developer並翻譯,
Media player可以詢問 ContentResolver來取得media file

ContentResolver contentResolver = getContentResolver();
Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
if (cursor == null) {
// query failed, handle error.
} else if (!cursor.moveToFirst()) {
// no media on the device
} else {
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
do {
long thisId = cursor.getLong(idColumn);
String thisTitle = cursor.getString(titleColumn);
// ...process entry...
} while (cursor.moveToNext());
}
那如何使用呢?請看底下程式碼:

2011年9月26日

MyCuber (for Rubik Cube) 我的魔方

Available in Android Market
MyCuber @ Android Market

 MyCuber (Rubik cube3x3)
    • 依據世界方塊協會World Cube Association比賽規則設計,模擬比賽情境計時,加上獨特的語音讀秒功能,讓使用者在解魔術方塊的同時,也能得知各階段所花費的時間,以利針對弱點加強練習,另外也可以針對先前解過的亂轉序列,重新再試一次。
    • 針對推廣魔術方塊運動而言,可以取代昂貴的計時裝置,提供方便又有效的計時紀錄工具。
    • 畫面配色簡捷,強調大字幕的數字方便閱讀。      

     剛出爐熱騰騰的軟體還在冒煙zZZ..搞了整個晚上終於成功上架了,原來還要等一陣子才會出現在市集,我真是太心急了點,連忙Google了大半夜想搞清楚是哪裡出錯(愛用網路Google的通病:-),百思不解結果休息一會兒就自動OK了,真是天下本無事,庸人自擾之。

2011年9月21日

連結: Android Shapes – Example » Developer Papercuts

Android Shapes – Example » Developer Papercuts:

漸層底圖效果

Android: 使用資源Resource中的顏色和字串

首先在/res/values/目錄底下產生一個xml檔
<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<string name="title">MyCuber</string>
<color  name=”backcolor”>#006fff</color>
</resources>

Android: 網路是否通?

記得在AndroidManifest.xml加上
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
public boolean isNetworkAvailable() {
 ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
 NetworkInfo networkInfo = cm.getActiveNetworkInfo();
  // if no network is available networkInfo will be null, otherwise check if we are connected
  if (networkInfo != null && networkInfo.isConnected())
        return true;
  return false;
}

Android: 免費圖示icon


http://commons.wikimedia.org/wiki/Crystal_Clear
http://www.famfamfam.com
http://iconlet.com
http://www.iconfinder.net/browse

2011年9月20日

小米手机: 值得期待!

小米手机官网:
應該是便宜(1999元人民幣)又好的手機,對大陸手機越來越有好感。目前手上的是華為的ideos手機,用起來中規中矩的。

处理器高通双核 MSM8260 1.5GHz
网络 GSM/WCDMA
RAM 1GB DDR2 RAM
ROM 4GB
图形处理器Adreno 220
屏幕夏普4寸854*480像素 TFT(半反半透)
相机800万像素、2.4最大光圈、自动对焦+LED
操作系统MIUI—深度定制的Android系统(開放刷機)
机身尺寸125*63*11.9mm
重量149g
电池1930mAh


2011年9月19日

蘇三起解...

還記得小時候 (嗯,是很小很小的時候 : )
聽姊姊唱這段京劇,只覺得此人好慘呀,覺得心中難過,卻又說不上來。
現在我明白了...
一位弱女子在腐敗官僚的嚴刑逼迫下,她的慘只能往心裡忍,也想認命算了,
但心裡最終還是捨不下那日思夜盼的情郎。
那哀怨泣訴無助,願來世作犬馬報答,她是多麼想念他呀,真是令人憐惜不忍。
現在拜網路之賜,可以聽到並看到各種版本的表演,真是Good Go !
唱詞如下:
蘇三離了洪桐縣,將身來在大街前,未曾開言我心內慘,過往的君子聽我言。
哪一位去往南京轉,與我那三郎把信傳。就說蘇三把命斷,來生變犬馬我當報還。
經典版的
底下有年輕版和幼兒版的更是棒...

連結: 臺北市政府公開資料平台

臺北市政府公開資料平台:
底下引自上述網址

data.taipei臺北市政府公開資料平台
臺北市政府為推動開放政府(Open Government)之資料公開政策,整合本府公開資料於單一入口網站以供大眾利用。目前資料目錄包含約130項以上資料集,不僅格式多元且隨時更新,另為提供更佳服務品質,新資料集將持續加入。
我們的目標:
  • 提供政府公開資料更簡易的取得管道
    將資料查詢及使用說明集中於單一入口,以提升資訊服務品質。
  • 提倡政府公開資料加值及應用
    鼓勵個人、企業和組織運用政府公開資料創造知識資產及便民服務,提昇臺北城市友善度。
  • 提高政府施政透明度及效能
    以服務、資料集、統計數據等形式公開資料,營造民眾參與協同合作的資訊基礎環境。