Update animation sample to use new activity options API.
Change-Id: Id73663f1e5f159c5b073cd9c074501958ca5a81f
This commit is contained in:
@@ -38,5 +38,16 @@
|
||||
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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.example.android.apis.R;
|
||||
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 @@ public class Animation extends Activity {
|
||||
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 @@ public class Animation extends Activity {
|
||||
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());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user