Skip to content
Browse files

Update to 2nd edition

  • Loading branch information...
1 parent 92a8c8c commit 4800c4aca55032bcc1c4d54bbd48b3eb51a07ff3 @bmeike committed
Showing with 9 additions and 9,740 deletions.
  1. +9 −0 .gitignore
  2. +0 −6 02/FillListTask/.gitignore
  3. +0 −11 02/FillListTask/default.properties
  4. +0 −76 02/FillListTask/src/com/oreilly/demo/android/ch02/filllisttask/FillListTask.java
  5. +0 −6 02/FillListTask/tools/ide/eclipse/classpath
  6. +0 −6 02/SharedListTask/.gitignore
  7. +0 −11 02/SharedListTask/default.properties
  8. +0 −53 02/SharedListTask/src/com/oreilly/demo/android/ch02/sharedlisttask/SharedListTask.java
  9. +0 −6 02/SharedListTask/tools/ide/eclipse/classpath
  10. +0 −5 03/TestApp/.gitignore
  11. +0 −37 03/TestApp/AndroidManifest.xml
  12. +0 −11 03/TestApp/default.properties
  13. +0 −10 03/TestApp/res/layout/main.xml
  14. +0 −15 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestActivity.java
  15. +0 −11 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestBroadcastReceiver.java
  16. +0 −47 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestProvider.java
  17. +0 −12 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestService.java
  18. +0 −7 03/TestApp/tools/ide/eclipse/classpath
  19. +0 −33 03/TestApp/tools/ide/eclipse/project
  20. +0 −5 06/AIDLDemo/.gitignore
  21. +0 −20 06/AIDLDemo/AndroidManifest.xml
  22. +0 −11 06/AIDLDemo/default.properties
  23. +0 −13 06/AIDLDemo/res/layout/main.xml
  24. +0 −107 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/client/AIDLDemo.java
  25. +0 −59 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/parcelables/ParcelableList.java
  26. +0 −89 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/parcelables/SimpleParcelable.java
  27. +0 −3 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/Path.aidl
  28. +0 −88 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/Path.java
  29. +0 −8 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/PathService.aidl
  30. +0 −34 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/Point.java
  31. +0 −74 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/SimplePathService.java
  32. +0 −7 06/AIDLDemo/tools/ide/eclipse/classpath
  33. +0 −5 06/AsyncTaskDemo/.gitignore
  34. +0 −18 06/AsyncTaskDemo/AndroidManifest.xml
  35. +0 −11 06/AsyncTaskDemo/default.properties
  36. +0 −31 06/AsyncTaskDemo/res/layout/asyncdemo.xml
  37. +0 −38 06/AsyncTaskDemo/res/layout/asyncdemoprogress.xml
  38. +0 −127 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemo.java
  39. +0 −115 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemoWithProgress.java
  40. +0 −92 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskSample.java
  41. +0 −68 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/game/Game.java
  42. +0 −39 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/game/MockGame.java
  43. +0 −33 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/game/PersistentModel.java
  44. +0 −7 06/AsyncTaskDemo/tools/ide/eclipse/classpath
  45. +0 −5 06/JSerializable/.gitignore
  46. +0 −20 06/JSerializable/AndroidManifest.xml
  47. +0 −11 06/JSerializable/default.properties
  48. +0 −12 06/JSerializable/res/layout/main.xml
  49. +0 −61 06/JSerializable/src/com/oreilly/demo/android/ch06/JSerialize.java
  50. +0 −7 06/JSerializable/tools/ide/eclipse/classpath
  51. +0 −5 07/AndroidUIDemo/.gitignore
  52. +0 −15 07/AndroidUIDemo/AndroidManifest.xml
  53. +0 −22 07/AndroidUIDemo/default.properties
  54. +0 −56 07/AndroidUIDemo/res/layout/main.xml
  55. +0 −9 07/AndroidUIDemo/res/values/colors.xml
  56. +0 −7 07/AndroidUIDemo/res/values/strings.xml
  57. +0 −250 07/AndroidUIDemo/src/com/oreilly/demo/android/ch07/TouchMe.java
  58. +0 −34 07/AndroidUIDemo/src/com/oreilly/demo/android/ch07/model/Dot.java
  59. +0 −56 07/AndroidUIDemo/src/com/oreilly/demo/android/ch07/model/Dots.java
  60. +0 −67 07/AndroidUIDemo/src/com/oreilly/demo/android/ch07/view/DotView.java
  61. +0 −7 07/AndroidUIDemo/tools/ide/eclipse/classpath
  62. +0 −5 08/SimpleFragment/.gitignore
  63. +0 −19 08/SimpleFragment/AndroidManifest.xml
  64. +0 −11 08/SimpleFragment/default.properties
  65. +0 −36 08/SimpleFragment/proguard.cfg
  66. +0 −33 08/SimpleFragment/res/layout/date_time.xml
  67. +0 −43 08/SimpleFragment/res/layout/main.xml
  68. +0 −6 08/SimpleFragment/res/values/strings.xml
  69. +0 −91 08/SimpleFragment/src/com/oreilly/demo/android/ch08/simplefragment/DateTime.java
  70. +0 −78 08/SimpleFragment/src/com/oreilly/demo/android/ch08/simplefragment/SimpleFragment.java
  71. +0 −7 08/SimpleFragment/tools/ide/eclipse/classpath
  72. +0 −5 09/AndroidViewDemo/.gitignore
  73. +0 −15 09/AndroidViewDemo/AndroidManifest.xml
  74. +0 −22 09/AndroidViewDemo/default.properties
  75. +0 −12 09/AndroidViewDemo/res/drawable/throbber.xml
  76. +0 −51 09/AndroidViewDemo/res/layout/main.xml
  77. +0 −234 09/AndroidViewDemo/src/com/oreilly/demo/android/ch09/TransformIt.java
  78. +0 −50 09/AndroidViewDemo/src/com/oreilly/demo/android/ch09/drawable/HelloAndroidTextDrawable.java
  79. +0 −133 09/AndroidViewDemo/src/com/oreilly/demo/android/ch09/efx/RotationTransitionAnimation.java
  80. +0 −75 09/AndroidViewDemo/src/com/oreilly/demo/android/ch09/widget/EffectsWidget.java
  81. +0 −229 09/AndroidViewDemo/src/com/oreilly/demo/android/ch09/widget/GLDemoWidget.java
  82. +0 −86 09/AndroidViewDemo/src/com/oreilly/demo/android/ch09/widget/TransformedViewWidget.java
  83. +0 −7 09/AndroidViewDemo/tools/ide/eclipse/classpath
  84. +0 −5 10/MicroJobs/.gitignore
  85. +0 −92 10/MicroJobs/AndroidManifest.xml
  86. +0 −11 10/MicroJobs/default.properties
  87. +0 −68 10/MicroJobs/res/layout/addjob.xml
  88. +0 −85 10/MicroJobs/res/layout/editjob.xml
  89. +0 −43 10/MicroJobs/res/layout/main.xml
  90. +0 −4 10/MicroJobs/res/layout/microjobs_row.xml
  91. +0 −117 10/MicroJobs/res/layout/microjobsdetail.xml
  92. +0 −188 10/MicroJobs/res/layout/microjobsempdetail.xml
  93. +0 −18 10/MicroJobs/res/layout/microjobslist.xml
  94. +0 −62 10/MicroJobs/res/values/strings.xml
  95. +0 −119 10/MicroJobs/src/com/oreilly/demo/pa/ch10/AddJob.java
  96. +0 −123 10/MicroJobs/src/com/oreilly/demo/pa/ch10/EditJob.java
  97. +0 −369 10/MicroJobs/src/com/oreilly/demo/pa/ch10/MicroJobs.java
  98. +0 −517 10/MicroJobs/src/com/oreilly/demo/pa/ch10/MicroJobsDatabase.java
  99. +0 −184 10/MicroJobs/src/com/oreilly/demo/pa/ch10/MicroJobsDetail.java
  100. +0 −169 10/MicroJobs/src/com/oreilly/demo/pa/ch10/MicroJobsEmpDetail.java
  101. +0 −237 10/MicroJobs/src/com/oreilly/demo/pa/ch10/MicroJobsList.java
  102. +0 −84 10/MicroJobs/tools/ant/build.xml
  103. +0 −7 10/MicroJobs/tools/ide/eclipse/classpath
  104. +0 −5 11/FinchLifecycle/.gitignore
  105. +0 −18 11/FinchLifecycle/AndroidManifest.xml
  106. +0 −11 11/FinchLifecycle/default.properties
  107. +0 −36 11/FinchLifecycle/proguard.cfg
  108. +0 −18 11/FinchLifecycle/res/layout/main.xml
  109. +0 −49 11/FinchLifecycle/src/com/oreilly/demo/pa/ch10/finchlifecycle/FinchApplication.java
  110. +0 −139 11/FinchLifecycle/src/com/oreilly/demo/pa/ch10/finchlifecycle/FinchLifecycle.java
  111. +0 −82 11/FinchLifecycle/src/com/oreilly/demo/pa/ch10/finchlifecycle/TestFragment.java
  112. +0 −7 11/FinchLifecycle/tools/ide/eclipse/classpath
  113. +0 −5 11/FinchLifecycleBackport/.gitignore
  114. +0 −18 11/FinchLifecycleBackport/AndroidManifest.xml
  115. +0 −11 11/FinchLifecycleBackport/default.properties
  116. +0 −36 11/FinchLifecycleBackport/proguard.cfg
  117. +0 −18 11/FinchLifecycleBackport/res/layout/main.xml
  118. +0 −49 11/FinchLifecycleBackport/src/com/oreilly/demo/pa/ch10/finchlifecyclebackport/FinchApplication.java
  119. +0 −161 11/FinchLifecycleBackport/src/com/oreilly/demo/pa/ch10/finchlifecyclebackport/FinchLifecycle.java
  120. +0 −82 11/FinchLifecycleBackport/src/com/oreilly/demo/pa/ch10/finchlifecyclebackport/TestFragment.java
  121. +0 −8 11/FinchLifecycleBackport/tools/ide/eclipse/classpath
  122. +0 −5 12/FinchVideo/.gitignore
  123. +0 −32 12/FinchVideo/AndroidManifest.xml
  124. +0 −13 12/FinchVideo/default.properties
  125. +0 −10 12/FinchVideo/local.properties
  126. +0 −96 12/FinchVideo/res/layout/simple_video_activity.xml
  127. +0 −28 12/FinchVideo/res/layout/simple_video_list_item.xml
  128. +0 −34 12/FinchVideo/res/layout/video_list_item.xml
  129. +0 −50 12/FinchVideo/res/layout/video_query_activity.xml
  130. +0 −5 12/FinchVideo/src/com/oreilly/demo/pa/finchvideo/Ch12.java
  131. +0 −151 12/FinchVideo/src/com/oreilly/demo/pa/finchvideo/FinchVideoActivity.java
  132. +0 −110 12/FinchVideo/src/com/oreilly/demo/pa/finchvideo/SimpleFinchVideoActivity.java
  133. +0 −199 12/FinchVideo/src/com/oreilly/demo/pa/finchvideo/provider/FinchVideo.java
  134. +0 −470 12/FinchVideo/src/com/oreilly/demo/pa/finchvideo/provider/FinchVideoContentProvider.java
  135. +0 −286 12/FinchVideo/src/com/oreilly/demo/pa/finchvideo/provider/SimpleFinchVideoContentProvider.java
  136. +0 −318 12/FinchVideo/src/com/oreilly/demo/pa/finchvideo/provider/YouTubeHandler.java
  137. +0 −84 12/FinchVideo/tools/ant/build.xml
  138. +0 −8 12/FinchVideo/tools/ide/eclipse/classpath
  139. +0 −45 12/FinchVideo/tools/ide/eclipse/project
  140. +0 −3 13/README
  141. +0 −5 14/AudioPlayer/.gitignore
  142. +0 −32 14/AudioPlayer/AndroidManifest.xml
  143. +0 −5 14/AudioPlayer/README.txt
  144. +0 −11 14/AudioPlayer/default.properties
  145. +0 −30 14/AudioPlayer/res/layout/audioplayer.xml
  146. +0 −7 14/AudioPlayer/res/layout/audioplayerwmediacontrol.xml
  147. +0 −42 14/AudioPlayer/res/layout/audiorecorder.xml
  148. +0 −80 14/AudioPlayer/res/layout/main.xml
  149. +0 −11 14/AudioPlayer/res/layout/videoplayer.xml
  150. +0 −44 14/AudioPlayer/res/layout/videorecorder.xml
  151. +0 −213 14/AudioPlayer/src/com/oreilly/demo/pa/ch14/AudioPlayer.java
  152. +0 −180 14/AudioPlayer/src/com/oreilly/demo/pa/ch14/AudioPlayerWAudioTrack.java
  153. +0 −141 14/AudioPlayer/src/com/oreilly/demo/pa/ch14/AudioPlayerWMediaController.java
  154. +0 −156 14/AudioPlayer/src/com/oreilly/demo/pa/ch14/AudioRecorder.java
  155. +0 −38 14/AudioPlayer/src/com/oreilly/demo/pa/ch14/AudioRecorderViaIntent.java
  156. +0 −186 14/AudioPlayer/src/com/oreilly/demo/pa/ch14/AudioRecorderWAudioRecord.java
