2008年2月28日 星期四

Google releases new version of Android SDK m5-rc14

Android SDK m5-rc14 now available!

1. user interface - As I mentioned when we introduced the m3 version of the Android SDK, we're continuing to refine the UI that's available for Android. m5-rc14 replaces the previous placeholder with a new UI, but as before, work on it is still in-progress.

2. Layout animations - Developers can now create layout animations for their applications using the capabilities introduced in the android.view.animation package. Check out the LayoutAnimation*.java files in the APIDemos sample code for examples of how this works.

3. Geo-coding - android.location.Geocoder enables developers to forward and reverse geo-code (i.e. translate an address into a coordinate and vice-versa), and also search for businesses.

4. New media codecs - The MediaPlayer class has added support for the OGG Vorbis, MIDI, XMF, iMelody, RTTL/RTX, and OTA audio file formats.

5. Updated Eclipse plug-in - A new version of ADT is available and provides improvements to the Android developer experience. In particular, check out the new Android Manifest editor.

1. 新的使用者介面
2. 可建立Layout animations
3. 地址查詢經緯支援
4. 新的媒體編碼格式
5. 新的Eclipse plug-in

MapActivity in Android 4 - GPS

You can use GPS in Android. Here is a demo for driving around Google by using GPS.

MapActivity亦可使用GPS定位Google map,不過目前透過內部模擬在Google附近開車的GPS資料進行模擬。

1. mapdemo.java:再將上一篇的程式碼主要加上籃色部份,透過LocationManager使用GPS定位,選單增加GPS項目,P為定位、G為到選單。



package com.test.demo;

import java.util.List;
import com.google.android.maps.MapActivity;
import android.app.Activity;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;

