13a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton/* 23a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Copyright (C) 2012 The Android Open Source Project 33a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * 43a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Licensed under the Apache License, Version 2.0 (the "License"); 53a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * you may not use this file except in compliance with the License. 63a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * You may obtain a copy of the License at 73a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * 83a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * http://www.apache.org/licenses/LICENSE-2.0 93a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * 103a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Unless required by applicable law or agreed to in writing, software 113a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * distributed under the License is distributed on an "AS IS" BASIS, 123a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * See the License for the specific language governing permissions and 143a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * limitations under the License. 153a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton */ 163a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 173a96487b54eca412f51ad00b8f8096055e94dcbbJake Whartonpackage android.support.v4.app; 183a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 193a96487b54eca412f51ad00b8f8096055e94dcbbJake Whartonimport android.content.Context; 203a96487b54eca412f51ad00b8f8096055e94dcbbJake Whartonimport android.graphics.Bitmap; 213a96487b54eca412f51ad00b8f8096055e94dcbbJake Whartonimport android.os.Build; 223a96487b54eca412f51ad00b8f8096055e94dcbbJake Whartonimport android.os.Bundle; 233a96487b54eca412f51ad00b8f8096055e94dcbbJake Whartonimport android.view.View; 243a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 253a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton/** 263a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Helper for accessing features in {@link android.app.ActivityOptions} 273a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * introduced in API level 16 in a backwards compatible fashion. 283a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton */ 293a96487b54eca412f51ad00b8f8096055e94dcbbJake Whartonpublic class ActivityOptionsCompat { 303a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton /** 313a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Create an ActivityOptions specifying a custom animation to run when the 323a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * activity is displayed. 333a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * 343a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param context Who is defining this. This is the application that the 353a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * animation resources will be loaded from. 363a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param enterResId A resource ID of the animation resource to use for the 373a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * incoming activity. Use 0 for no animation. 383a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param exitResId A resource ID of the animation resource to use for the 393a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * outgoing activity. Use 0 for no animation. 403a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @return Returns a new ActivityOptions object that you can use to supply 413a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * these options as the options Bundle when starting an activity. 423a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton */ 433a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton public static ActivityOptionsCompat makeCustomAnimation(Context context, 443a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton int enterResId, int exitResId) { 453a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton if (Build.VERSION.SDK_INT >= 16) { 463a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return new ActivityOptionsImplJB( 473a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton ActivityOptionsCompatJB.makeCustomAnimation(context, enterResId, exitResId)); 483a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 493a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return new ActivityOptionsCompat(); 503a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 513a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 523a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton /** 533a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Create an ActivityOptions specifying an animation where the new activity is 543a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * scaled from a small originating area of the screen to its final full 553a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * representation. 563a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * <p/> 573a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * If the Intent this is being used with has not set its 583a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * {@link android.content.Intent#setSourceBounds(android.graphics.Rect)}, 593a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * those bounds will be filled in for you based on the initial bounds passed 603a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * in here. 613a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * 623a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param source The View that the new activity is animating from. This 633a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * defines the coordinate space for startX and startY. 643a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param startX The x starting location of the new activity, relative to 653a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * source. 663a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param startY The y starting location of the activity, relative to source. 673a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param startWidth The initial width of the new activity. 683a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param startHeight The initial height of the new activity. 693a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @return Returns a new ActivityOptions object that you can use to supply 703a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * these options as the options Bundle when starting an activity. 713a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton */ 723a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton public static ActivityOptionsCompat makeScaleUpAnimation(View source, 733a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton int startX, int startY, int startWidth, int startHeight) { 743a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton if (Build.VERSION.SDK_INT >= 16) { 753a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return new ActivityOptionsImplJB( 763a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton ActivityOptionsCompatJB.makeScaleUpAnimation(source, startX, startY, 773a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton startWidth, startHeight)); 783a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 793a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return new ActivityOptionsCompat(); 803a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 813a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 823a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton /** 833a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Create an ActivityOptions specifying an animation where a thumbnail is 843a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * scaled from a given position to the new activity window that is being 853a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * started. 863a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * <p/> 873a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * If the Intent this is being used with has not set its 883a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * {@link android.content.Intent#setSourceBounds(android.graphics.Rect)}, 893a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * those bounds will be filled in for you based on the initial thumbnail 903a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * location and size provided here. 913a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * 923a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param source The View that this thumbnail is animating from. This 933a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * defines the coordinate space for startX and startY. 943a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param thumbnail The bitmap that will be shown as the initial thumbnail 953a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * of the animation. 963a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param startX The x starting location of the bitmap, relative to source. 973a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @param startY The y starting location of the bitmap, relative to source. 983a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * @return Returns a new ActivityOptions object that you can use to supply 993a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * these options as the options Bundle when starting an activity. 1003a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton */ 1013a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton public static ActivityOptionsCompat makeThumbnailScaleUpAnimation(View source, 1023a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton Bitmap thumbnail, int startX, int startY) { 1033a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton if (Build.VERSION.SDK_INT >= 16) { 1043a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return new ActivityOptionsImplJB( 1053a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton ActivityOptionsCompatJB.makeThumbnailScaleUpAnimation(source, thumbnail, 1063a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton startX, startY)); 1073a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1083a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return new ActivityOptionsCompat(); 1093a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1103a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1113a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1123a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton private static class ActivityOptionsImplJB extends ActivityOptionsCompat { 1133a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton private final ActivityOptionsCompatJB mImpl; 1143a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1153a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton ActivityOptionsImplJB(ActivityOptionsCompatJB impl) { 1163a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton mImpl = impl; 1173a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1183a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1193a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton @Override 1203a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton public Bundle toBundle() { 1213a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return mImpl.toBundle(); 1223a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1233a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1243a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton @Override 1253a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton public void update(ActivityOptionsCompat otherOptions) { 1263a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton if (otherOptions instanceof ActivityOptionsImplJB) { 1273a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton ActivityOptionsImplJB otherImpl = (ActivityOptionsImplJB)otherOptions; 1283a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton mImpl.update(otherImpl.mImpl); 1293a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1303a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1313a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1323a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1333a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1343a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton protected ActivityOptionsCompat() { 1353a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1363a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1373a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton /** 1383a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Returns the created options as a Bundle, which can be passed to 1393a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * {@link ActivityCompat#startActivity(android.app.Activity, android.content.Intent, android.os.Bundle)}. 1403a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Note that the returned Bundle is still owned by the ActivityOptions 1413a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * object; you must not modify it, but can supply it to the startActivity 1423a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * methods that take an options Bundle. 1433a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton */ 1443a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton public Bundle toBundle() { 1453a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton return null; 1463a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1473a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton 1483a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton /** 1493a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * Update the current values in this ActivityOptions from those supplied in 1503a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * otherOptions. Any values defined in otherOptions replace those in the 1513a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton * base options. 1523a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton */ 1533a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton public void update(ActivityOptionsCompat otherOptions) { 1543a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton // Do nothing. 1553a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton } 1563a96487b54eca412f51ad00b8f8096055e94dcbbJake Wharton} 157