ActivityOptions.java revision 125578a8637a9ad5e7430d16b9fc0096a8b596d7
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.app; 18 19import android.content.Context; 20import android.content.Intent; 21import android.graphics.Bitmap; 22import android.os.Bundle; 23import android.os.Handler; 24import android.os.IRemoteCallback; 25import android.os.RemoteException; 26import android.os.ResultReceiver; 27import android.util.Pair; 28import android.view.View; 29import android.view.Window; 30 31import java.util.ArrayList; 32 33/** 34 * Helper class for building an options Bundle that can be used with 35 * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle) 36 * Context.startActivity(Intent, Bundle)} and related methods. 37 */ 38public class ActivityOptions { 39 private static final String TAG = "ActivityOptions"; 40 41 /** 42 * The package name that created the options. 43 * @hide 44 */ 45 public static final String KEY_PACKAGE_NAME = "android:packageName"; 46 47 /** 48 * Type of animation that arguments specify. 49 * @hide 50 */ 51 public static final String KEY_ANIM_TYPE = "android:animType"; 52 53 /** 54 * Custom enter animation resource ID. 55 * @hide 56 */ 57 public static final String KEY_ANIM_ENTER_RES_ID = "android:animEnterRes"; 58 59 /** 60 * Custom exit animation resource ID. 61 * @hide 62 */ 63 public static final String KEY_ANIM_EXIT_RES_ID = "android:animExitRes"; 64 65 /** 66 * Bitmap for thumbnail animation. 67 * @hide 68 */ 69 public static final String KEY_ANIM_THUMBNAIL = "android:animThumbnail"; 70 71 /** 72 * Start X position of thumbnail animation. 73 * @hide 74 */ 75 public static final String KEY_ANIM_START_X = "android:animStartX"; 76 77 /** 78 * Start Y position of thumbnail animation. 79 * @hide 80 */ 81 public static final String KEY_ANIM_START_Y = "android:animStartY"; 82 83 /** 84 * Initial width of the animation. 85 * @hide 86 */ 87 public static final String KEY_ANIM_START_WIDTH = "android:animStartWidth"; 88 89 /** 90 * Initial height of the animation. 91 * @hide 92 */ 93 public static final String KEY_ANIM_START_HEIGHT = "android:animStartHeight"; 94 95 /** 96 * Callback for when animation is started. 97 * @hide 98 */ 99 public static final String KEY_ANIM_START_LISTENER = "android:animStartListener"; 100 101 /** 102 * For Activity transitions, the calling Activity's TransitionListener used to 103 * notify the called Activity when the shared element and the exit transitions 104 * complete. 105 */ 106 private static final String KEY_TRANSITION_COMPLETE_LISTENER 107 = "android:transitionCompleteListener"; 108 109 private static final String KEY_TRANSITION_IS_RETURNING = "android:transitionIsReturning"; 110 private static final String KEY_TRANSITION_SHARED_ELEMENTS = "android:sharedElementNames"; 111 private static final String KEY_LOCAL_SHARED_ELEMENTS = "android:localSharedElementNames"; 112 private static final String KEY_RESULT_DATA = "android:resultData"; 113 private static final String KEY_RESULT_CODE = "android:resultCode"; 114 115 /** @hide */ 116 public static final int ANIM_NONE = 0; 117 /** @hide */ 118 public static final int ANIM_CUSTOM = 1; 119 /** @hide */ 120 public static final int ANIM_SCALE_UP = 2; 121 /** @hide */ 122 public static final int ANIM_THUMBNAIL_SCALE_UP = 3; 123 /** @hide */ 124 public static final int ANIM_THUMBNAIL_SCALE_DOWN = 4; 125 /** @hide */ 126 public static final int ANIM_SCENE_TRANSITION = 5; 127 128 private String mPackageName; 129 private int mAnimationType = ANIM_NONE; 130 private int mCustomEnterResId; 131 private int mCustomExitResId; 132 private Bitmap mThumbnail; 133 private int mStartX; 134 private int mStartY; 135 private int mStartWidth; 136 private int mStartHeight; 137 private IRemoteCallback mAnimationStartedListener; 138 private ResultReceiver mTransitionReceiver; 139 private boolean mIsReturning; 140 private ArrayList<String> mSharedElementNames; 141 private ArrayList<String> mLocalSharedElementNames; 142 private Intent mResultData; 143 private int mResultCode; 144 145 /** 146 * Create an ActivityOptions specifying a custom animation to run when 147 * the activity is displayed. 148 * 149 * @param context Who is defining this. This is the application that the 150 * animation resources will be loaded from. 151 * @param enterResId A resource ID of the animation resource to use for 152 * the incoming activity. Use 0 for no animation. 153 * @param exitResId A resource ID of the animation resource to use for 154 * the outgoing activity. Use 0 for no animation. 155 * @return Returns a new ActivityOptions object that you can use to 156 * supply these options as the options Bundle when starting an activity. 157 */ 158 public static ActivityOptions makeCustomAnimation(Context context, 159 int enterResId, int exitResId) { 160 return makeCustomAnimation(context, enterResId, exitResId, null, null); 161 } 162 163 /** 164 * Create an ActivityOptions specifying a custom animation to run when 165 * the activity is displayed. 166 * 167 * @param context Who is defining this. This is the application that the 168 * animation resources will be loaded from. 169 * @param enterResId A resource ID of the animation resource to use for 170 * the incoming activity. Use 0 for no animation. 171 * @param exitResId A resource ID of the animation resource to use for 172 * the outgoing activity. Use 0 for no animation. 173 * @param handler If <var>listener</var> is non-null this must be a valid 174 * Handler on which to dispatch the callback; otherwise it should be null. 175 * @param listener Optional OnAnimationStartedListener to find out when the 176 * requested animation has started running. If for some reason the animation 177 * is not executed, the callback will happen immediately. 178 * @return Returns a new ActivityOptions object that you can use to 179 * supply these options as the options Bundle when starting an activity. 180 * @hide 181 */ 182 public static ActivityOptions makeCustomAnimation(Context context, 183 int enterResId, int exitResId, Handler handler, OnAnimationStartedListener listener) { 184 ActivityOptions opts = new ActivityOptions(); 185 opts.mPackageName = context.getPackageName(); 186 opts.mAnimationType = ANIM_CUSTOM; 187 opts.mCustomEnterResId = enterResId; 188 opts.mCustomExitResId = exitResId; 189 opts.setOnAnimationStartedListener(handler, listener); 190 return opts; 191 } 192 193 private void setOnAnimationStartedListener(Handler handler, 194 OnAnimationStartedListener listener) { 195 if (listener != null) { 196 final Handler h = handler; 197 final OnAnimationStartedListener finalListener = listener; 198 mAnimationStartedListener = new IRemoteCallback.Stub() { 199 @Override public void sendResult(Bundle data) throws RemoteException { 200 h.post(new Runnable() { 201 @Override public void run() { 202 finalListener.onAnimationStarted(); 203 } 204 }); 205 } 206 }; 207 } 208 } 209 210 /** 211 * Callback for use with {@link ActivityOptions#makeThumbnailScaleUpAnimation} 212 * to find out when the given animation has started running. 213 * @hide 214 */ 215 public interface OnAnimationStartedListener { 216 void onAnimationStarted(); 217 } 218 219 /** 220 * Create an ActivityOptions specifying an animation where the new 221 * activity is scaled from a small originating area of the screen to 222 * its final full representation. 223 * 224 * <p>If the Intent this is being used with has not set its 225 * {@link android.content.Intent#setSourceBounds Intent.setSourceBounds}, 226 * those bounds will be filled in for you based on the initial 227 * bounds passed in here. 228 * 229 * @param source The View that the new activity is animating from. This 230 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 231 * @param startX The x starting location of the new activity, relative to <var>source</var>. 232 * @param startY The y starting location of the activity, relative to <var>source</var>. 233 * @param startWidth The initial width of the new activity. 234 * @param startHeight The initial height of the new activity. 235 * @return Returns a new ActivityOptions object that you can use to 236 * supply these options as the options Bundle when starting an activity. 237 */ 238 public static ActivityOptions makeScaleUpAnimation(View source, 239 int startX, int startY, int startWidth, int startHeight) { 240 ActivityOptions opts = new ActivityOptions(); 241 opts.mPackageName = source.getContext().getPackageName(); 242 opts.mAnimationType = ANIM_SCALE_UP; 243 int[] pts = new int[2]; 244 source.getLocationOnScreen(pts); 245 opts.mStartX = pts[0] + startX; 246 opts.mStartY = pts[1] + startY; 247 opts.mStartWidth = startWidth; 248 opts.mStartHeight = startHeight; 249 return opts; 250 } 251 252 /** 253 * Create an ActivityOptions specifying an animation where a thumbnail 254 * is scaled from a given position to the new activity window that is 255 * being started. 256 * 257 * <p>If the Intent this is being used with has not set its 258 * {@link android.content.Intent#setSourceBounds Intent.setSourceBounds}, 259 * those bounds will be filled in for you based on the initial 260 * thumbnail location and size provided here. 261 * 262 * @param source The View that this thumbnail is animating from. This 263 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 264 * @param thumbnail The bitmap that will be shown as the initial thumbnail 265 * of the animation. 266 * @param startX The x starting location of the bitmap, relative to <var>source</var>. 267 * @param startY The y starting location of the bitmap, relative to <var>source</var>. 268 * @return Returns a new ActivityOptions object that you can use to 269 * supply these options as the options Bundle when starting an activity. 270 */ 271 public static ActivityOptions makeThumbnailScaleUpAnimation(View source, 272 Bitmap thumbnail, int startX, int startY) { 273 return makeThumbnailScaleUpAnimation(source, thumbnail, startX, startY, null); 274 } 275 276 /** 277 * Create an ActivityOptions specifying an animation where a thumbnail 278 * is scaled from a given position to the new activity window that is 279 * being started. 280 * 281 * @param source The View that this thumbnail is animating from. This 282 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 283 * @param thumbnail The bitmap that will be shown as the initial thumbnail 284 * of the animation. 285 * @param startX The x starting location of the bitmap, relative to <var>source</var>. 286 * @param startY The y starting location of the bitmap, relative to <var>source</var>. 287 * @param listener Optional OnAnimationStartedListener to find out when the 288 * requested animation has started running. If for some reason the animation 289 * is not executed, the callback will happen immediately. 290 * @return Returns a new ActivityOptions object that you can use to 291 * supply these options as the options Bundle when starting an activity. 292 * @hide 293 */ 294 public static ActivityOptions makeThumbnailScaleUpAnimation(View source, 295 Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) { 296 return makeThumbnailAnimation(source, thumbnail, startX, startY, listener, true); 297 } 298 299 /** 300 * Create an ActivityOptions specifying an animation where an activity window 301 * is scaled from a given position to a thumbnail at a specified location. 302 * 303 * @param source The View that this thumbnail is animating to. This 304 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 305 * @param thumbnail The bitmap that will be shown as the final thumbnail 306 * of the animation. 307 * @param startX The x end location of the bitmap, relative to <var>source</var>. 308 * @param startY The y end location of the bitmap, relative to <var>source</var>. 309 * @param listener Optional OnAnimationStartedListener to find out when the 310 * requested animation has started running. If for some reason the animation 311 * is not executed, the callback will happen immediately. 312 * @return Returns a new ActivityOptions object that you can use to 313 * supply these options as the options Bundle when starting an activity. 314 * @hide 315 */ 316 public static ActivityOptions makeThumbnailScaleDownAnimation(View source, 317 Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) { 318 return makeThumbnailAnimation(source, thumbnail, startX, startY, listener, false); 319 } 320 321 private static ActivityOptions makeThumbnailAnimation(View source, 322 Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener, 323 boolean scaleUp) { 324 ActivityOptions opts = new ActivityOptions(); 325 opts.mPackageName = source.getContext().getPackageName(); 326 opts.mAnimationType = scaleUp ? ANIM_THUMBNAIL_SCALE_UP : ANIM_THUMBNAIL_SCALE_DOWN; 327 opts.mThumbnail = thumbnail; 328 int[] pts = new int[2]; 329 source.getLocationOnScreen(pts); 330 opts.mStartX = pts[0] + startX; 331 opts.mStartY = pts[1] + startY; 332 opts.setOnAnimationStartedListener(source.getHandler(), listener); 333 return opts; 334 } 335 336 /** 337 * Create an ActivityOptions to transition between Activities using cross-Activity scene 338 * animations. This method carries the position of one shared element to the started Activity. 339 * The position of <code>sharedElement</code> will be used as the epicenter for the 340 * exit Transition. The position of the shared element in the launched Activity will be the 341 * epicenter of its entering Transition. 342 * 343 * <p>This requires {@link android.view.Window#FEATURE_CONTENT_TRANSITIONS} to be 344 * enabled on the calling Activity to cause an exit transition. The same must be in 345 * the called Activity to get an entering transition.</p> 346 * @param activity The Activity whose window contains the shared elements. 347 * @param sharedElement The View to transition to the started Activity. sharedElement must 348 * have a non-null sharedElementName. 349 * @param sharedElementName The shared element name as used in the target Activity. This may 350 * be null if it has the same name as sharedElement. 351 * @return Returns a new ActivityOptions object that you can use to 352 * supply these options as the options Bundle when starting an activity. 353 * @see android.transition.Transition#setEpicenterCallback( 354 * android.transition.Transition.EpicenterCallback) 355 */ 356 public static ActivityOptions makeSceneTransitionAnimation(Activity activity, 357 View sharedElement, String sharedElementName) { 358 return makeSceneTransitionAnimation(activity, Pair.create(sharedElement, sharedElementName)); 359 } 360 361 /** 362 * Create an ActivityOptions to transition between Activities using cross-Activity scene 363 * animations. This method carries the position of multiple shared elements to the started 364 * Activity. The position of the first element in sharedElements 365 * will be used as the epicenter for the exit Transition. The position of the associated 366 * shared element in the launched Activity will be the epicenter of its entering Transition. 367 * 368 * <p>This requires {@link android.view.Window#FEATURE_CONTENT_TRANSITIONS} to be 369 * enabled on the calling Activity to cause an exit transition. The same must be in 370 * the called Activity to get an entering transition.</p> 371 * @param activity The Activity whose window contains the shared elements. 372 * @param sharedElements The names of the shared elements to transfer to the called 373 * Activity and their associated Views. The Views must each have 374 * a unique shared element name. 375 * @return Returns a new ActivityOptions object that you can use to 376 * supply these options as the options Bundle when starting an activity. 377 * Returns null if the Window does not have {@link Window#FEATURE_CONTENT_TRANSITIONS}. 378 * @see android.transition.Transition#setEpicenterCallback( 379 * android.transition.Transition.EpicenterCallback) 380 */ 381 public static ActivityOptions makeSceneTransitionAnimation(Activity activity, 382 Pair<View, String>... sharedElements) { 383 if (!activity.getWindow().hasFeature(Window.FEATURE_CONTENT_TRANSITIONS)) { 384 return null; 385 } 386 ActivityOptions opts = new ActivityOptions(); 387 opts.mAnimationType = ANIM_SCENE_TRANSITION; 388 389 ArrayList<String> names = new ArrayList<String>(); 390 ArrayList<String> mappedNames = new ArrayList<String>(); 391 392 if (sharedElements != null) { 393 for (int i = 0; i < sharedElements.length; i++) { 394 Pair<View, String> sharedElement = sharedElements[i]; 395 String sharedElementName = sharedElement.second; 396 if (sharedElementName == null) { 397 throw new IllegalArgumentException("Shared element name must not be null"); 398 } 399 String name = sharedElement.first.getTransitionName(); 400 if (name == null) { 401 throw new IllegalArgumentException("Shared elements must have non-null " + 402 "transitionNames"); 403 } 404 405 names.add(sharedElementName); 406 mappedNames.add(name); 407 } 408 } 409 410 ExitTransitionCoordinator exit = new ExitTransitionCoordinator(activity, names, names, 411 mappedNames, false); 412 opts.mTransitionReceiver = exit; 413 opts.mSharedElementNames = names; 414 opts.mLocalSharedElementNames = mappedNames; 415 opts.mIsReturning = false; 416 return opts; 417 } 418 419 /** @hide */ 420 public static ActivityOptions makeSceneTransitionAnimation(Activity activity, 421 ExitTransitionCoordinator exitCoordinator, ArrayList<String> sharedElementNames, 422 int resultCode, Intent resultData) { 423 ActivityOptions opts = new ActivityOptions(); 424 opts.mAnimationType = ANIM_SCENE_TRANSITION; 425 opts.mSharedElementNames = sharedElementNames; 426 opts.mTransitionReceiver = exitCoordinator; 427 opts.mIsReturning = true; 428 opts.mResultCode = resultCode; 429 opts.mResultData = resultData; 430 return opts; 431 } 432 433 private ActivityOptions() { 434 } 435 436 /** @hide */ 437 public ActivityOptions(Bundle opts) { 438 mPackageName = opts.getString(KEY_PACKAGE_NAME); 439 mAnimationType = opts.getInt(KEY_ANIM_TYPE); 440 switch (mAnimationType) { 441 case ANIM_CUSTOM: 442 mCustomEnterResId = opts.getInt(KEY_ANIM_ENTER_RES_ID, 0); 443 mCustomExitResId = opts.getInt(KEY_ANIM_EXIT_RES_ID, 0); 444 mAnimationStartedListener = IRemoteCallback.Stub.asInterface( 445 opts.getBinder(KEY_ANIM_START_LISTENER)); 446 break; 447 448 case ANIM_SCALE_UP: 449 mStartX = opts.getInt(KEY_ANIM_START_X, 0); 450 mStartY = opts.getInt(KEY_ANIM_START_Y, 0); 451 mStartWidth = opts.getInt(KEY_ANIM_START_WIDTH, 0); 452 mStartHeight = opts.getInt(KEY_ANIM_START_HEIGHT, 0); 453 break; 454 455 case ANIM_THUMBNAIL_SCALE_UP: 456 case ANIM_THUMBNAIL_SCALE_DOWN: 457 mThumbnail = (Bitmap)opts.getParcelable(KEY_ANIM_THUMBNAIL); 458 mStartX = opts.getInt(KEY_ANIM_START_X, 0); 459 mStartY = opts.getInt(KEY_ANIM_START_Y, 0); 460 mAnimationStartedListener = IRemoteCallback.Stub.asInterface( 461 opts.getBinder(KEY_ANIM_START_LISTENER)); 462 break; 463 464 case ANIM_SCENE_TRANSITION: 465 mTransitionReceiver = opts.getParcelable(KEY_TRANSITION_COMPLETE_LISTENER); 466 mIsReturning = opts.getBoolean(KEY_TRANSITION_IS_RETURNING, false); 467 mSharedElementNames = opts.getStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS); 468 mLocalSharedElementNames = opts.getStringArrayList(KEY_LOCAL_SHARED_ELEMENTS); 469 mResultData = opts.getParcelable(KEY_RESULT_DATA); 470 mResultCode = opts.getInt(KEY_RESULT_CODE); 471 break; 472 } 473 } 474 475 /** @hide */ 476 public String getPackageName() { 477 return mPackageName; 478 } 479 480 /** @hide */ 481 public int getAnimationType() { 482 return mAnimationType; 483 } 484 485 /** @hide */ 486 public int getCustomEnterResId() { 487 return mCustomEnterResId; 488 } 489 490 /** @hide */ 491 public int getCustomExitResId() { 492 return mCustomExitResId; 493 } 494 495 /** @hide */ 496 public Bitmap getThumbnail() { 497 return mThumbnail; 498 } 499 500 /** @hide */ 501 public int getStartX() { 502 return mStartX; 503 } 504 505 /** @hide */ 506 public int getStartY() { 507 return mStartY; 508 } 509 510 /** @hide */ 511 public int getStartWidth() { 512 return mStartWidth; 513 } 514 515 /** @hide */ 516 public int getStartHeight() { 517 return mStartHeight; 518 } 519 520 /** @hide */ 521 public IRemoteCallback getOnAnimationStartListener() { 522 return mAnimationStartedListener; 523 } 524 525 /** @hide */ 526 public void dispatchActivityStopped() { 527 if (mTransitionReceiver != null) { 528 mTransitionReceiver.send(ActivityTransitionCoordinator.MSG_ACTIVITY_STOPPED, null); 529 } 530 } 531 532 /** @hide */ 533 public void dispatchStartExit() { 534 if (mTransitionReceiver != null) { 535 mTransitionReceiver.send(ActivityTransitionCoordinator.MSG_START_EXIT_TRANSITION, null); 536 } 537 } 538 539 /** @hide */ 540 public void abort() { 541 if (mAnimationStartedListener != null) { 542 try { 543 mAnimationStartedListener.sendResult(null); 544 } catch (RemoteException e) { 545 } 546 } 547 } 548 549 /** @hide */ 550 public void setReturning() { 551 mIsReturning = true; 552 } 553 554 /** @hide */ 555 public boolean isReturning() { 556 return mIsReturning; 557 } 558 559 /** @hide */ 560 public ArrayList<String> getSharedElementNames() { 561 return mSharedElementNames; 562 } 563 564 /** @hide */ 565 public ArrayList<String> getLocalSharedElementNames() { return mLocalSharedElementNames; } 566 567 /** @hide */ 568 public ResultReceiver getResultReceiver() { return mTransitionReceiver; } 569 570 /** @hide */ 571 public int getResultCode() { return mResultCode; } 572 573 /** @hide */ 574 public Intent getResultData() { return mResultData; } 575 576 /** @hide */ 577 public static void abort(Bundle options) { 578 if (options != null) { 579 (new ActivityOptions(options)).abort(); 580 } 581 } 582 583 /** 584 * Update the current values in this ActivityOptions from those supplied 585 * in <var>otherOptions</var>. Any values 586 * defined in <var>otherOptions</var> replace those in the base options. 587 */ 588 public void update(ActivityOptions otherOptions) { 589 if (otherOptions.mPackageName != null) { 590 mPackageName = otherOptions.mPackageName; 591 } 592 mTransitionReceiver = null; 593 mSharedElementNames = null; 594 mLocalSharedElementNames = null; 595 mIsReturning = false; 596 mResultData = null; 597 mResultCode = 0; 598 switch (otherOptions.mAnimationType) { 599 case ANIM_CUSTOM: 600 mAnimationType = otherOptions.mAnimationType; 601 mCustomEnterResId = otherOptions.mCustomEnterResId; 602 mCustomExitResId = otherOptions.mCustomExitResId; 603 mThumbnail = null; 604 if (mAnimationStartedListener != null) { 605 try { 606 mAnimationStartedListener.sendResult(null); 607 } catch (RemoteException e) { 608 } 609 } 610 mAnimationStartedListener = otherOptions.mAnimationStartedListener; 611 break; 612 case ANIM_SCALE_UP: 613 mAnimationType = otherOptions.mAnimationType; 614 mStartX = otherOptions.mStartX; 615 mStartY = otherOptions.mStartY; 616 mStartWidth = otherOptions.mStartWidth; 617 mStartHeight = otherOptions.mStartHeight; 618 if (mAnimationStartedListener != null) { 619 try { 620 mAnimationStartedListener.sendResult(null); 621 } catch (RemoteException e) { 622 } 623 } 624 mAnimationStartedListener = null; 625 break; 626 case ANIM_THUMBNAIL_SCALE_UP: 627 case ANIM_THUMBNAIL_SCALE_DOWN: 628 mAnimationType = otherOptions.mAnimationType; 629 mThumbnail = otherOptions.mThumbnail; 630 mStartX = otherOptions.mStartX; 631 mStartY = otherOptions.mStartY; 632 if (mAnimationStartedListener != null) { 633 try { 634 mAnimationStartedListener.sendResult(null); 635 } catch (RemoteException e) { 636 } 637 } 638 mAnimationStartedListener = otherOptions.mAnimationStartedListener; 639 break; 640 case ANIM_SCENE_TRANSITION: 641 mAnimationType = otherOptions.mAnimationType; 642 mTransitionReceiver = otherOptions.mTransitionReceiver; 643 mSharedElementNames = otherOptions.mSharedElementNames; 644 mLocalSharedElementNames = otherOptions.mLocalSharedElementNames; 645 mIsReturning = otherOptions.mIsReturning; 646 mThumbnail = null; 647 mAnimationStartedListener = null; 648 mResultData = otherOptions.mResultData; 649 mResultCode = otherOptions.mResultCode; 650 break; 651 } 652 } 653 654 /** 655 * Returns the created options as a Bundle, which can be passed to 656 * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle) 657 * Context.startActivity(Intent, Bundle)} and related methods. 658 * Note that the returned Bundle is still owned by the ActivityOptions 659 * object; you must not modify it, but can supply it to the startActivity 660 * methods that take an options Bundle. 661 */ 662 public Bundle toBundle() { 663 Bundle b = new Bundle(); 664 if (mPackageName != null) { 665 b.putString(KEY_PACKAGE_NAME, mPackageName); 666 } 667 switch (mAnimationType) { 668 case ANIM_CUSTOM: 669 b.putInt(KEY_ANIM_TYPE, mAnimationType); 670 b.putInt(KEY_ANIM_ENTER_RES_ID, mCustomEnterResId); 671 b.putInt(KEY_ANIM_EXIT_RES_ID, mCustomExitResId); 672 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener 673 != null ? mAnimationStartedListener.asBinder() : null); 674 break; 675 case ANIM_SCALE_UP: 676 b.putInt(KEY_ANIM_TYPE, mAnimationType); 677 b.putInt(KEY_ANIM_START_X, mStartX); 678 b.putInt(KEY_ANIM_START_Y, mStartY); 679 b.putInt(KEY_ANIM_START_WIDTH, mStartWidth); 680 b.putInt(KEY_ANIM_START_HEIGHT, mStartHeight); 681 break; 682 case ANIM_THUMBNAIL_SCALE_UP: 683 case ANIM_THUMBNAIL_SCALE_DOWN: 684 b.putInt(KEY_ANIM_TYPE, mAnimationType); 685 b.putParcelable(KEY_ANIM_THUMBNAIL, mThumbnail); 686 b.putInt(KEY_ANIM_START_X, mStartX); 687 b.putInt(KEY_ANIM_START_Y, mStartY); 688 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener 689 != null ? mAnimationStartedListener.asBinder() : null); 690 break; 691 case ANIM_SCENE_TRANSITION: 692 b.putInt(KEY_ANIM_TYPE, mAnimationType); 693 if (mTransitionReceiver != null) { 694 b.putParcelable(KEY_TRANSITION_COMPLETE_LISTENER, mTransitionReceiver); 695 } 696 b.putBoolean(KEY_TRANSITION_IS_RETURNING, mIsReturning); 697 b.putStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS, mSharedElementNames); 698 b.putStringArrayList(KEY_LOCAL_SHARED_ELEMENTS, mLocalSharedElementNames); 699 b.putParcelable(KEY_RESULT_DATA, mResultData); 700 b.putInt(KEY_RESULT_CODE, mResultCode); 701 break; 702 } 703 return b; 704 } 705 706 /** 707 * Return the filtered options only meant to be seen by the target activity itself 708 * @hide 709 */ 710 public ActivityOptions forTargetActivity() { 711 if (mAnimationType == ANIM_SCENE_TRANSITION) { 712 final ActivityOptions result = new ActivityOptions(); 713 result.update(this); 714 return result; 715 } 716 717 return null; 718 } 719 720} 721