public class mapdemo extends MapActivity{
/** Called when the activity is first created. */
public static final int change = 3000;
private MapView mapView;
private MapController mapConrtoller;
private Spinner s1;
private LocationManager locMan;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

s1 = (Spinner) findViewById(R.id.spinner1);
Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter adapter = ArrayAdapter.createFromResource(
this, R.array.city, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
//It seems a bug for LocationManager,we can't get location in first time.
getLocation();
mapView =(MapView) findViewById(R.id.my_map);
mapConrtoller = mapView.getController();
mapConrtoller.zoomTo(17);
updateView();
}

private void getLocation(){
Location loc;
LocationProvider locPro;
List proList;
locMan = (LocationManager)this.getSystemService(Activity.LOCATION_SERVICE);
proList = locMan.getProviders();
locPro = proList.get(0);
loc = locMan.getCurrentLocation("gps");

Double lat = 0.0;
Double lon = 0.0;
lat = (Double)loc.getLatitude()*1E6;
lon = (Double)loc.getLongitude()*1E6;
Point point = new Point(lat.intValue(),lon.intValue());
if(lat.intValue()!=0 && lon.intValue()!=0){
mapConrtoller.animateTo(point);
}
}

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_I) {
mapView.requestFocus();
// zoom in
mapView.getController().zoomTo(mapView.getZoomLevel() + 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_P) {
// position
Double lat=0.0;
Double lng=0.0;
if(s1.getSelectedItemIndex()==0){
lat = 25.08421662*1E6;
lng = 121.5588632*1E6;
}else if(s1.getSelectedItemIndex()==1){
lat = 25.156109*1E6;
lng = 121.695457*1E6;
}else if(s1.getSelectedItemIndex()==2){
lat = 25.02723286*1E6;
lng = 121.4777282*1E6;
}else if(s1.getSelectedItemIndex()==3){
lat = 24.766944444*1E6;
lng = 121.758333333*1E6;
}else if(s1.getSelectedItemIndex()==4){
lat = 24.7952904064701*1E6;
lng = 121.005980402031*1E6;
}else if(s1.getSelectedItemIndex()==5){
lat = 25.01049145*1E6;
lng = 121.2988981*1E6;
}else if(s1.getSelectedItemIndex()==6){
lat = 24.6929396881103*1E6;
lng = 120.916988073054*1E6;
}else if(s1.getSelectedItemIndex()==7){
lat = 24.165632*1E6;
lng = 120.640234*1E6;
}else if(s1.getSelectedItemIndex()==8){
lat = 24.085467449249*1E6;
lng = 120.53489812506*1E6;
}else if(s1.getSelectedItemIndex()==9){
lat = 23.831933886322*1E6;
lng = 120.71674349869*1E6;
}else if(s1.getSelectedItemIndex()==10){
lat = 23.4670607206971*1E6;
lng = 120.424347942069*1E6;
}else if(s1.getSelectedItemIndex()==11){
lat = 23.68080782*1E6;
lng = 120.4857101*1E6;
}else if(s1.getSelectedItemIndex()==12){
lat = 23.015307619667*1E6;
lng = 120.19802892001*1E6;
}else if(s1.getSelectedItemIndex()==13){
lat = 22.6516357159836*1E6;
lng = 120.305947184541*1E6;
} else if(s1.getSelectedItemIndex()==14){
lat = 22.568397*1E6;
lng = 120.539828*1E6;
} else if(s1.getSelectedItemIndex()==15){
lat = 22.736944444*1E6;
lng = 121.122777778*1E6;
}else if(s1.getSelectedItemIndex()==16){
lat = 23.973333333*1E6;
lng = 121.588055556*1E6;
}else if(s1.getSelectedItemIndex()==16){
lat = 23.973333333*1E6;
lng = 121.588055556*1E6;
}else if(s1.getSelectedItemIndex()==17){
getLocation();
}
Point point = new Point(lat.intValue(), lng.intValue());
mapConrtoller.centerMapTo(point, false);
mapView.requestFocus();
return true;
}else if (keyCode == KeyEvent.KEYCODE_G) {
// zoom out
s1.requestFocus();
return true;
}else if (keyCode == KeyEvent.KEYCODE_O) {
mapView.requestFocus();
// zoom out
mapView.getController().zoomTo(mapView.getZoomLevel() - 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_S) {
mapView.requestFocus();
// Satellite,衛星地图
if(!mapView.isSatellite()){
mapView.toggleSatellite();
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_M) {
mapView.requestFocus();
// traffic,路况
if(mapView.isSatellite()){
mapView.toggleSatellite();
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {

mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lat=lat+change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lat=lat-change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;

} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lng=lng-change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lng=lng+change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;
}
return false;
}

private void updateView(){

Double lat = 25.025708*1E6;
Double lng = 121.526403*1E6;
Point point = new Point(lat.intValue(), lng.intValue());
mapConrtoller.centerMapTo(point, false);
}

}


2. arrays.xml:加上GPS項目。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="city">
<item>台北市</item>
<item>基隆市</item>
<item>台北縣</item>
<item>宜蘭縣</item>
<item>新竹市</item>
<item>桃園市</item>
<item>苗栗縣</item>
<item>台中市</item>
<item>彰化縣</item>
<item>南投縣</item>
<item>嘉義市</item>
<item>雲林縣</item>
<item>臺南市</item>
<item>高雄市</item>
<item>屏東縣</item>
<item>臺東縣</item>
<item>花蓮縣</item>
<item>GPS</item>
</array>
</resources>

2008年2月26日 星期二

MapActivity in Android 3 - city menu

We apply city menu in Taiwan for app. You can choose city to position the map. "P" for Position."G" for focusing in city menu.

加入各縣市表單,你可以更進一步地定位Google map。

1. mapdemo.java:再將上一篇的程式碼主要加上籃色部份,其他部份亦有加上小部份修改,P為定位、G為到城市選單。


package com.test.demo;

import com.google.android.maps.MapActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;

public class mapdemo extends MapActivity{
/** Called when the activity is first created. */
public static final int change = 3000;
private MapView mapView;
private MapController mapConrtoller;
private Spinner s1;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

s1 = (Spinner) findViewById(R.id.spinner1);
Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter adapter = ArrayAdapter.createFromResource(
this, R.array.city, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);

mapView =(MapView) findViewById(R.id.my_map);
mapConrtoller = mapView.getController();
mapConrtoller.zoomTo(17);
updateView();
}

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_I) {
mapView.requestFocus();
// zoom in
mapView.getController().zoomTo(mapView.getZoomLevel() + 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_P) {
// position
Double lat=0.0;
Double lng=0.0;
if(s1.getSelectedItemIndex()==0){
lat = 25.08421662*1E6;
lng = 121.5588632*1E6;
}else if(s1.getSelectedItemIndex()==1){
lat = 25.156109*1E6;
lng = 121.695457*1E6;
}else if(s1.getSelectedItemIndex()==2){
lat = 25.02723286*1E6;
lng = 121.4777282*1E6;
}else if(s1.getSelectedItemIndex()==3){
lat = 24.766944444*1E6;
lng = 121.758333333*1E6;
}else if(s1.getSelectedItemIndex()==4){
lat = 24.7952904064701*1E6;
lng = 121.005980402031*1E6;
}else if(s1.getSelectedItemIndex()==5){
lat = 25.01049145*1E6;
lng = 121.2988981*1E6;
}else if(s1.getSelectedItemIndex()==6){
lat = 24.6929396881103*1E6;
lng = 120.916988073054*1E6;
}else if(s1.getSelectedItemIndex()==7){
lat = 24.165632*1E6;
lng = 120.640234*1E6;
}else if(s1.getSelectedItemIndex()==8){
lat = 24.085467449249*1E6;
lng = 120.53489812506*1E6;
}else if(s1.getSelectedItemIndex()==9){
lat = 23.831933886322*1E6;
lng = 120.71674349869*1E6;
}else if(s1.getSelectedItemIndex()==10){
lat = 23.4670607206971*1E6;
lng = 120.424347942069*1E6;
}else if(s1.getSelectedItemIndex()==11){
lat = 23.68080782*1E6;
lng = 120.4857101*1E6;
}else if(s1.getSelectedItemIndex()==12){
lat = 23.015307619667*1E6;
lng = 120.19802892001*1E6;
}else if(s1.getSelectedItemIndex()==13){
lat = 22.6516357159836*1E6;
lng = 120.305947184541*1E6;
} else if(s1.getSelectedItemIndex()==14){
lat = 22.568397*1E6;
lng = 120.539828*1E6;
} else if(s1.getSelectedItemIndex()==15){
lat = 22.736944444*1E6;
lng = 121.122777778*1E6;
}else if(s1.getSelectedItemIndex()==16){
lat = 23.973333333*1E6;
lng = 121.588055556*1E6;
}
Point point = new Point(lat.intValue(), lng.intValue());
mapConrtoller.centerMapTo(point, false);
mapView.requestFocus();
return true;
}else if (keyCode == KeyEvent.KEYCODE_G) {
// zoom out
s1.requestFocus();
return true;
}else if (keyCode == KeyEvent.KEYCODE_O) {
mapView.requestFocus();
// zoom out
mapView.getController().zoomTo(mapView.getZoomLevel() - 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_S) {
mapView.requestFocus();
// Satellite,衛星地图
if(!mapView.isSatellite()){
mapView.toggleSatellite();
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_M) {
mapView.requestFocus();
// traffic,路况
if(mapView.isSatellite()){
mapView.toggleSatellite();
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {

mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lat=lat+change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lat=lat-change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;

} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lng=lng-change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
mapView.requestFocus();
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lng=lng+change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point);
return true;
}
return false;
}

private void updateView(){
Double lat = 25.025708*1E6;
Double lng = 121.526403*1E6;
Point point = new Point(lat.intValue(), lng.intValue());
mapConrtoller.centerMapTo(point, false);
}

}


2. arrays.xml:在目錄res下的values目錄下建立一arrays.xml,是要存放城市表單內容。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="city">
<item>台北市</item>
<item>基隆市</item>
<item>台北縣</item>
<item>宜蘭縣</item>
<item>新竹市</item>
<item>桃園市</item>
<item>苗栗縣</item>
<item>台中市</item>
<item>彰化縣</item>
<item>南投縣</item>
<item>嘉義市</item>
<item>雲林縣</item>
<item>臺南市</item>
<item>高雄市</item>
<item>屏東縣</item>
<item>臺東縣</item>
<item>花蓮縣</item>
</array>
</resources>

3. 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"
>
<view id="@+id/my_map" class="com.google.android.maps.MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" /
>

<Spinner id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
/
>
</LinearLayout>


2008年2月25日 星期一

MapActivity in Android 2

You can control google map further. 你可以更進一步地使用Google map。

1. mapdemo.java:再將上一篇的程式碼加上籃色部份,可用手機按鍵控制地圖,O為拉遠、I為拉近、S為衛星地圖、上下左右鍵為移動。


package com.test.demo;

import com.google.android.maps.MapActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;

public class mapdemo extends MapActivity{
/** Called when the activity is first created. */
public static final int change = 3000;
private MapView mapView;
private MapController mapConrtoller;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

//get id from main.xml
mapView =(MapView) findViewById(R.id.my_map);
mapConrtoller = mapView.getController();
mapConrtoller.zoomTo(17); updateView();
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_I) {
// zoom in
mapView.getController().zoomTo(mapView.getZoomLevel() + 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_O) {
// zoom out
mapView.getController().zoomTo(mapView.getZoomLevel() - 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_S) {
// 衛星地图
if(!mapView.isSatellite()){
mapView.toggleSatellite(); }
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lat=lat+change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point); return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lat=lat-change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point); return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lng=lng-change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point); return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
Double lat = mapView.getMapCenter().getLatitudeE6()/1.0;
Double lng = mapView.getMapCenter().getLongitudeE6()/1.0;
lng=lng+change;
Point point = new Point(lat.intValue(),lng.intValue());
mapConrtoller.animateTo(point); return true;
}
return false;
}
private void updateView(){
Double lat = 25.025708*1E6;
Double lng = 121.526403*1E6;
Point point = new Point(lat.intValue(), lng.intValue());
mapConrtoller.centerMapTo(point, false); }

}


