Lachen in der U-Bahn - www.lachen-verbindet.de
這是不是大腦的鏡像神經元發作呀?
看別人那麼開懷大笑,自己也會不由自主地跟著起笑 :-)
2011年12月20日
2011年12月18日
Android: 檢查SD卡可用容量MB
public boolean isAvaiableSpace(float sizeMB){
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
String sdcard =Environment.getExternalStorageDirectory().getPath();
StatFs statFs =new StatFs(sdcard);
long blockSize=statFs.getBlockSize();
long ablocks =statFs.getAvailableBlocks();
float available=(float)((ablocks*blockSize)/(1024*1024));
if (sizeMB > available)
return false;
else
return true;
}
return false;
}
2011年12月14日
Java: 刪除整個目錄(子目錄和檔案)
public boolean deleteDir(File dir) {
if (dir.isDirectory()) {
File[] files = dir.listFiles();
for (int i=0;i<files.length;i++) {
if (!deleteDir(files[i]))
return false;
}
}
//目錄現在清空了可以刪除
return dir.delete();
}
Progressive Education Why It’s Hard to Beat, But Also Hard to Find: 進步教育部份筆記
Progressive Education
Why It’s Hard to Beat, But Also Hard to Find (By Alfie Kohn)
進步教育本身並無一個固定的定義,這似乎和它反對一致性和標準化的聲譽相符。任何兩個自認了解此"傳統"的教育工作者,也可能會以不同的角度來看待,或者至少會對哪些是最重要的有爭議.
和多位進步教育工作者交談後,其實你會開始注意到某些弔詭:有些人專注於個別學生的獨特需要,而有些人強調學習者社群的重要,有些人形容學習為一個過程,旅程比目的地重要,而另一些認為學習任務應該導致可共享的真實產物。
它是什麼?
Why It’s Hard to Beat, But Also Hard to Find (By Alfie Kohn)
進步教育本身並無一個固定的定義,這似乎和它反對一致性和標準化的聲譽相符。任何兩個自認了解此"傳統"的教育工作者,也可能會以不同的角度來看待,或者至少會對哪些是最重要的有爭議.
和多位進步教育工作者交談後,其實你會開始注意到某些弔詭:有些人專注於個別學生的獨特需要,而有些人強調學習者社群的重要,有些人形容學習為一個過程,旅程比目的地重要,而另一些認為學習任務應該導致可共享的真實產物。
它是什麼?
2011年12月13日
牛頓手稿數位化 Cambridge Digital Library - University of Cambridge
Cambridge Digital Library - University of Cambridge:
"Cambridge University Library contains evidence of some of the greatest ideas and discoveries over two millennia. We want to make our collections accessible to anyone, anywhere in the world with an internet connection and a thirst for knowledge." —Anne Jarvis, University Librarian
Explore the British Library here:
"Cambridge University Library contains evidence of some of the greatest ideas and discoveries over two millennia. We want to make our collections accessible to anyone, anywhere in the world with an internet connection and a thirst for knowledge." —Anne Jarvis, University Librarian
Explore the British Library here:
2011年11月30日
Android: AsyncTask 非同步任務
AsyncTask 讓我們可在UI thread中執行非同步工作。它在worker thread中執行需長時間的作業,然後將結果傳回使用介面緒,省掉我們親自處理Thread或Handlers的麻煩。
2011年11月23日
2011年11月21日
2011年10月31日
2011年10月29日
2011年10月20日
Android: ColorPickerDialog 選不到黑色
原來在Android的原始Demo程式中修改mColors的設定,加入黑色即可。
一口氣加了3個黑色!(別再跟我說選不到了吧:-)
一口氣加了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連結並顯示一個分享使用介面。只需觸摸螢幕就能分享他們在其他裝置看到的任何東西 (見底下示範影片)。
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
用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("\\^");
剛好 \ 也在其中所以必須用兩個 \\
例如用"^"切字串,必須寫成 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之間用來判斷某些事物時很有用。
應用程式可以放些資料在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全家和學校其他家庭一起去南澳溯溪,途中一隻蜂突然飛入車中,
靠窗小朋友抱頭躲著,我這自作聰明的大人,見狀急忙用手去揮趕...
沒錯,就被螫在大拇指上還停在上面不肯走哩,我急忙用左手捏起它,往窗外扔去.
是中午烤肉時煙燻大拇指太香了是嗎 :-)
周末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
底下節錄翻譯自上面:
底下節錄翻譯自上面:
- 所有提供器的URIs以字符串"content://"開頭
- 輔助函數ContentUris.withAppendedId()和Uri.withAppendedPath()使得將URI變成ID容易許多
//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
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());
}
那如何使用呢?請看底下程式碼:
訂閱:
文章 (Atom)