2010年8月27日星期五

香港HTC Legend/Wildfire軟體無線更新


香港HTC已公佈Legend和Wildfire的軟體無線更新. 系統會陸續送出更新提示,當您收到系統提示只要點選立即下載即可經由3G/GPRS或無線網路的連線方式,完成您的手機系統更新。

2010年8月23日星期一

Android 的剪貼板(Clipboard)

於程序碼使用剪貼板(Clipboard), 可通過ClipboardManager類.

Android 的剪貼板(Clipboard)

ClipboardManager是剪貼板服務的接口, 在剪貼板上放置和檢索文字.

你不直接實例化這個類,而是通過getSystemService(String)取得ClipboardManager. 再利用setText(CharSequence text)和getText()方法放置和檢索文字.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/copyto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Copy To ClipBoard"
/>
<Button
android:id="@+id/pastefrom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Paste From ClipBoard"
/>
</LinearLayout>


AndroidClipBoard.java

package com.AndroidClipBoard;

import android.app.Activity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AndroidClipBoard extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText editText = (EditText)findViewById(R.id.edittext);
Button buttonCopyTo = (Button)findViewById(R.id.copyto);
Button buttonPasteFrom = (Button)findViewById(R.id.pastefrom);

final ClipboardManager myClipBoard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

buttonCopyTo.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myClipBoard.setText(editText.getText());
}});

buttonPasteFrom.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
editText.setText(myClipBoard.getText());
}});
}
}

2010年8月17日星期二

通過設定能見度(visibility)實現隱藏視圖

通過設定能見度android:visibility, 可控制視圖的能見度.

visible: 可見(默認值).
invisible: 不可見, 但仍佔用空間.
gone: 完全不可見, 不佔用空間.

VISIBLE
INVISIBLE
GONE

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Spinner
android:id="@+id/hidenoption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="@+id/hidenlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="可被隱藏"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" test "
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="正常顯示:不會被隱藏"
/>
</LinearLayout>


主代碼, AndroidHidenMenu.java
package com.AndroidHidenMenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.Spinner;

public class AndroidHidenMenu extends Activity {

private static final String[] visibility = {"VISIBLE", "INVISIBLE", "GONE"};
private static final int[] visibilitySetting ={ View.VISIBLE, View.INVISIBLE, View.GONE};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner hidenOption = (Spinner)findViewById(R.id.hidenoption);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, visibility);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
hidenOption.setAdapter(adapter);

final LinearLayout hidenLayout = (LinearLayout)findViewById(R.id.hidenlayout);

hidenOption.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
hidenLayout.setVisibility(visibilitySetting[arg2]);

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}});
}
}

2010年8月5日星期四

Android用戶數據處理的最佳實踐(Best Practices for Handling Android User Data )

可能因為最近很多媒體紛紛報導有關Android和iPhone的應用程http://www.blogger.com/img/blank.gif式可能令用戶數據外泄, Android 的官方開發者博客(Android Developers Blog)最近發報了一篇文章有關用戶數據的處理: Android用戶數據處理的最佳實踐(Best Practices for Handling Android User Data ).

當中提及如何編寫可信的Android應用程序的一些提示, 包括:

1. 保持自己的隱私政策(Maintain a privacy policy)
2. 使用最小權限(Minimize permissions)
3. 給用戶選擇有關的數據收集(Give your users a choice regarding data collection)
4. 不要收集不必要的信息(Don’t collect unnecessary information)
5. 不要發送數據(Don’t send data off the device)
6. 但如果你必須發送數據, 使用數據加密, 和盡量減少要發送的數據(...but if you have to, use encryption and data minimization)
7. 不要使用你不明白的代碼(Don’t use code you don’t understand)
8. 不要記錄設備或用戶的特定信息(Don’t log device or user specific information)

此文章十分值得參考, 特別推薦.

2010年8月4日星期三

Google官方發佈 Android 2.2 用戶指南




最近各方紛紛傳出Android 2.1手機可通過OTA(Over The Air)方式升級Android 2.2 Froyo. 而Google方面亦發佈了官方的 Android 2.2 用戶指南.

下載網址: AndroidUsersGuide.pdf

2010年8月3日星期二

中國版「HTC 野火」直上Android 2.2

筆者最近購入香港版HTC Wildfire (即中國版的「野火」), 是運行Android 2.1, 這個一點也不意外; 如果是2.2才意外.

但偶然發覺中國版「HTC 野火」的產品規格, 已直上Android 2.2. 原來中國版HTC的Android手機, 包括「渴望」(Desire), 「天怡」都是運行Android 2.2.

中國版「HTC 野火」直上Android 2.2

相信手上的HTC Wildfire也會很快可以升級Android 2.2吧:)