2008年2月21日 星期四

MapActivity in Android

你可以透過com.google.android.maps.MapActivity輕鬆使用Google map。

1. mapdemo.java:將Acitivity改為MapAcitivity如籃色部份,MapAcitivity是Google map使用的class。

package com.test.demo;

import com.google.android.maps.MapActivity;
import android.os.Bundle;

public class mapdemo extends MapActivity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
}


2. main.xml:將TextView的xml部份換成籃色部份,請注意MapView的部份都是如此定義標籤。
<?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"
>
<view id="@+id/my_map" class="com.google.android.maps.MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>


2008年2月20日 星期三

Debug in Android

You can debug in Android by applying android.util.Log.

開發程式時,Debug的訊息是很有幫助的!
在Android中,你可以透過 android.util.Log 來Debug!

package com.test;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class hello extends Activity {
/** Called when the activity is first created. */
private static final String TAG = "DEBUG";
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

for(int i=0;i<5;i++){
Log.v(
TAG, "i:"+i);
}


How to see log? LogCat
如何看Debug Message? 使用LogCat
Window >> Show View >> Others


選擇LogCat



訊息出現在LogCat視窗,i=0......


You can click the green icon + to filter log by tag you define in code.And then it's easier to see log.
這麼多Log要怎麼看?你可以點綠+的部分,將剛程式中你所定義的
private static final String TAG = "DEBUG"來加到Filter,如此一來便可方便地只看到自己定義的Log。

2008年2月13日 星期三

How to Android? Step3: Get contacts data from android.provider


如何透過Google的android.provider來取得手機通訊錄資料?

1. AndroidManifest.xml : 在此xml檔案加入下列籃色那個安全性設定,不然會一直發生安全性錯誤!

<?xml version="1.0" encoding="utf-8"?>
<manifest android="http://schemas.android.com/apk/res/android"
package="com.google.test">
<uses-permission android:name="android.permission.READ_CONTACTS" />

<application icon="@drawable/icon">
<activity class=".hello" label="@string/app_name">
<intent-filter>
<action value="android.intent.action.MAIN">
<category value="android.intent.category.LAUNCHER">
</category>
</action>
</intent-filter>
</activity>
</application></manifest>



2. hello.java : 在Activity java檔中加入下列籃色部份程式碼!
package com.google.test;

import android.app.Activity;
import android.database.Cursor;
import com.google.test.R;
import android.os.Bundle;
import android.widget.TextView;

public class hello extends Activity {
private TextView tv;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
tv =(TextView) findViewById(R.id.test);

// An array specifying which columns to return.
String[] projection = new String[] {
android.provider.BaseColumns._ID,
android.provider.Contacts.PeopleColumns.NAME,
android.provider.Contacts.PhonesColumns.NUMBER
};

// Best way to retrieve a query; returns a managed query.
Cursor managedCursor = managedQuery( android.provider.Contacts.Phones.CONTENT_URI,
projection, //Which columns to return.
null, // WHERE clause--we won't specify.
android.provider.Contacts.PeopleColumns.NAME + " ASC"); // Order-by clause.
getColumnData(managedCursor);

}

private void getColumnData(Cursor cur){
String name;
String phoneNumber;
int nameColumn = cur.getColumnIndex(android.provider.Contacts.PeopleColumns.NAME);
int phoneColumn = cur.getColumnIndex(android.provider.Contacts.PhonesColumns.NUMBER);

String imagePath;
tv.setText("");
while (cur.next()) {
name = cur.getString(nameColumn);
phoneNumber = cur.getString(phoneColumn);

tv.append(name+" : "+phoneNumber+"\n");
}
}
}


