Permalink
Browse files

Fixed to match ch08

  • Loading branch information...
1 parent 15fb7ba commit a99869d08daa2e8e3ddf334c936e545987c6ffc3 @bmeike committed Mar 6, 2012
@@ -3,7 +3,10 @@
android:versionCode="1"
android:versionName="1.0.0" package="com.oreilly.demo.android.pa.viewdemo">
<uses-sdk android:targetSdkVersion="14"></uses-sdk>
- <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <application
+ android:icon="@drawable/icon"
+ android:label="@string/app_name"
+ android:hardwareAccelerated="true">
<activity android:name=".TransformIt"
android:label="@string/app_name">
<intent-filter>
@@ -2,11 +2,11 @@
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
- <item android:drawable="@drawable/throbber_f0" android:duration="70" />
- <item android:drawable="@drawable/throbber_f1" android:duration="70" />
- <item android:drawable="@drawable/throbber_f2" android:duration="70" />
- <item android:drawable="@drawable/throbber_f3" android:duration="70" />
- <item android:drawable="@drawable/throbber_f4" android:duration="70" />
- <item android:drawable="@drawable/throbber_f5" android:duration="70" />
- <item android:drawable="@drawable/throbber_f6" android:duration="70" />
+ <item android:drawable="@drawable/throbber_f0" android:duration="160" />
+ <item android:drawable="@drawable/throbber_f1" android:duration="140" />
+ <item android:drawable="@drawable/throbber_f2" android:duration="120" />
+ <item android:drawable="@drawable/throbber_f3" android:duration="100" />
+ <item android:drawable="@drawable/throbber_f4" android:duration="120" />
+ <item android:drawable="@drawable/throbber_f5" android:duration="140" />
+ <item android:drawable="@drawable/throbber_f6" android:duration="160" />
</animation-list>
@@ -36,7 +36,9 @@
/** the view up next */
View next;
+ private AnimationDrawable throbber;
private GLDemoWidget glWidget;
+ private View efxView;
/** @see android.app.Activity#onCreate(android.os.Bundle) */
@@ -55,10 +57,13 @@ public void onCreate(Bundle savedInstanceState) {
// and the next one
next = findViewById(R.id.efx_v);
next.setVisibility(View.GONE);
- buildEfxView(
+ throbber = buildEfxView(
(LinearLayout) findViewById(R.id.efx_v_left),
(LinearLayout) findViewById(R.id.efx_v_right));
+ glWidget = (GLDemoWidget) findViewById(R.id.efx_gl);
+ efxView = next;
+
// install the animation click listener
final View root = findViewById(R.id.main);
findViewById(R.id.main).setOnClickListener(
@@ -70,6 +75,7 @@ public void onCreate(Bundle savedInstanceState) {
View t = cur;
cur = next;
next = t;
+ toggleThrobber();
} });
}
@@ -136,7 +142,7 @@ private void buildXformView(LinearLayout lv, LinearLayout rv) {
} }));
}
- private void buildEfxView(LinearLayout lv, LinearLayout rv) {
+ private AnimationDrawable buildEfxView(LinearLayout lv, LinearLayout rv) {
lv.addView(new EffectsWidget(
this,
1,
@@ -200,13 +206,10 @@ private void buildEfxView(LinearLayout lv, LinearLayout rv) {
rv.addView(w);
w.setBackgroundResource(R.drawable.throbber);
- w.setOnClickListener(new OnClickListener() {
- @Override public void onClick(View v) {
- AnimationDrawable animation
- = (AnimationDrawable) v.getBackground();
- if (animation.isRunning()) { animation.stop(); }
- else { animation.start(); }
- } });
+ lv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+ rv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+
+ return (AnimationDrawable) w.getBackground();
}
/**
@@ -215,6 +218,7 @@ private void buildEfxView(LinearLayout lv, LinearLayout rv) {
@Override
protected void onPause() {
super.onPause();
+ if (null != throbber) { throbber.stop(); }
if (null != glWidget) { glWidget.onPause(); }
}
@@ -224,6 +228,14 @@ protected void onPause() {
@Override
protected void onResume() {
super.onResume();
+ toggleThrobber();
if (null != glWidget) { glWidget.onResume(); }
}
+
+ void toggleThrobber() {
+ if (null != throbber) {
+ if (efxView.equals(cur)) { throbber.start(); }
+ else { throbber.stop(); }
+ }
+ }
}
@@ -28,9 +28,10 @@
/** the transition target */
final View nextView;
+ final float xCenter;
+ final float yCenter;
+
private final int dir;
- private final float xCenter;
- private final float yCenter;
private final Camera camera = new Camera();
/**
@@ -55,8 +56,22 @@ public RotationTransitionAnimation(
curView = cur;
nextView = nxt;
- xCenter = root.getWidth() / 2.0f;
- yCenter = root.getHeight() / 2.0f;
+ xCenter = cur.getWidth() / 2.0f;
+ yCenter = cur.getHeight() / 2.0f;
+ }
+
+ RotationTransitionAnimation(
+ View r,
+ View cur,
+ float xc,
+ float yc)
+ {
+ dir = -1;
+ root = r;
+ curView = cur;
+ nextView = null;
+ xCenter = xc;
+ yCenter = yc;
}
/**
@@ -98,8 +113,8 @@ public void onAnimationEnd(Animation animation) {
curView.setVisibility(View.GONE);
nextView.setVisibility(View.VISIBLE);
nextView.requestFocus();
- new RotationTransitionAnimation(-1, root, nextView, null)
- . animateOnce(new DecelerateInterpolator(), null);
+ new RotationTransitionAnimation(root, nextView, xCenter, yCenter)
+ .animateOnce(new DecelerateInterpolator(), null);
} });
}

0 comments on commit a99869d

Please sign in to comment.