Skip to content

Commit a99869d

Browse files
committed
Fixed to match ch08
1 parent 15fb7ba commit a99869d

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

AndroidViewDemo/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
android:versionCode="1"
44
android:versionName="1.0.0" package="com.oreilly.demo.android.pa.viewdemo">
55
<uses-sdk android:targetSdkVersion="14"></uses-sdk>
6-
<application android:icon="@drawable/icon" android:label="@string/app_name">
6+
<application
7+
android:icon="@drawable/icon"
8+
android:label="@string/app_name"
9+
android:hardwareAccelerated="true">
710
<activity android:name=".TransformIt"
811
android:label="@string/app_name">
912
<intent-filter>

AndroidViewDemo/res/drawable/throbber.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<animation-list
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:oneshot="false">
5-
<item android:drawable="@drawable/throbber_f0" android:duration="70" />
6-
<item android:drawable="@drawable/throbber_f1" android:duration="70" />
7-
<item android:drawable="@drawable/throbber_f2" android:duration="70" />
8-
<item android:drawable="@drawable/throbber_f3" android:duration="70" />
9-
<item android:drawable="@drawable/throbber_f4" android:duration="70" />
10-
<item android:drawable="@drawable/throbber_f5" android:duration="70" />
11-
<item android:drawable="@drawable/throbber_f6" android:duration="70" />
5+
<item android:drawable="@drawable/throbber_f0" android:duration="160" />
6+
<item android:drawable="@drawable/throbber_f1" android:duration="140" />
7+
<item android:drawable="@drawable/throbber_f2" android:duration="120" />
8+
<item android:drawable="@drawable/throbber_f3" android:duration="100" />
9+
<item android:drawable="@drawable/throbber_f4" android:duration="120" />
10+
<item android:drawable="@drawable/throbber_f5" android:duration="140" />
11+
<item android:drawable="@drawable/throbber_f6" android:duration="160" />
1212
</animation-list>

AndroidViewDemo/src/com/oreilly/demo/android/pa/viewdemo/TransformIt.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public class TransformIt extends Activity {
3636
/** the view up next */
3737
View next;
3838

39+
private AnimationDrawable throbber;
3940
private GLDemoWidget glWidget;
41+
private View efxView;
4042

4143

4244
/** @see android.app.Activity#onCreate(android.os.Bundle) */
@@ -55,10 +57,13 @@ public void onCreate(Bundle savedInstanceState) {
5557
// and the next one
5658
next = findViewById(R.id.efx_v);
5759
next.setVisibility(View.GONE);
58-
buildEfxView(
60+
throbber = buildEfxView(
5961
(LinearLayout) findViewById(R.id.efx_v_left),
6062
(LinearLayout) findViewById(R.id.efx_v_right));
6163

64+
glWidget = (GLDemoWidget) findViewById(R.id.efx_gl);
65+
efxView = next;
66+
6267
// install the animation click listener
6368
final View root = findViewById(R.id.main);
6469
findViewById(R.id.main).setOnClickListener(
@@ -70,6 +75,7 @@ public void onCreate(Bundle savedInstanceState) {
7075
View t = cur;
7176
cur = next;
7277
next = t;
78+
toggleThrobber();
7379
} });
7480
}
7581

@@ -136,7 +142,7 @@ private void buildXformView(LinearLayout lv, LinearLayout rv) {
136142
} }));
137143
}
138144

139-
private void buildEfxView(LinearLayout lv, LinearLayout rv) {
145+
private AnimationDrawable buildEfxView(LinearLayout lv, LinearLayout rv) {
140146
lv.addView(new EffectsWidget(
141147
this,
142148
1,
@@ -200,13 +206,10 @@ private void buildEfxView(LinearLayout lv, LinearLayout rv) {
200206
rv.addView(w);
201207
w.setBackgroundResource(R.drawable.throbber);
202208

203-
w.setOnClickListener(new OnClickListener() {
204-
@Override public void onClick(View v) {
205-
AnimationDrawable animation
206-
= (AnimationDrawable) v.getBackground();
207-
if (animation.isRunning()) { animation.stop(); }
208-
else { animation.start(); }
209-
} });
209+
lv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
210+
rv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
211+
212+
return (AnimationDrawable) w.getBackground();
210213
}
211214

212215
/**
@@ -215,6 +218,7 @@ private void buildEfxView(LinearLayout lv, LinearLayout rv) {
215218
@Override
216219
protected void onPause() {
217220
super.onPause();
221+
if (null != throbber) { throbber.stop(); }
218222
if (null != glWidget) { glWidget.onPause(); }
219223
}
220224

@@ -224,6 +228,14 @@ protected void onPause() {
224228
@Override
225229
protected void onResume() {
226230
super.onResume();
231+
toggleThrobber();
227232
if (null != glWidget) { glWidget.onResume(); }
228233
}
234+
235+
void toggleThrobber() {
236+
if (null != throbber) {
237+
if (efxView.equals(cur)) { throbber.start(); }
238+
else { throbber.stop(); }
239+
}
240+
}
229241
}

AndroidViewDemo/src/com/oreilly/demo/android/pa/viewdemo/efx/RotationTransitionAnimation.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ public class RotationTransitionAnimation
2828
/** the transition target */
2929
final View nextView;
3030

31+
final float xCenter;
32+
final float yCenter;
33+
3134
private final int dir;
32-
private final float xCenter;
33-
private final float yCenter;
3435
private final Camera camera = new Camera();
3536

3637
/**
@@ -55,8 +56,22 @@ public RotationTransitionAnimation(
5556
curView = cur;
5657
nextView = nxt;
5758

58-
xCenter = root.getWidth() / 2.0f;
59-
yCenter = root.getHeight() / 2.0f;
59+
xCenter = cur.getWidth() / 2.0f;
60+
yCenter = cur.getHeight() / 2.0f;
61+
}
62+
63+
RotationTransitionAnimation(
64+
View r,
65+
View cur,
66+
float xc,
67+
float yc)
68+
{
69+
dir = -1;
70+
root = r;
71+
curView = cur;
72+
nextView = null;
73+
xCenter = xc;
74+
yCenter = yc;
6075
}
6176

6277
/**
@@ -98,8 +113,8 @@ public void onAnimationEnd(Animation animation) {
98113
curView.setVisibility(View.GONE);
99114
nextView.setVisibility(View.VISIBLE);
100115
nextView.requestFocus();
101-
new RotationTransitionAnimation(-1, root, nextView, null)
102-
. animateOnce(new DecelerateInterpolator(), null);
116+
new RotationTransitionAnimation(root, nextView, xCenter, yCenter)
117+
.animateOnce(new DecelerateInterpolator(), null);
103118
} });
104119
}
105120

0 commit comments

Comments
 (0)