3. main.xml : 在layout資料夾下的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 id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

2008年2月12日 星期二

How to Android?Step2:Set up Hello Android

建立"hello"的大綱
  1. 經由File > New > Project 目錄建立一個"Android專案"
  2. 在新專案視窗填入相關明細
  3. 編輯自動產生的空殼程式,顯示輸出

就是這麼簡單,下面說明每一個步驟

1.建立新的Android專案

選好Android Project後按Next按紐 再填入專案明細

3.編輯自動產生的空殼程式
外掛執行後,有支產生的程式叫hello.java看起來像這樣


public class HelloAndroid extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
}
}
}


執行程式碼: hello

Eclipse外掛很容易就可以執行你的程式,開始是從目錄選取Run>Open Run Dialog,會看到

下一步選取"Android Application",按左上角的圖示(一張紙上面有個+號的那個),或是直接在double click "Android Application" ,會載入一個名為"New_configuration" 的新設定

然後按Browse按紐選擇您的專案,外掛會掃瞄專案內的每一個Activity的子類別加到 Activity:標籤下的下拉方塊,因為"Android!您好"只有一個Activity,所以預設就是它了,再來按"Apply"套用,範例如下:

就是這樣 - 您完成了,按Run按紐,Android模擬器啟動後,您的程式就會出現,看起來就像這樣

