Permalink
Browse files

Make the most complex version of AsyncTaskDemo the default, and fix i…

…t to use the smaller images
  • Loading branch information...
1 parent 77aaf46 commit cce410834cc270ff1a2d30bbad5c249b23751f3f @bmeike bmeike committed Jul 18, 2011
View
2 06/AsyncTaskDemo/AndroidManifest.xml
@@ -4,7 +4,7 @@
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=".AsyncTaskDemo"
+ <activity android:name=".AsyncTaskDemoWithProgress"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
View
6 06/AsyncTaskDemo/res/layout/asyncdemoprogress.xml
@@ -29,4 +29,10 @@
android:textColor="@android:color/black"
/>
+ <FrameLayout
+ android:id="@+id/dots"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ />
+
</LinearLayout>
View
10 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemo.java
@@ -99,7 +99,7 @@ public void onCreate(Bundle state) {
* DO NOT USE!!
*/
void initGame(
- View root,
+ View dots,
Drawable bg,
Game game,
TextView resp,
@@ -108,8 +108,8 @@ void initGame(
// if the animation hasn't been started,
// initialize and start it
if (0 >= mInFlight++ ) {
- root.setBackgroundResource(R.anim.dots);
- ((AnimationDrawable) root.getBackground()).start();
+ dots.setBackgroundResource(R.anim.dots);
+ ((AnimationDrawable) dots.getBackground()).start();
}
// get the response from the remote service
@@ -118,8 +118,8 @@ void initGame(
// if this is the last running initialization
// remove and clean up the animation
if (0 >= --mInFlight) {
- ((AnimationDrawable) root.getBackground()).stop();
- root.setBackgroundDrawable(bg);
+ ((AnimationDrawable) dots.getBackground()).stop();
+ dots.setBackgroundDrawable(bg);
}
resp.setText(msg);
View
20 06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemoWithProgress.java
@@ -21,18 +21,18 @@
extends AsyncTask<String, Integer, String>
implements Game.InitProgressListener
{
- private final View root;
+ private final View dots;
private final Game game;
private final TextView message;
private final Drawable bg;
public AsyncInit(
- View root,
+ View dots,
Drawable bg,
Game game,
TextView msg)
{
- this.root = root;
+ this.dots = dots;
this.bg = bg;
this.game = game;
this.message = msg;
@@ -41,16 +41,16 @@ public AsyncInit(
// runs on the UI thread
@Override protected void onPreExecute() {
if (0 >= mInFlight++) {
- root.setBackgroundResource(R.anim.dots);
- ((AnimationDrawable) root.getBackground()).start();
+ dots.setBackgroundResource(R.anim.dots);
+ ((AnimationDrawable) dots.getBackground()).start();
}
}
// runs on the UI thread
@Override protected void onPostExecute(String msg) {
if (0 >= --mInFlight) {
- ((AnimationDrawable) root.getBackground()).stop();
- root.setBackgroundDrawable(bg);
+ ((AnimationDrawable) dots.getBackground()).stop();
+ dots.setBackgroundDrawable(bg);
}
message.setText(msg);
@@ -82,8 +82,8 @@ public void onCreate(Bundle state) {
setContentView(R.layout.asyncdemoprogress);
- final View root = findViewById(R.id.root);
- final Drawable bg = root.getBackground();
+ final View dots = findViewById(R.id.dots);
+ final Drawable bg = dots.getBackground();
final TextView msg = ((TextView) findViewById(R.id.msg));
@@ -94,7 +94,7 @@ public void onCreate(Bundle state) {
@Override public void onClick(View v) {
mComplete = 0;
new AsyncInit(
- root,
+ dots,
bg,
game,
msg)

0 comments on commit cce4108

Please sign in to comment.