Update animation sample to use new activity options API.
Change-Id: Id73663f1e5f159c5b073cd9c074501958ca5a81f
diff --git a/samples/ApiDemos/res/layout/activity_animation.xml b/samples/ApiDemos/res/layout/activity_animation.xml
index 2432c90..34db58b 100644
--- a/samples/ApiDemos/res/layout/activity_animation.xml
+++ b/samples/ApiDemos/res/layout/activity_animation.xml
@@ -28,15 +28,26 @@
android:text="@string/activity_animation_msg"/>
<Button android:id="@+id/fade_animation"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/activity_animation_fade">
<requestFocus />
</Button>
<Button android:id="@+id/zoom_animation"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/activity_animation_zoom">
</Button>
+ <Button android:id="@+id/modern_fade_animation"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/activity_modern_animation_fade">
+ <requestFocus />
+ </Button>
+
+ <Button android:id="@+id/modern_zoom_animation"
+ android:layout_width="wrap_content" android:layout_height="wrap_content"
+ android:text="@string/activity_modern_animation_zoom">
+ </Button>
+
</LinearLayout>
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index fd15983..0b68807 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -64,6 +64,8 @@
<string name="activity_animation_msg">Press a button to launch an activity with a custom animation.</string>
<string name="activity_animation_fade">Fade in</string>
<string name="activity_animation_zoom">Zoom in</string>
+ <string name="activity_modern_animation_fade">Modern fade in</string>
+ <string name="activity_modern_animation_zoom">Modern zoom in</string>
<string name="activity_save_restore">App/Activity/Save & Restore State</string>
<string name="save_restore_msg">Demonstration of saving and restoring activity state in onSaveInstanceState() and onCreate().</string>
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/Animation.java b/samples/ApiDemos/src/com/example/android/apis/app/Animation.java
index bd2bd89..5d55691 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/Animation.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/Animation.java
@@ -22,6 +22,7 @@
import com.example.android.apis.view.Controls1;
import android.app.Activity;
+import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@@ -44,6 +45,15 @@
button.setOnClickListener(mFadeListener);
button = (Button)findViewById(R.id.zoom_animation);
button.setOnClickListener(mZoomListener);
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
+ button = (Button)findViewById(R.id.modern_fade_animation);
+ button.setOnClickListener(mModernFadeListener);
+ button = (Button)findViewById(R.id.modern_zoom_animation);
+ button.setOnClickListener(mModernZoomListener);
+ } else {
+ findViewById(R.id.modern_fade_animation).setEnabled(false);
+ findViewById(R.id.modern_zoom_animation).setEnabled(false);
+ }
}
private OnClickListener mFadeListener = new OnClickListener() {
@@ -70,5 +80,33 @@
overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
}
};
+
+ private OnClickListener mModernFadeListener = new OnClickListener() {
+ public void onClick(View v) {
+ // Create the desired custom animation, involving transformations
+ // on both this (exit) and the new (enter) activity. Note how for
+ // the duration of the animation we force the exiting activity
+ // to be Z-ordered on top (even though it really isn't) to achieve
+ // the effect we want.
+ ActivityOptions opts = ActivityOptions.makeCustomAnimation(Animation.this,
+ R.anim.fade, R.anim.hold);
+ // Request the activity be started, using the custom animation options.
+ startActivity(new Intent(Animation.this, Controls1.class), opts.toBundle());
+ }
+ };
+
+ private OnClickListener mModernZoomListener = new OnClickListener() {
+ public void onClick(View v) {
+ // Create a more complicated animation, involving transformations
+ // on both this (exit) and the new (enter) activity. Note how for
+ // the duration of the animation we force the exiting activity
+ // to be Z-ordered on top (even though it really isn't) to achieve
+ // the effect we want.
+ ActivityOptions opts = ActivityOptions.makeCustomAnimation(Animation.this,
+ R.anim.zoom_enter, R.anim.zoom_enter);
+ // Request the activity be started, using the custom animation options.
+ startActivity(new Intent(Animation.this, Controls1.class), opts.toBundle());
+ }
+ };
}