2008年2月11日 星期一

How to Android? Step1:Tools and SDK

We can use the Eclipse IDE as our environment for developing Android applications, and install a custom plugin called Android Development Tools (ADT), which adds integrated support for Android projects and tools. The ADT plugin includes a variety of powerful extensions that make creating, running, and debugging Android applications faster and easier.


To download and install the ADT plugin, set up an Eclipse remote update site as described in the steps below.

  1. Start Eclipse, then select Help > Software Updates > Find and Install....
  2. In the dialog that appears, select Search for new features to install and press Next.
  3. Press New Remote Site.
  4. In the resulting dialog box, enter a name for the remote site (e.g. Android Plugin) and enter this as its URL:
    https://dl-ssl.google.com/android/eclipse/
    Press OK.
  5. You should now see the new site added to the search list (and checked). Press Finish.
  6. In the subsequent Search Results dialog box, select the checkbox for Android Plugin > Eclipse Integration > Android Development Tools and press Next.
  7. Read the license agreement and then select Accept terms of the license agreement, if appropriate. Press Next.
  8. Press Finish.
  9. The ADT plugin is not signed; you can accept the installation anyway by pressing Install All.
  10. Restart Eclipse.
  11. After restart, update your Eclipse preferences to point to the SDK directory:
    1. Select Window > Preferences... to open the Preferences panel. (Mac OS X: Eclipse > Preferences)
    2. Select Android from the left panel.
    3. For the SDK Location in the main panel, press Browse... and locate the SDK directory.
    4. Press Apply, then OK.
