Android Application: Introduction

13,596 views

Published on

Jollen's Android Training. Introducing App Dev - China Shanghai (Day2-6hr)

Published in: Education, Business, Technology
1 Comment
20 Likes
Statistics
Notes
No Downloads
Views
Total views
13,596
On SlideShare
0
From Embeds
0
Number of Embeds
774
Actions
Shares
0
Downloads
1,163
Comments
1
Likes
20
Embeds 0
No embeds

No notes for slide

Android Application: Introduction

  1. 1. 发 术
  2. 2. Jollen’s Consulting 业 , 发, 发 , : www.jollen.org/consulting
  3. 3. www.jollen.org/consulting Jollen Chen <jollen@jollen.org> Embedded Linux 师 Embedded Linux Linux 动 经 时 Openmoko 华区 过 Openmoko 对 Android OS 术 Android 设 务 Openmoko 华区 湾 联 -Android 师 学 画发 师 联 - 发 参 Android 发 画 长 Android porting (s3c244x/s3c64x0) Linux 动 发 Linux 设 术 Jollen - www.jollen.org/blog Jollen - www.jollen.org/consulting
  4. 4. 时间 点
  5. 5. 经 变动 将 电 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  6. 6. 发 拟 协 设 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  7. 7. 拟 拟 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  8. 8. power management RAM console Android gadget Android kernel debug Android IPC git.android.com patch Openmoko 对ARMv4 Neo FreeRunner Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  9. 9. Eclipse 发环 target device 环 Android 发 执 Eclipse 拟 (AVD) Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  10. 10. Eclipse 发环 target device 环 Android SDK tools/ 录 DDMS Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  11. 11. 设 径 http://www.eclipse.org/downloads/ Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  12. 12. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  13. 13. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  14. 14. 类别 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  15. 15. 类别 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  16. 16. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  17. 17. 执 选 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  18. 18. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  19. 19. 类别 package com.moko.hello; import com.moko.hello.R; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloMoko extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  20. 20. public class HelloMoko extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } onCreate() View Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  21. 21. 动 视 过View UI Activity foreground执 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  22. 22. 执 Activity 画 Activity盖 时 Activity paused Activity 统 亿 时 会 kill 执 Activity 画 Activity 时 Activity stopped 当 统 时 Activity会 统 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  23. 23. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  24. 24. android:autoLink 属 动将 点 URL 过 autoLink 属 将 属 设 web Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  25. 25. <?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="Jollen's Blog - http://www.jollen.org/blog" android:autoLink="web" /> </LinearLayout> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  26. 26. public class HelloMoko extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello Moko"); setContentView(tv); } } 写 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  27. 27. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  28. 28. 类别 R.java Android Development Kit 动 R.layout 类别 UI 类别 R.layout类别 main Android Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  29. 29. 执 统 kernel 个apk 个 process 执 Android 个 Linux process Android 统 process Android 决 统 决 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  30. 30. 类别 package com.moko.hello; import android.app.Service; import android.content.Intent; import android.os.IBinder; public class MokoService extends Service { @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  31. 31. 类别 没 UI Service 个background process Service separated process 执 这 Service UI Activity 个process 执 个 process 执 Android Activity 启动 Service Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  32. 32. 义 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.moko.player" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MokoPlayer" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".MokoService"> <intent-filter> <action android:name="com.moko.player.START_MUSIC" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> </application> </manifest> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  33. 33. 启动 public class MokoPlayer extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); startService(new Intent ("com.moko.player.START_MUSIC")); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  34. 34. public class MokoService extends Service { @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onStart(Intent intent, int startId) { } @Override public void onDestroy() { } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  35. 35. 设 点 Activity / Service main.xml View AndroidManifest.xml - Android Intent / BroadcastReceiver Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  36. 36. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  37. 37. UI View UI 处 event Android UI从 view tree 写 过 XML layout view tree Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  38. 38. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  39. 39. foreground process visible process service process background process empty process Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  40. 40. Source: Android SDK
  41. 41. android.widget.DatePicker android.widget.TimePicker Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  42. 42. android.widget.Spinner android.widget.AutoCompl eteTextView Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  43. 43. android.widget.Button android.widget.EditText android.widget.CheckBoxa android.widget.ImageButton ndroid.widget.RadioButton Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  44. 44. android.widget.Gallery android.widget.ImageSwitcher Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  45. 45. android.widget.ListView android.widget.GridView Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  46. 46. android.widget.LinearLayout (Horizontal) (Vertical) Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  47. 47. android.widget.RelativeLayout android.widget.TableLayout Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  48. 48. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  49. 49. public class HelloMoko extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } 当Activity setContentView() 将 UI R.layout.main 视 R.layout.main 个TextView 义 main.xml Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  50. 50. <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> 'android:layout_width' - View 'android:layout_height' - View 'android:text' - TextView Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  51. 51. 战 <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableRow> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="www.jollen.org" android:padding="3dip" android:autoLink="web" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="www.google.com" android:autoLink="web" /> </TableRow> </TableLayout> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  52. 52. package com.moko.layout; import com.moko.layout.R; import android.app.Activity; import android.os.Bundle; public class HelloLayout extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  53. 53. 变 从 对 dialog widget 对 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  54. 54. 变 Apple iPhone 萤 touch screen 统 点 click 萤 设 经 统 环 当 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  55. 55. 变 Android 萤 设 Android Android 经 经 过 点 统 选单 Menu 对 Dialog Toast Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  56. 56. TextView Widget Android Widget Android Cupcake App Widget API 这 个 实 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  57. 57. Android res/ 录 个menu/ 录 options_menu.xml Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  58. 58. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  59. 59. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  60. 60. <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/new_message" android:title="New Message" /> <item android:id="@+id/quit" android:title="Quit" /> </menu> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  61. 61. onCreateOptionsMenu() MenuInflater类别将 义 选单 个类别 Menu MenuInflater import这 个 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  62. 62. 实 public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options_menu, menu); return true; } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  63. 63. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  64. 64. 处 过onOptionsItemSelected() 当 时 Android 压 选 类别 MenuItem 义 选单UI会 R类别 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  65. 65. 处 断 import android.view.MenuItem; public boolean onOptionsItemSelected(MenuItem item) { return true; } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  66. 66. package com.moko.hellomenu; public final class R { public static final class attr { } public static final class drawable { public static final int icon=0x7f020000; } public static final class id { public static final int new_message=0x7f060000; public static final int quit=0x7f060001; } public static final class layout { public static final int main=0x7f030000; } public static final class menu { public static final int options_menu=0x7f050000; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  67. 67. 选 MenuItem getItemId() 选 ID 压 选 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  68. 68. 处 public boolean onOptionsItemSelected(MenuItem item) { int item_id = item.getItemId(); switch (item_id){ case R.id.new_message: break; case R.id.quit: break; default: return false; } return true; } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  69. 69. Toast Android 类别 时 import android.widget.Toast 选单 将 onOptionsItemSelected() 数实 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  70. 70. public boolean onOptionsItemSelected(MenuItem item) { int item_id = item.getItemId(); switch (item_id){ case R.id.new_message: Toast.makeText( this, "Please enter your message." + " Your message is at max 255 characters.", Toast.LENGTH_LONG).show(); break; case R.id.quit: Toast.makeText( this, "Going to quit.", Toast.LENGTH_LONG).show(); break; default: return false; } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  71. 71. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  72. 72. 对 个 对 过对 对 询 Yes/No 询 选 单选 选 状 状 处 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  73. 73. Android 对 android.app.Dialog 实 Dialog AlertDialog 对 AlertDialog对 询 询 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  74. 74. Menu “New Message”选 对 询 “Yes/No” Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  75. 75. 实 onOptionsItemSelected() 断 R.id.new_message 时 UI 个对 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  76. 76. 实 public boolean onOptionsItemSelected(MenuItem item) { int item_id = item.getItemId(); switch (item_id){ case R.id.new_message: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Also post your message to Twitter?"); builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); AlertDialog alert = builder.create(); alert.show(); break; case R.id.quit: Toast.makeText( this, "Going to quit.", Toast.LENGTH_LONG).show(); break; default: return false; } return true; } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  77. 77. 实 点 AlertDialog.builder dialog builder 这 个 对 内 设 dialog builder - builder.setMessage() 设 对 - builder.setCancelable() Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  78. 78. 实 点 dialog builder 对 个 Yes No -builder.setPositiveButton() builder.setNegativeButton() dialog builder AlertDialog AlertDialog 对 -builder.create() 将AlertDialog UI -alert.show() Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  79. 79. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  80. 80. 处 builder.setPositiveButton() 个 Yes 参数 个参数 个参数 click listener 个 个click listener 当 压 时 click listener android.content.DialogInterface类别 click listener Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  81. 81. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  82. 82. Intent 类 Notification Android 统 达 Intent Intent将 处 电 ... 个 达 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  83. 83. Web 电 voice mail 启Google map 启Street View Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  84. 84. 处 启动 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.moko.hello" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloMoko" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  85. 85. startService(Intent service) - Intent 启动Service voice mail 启Google map 启Street View Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  86. 86. public class MokoPlayer extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); startService(new Intent ("com.moko.player.START_MUSIC")); } } 电 丢 android.intent.action.DIAL Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  87. 87. Intent action data android.intent.action.VIEW - tel:0988082 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  88. 88. 电 号 import android.app.Activity; import android.os.Bundle; import android.content.Intent; import android.net.Uri; public class MokoPlayer extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent dial = new Intent(); dial.setAction("android.intent.action.VIEW"); dial.setData(Uri.parse("tel:0988082134")); startActivity(dial); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  89. 89. 电 号 dial.setData(Uri.parse("mailto:jollen@jollen.org")); dial.setData(Uri.parse("http://www.jollen.org")); Android Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  90. 90. 个 Intent 个动 action 动 动 Intent 动 义 内 义 Android Intent 实 内 动 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  91. 91. Intent action 这个Intent 动 动 处 action 笔 Uri 写 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  92. 92. ACTION_CALL: 号 ACTION_GET_CONTENT:启动内 选 ACTION_SET_WALLPAPER:设 Wallpaper Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  93. 93. Android内 Intent action Activity Action:启动Activity action Broadcast Action: 过 处 action activity action: 启动Activity Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  94. 94. 实 动 号 public class HelloIntentDialer extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent dial = new Intent(); dial.setAction("android.intent.action.CALL"); dial.setData(Uri.parse("tel:119")); startActivity(dial); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  95. 95. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.moko.hellointentdialer" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloIntentDialer" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.CALL_PHONE" /> </manifest> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  96. 96. 实 个 执 个 选 个 实 选 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  97. 97. 1. action ACTION_GET_CONTENT Intent Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 2.设 Intent mime type 设 Intent mime type 声 intent.setType("audio/*"); 3. 内 选 Intent startActivity(Intent.createChooser(intent, "Select music")); Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  98. 98. 写 属 写 数写 类别 义 数 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  99. 99. 执 画 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  100. 100. public class HelloIntentWallpaper extends Activity implements View.OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.set_wallpaper); button.setOnClickListener(this); } public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER); startActivity(Intent.createChooser(intent, "Select Wallpaper")); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  101. 101. <?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" /> <Button android:id="@+id/set_wallpaper" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/set_wallpaper"> <requestFocus /> </Button> </LinearLayout> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  102. 102. 设 处 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  103. 103. UI 处 View 处 个 View 类别 动 Android 设 event listener 处 UI Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  104. 104. Android UI 处 学 View UI 类别 个 View Android 册 个 个 个 数 callback method 这个 数 callback method 处 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  105. 105. touch 动 当 View 处 时 Android 册View.OnClickListener 当 touch 发 时 Android 数 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  106. 106. View.OnClickListener click listener 这 UI Click动 当 对View Click 时 画 UI Android 会 这个 View.OnClickListener 数 View.OnClickListerner 数 OnClick() Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  107. 107. 实 个 实 Acitivty类 别 实 View.OnClickListener Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  108. 108. 个View 册 个event listener 当Android click event listener callback method Button类别 处 时 Button类别 setOnClickListener() 册click listener Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  109. 109. 实 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.btn); button.setOnClickListener(this); } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  110. 110. 实 public void onClick(View v) { Toast.makeText( this, "Yes.", Toast.LENGTH_LONG).show(); } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  111. 111. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  112. 112. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  113. 113. AppWidgetProviderInfo Widget layout XML AppWidgetProvider View layout Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  114. 114. AppWidgetProviderInfo AppWidgetProvider 义basic method interfacing with App Widgets 当Widget 启动 删 时会 broadcast View layout Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  115. 115. AppWidgetProviderInfo AppWidgetProvider View layout 义App Widget layout XML Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  116. 116. <receiver android:name="ExampleAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/example_appwidget_info" /> </receiver> AndroidManifest.xml Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  117. 117. <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="240dp" <!-- density-independent pixels --> android:minHeight="72dp" android:initialLayout="@layout/example_appwidget" android:configure="com.example.android.ExampleAppWidgetConfigure" > </appwidget-provider> <appwidget-provider> 义 res/xml/ Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  118. 118. <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="240dp" <!-- density-independent pixels --> android:minHeight="72dp" android:updatePeriodMillis="86400000" <!-- once per day --> android:initialLayout="@layout/example_appwidget" android:configure="com.example.android.ExampleAppWidgetConfigure" > </appwidget-provider> App widget timely information 时间 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  119. 119. widget Source: Android Dev Guide Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  120. 120. 实 public class ExampleAppWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; // Create an Intent to launch ExampleActivity Intent intent = new Intent(context, ExampleActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); // Get the layout for the App Widget and attach an on-click listener to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout); views.setOnClickPendingIntent(R.id.button, pendingIntent); // Tell the AppWidgetManager to perform an update on the current App Widget appWidgetManager.updateAppWidget(appWidgetId, views); } } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  121. 121. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.app.myapp" > <uses-permission android:name="android.permission.RECEIVE_SMS" /> </manifest> 装时 installer Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  122. 122. widget Source: Android Dev Guide Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  123. 123. Source: Android Dev Guide Landscape Orientation Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  124. 124. 设 决 widget 选 frame 阴 设 设 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  125. 125. PNG-24 设 transparent background 8-bit color Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  126. 126. 设 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  127. 127. 样 长 别 样 对 样 还 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  128. 128. 样 义 样 个 义 个样 个样 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  129. 129. 义样 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  130. 130. <?xml version="1.0" encoding="utf-8"?> <resources> <style name="myText"> <item name="android:textSize">18sp</item> <item name="android:textColor">#880</item> </style> </resources> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  131. 131. 样 <?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="Hello, this is HelloStyles." style="@style/myText" /> </LinearLayout> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  132. 132. 执 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  133. 133. 个萤 从 个 个 个 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  134. 134. 设 视 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="myTheme"> <item name="android:windowNoTitle">true</item> </style> </resources> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  135. 135. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.moko.hellotheme" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/myTheme"> <activity android:name=".HelloTheme" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  136. 136. 执 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  137. 137. package com.moko.hellotheme; import android.app.Activity; import android.os.Bundle; public class HelloTheme extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* setTheme(R.style.myTheme); */ setContentView(R.layout.main); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  138. 138. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  139. 139. 动画 <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2007 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0" android:toXDelta="10" android:duration="1000" android:interpolator="@anim/cycle_7" /> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  140. 140. <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2007 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" /> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  141. 141. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="10dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dip" android:text="@string/animation_1_instructions" /> <EditText android:id="@+id/pw" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:singleLine="true" android:password="true" /> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/googlelogin_login" /> </LinearLayout> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  142. 142. package com.example.android.apis.view; import com.example.android.apis.R; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; public class Animation1 extends Activity implements View.OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.animation_1); View loginButton = findViewById(R.id.login); loginButton.setOnClickListener(this); } public void onClick(View v) { Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake); findViewById(R.id.pw).startAnimation(shake); } } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  143. 143. 执 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  144. 144. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  145. 145. 将 动 边 边 义 区 区内 Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  146. 146. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  147. 147. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  148. 148. <?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" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="small world" android:textSize="12sp" android:background="@drawable/arrow" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="big world" android:textSize="24sp" android:background="@drawable/arrow" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="super world" android:textSize="48sp" android:background="@drawable/arrow" /> </LinearLayout> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  149. 149. www.jollen.org/consulting

×