下面列出了android.app.ActivityOptions#toBundle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void toLogin(View v) {
final android.util.Pair[] pairs =
TransitionHelper.createSafeTransitionParticipants
(
activity,
false,
new android.util.Pair<>(v, LoginActivity.VIEW_TOOLBAR_TITLE)
);
if ((v != null) && (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP)) {
ActivityOptions sceneTransitionAnimation = ActivityOptions
.makeSceneTransitionAnimation(activity, pairs);
final Bundle transitionBundle = sceneTransitionAnimation.toBundle();
Intent loginLollipopIntent = new Intent(activity, LoginActivity.class);
ActivityCompat.startActivity(activity, loginLollipopIntent, transitionBundle);
} else {
Intent loginIntent = new Intent(activity, LoginActivity.class);
ActivityCompat.startActivity(activity, loginIntent, null);
activity.overridePendingTransition(0, 0);
}
}
/**
* Merges two activity options into one, with {@code options2} taking precedence in case of a
* conflict.
*/
@VisibleForTesting
@Nullable ActivityOptions mergeActivityOptions(@Nullable ActivityOptions options1,
@Nullable ActivityOptions options2) {
if (options1 == null) {
return options2;
}
if (options2 == null) {
return options1;
}
final Bundle b1 = options1.toBundle();
final Bundle b2 = options2.toBundle();
b1.putAll(b2);
return ActivityOptions.fromBundle(b1);
}
/**
* Creates an ActivityOptions Bundle with basic options and the LaunchDisplayId set.
* @param displayId The id of the display to launch into.
* @return The created bundle, or null if unsupported.
*/
public static Bundle createLaunchDisplayIdActivityOptions(int displayId) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return null;
ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchDisplayId(displayId);
return options.toBundle();
}
private static Bundle getActivityOptionsBundle(Context context,
ApplicationType applicationType,
View view,
int left,
int top,
int right,
int bottom) {
ActivityOptions options = getActivityOptions(context, applicationType, view);
if(options == null) return null;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
return options.toBundle();
return options.setLaunchBounds(new Rect(left, top, right, bottom)).toBundle();
}
private Bundle getActivityAnimationOpts(View view) {
Bundle bundle = null;
if (view == null) {
return null;
}
ActivityOptions options = null;
if (VERSION.SDK_INT >= 23) {
int left = 0;
int top = 0;
int width = view.getMeasuredWidth();
int height = view.getMeasuredHeight();
if (view instanceof AppItemView) {
width = (int) ((AppItemView) view).getIconSize();
left = (int) ((AppItemView) view).getDrawIconLeft();
top = (int) ((AppItemView) view).getDrawIconTop();
}
options = ActivityOptions.makeClipRevealAnimation(view, left, top, width, height);
} else if (VERSION.SDK_INT < 21) {
options = ActivityOptions.makeScaleUpAnimation(view, 0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
}
if (options != null) {
bundle = options.toBundle();
}
return bundle;
}