Last step, Let's download Android SDK.

所謂工欲善其事必先利其器,而Android主要是已Java-based進行開發,所以在此建議你使用Eclipse IDE來開發Android。你可以在下方連結進行下載:
Eclipse Downloads Home

當你安裝Eclipse後,然後再安裝Android Development Tools (ADT) 的外掛,ADT提供了Android專案與工具的整體支援。
  1. 啟動Eclipse,選擇Help > Software Updates > Find and Install....


  2. 對話視窗出現後,選擇Search for new features to install後按Next.
  3. New Remote Site .

  4. 在最後的對話視窗的remote site鍵入名稱(如Android 外掛)與以下URL
    https://dl-ssl।google।com/android/eclipse/
    後按OK
  5. 然後您會看到新站台出現在搜尋清單上(且被選取),按Finish.
  6. 在接下來的搜尋結果對話視窗核取然Android Plugin > Eclipse Integration > Android Development Tools 後按Next.
  7. 閱讀許可條款, 如果同意的話選取Accept terms of the license agreement,按Next
  8. finish.
  9. ADT外掛未經簽署,您可以按Install All. 同意安裝
  10. 重新啟動Eclipse
  11. 重新啟動後,更新您的Eclipse的preferences 指定SDK的目錄路徑
    A.選擇Window > Preferences... 開啟Preferences panel. (Mac OS X: Eclipse > Preferences)
    B.選擇左邊版面的Android
    C.在主版面上的SDK Location ,按Browse... ,指定SDK的目錄路徑
    D.按apply後再按OK

最後再安裝Android SDK

2008年2月8日 星期五

Android structure

The following diagram shows the major components of the Android operating system.



Android structure

2008年2月7日 星期四

Flash Lite

Flash Lite History - Flash Lite的歷史
In 2003, Macromedia released Flash Lite1.0, a mobile flash player based on Flash4. It has basic functions and Internet-connection function. NTT DoCoMo and i-mode in Japan are the first service provider for Flash Lite.

In 2006, Macromedia released Flash Lite2.0, great progress in new version. It's based on Flash6 and supported chinese.

In 2007, Adobe(Macromedia merged by Adobe) released Flash Lite3.0. It's based on Flash8 and supported FLV streaming video and dynamic loading XML. It's a powerful version.

Macromedia在2003年推出Flash Lite1.0,以Flash4指令碼引擎為基礎的全新Flash行動版本,也就是手機版的Flash,早期提供了基本動畫與網路連接功能。最先採用Flash Lite的行動電話服務業者是日本的NTT DoCoMo與NTT的i-mode服務。

在2006年Macromedia推出Flash Lite2.0,新版本的功能有大幅提升,以Flash6指令碼引擎為基礎,並支援中文字體。

