Skip to content

Commit cce4108

Browse files
committed
Make the most complex version of AsyncTaskDemo the default, and fix it to use the smaller images
1 parent 77aaf46 commit cce4108

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

06/AsyncTaskDemo/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:versionName="1.0" package="com.oreilly.demo.android.ch06">
55
<uses-sdk android:targetSdkVersion="9"></uses-sdk>
66
<application android:icon="@drawable/icon" android:label="@string/app_name">
7-
<activity android:name=".AsyncTaskDemo"
7+
<activity android:name=".AsyncTaskDemoWithProgress"
88
android:label="@string/app_name">
99
<intent-filter>
1010
<action android:name="android.intent.action.MAIN" />

06/AsyncTaskDemo/res/layout/asyncdemoprogress.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@
2929
android:textColor="@android:color/black"
3030
/>
3131

32+
<FrameLayout
33+
android:id="@+id/dots"
34+
android:layout_width="fill_parent"
35+
android:layout_height="wrap_content"
36+
/>
37+
3238
</LinearLayout>

06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void onCreate(Bundle state) {
9999
* DO NOT USE!!
100100
*/
101101
void initGame(
102-
View root,
102+
View dots,
103103
Drawable bg,
104104
Game game,
105105
TextView resp,
@@ -108,8 +108,8 @@ void initGame(
108108
// if the animation hasn't been started,
109109
// initialize and start it
110110
if (0 >= mInFlight++ ) {
111-
root.setBackgroundResource(R.anim.dots);
112-
((AnimationDrawable) root.getBackground()).start();
111+
dots.setBackgroundResource(R.anim.dots);
112+
((AnimationDrawable) dots.getBackground()).start();
113113
}
114114

115115
// get the response from the remote service
@@ -118,8 +118,8 @@ void initGame(
118118
// if this is the last running initialization
119119
// remove and clean up the animation
120120
if (0 >= --mInFlight) {
121-
((AnimationDrawable) root.getBackground()).stop();
122-
root.setBackgroundDrawable(bg);
121+
((AnimationDrawable) dots.getBackground()).stop();
122+
dots.setBackgroundDrawable(bg);
123123
}
124124

125125
resp.setText(msg);

06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemoWithProgress.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ private final class AsyncInit
2121
extends AsyncTask<String, Integer, String>
2222
implements Game.InitProgressListener
2323
{
24-
private final View root;
24+
private final View dots;
2525
private final Game game;
2626
private final TextView message;
2727
private final Drawable bg;
2828

2929
public AsyncInit(
30-
View root,
30+
View dots,
3131
Drawable bg,
3232
Game game,
3333
TextView msg)
3434
{
35-
this.root = root;
35+
this.dots = dots;
3636
this.bg = bg;
3737
this.game = game;
3838
this.message = msg;
@@ -41,16 +41,16 @@ public AsyncInit(
4141
// runs on the UI thread
4242
@Override protected void onPreExecute() {
4343
if (0 >= mInFlight++) {
44-
root.setBackgroundResource(R.anim.dots);
45-
((AnimationDrawable) root.getBackground()).start();
44+
dots.setBackgroundResource(R.anim.dots);
45+
((AnimationDrawable) dots.getBackground()).start();
4646
}
4747
}
4848

4949
// runs on the UI thread
5050
@Override protected void onPostExecute(String msg) {
5151
if (0 >= --mInFlight) {
52-
((AnimationDrawable) root.getBackground()).stop();
53-
root.setBackgroundDrawable(bg);
52+
((AnimationDrawable) dots.getBackground()).stop();
53+
dots.setBackgroundDrawable(bg);
5454
}
5555

5656
message.setText(msg);
@@ -82,8 +82,8 @@ public void onCreate(Bundle state) {
8282

8383
setContentView(R.layout.asyncdemoprogress);
8484

85-
final View root = findViewById(R.id.root);
86-
final Drawable bg = root.getBackground();
85+
final View dots = findViewById(R.id.dots);
86+
final Drawable bg = dots.getBackground();
8787

8888
final TextView msg = ((TextView) findViewById(R.id.msg));
8989

@@ -94,7 +94,7 @@ public void onCreate(Bundle state) {
9494
@Override public void onClick(View v) {
9595
mComplete = 0;
9696
new AsyncInit(
97-
root,
97+
dots,
9898
bg,
9999
game,
100100
msg)

0 commit comments

Comments
 (0)