Sorry, we could not display the entire diff because too many files (1,041) changed.
View
9 .gitignore
@@ -1 +1,10 @@
+.DS_*
+.checkstyle
+.classpath
+.project
+.settings
+bin
+gen
+lint.xml
/.metadata
+
View
6 02/FillListTask/.gitignore
@@ -1,6 +0,0 @@
-/gen
-/assets
-/eclipse
-/.project
-/.classpath
-/bin
View
11 02/FillListTask/default.properties
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=Google Inc.:Google APIs:8
View
76 02/FillListTask/src/com/oreilly/demo/android/ch02/filllisttask/FillListTask.java
@@ -1,76 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch02.filllisttask;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * Demonstrate cooperative concurrent programming
- */
-public class FillListTask implements Runnable {
- private final int size;
-
- private List<String> strings;
-
- /** @param size the size of the desired list */
- public FillListTask(int size) {
- this.size = size;
- }
-
- /** @return true if the list has been filled */
- public synchronized boolean isFinished() {
- return null != strings;
- }
-
- /** @return null or the filled list */
- public synchronized List<String> getList() {
- return strings;
- }
-
- /** @see java.lang.Runnable#run() */
- @Override
- public void run() {
- List<String> strs = new ArrayList<String>(size);
- try {
- for (int i = 0; i < size; i++ ) {
- Thread.sleep(2000);
- strs.add("element " + String.valueOf(i));
- }
-
- synchronized (this) {
- strings = strs;
- this.notifyAll();
- }
- }
- catch (InterruptedException e) {
- // catch interrupted exception outside loop,
- // since interrupted exception is a sign that
- // the thread should quit.
- }
- }
-
-
- /**
- * Waits for the fill array task to complete
- *
- * @param args unused
- * @throws InterruptedException if slumber interrupted
- */
- public static void main(String[] args)
- throws InterruptedException
- {
- FillListTask task = new FillListTask(7);
-
- new Thread(task).start();
-
- synchronized (task) {
- while ( !task.isFinished()) {
- task.wait();
- }
- }
-
- System.out.println("Array full: " + task.getList());
- }
-}
View
6 02/FillListTask/tools/ide/eclipse/classpath
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="output" path="eclipse/classes"/>
-</classpath>
View
0 02/FillListTask/tools/ide/eclipse/project
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
6 02/SharedListTask/.gitignore
@@ -1,6 +0,0 @@
-/gen
-/assets
-/eclipse
-/.project
-/.classpath
-/bin
View
11 02/SharedListTask/default.properties
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=Google Inc.:Google APIs:8
View
53 02/SharedListTask/src/com/oreilly/demo/android/ch02/sharedlisttask/SharedListTask.java
@@ -1,53 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch02.sharedlisttask;
-
-import java.util.Vector;
-
-
-/**
- * Demonstrate that atomic methods may not be sufficient
- */
-public class SharedListTask implements Runnable {
- private final Vector<String> list;
-
- /** @param l the list to share */
- public SharedListTask(Vector<String> l) {
- this.list = l;
- }
-
- /** @see java.lang.Runnable#run() */
- @Override
- public void run() {
- // the size of the list is obtained early
- int s = list.size();
-
- while (true) {
- for (int i = 0; i < s; i++ ) {
- // throws IndexOutOfBoundsException!!
- // when the list is size 3, and s is 4.
- System.out.println(list.get(i));
- }
- }
- }
-
- /**
- * @param args ignored
- */
- public static void main(String[] args) {
- Vector<String> list = new Vector<String>();
- list.add("one");
- list.add("two");
- list.add("three");
- list.add("four");
-
- new Thread(new SharedListTask(list)).start();
-
- try { Thread.sleep(2000); }
- catch (InterruptedException e) { /* ignore */}
-
- // the data structure is fully synchronized,
- // but that only protects the individual methods!
- list.remove("three");
- }
-}
View
6 02/SharedListTask/tools/ide/eclipse/classpath
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="output" path="eclipse/classes"/>
-</classpath>
View
0 02/SharedListTask/tools/ide/eclipse/project
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
5 03/TestApp/.gitignore
@@ -1,5 +0,0 @@
-/gen
-/assets
-/.project
-/.classpath
-/bin
View
37 03/TestApp/AndroidManifest.xml
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.oreilly.demo.pa.ch03.testapp"
- android:versionCode="1"
- android:versionName="1.0">
-
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.CALL_PHONE" />
- <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
- <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
- <uses-permission android:name="android.permission.INTERNET" />
-
-
- <application android:icon="@drawable/icon" android:label="@string/app_name"
- android:debuggable="true">
-
- <activity android:name=".TestActivity"
- android:label="Test Activity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
-
- <provider android:name=".TestProvider"
- android:authorities= "com.oreilly.demo.pa.ch03.TestProvider"
- />
-
- <service android:name=".TestService"
- android:label="Test Service"/>
-
- <receiver
- android:name=".TestBroadcastReceiver"
- android:label="Test Broadcast Receiver"/>
- </application>
- <uses-sdk android:targetSdkVersion="9"/>
-</manifest>
View
11 03/TestApp/default.properties
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=Google Inc.:Google APIs:9
View
0 03/TestApp/res/drawable/icon.png
Deleted file not rendered
View
10 03/TestApp/res/layout/main.xml
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:id="@+id/video_layout"
- android:orientation="vertical"
- >
-</LinearLayout>
View
0 03/TestApp/res/values/strings.xml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
15 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestActivity.java
@@ -1,15 +0,0 @@
-package com.oreilly.demo.pa.ch03.testapp;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-import com.oreilly.demo.pa.ch03.testapp.R;
-
-public class TestActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
-}
View
11 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestBroadcastReceiver.java
@@ -1,11 +0,0 @@
-package com.oreilly.demo.pa.ch03.testapp;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-public class TestBroadcastReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- }
-}
View
47 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestProvider.java
@@ -1,47 +0,0 @@
-package com.oreilly.demo.pa.ch03.testapp;
-
-import android.content.ContentProvider;
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.net.Uri;
-
-/**
- * A stub content provider.
- */
-public class TestProvider extends ContentProvider {
- @Override
- public boolean onCreate() {
- return false;
- }
-
- @Override
- public Cursor query(Uri uri, String[] projection, String where,
- String[] whereArgs, String sortBy)
- {
- return null;
- }
-
- @Override
- public String getType(Uri uri) {
- return null;
- }
-
- @Override
- public Uri insert(Uri uri, ContentValues contentValues)
- {
- return null;
- }
-
- @Override
- public int delete(Uri uri, String where, String[] whereArgs)
- {
- return 0;
- }
-
- @Override
- public int update(Uri uri, ContentValues contentValues,
- String where, String[] whereArgs)
- {
- return 0;
- }
-}
View
12 03/TestApp/src/com/oreilly/demo/pa/ch03/testapp/TestService.java
@@ -1,12 +0,0 @@
-package com.oreilly.demo.pa.ch03.testapp;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-
-public class TestService extends Service {
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-}
View
7 03/TestApp/tools/ide/eclipse/classpath
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
View
33 03/TestApp/tools/ide/eclipse/project
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>TestActivity</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.ApkBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
View
5 06/AIDLDemo/.gitignore
@@ -1,5 +0,0 @@
-/gen
-/assets
-/.project
-/.classpath
-/bin
View
20 06/AIDLDemo/AndroidManifest.xml
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- android:versionCode="1"
- android:versionName="1.0" package="com.oreilly.demo.android.ch06.aidl">
- <uses-sdk android:targetSdkVersion="9"></uses-sdk>
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:label="@string/app_name" android:name=".client.AIDLDemo">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <service android:name="com.oreilly.demo.android.ch06.aidl.service.SimplePathService">
- <intent-filter>
- <action android:name="com.oreilly.demo.android.ch06.aidl.service.PathService" />
- </intent-filter>
- </service>
-
- </application>
-</manifest>
View
11 06/AIDLDemo/default.properties
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=Google Inc.:Google APIs:9
View
0 06/AIDLDemo/res/drawable-hdpi/icon.png
Deleted file not rendered
View
0 06/AIDLDemo/res/drawable-ldpi/icon.png
Deleted file not rendered
View
0 06/AIDLDemo/res/drawable-mdpi/icon.png
Deleted file not rendered
View
13 06/AIDLDemo/res/layout/main.xml
@@ -1,13 +0,0 @@
-<?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:id="@+id/button"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
-</LinearLayout>
View
0 06/AIDLDemo/res/values/strings.xml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
107 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/client/AIDLDemo.java
@@ -1,107 +0,0 @@
-package com.oreilly.demo.android.ch06.aidl.client;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import android.app.Activity;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.Parcel;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-
-import com.oreilly.demo.android.ch06.aidl.R;
-import com.oreilly.demo.android.ch06.aidl.parcelables.ParcelableList;
-import com.oreilly.demo.android.ch06.aidl.service.PathService;
-
-
-/**
- * AIDLDemo
- */
-public class AIDLDemo extends Activity {
- Button button;
- PathService service;
- ServiceConnection connection = new ServiceConnection() {
- @Override
- public void onServiceConnected(
- ComponentName conn,
- IBinder binder)
- {
- service = PathService.Stub.asInterface(binder);
- Log.d("AIDLDemo", "Connected: " + service);
- try {
- button.setText(service.getPoint("blake"));
- }
- catch (Exception e) { e.printStackTrace(); }
- }
-
- @Override
- public void onServiceDisconnected(ComponentName arg0) {
- Log.d("AIDLDemo", "Disconnected: " + service);
- service = null;
- }
- };
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- button = ((Button) findViewById(R.id.button));
- button.setOnClickListener(
- new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- testParcelable();
- Log.d("AIDLDemo", "Binding: "
- + bindService(
- new Intent(PathService.class.getName()),
- connection,
- Context.BIND_AUTO_CREATE));
- Log.d("AIDLDemo", "Service: " + service);
- }
- });
-
- Log.d("AIDLDemo", "Created");
- }
-
- void testParcelable() {
- Parcel p1 = Parcel.obtain();
- Parcel p2 = Parcel.obtain();
-
- List<List<String>> list = new ArrayList<List<String>>();
- List<String> l = new ArrayList<String>();
- l.add("foo");
- list.add(l);
- l = new ArrayList<String>();
- l.add("bar");
- list.add(l);
- l = new ArrayList<String>();
- l.add("baz");
- list.add(l);
- ParcelableList orig = new ParcelableList(list);
-
- try {
- p1.writeParcelable(orig, 0);
- byte[] bytes = p1.marshall();
-
- p2.unmarshall(bytes, 0, bytes.length);
- p2.setDataPosition(0);
- ParcelableList result = p2.readParcelable(ParcelableList.class.getClassLoader());
- Log.d("AIDLDemo", result.toString());
- }
- catch (Exception e) { e.printStackTrace(); }
- finally {
- p1.recycle();
- p2.recycle();
- }
-
- }
-}
View
59 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/parcelables/ParcelableList.java
@@ -1,59 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06.aidl.parcelables;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-
-/**
- *
- * @version $Revision: $
- * @author <a href="mailto:bmeike@callmeike.net">Blake Meike</a>
- */
-public class ParcelableList implements Parcelable {
- public static final Parcelable.Creator<ParcelableList> CREATOR
- = new Parcelable.Creator<ParcelableList>() {
- public ParcelableList createFromParcel(Parcel src) {
- List<List<String>> l = new ArrayList<List<String>>();
- src.readList(l, null);
- return new ParcelableList(l);
- }
-
- public ParcelableList[] newArray(int size) {
- return new ParcelableList[size];
- }
- };
-
-
- private List<List<String>> list;
-
- public ParcelableList(List<List<String>> list) {
- this.list = list;
- }
-
- public List<List<String>> getList() { return list; }
- public void setList(List<List<String>> list) { this.list = list; }
-
- @Override
- public int describeContents() { return 0; }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeList(list);
- }
-
- @Override
- public String toString() {
- StringBuilder s = new StringBuilder("ParcelableList{");
- for (List<String> l: list) {
- s.append("[");
- for (String i: l) { s.append(i).append(","); }
- s.append("]");
- }
- return s.append("}").toString();
- }
-}
View
89 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/parcelables/SimpleParcelable.java
@@ -1,89 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06.aidl.parcelables;
-
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-
-/**
- *
- * @version $Revision: $
- * @author <a href="mailto:bmeike@callmeike.net">Blake Meike</a>
- */
-public class SimpleParcelable implements Parcelable {
- public enum State { BEGIN, MIDDLE, END; }
-
- private static final Map<State, String> marshalState;
- static {
- Map<State, String> m = new HashMap<State, String>();
- m.put(State.BEGIN, "begin");
- m.put(State.MIDDLE, "middle");
- m.put(State.END, "end");
- marshalState = Collections.unmodifiableMap(m);
- }
- private static final Map<String, State> unmarshalState;
- static {
- Map<String, State> m = new HashMap<String, State>();
- m.put("begin", State.BEGIN);
- m.put("middle", State.MIDDLE);
- m.put("end", State.END);
- unmarshalState = Collections.unmodifiableMap(m);
- }
-
- public static final Parcelable.Creator<SimpleParcelable> CREATOR
- = new Parcelable.Creator<SimpleParcelable>() {
- public SimpleParcelable createFromParcel(Parcel src) {
- return new SimpleParcelable(
- src.readLong(),
- src.readString());
- }
-
- public SimpleParcelable[] newArray(int size) {
- return new SimpleParcelable[size];
- }
- };
-
- private State state;
- private Date date;
-
- public SimpleParcelable(long date, String state) {
- if (0 <= date) { this.date = new Date(date); }
- if ((null != state) && (0 < state.length())) {
- this.state = unmarshalState.get(state);
- }
- }
-
- public State getState() { return state; }
- public void setState(State state) { this.state = state; }
-
- public Date getDate() { return date; }
- public void setDate(Date date) { this.date = date; }
-
- @Override
- public int describeContents() { return 0; }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- // translate the Date to a long
- dest.writeLong(
- (null == date)
- ? -1
- : date.getTime());
-
- dest.writeString(
- (null == state)
- ? ""
- : marshalState.get(state));
- }
-
- @Override
- public String toString() {
- return "SimpleParcelable{" + date + "," + state + "}";
- }
-}
View
3 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/Path.aidl
@@ -1,3 +0,0 @@
-package com.oreilly.demo.android.ch06.aidl.service;
-
-parcelable Path;
View
88 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/Path.java
@@ -1,88 +0,0 @@
-package com.oreilly.demo.android.ch06.aidl.service;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-
-/** A list of points. */
-public class Path implements Parcelable {
- public static final Parcelable.Creator<Path> CREATOR
- = new Parcelable.Creator<Path>() {
-
- @Override
- public Path createFromParcel(Parcel source) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Path[] newArray(int size) {
- // TODO Auto-generated method stub
- return null;
- }
- };
-
- /** PathChangeListener. */
- public interface PathChangeListener {
- /** @param points the points that changed. */
- void onPathChange(Path points);
- }
-
- private final LinkedList<Point> points = new LinkedList<Point>();
- private final List<Point> safePoints
- = Collections.unmodifiableList(points);
-
- private PathChangeListener pathChangeListener;
-
- /** @param l set the change listener. */
- public void setPathChangeListener(PathChangeListener l) {
- pathChangeListener = l;
- }
-
- /** @return the most recently added point. */
- public Point getLastPoint() {
- return (points.size() <= 0) ? null : points.getLast();
- }
-
- /** @return immutable list of points. */
- public List<Point> getPoints() { return safePoints; }
-
- /**
- * @param x point horizontal coordinate.
- * @param y point vertical coordinate.
- * @param color point color.
- * @param diameter point size.
- */
- public void addPoint(float x, float y, int color, int diameter) {
- points.add(new Point(x, y, color, diameter));
- notifyListener();
- }
-
- /** Remove all points. */
- public void clear() {
- points.clear();
- notifyListener();
- }
-
- private void notifyListener() {
- if (null != pathChangeListener) {
- pathChangeListener.onPathChange(this);
- }
- }
-
- @Override
- public int describeContents() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- // TODO Auto-generated method stub
-
- }
-}
View
8 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/PathService.aidl
@@ -1,8 +0,0 @@
-
-package com.oreilly.demo.android.ch06.aidl.service;
-
-interface PathService {
- void setPoint(in String name, in String path);
- String getPoint(in String name);
- void deletePoint(in String name);
-}
View
34 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/Point.java
@@ -1,34 +0,0 @@
-package com.oreilly.demo.android.ch06.aidl.service;
-
-
-/** A dot: the coordinates, color and size. */
-public final class Point {
- private final float x, y;
- private final int color;
- private final int diameter;
-
- /**
- * @param x horizontal coordinate.
- * @param y vertical coordinate.
- * @param color the color.
- * @param diameter dot diameter.
- */
- public Point(float x, float y, int color, int diameter) {
- this.x = x;
- this.y = y;
- this.color = color;
- this.diameter = diameter;
- }
-
- /** @return the horizontal coordinate. */
- public float getX() { return x; }
-
- /** @return the vertical coordinate. */
- public float getY() { return y; }
-
- /** @return the color. */
- public int getColor() { return color; }
-
- /** @return the dot diameter. */
- public int getDiameter() { return diameter; }
-}
View
74 06/AIDLDemo/src/com/oreilly/demo/android/ch06/aidl/service/SimplePathService.java
@@ -1,74 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06.aidl.service;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.util.Log;
-
-import com.oreilly.demo.android.ch06.aidl.service.PathService;
-
-
-/**
- *
- * @version $Revision: $
- * @author <a href="mailto:bmeike@callmeike.net">Blake Meike</a>
- */
-public class SimplePathService extends Service {
-
- @Override
- public void onCreate() {
- super.onCreate();
- Log.d("PathService", "onCreate()");
- }
-
- @Override
- public void onDestroy() {
- super.onCreate();
- Log.d("PathService", "onDestroy()");
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- Log.d("PathService", "onBind()");
-
- return new PathService.Stub() {
-
- @Override
- public void deletePoint(String name)
- throws RemoteException
- {
- SimplePathService.this.deletePoint(name);
- }
-
- @Override
- public String getPoint(String name)
- throws RemoteException
- {
- return SimplePathService.this.getPoint(name);
- }
-
- @Override
- public void setPoint(String name, String path)
- throws RemoteException
- {
- SimplePathService.this.setPoint(name, path);
- }
- };
- }
-
- void deletePoint(String name) {
- Log.d("PathService", "deletePoint(): " + name);
- }
-
- String getPoint(String name) {
- Log.d("PathService", "getPoint(): " + name);
- return "Service says: 'Hi!'"; // verify connectivity
- }
-
- void setPoint(String name, String path) {
- Log.d("PathService", "setPoint(): " + name + ", " + path);
- }
-}
View
7 06/AIDLDemo/tools/ide/eclipse/classpath
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry excluding="**/.svn|.svn" kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
View
0 06/AIDLDemo/tools/ide/eclipse/project
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
5 06/AsyncTaskDemo/.gitignore
@@ -1,5 +0,0 @@
-/gen
-/assets
-/.project
-/.classpath
-/bin
View
18 06/AsyncTaskDemo/AndroidManifest.xml
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- android:versionCode="1"
- android:versionName="1.0" package="com.oreilly.demo.android.ch06">
- <uses-sdk android:targetSdkVersion="9"></uses-sdk>
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".AsyncTaskDemoWithProgress"
- 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>
View
11 06/AsyncTaskDemo/default.properties
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=Google Inc.:Google APIs:9
View
0 06/AsyncTaskDemo/res/anim/dots.xml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 06/AsyncTaskDemo/res/drawable-hdpi/icon.png
Deleted file not rendered
View
0 06/AsyncTaskDemo/res/drawable-ldpi/icon.png
Deleted file not rendered
View
0 06/AsyncTaskDemo/res/drawable-mdpi/icon.png
Deleted file not rendered
View
0 06/AsyncTaskDemo/res/drawable/dots_f0.png
Deleted file not rendered
View
0 06/AsyncTaskDemo/res/drawable/dots_f1.png
Deleted file not rendered
View
0 06/AsyncTaskDemo/res/drawable/dots_f2.png
Deleted file not rendered
View
0 06/AsyncTaskDemo/res/drawable/dots_f3.png
Deleted file not rendered
View
0 06/AsyncTaskDemo/res/drawable/dots_f4.png
Deleted file not rendered
View
31 06/AsyncTaskDemo/res/layout/asyncdemo.xml
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/root"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@android:color/white"
- >
-
- <Button
- android:id="@+id/start"
- android:text="@string/start"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-
- <TextView
- android:id="@+id/msg"
- android:text="@string/waiting"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textColor="@android:color/black"
- />
-
- <FrameLayout
- android:id="@+id/dots"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-
-</LinearLayout>
View
38 06/AsyncTaskDemo/res/layout/asyncdemoprogress.xml
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/root"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@android:color/white"
- >
-
- <Button
- android:id="@+id/start"
- android:text="@string/start"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-
- <ProgressBar
- android:id="@+id/progress"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleHorizontal"
- />
-
- <TextView
- android:id="@+id/msg"
- android:text="@string/waiting"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textColor="@android:color/black"
- />
-
- <FrameLayout
- android:id="@+id/dots"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-
-</LinearLayout>
View
0 06/AsyncTaskDemo/res/values/strings.xml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
127 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemo.java
@@ -1,127 +0,0 @@
-package com.oreilly.demo.android.ch06;
-
-import android.app.Activity;
-import android.graphics.Color;
-import android.graphics.drawable.AnimationDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
-import android.widget.TextView;
-
-import com.oreilly.demo.android.ch06.R;
-import com.oreilly.demo.android.ch06.game.Game;
-
-
-/** AsyncTaskDemo */
-public class AsyncTaskDemo extends Activity {
-
- private final class AsyncInitGame
- extends AsyncTask<String, Void, String>
- {
- private final View dots;
- private final Game game;
- private final TextView message;
- private final Drawable bg;
-
- public AsyncInitGame(
- View dots,
- Drawable bg,
- Game game,
- TextView msg)
- {
- this.dots = dots;
- this.bg = bg;
- this.game = game;
- this.message = msg;
- }
-
- // runs on the UI thread
- @Override protected void onPreExecute() {
- if (0 >= mInFlight++) {
- dots.setBackgroundResource(R.anim.dots);
- ((AnimationDrawable) dots.getBackground()).start();
- }
- }
-
- // runs on the UI thread
- @Override protected void onPostExecute(String msg) {
- if (0 >= --mInFlight) {
- ((AnimationDrawable) dots.getBackground()).stop();
- dots.setBackgroundDrawable(bg);
- }
-
- message.setText(msg);
- }
-
- // runs on its own thread
- @Override protected String doInBackground(String... args) {
- return ((1 != args.length) || (null == args[0]))
- ? null
- : game.initialize(args[0]);
- }
- }
-
- int mInFlight;
-
- /** @see android.app.Activity#onCreate(android.os.Bundle) */
- @Override
- public void onCreate(Bundle state) {
- super.onCreate(state);
-
- setContentView(R.layout.asyncdemo);
-
- final View dots = findViewById(R.id.dots);
- final Drawable bg = dots.getBackground();
-
- final TextView msg = ((TextView) findViewById(R.id.msg));
-
- final Game game = Game.newGame();
-
- ((Button) findViewById(R.id.start)).setOnClickListener(
- new View.OnClickListener() {
- @Override public void onClick(View v) {
- //initGame(
- new AsyncInitGame(
- dots,
- bg,
- game,
- //msg,
- //"basic");
- msg)
- .execute("basic");
- } });
- }
-
- /**
- * Synchronous request to remote service
- * DO NOT USE!!
- */
- void initGame(
- View dots,
- Drawable bg,
- Game game,
- TextView resp,
- String level)
- {
- // if the animation hasn't been started,
- // initialize and start it
- if (0 >= mInFlight++ ) {
- dots.setBackgroundResource(R.anim.dots);
- ((AnimationDrawable) dots.getBackground()).start();
- }
-
- // get the response from the remote service
- String msg = game.initialize(level);
-
- // if this is the last running initialization
- // remove and clean up the animation
- if (0 >= --mInFlight) {
- ((AnimationDrawable) dots.getBackground()).stop();
- dots.setBackgroundDrawable(bg);
- }
-
- resp.setText(msg);
- }
-}
View
115 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemoWithProgress.java
@@ -1,115 +0,0 @@
-package com.oreilly.demo.android.ch06;
-
-import android.app.Activity;
-import android.graphics.drawable.AnimationDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-
-import com.oreilly.demo.android.ch06.R;
-import com.oreilly.demo.android.ch06.game.Game;
-
-
-/** AsyncTaskDemo */
-public class AsyncTaskDemoWithProgress extends Activity {
-
- private final class AsyncInit
- extends AsyncTask<String, Integer, String>
- implements Game.InitProgressListener
- {
- private final View root;
- private final Game game;
- private final TextView message;
- private final Drawable bg;
-
- public AsyncInit(
- View root,
- Drawable bg,
- Game game,
- TextView msg)
- {
- this.root = root;
- this.bg = bg;
- this.game = game;
- this.message = msg;
- }
-
- // runs on the UI thread
- @Override protected void onPreExecute() {
- if (0 >= mInFlight++) {
- root.setBackgroundResource(R.anim.dots);
- ((AnimationDrawable) root.getBackground()).start();
- }
- }
-
- // runs on the UI thread
- @Override protected void onPostExecute(String msg) {
- if (0 >= --mInFlight) {
- ((AnimationDrawable) root.getBackground()).stop();
- root.setBackgroundDrawable(bg);
- }
-
- message.setText(msg);
- }
-
- // runs on its own thread
- @Override protected String doInBackground(String... args) {
- return ((1 != args.length) || (null == args[0]))
- ? null
- : game.initialize(args[0], this);
- }
-
- // runs on the UI thread
- @Override protected void onProgressUpdate(Integer... vals) {
- updateProgressBar(vals[0].intValue());
- }
-
- // runs on its own thread
- @Override public void onInitProgress(int pctComplete) {
- publishProgress(Integer.valueOf(pctComplete));
- }
- }
-
- int mInFlight;
- int mComplete;
-
- /** @see android.app.Activity#onCreate(android.os.Bundle) */
- @Override
- public void onCreate(Bundle state) {
- super.onCreate(state);
-
- setContentView(R.layout.asyncdemoprogress);
-
- final View dots = findViewById(R.id.dots);
- final Drawable bg = dots.getBackground();
-
- final TextView msg = ((TextView) findViewById(R.id.msg));
-
- final Game game = Game.newGame();
-
- ((Button) findViewById(R.id.start)).setOnClickListener(
- new View.OnClickListener() {
- @Override public void onClick(View v) {
- mComplete = 0;
- new AsyncInit(
- dots,
- bg,
- game,
- msg)
- .execute("basic");
- } });
- }
-
- void updateProgressBar(int progress) {
- int p = progress;
- if (mComplete < p) {
- mComplete = p;
- ((ProgressBar) findViewById(R.id.progress))
- .setProgress(p);
- }
- }
-}
View
92 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskSample.java
@@ -1,92 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06;
-
-import java.net.URI;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.Map;
-
-import android.os.AsyncTask;
-import android.view.View;
-import android.widget.Button;
-
-import org.apache.http.HttpResponse;
-
-
-/**
- *
- * @version $Revision: $
- * @author <a href="mailto:bmeike@callmeike.net">Blake Meike</a>
- */
-public class AsyncTaskSample {
-
- public class AsyncDBReq
- extends AsyncTask<PreparedStatement, Void, ResultSet>
- {
- @Override
- protected ResultSet doInBackground(PreparedStatement... q) {
- // implementation...
- return null;
- }
-
- @Override
- protected void onPostExecute(ResultSet result) {
- // implementation...
- }
- }
-
- public class AsyncContentReq
- extends AsyncTask<URI, Void, HttpResponse>
- {
- @Override
- protected HttpResponse doInBackground(URI... req) {
- // implementation...
- return null;
- }
-
-
- @Override
- protected void onPostExecute(HttpResponse result) {
- // implementation...
- }
- }
-
- int mCount;
-
- public void initButton1( Button button) {
- mCount = 0;
- button.setOnClickListener(
- new View.OnClickListener() {
- @Override public void onClick(View v) {
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... args) {
- mCount++; // !!! NOT THREAD SAFE!
- return null;
- }
- }.execute();
- } });
- }
-
- public void initButton2(
- Button button,
- final Map<String, String> vals)
- {
- button.setOnClickListener(
- new View.OnClickListener() {
- @SuppressWarnings("unchecked")
- @Override public void onClick(View v) {
- new AsyncTask<Map<String, String>, Void, Void>() {
- @Override
- protected Void doInBackground(
- Map<String, String>... params)
- {
- // examine the map
- return null;
- }
- }.execute(vals);
- vals.clear(); // !!! NOT THREAD SAFE!
- } });
- }
-}
View
68 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/game/Game.java
@@ -1,68 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06.game;
-
-
-/**
- *
- * @version $Revision: $
- * @author <a href="mailto:bmeike@callmeike.net">Blake Meike</a>
- */
-public abstract class Game {
-
- /** ProgressListener */
- public static interface InitProgressListener {
- /** @param percentComplete */
- void onInitProgress(int percentComplete);
- }
-
- /**
- * Game factory.
- *
- * @return the game object
- */
- public static Game newGame() { return new MockGame(); }
-
-
- private String level;
- private InitProgressListener progressListener;
-
-
- /** @return the size of the content, in bytes */
- protected abstract String init();
-
- /** @return return the game level */
- public final String getLevel() { return level; }
-
- /** @return return the progress listener */
- public final InitProgressListener getProgressListener() {
- return progressListener;
- }
-
- /**
- * Initialize the game
- *
- * @param lvl the game level
- * @return a welcome message
- */
- public final String initialize(String lvl) {
- return initialize(lvl, null);
- }
-
- /**
- * Initialize the game
- *
- * @param lvl the game level
- * @param lstnr the progress listener
- *
- * @return a welcome message
- */
- public final String initialize(
- String lvl,
- InitProgressListener lstnr)
- {
- level = lvl;
- progressListener = lstnr;
- return init();
- }
-}
View
39 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/game/MockGame.java
@@ -1,39 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06.game;
-
-
-/**
- *
- * A mock service
- */
-public class MockGame extends Game {
- /** Modeled network latency */
- public static final int LATENCY = 10;
-
- private static long serial = 1;
-
- private static synchronized long incSerial() { return serial++; }
-
- /**
- * Fake a game initialization, modeling latency
- *
- * @return an initialization message
- */
- @Override public String init() {
- InitProgressListener lstnr = getProgressListener();
-
- for (int i = 0; i < LATENCY; i++) {
- try { Thread.sleep(1000); }
- catch (InterruptedException e) { }
-
- if (null != lstnr) {
- lstnr.onInitProgress(((i + 1) * 100) / LATENCY);
- }
- }
-
- return "Game " + incSerial()
- + ", level " + getLevel() + ", ready!";
- }
-
-}
View
33 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/game/PersistentModel.java
@@ -1,33 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06.game;
-
-import android.os.Handler;
-import android.os.Looper;
-
-
-/**
- *
- * @version $Revision: $
- * @author <a href="mailto:bmeike@callmeike.net">Blake Meike</a>
- */
-public class PersistentModel implements Runnable {
- private final Handler ui;
-
- /**
- * @param ui
- */
- public PersistentModel(Handler ui) { this.ui = ui; }
-
- /** @see java.lang.Runnable#run() */
- @Override
- public void run() {
- Looper.prepare();
- Looper.loop();
- }
-
- public Handler getHandler() {
- // TODO Auto-generated method stub
- return null;
- }
-}
View
7 06/AsyncTaskDemo/tools/ide/eclipse/classpath
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
View
0 06/AsyncTaskDemo/tools/ide/eclipse/project
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
5 06/JSerializable/.gitignore
@@ -1,5 +0,0 @@
-/gen
-/assets
-/.project
-/.classpath
-/bin
View
20 06/JSerializable/AndroidManifest.xml
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.oreilly.android.demo"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:targetSdkVersion="9"></uses-sdk>
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name="com.oreilly.demo.android.ch06.JSerialize"
- 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>
View
11 06/JSerializable/default.properties
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=Google Inc.:Google APIs:9
View
0 06/JSerializable/res/drawable-hdpi/icon.png
Deleted file not rendered
View
0 06/JSerializable/res/drawable-ldpi/icon.png
Deleted file not rendered
View
0 06/JSerializable/res/drawable-mdpi/icon.png
Deleted file not rendered
View
12 06/JSerializable/res/layout/main.xml
@@ -1,12 +0,0 @@
-<?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"
- />
-</LinearLayout>
View
0 06/JSerializable/res/values/strings.xml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
61 06/JSerializable/src/com/oreilly/demo/android/ch06/JSerialize.java
@@ -1,61 +0,0 @@
-/* $Id: $
- */
-package com.oreilly.demo.android.ch06;
-
-import java.io.Serializable;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.os.Parcel;
-
-import com.oreilly.android.demo.R;
-
-
-/**
- *
- * @version $Revision: $
- * @author <a href="mailto:bmeike@callmeike.net">Blake Meike</a>
- */
-public class JSerialize extends Activity {
- public static final String APP_STATE
- = "com.oreilly.android.app.state";
-
- private static class AppState implements Serializable {
- // definitions, getters and setters
- // for application state parameters here.
- // ...
- }
-
- private AppState applicationState;
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedAppState) {
- super.onCreate(savedAppState);
-
- applicationState = (null == savedAppState)
- ? new AppState(/* ... */)
- : (AppState) savedAppState.getSerializable(APP_STATE);
-
- setContentView(R.layout.main);
-
- Bundle bundle = new Bundle();
- bundle.putFloat(APP_STATE, 3.14159F);
-
- Parcel p = Parcel.obtain();
- p.writeBundle(bundle);
-
- p.setDataPosition(0);
- bundle = p.readBundle();
- bundle.getInt(APP_STATE);
- }
-
- /**
- * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
- */
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putSerializable(APP_STATE, applicationState);
- }
-}
View
7 06/JSerializable/tools/ide/eclipse/classpath
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
View
0 06/JSerializable/tools/ide/eclipse/project
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
5 07/AndroidUIDemo/.gitignore
@@ -1,5 +0,0 @@
-/gen
-/assets
-/.project
-/.classpath
-/bin
View
15 07/AndroidUIDemo/AndroidManifest.xml
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- android:versionCode="1"
- android:versionName="1.0.0" package="com.oreilly.demo.android.ch07">
- <uses-sdk android:targetSdkVersion="9"></uses-sdk>
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".TouchMe"
- 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>
View
22 07/AndroidUIDemo/default.properties
@@ -1,22 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# apk configurations. This property allows creation of APK files with limited
-# resources. For example, if your application contains many locales and
-# you wish to release multiple smaller apks instead of a large one, you can
-# define configuration to create apks with limited language sets.
-# Format is a comma separated list of configuration names. For each
-# configuration, a property will declare the resource configurations to
-# include. Example:
-# apk-configurations=european,northamerica
-# apk-config-european=en,fr,it,de,es
-# apk-config-northamerica=en,es
-apk-configurations=
-# Project target.
-target=Google Inc.:Google APIs:9
View
0 07/AndroidUIDemo/res/drawable-hdpi/icon.png
Deleted file not rendered
View
0 07/AndroidUIDemo/res/drawable-ldpi/icon.png
Deleted file not rendered
View
0 07/AndroidUIDemo/res/drawable-mdpi/icon.png
Deleted file not rendered
View
56 07/AndroidUIDemo/res/layout/main.xml
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/root"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- android:background="@drawable/lt_grey"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
-
- <LinearLayout
- android:orientation="horizontal"
- android:background="@drawable/grey"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
-
- <EditText
- android:id="@+id/text1"
- android:text="@string/defaultText"
- android:focusable="false"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
-
- <EditText
- android:id="@+id/text2"
- android:text="@string/defaultText"
- android:focusable="false"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
- </LinearLayout>
-
- <LinearLayout
- android:orientation="horizontal"
- android:background="@drawable/dk_grey"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
-
- <Button
- android:id="@+id/button1"
- android:text="@string/labelRed"
- android:textColor="@drawable/red"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
-
- <Button
- android:id="@+id/button2"
- android:text="@string/labelGreen"
- android:textColor="@drawable/green"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
- </LinearLayout>
-</LinearLayout>
View
9 07/AndroidUIDemo/res/values/colors.xml
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<resources>
- <drawable name="red">#ffff0000</drawable>
- <drawable name="green">#ff00ff00</drawable>
- <drawable name="lt_grey">#dddddd</drawable>
- <drawable name="grey">#999999</drawable>
- <drawable name="dk_grey">#666666</drawable>
-</resources>
View
7 07/AndroidUIDemo/res/values/strings.xml
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <string name="app_name">TouchMe</string>
- <string name="defaultText">0</string>
- <string name="labelRed">Red</string>
- <string name="labelGreen">Green</string>
-</resources>
View
250 07/AndroidUIDemo/src/com/oreilly/demo/android/ch07/TouchMe.java