在2007年Adobe(Macromedia被併購)推出Flash Lite3.0,以Flash8指令碼引擎為基礎,支援FLV視訊功能,支援動態載入XML資料,功能十分強大。

Flash Lite Application - Flash Lite的應用
We can use Flash Lite to develop mobile application, such as tube guide, traffic query, rss reader, game, UI etc.

Flash Lite可用來開發手機的應用程式,如導覽地鐵路線圖的查詢應用程式、即時路況查詢、Rss閱讀器等。當然一般經常使用的遊戲、桌面主題或甚至是手機使用介面UI。

Example 應用程式:flash2U
Game & Screens:Smashing Ideas

Future - Flash Lite的未來發展
It is getting mature for Flash Lite, but comparing with J2ME or BREW, It's not popular.

Its strength is based on popularity in the Internet and many developers for Flash. Besides, data compression and user-frieandly are another advantage.

Its weakness is many limitations of mobile, and too many version of Flash Lite.

It's not popular for Flash Lite now. I think its version might take a little long time to be in unanimity.

The key is ISP must support Flash Lite service, whatever softwave or hardware.

FlashLite已由早期發展的平台,漸漸到成熟的平台,不過跟J2ME或BREW等相對成熟的技術比,普及率恐怕還是相差許多。

它所具有的優勢是基於Flash在網際網路上的普及率與現有的開發人員,另外就是FlashLite透過良好的設計跟壓縮最佳化,可以有效降低資料傳輸量,也就代表可能可以節省不少費用,同時提供良好的使用者介面。

但是目前所具有的劣勢是,在手機或embedded system這兩塊市場先天或後天的限制太多,目前在市面上的版本就有1.0與2.0之系列,而這也讓開發人員難以適從。

目前FlashLite手機並不算普及,因此要所有手機都支援FlashLite且版本較為一致時,恐怕還需要一段不短的時間。

而關鍵也就是行動網路服務供應商必須支援,無論是在金錢和硬體上投資或在行銷上推動Flash內容。
目前Flash Lite手機
下載 Macromedia Flash Lite 1.1 CDK
下載 Macromedia Flash Lite 2 CDK
Adobe Flash Lite 3 Developer Edition

Google Android vs Sun J2ME

Sun's worried that Google Android could fracture Java

Google and Sun may butt heads over Android

Google發布Android,Sun將何去何從?


Android動了Java的奶酪?

2008年2月4日 星期一

Android Comment

Unqualified Reservations: Five problems with Google Android

Google Buys Android for Its Mobile Arsenal


Analyzing Google's "Android" - Faster Forward

行動通訊市場即將改變生態


Android SDK不怎麼親民啊...

Android Demo

Sergey Brin and Steve Horowitz discuss the availability of the SDK, that it will be open source in the future, and demo some applications.

Android News

Google releases Android programming tools

Google sends Android to conquer mobile world


Sun's worried that Google Android could fracture Java

Google公布手機軟體:「比Gphone更有雄心」


世界首部搭載Google Android原型機

Android為Google品牌手機鋪路

Android SDK將大翻新,比賽延期!

Google Android平台Open Handset Alliance小整理

Where is Android ?

Android Website http://code.google.com/android/
Android SDK http://code.google.com/android/download.html
Android blog http://android-developers.blogspot.com/

What is Android ?

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

Android是一個包含作業系統、中介程式與應用程式的行動裝置軟體平台,初期的Android SDK提供必要的API(應用程式開發介面)與工具以使用Java語言開發在Android平台上開發應用軟體。

The picture shows The Tools(Eclipse) to develop Android project. Because there is no Android mobile now,so developers must use simulator of Android.

Google的Android手機軟體開發工具,上圖顯示在Eclipse程式工具計畫中所看到的編程情況,目前由於無實體的Android手機,因此開發人員必須透過模擬器來模擬操作。