Add to activity transition API as requested by consumers.

Change-Id: Iae01d7560770bab0ff9a1728d6552b98b17108ce
This commit is contained in:
George Mount
2014-05-19 07:09:00 -07:00
parent 2631da82ae
commit 800d72b0e0
8 changed files with 102 additions and 54 deletions

View File

@@ -1641,7 +1641,6 @@ package android {
field public static final int selectAll = 16908319; // 0x102001f
field public static final int selectTextMode = 16908333; // 0x102002d
field public static final int selectedIcon = 16908302; // 0x102000e
field public static final int shared_element = 16908354; // 0x1020042
field public static final int startSelectingText = 16908328; // 0x1020028
field public static final int stopSelectingText = 16908329; // 0x1020029
field public static final int summary = 16908304; // 0x1020010
@@ -3337,6 +3336,8 @@ package android.app {
method public void setContentView(android.view.View);
method public void setContentView(android.view.View, android.view.ViewGroup.LayoutParams);
method public final void setDefaultKeyMode(int);
method public void setEnterSharedElementListener(android.app.SharedElementListener);
method public void setExitSharedElementListener(android.app.SharedElementListener);
method public final void setFeatureDrawable(int, android.graphics.drawable.Drawable);
method public final void setFeatureDrawableAlpha(int, int);
method public final void setFeatureDrawableResource(int, int);
@@ -3352,7 +3353,6 @@ package android.app {
method public final void setResult(int);
method public final void setResult(int, android.content.Intent);
method public final void setSecondaryProgress(int);
method public void setSharedElementListener(android.app.SharedElementListener);
method public void setTaskDescription(android.app.ActivityManager.TaskDescription);
method public void setTitle(java.lang.CharSequence);
method public void setTitle(int);
@@ -4811,7 +4811,7 @@ package android.app {
field public static final int START_STICKY_COMPATIBILITY = 0; // 0x0
}
public class SharedElementListener {
public abstract class SharedElementListener {
ctor public SharedElementListener();
method public void handleRejectedSharedElements(java.util.List<android.view.View>);
method public void remapSharedElements(java.util.List<java.lang.String>, java.util.Map<java.lang.String, android.view.View>);

View File

@@ -779,7 +779,8 @@ public class Activity extends ContextThemeWrapper
final Handler mHandler = new Handler();
private ActivityTransitionState mActivityTransitionState = new ActivityTransitionState();
SharedElementListener mTransitionListener = new SharedElementListener();
SharedElementListener mEnterTransitionListener = SharedElementListener.NULL_LISTENER;
SharedElementListener mExitTransitionListener = SharedElementListener.NULL_LISTENER;
/** Return the intent that started this activity. */
public Intent getIntent() {
@@ -5557,16 +5558,32 @@ public class Activity extends ContextThemeWrapper
/**
* When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity,
* android.view.View, String)} was used to start an Activity, <var>listener</var>
* will be called to handle shared elements. This requires
* will be called to handle shared elements on the <i>launched</i> Activity. This requires
* {@link Window#FEATURE_CONTENT_TRANSITIONS}.
*
* @param listener Used to manipulate how shared element transitions function.
* @param listener Used to manipulate shared element transitions on the launched Activity.
*/
public void setSharedElementListener(SharedElementListener listener) {
public void setEnterSharedElementListener(SharedElementListener listener) {
if (listener == null) {
listener = new SharedElementListener();
listener = SharedElementListener.NULL_LISTENER;
}
mTransitionListener = listener;
mEnterTransitionListener = listener;
}
/**
* When {@link android.app.ActivityOptions#makeSceneTransitionAnimation(Activity,
* android.view.View, String)} was used to start an Activity, <var>listener</var>
* will be called to handle shared elements on the <i>launching</i> Activity. Most
* calls will only come when returning from the started Activity.
* This requires {@link Window#FEATURE_CONTENT_TRANSITIONS}.
*
* @param listener Used to manipulate shared element transitions on the launching Activity.
*/
public void setExitSharedElementListener(SharedElementListener listener) {
if (listener == null) {
listener = SharedElementListener.NULL_LISTENER;
}
mExitTransitionListener = listener;
}
// ------------------ Internal API ------------------
@@ -5882,7 +5899,8 @@ public class Activity extends ContextThemeWrapper
* have completed drawing. This is necessary only after an {@link Activity} has been made
* opaque using {@link Activity#convertFromTranslucent()} and before it has been drawn
* translucent again following a call to {@link
* Activity#convertToTranslucent(TranslucentConversionListener)}.
* Activity#convertToTranslucent(android.app.Activity.TranslucentConversionListener,
* ActivityOptions)}
*
* @hide
*/

View File

@@ -189,15 +189,17 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver {
final protected SharedElementListener mListener;
protected ResultReceiver mResultReceiver;
final private FixedEpicenterCallback mEpicenterCallback = new FixedEpicenterCallback();
final protected boolean mIsReturning;
public ActivityTransitionCoordinator(Window window,
ArrayList<String> allSharedElementNames,
ArrayList<String> accepted, ArrayList<String> localNames,
SharedElementListener listener) {
SharedElementListener listener, boolean isReturning) {
super(new Handler());
mWindow = window;
mListener = listener;
mAllSharedElementNames = allSharedElementNames;
mIsReturning = isReturning;
setSharedElements(accepted, localNames);
if (getViewsTransition() != null) {
getDecor().captureTransitioningViews(mTransitioningViews);
@@ -330,7 +332,21 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver {
mResultReceiver = resultReceiver;
}
protected abstract Transition getViewsTransition();
protected Transition getViewsTransition() {
if (mIsReturning) {
return getWindow().getExitTransition();
} else {
return getWindow().getEnterTransition();
}
}
protected Transition getSharedElementTransition() {
if (mIsReturning) {
return getWindow().getSharedElementExitTransition();
} else {
return getWindow().getSharedElementEnterTransition();
}
}
private static class FixedEpicenterCallback extends Transition.EpicenterCallback {
private Rect mEpicenter;
@@ -342,4 +358,5 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver {
return mEpicenter;
}
}
}

View File

@@ -51,7 +51,6 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator {
private static final long MAX_WAIT_MS = 1500;
private boolean mSharedElementTransitionStarted;
private boolean mIsReturning;
private Activity mActivity;
private boolean mHasStopped;
private Handler mHandler;
@@ -61,9 +60,8 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator {
ArrayList<String> sharedElementNames,
ArrayList<String> acceptedNames, ArrayList<String> mappedNames) {
super(activity.getWindow(), sharedElementNames, acceptedNames, mappedNames,
activity.mTransitionListener);
getListener(activity, acceptedNames), acceptedNames != null);
mActivity = activity;
mIsReturning = acceptedNames != null;
setResultReceiver(resultReceiver);
prepareEnter();
Bundle resultReceiverBundle = new Bundle();
@@ -80,6 +78,12 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator {
}
}
private static SharedElementListener getListener(Activity activity,
ArrayList<String> acceptedNames) {
boolean isReturning = acceptedNames != null;
return isReturning ? activity.mExitTransitionListener : activity.mEnterTransitionListener;
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
switch (resultCode) {
@@ -299,7 +303,6 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator {
if (sharedElementBundle != null) {
Bitmap bitmap = sharedElementBundle.getParcelable(KEY_BITMAP);
View snapshot = new View(context);
snapshot.setId(com.android.internal.R.id.shared_element);
Resources resources = getWindow().getContext().getResources();
snapshot.setBackground(new BitmapDrawable(resources, bitmap));
snapshot.setViewName(name);
@@ -420,12 +423,4 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator {
}
}
@Override
protected Transition getViewsTransition() {
return getWindow().getEnterTransition();
}
protected Transition getSharedElementTransition() {
return getWindow().getSharedElementEnterTransition();
}
}

View File

@@ -53,20 +53,22 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator {
private boolean mIsBackgroundReady;
private boolean mIsReturning;
private boolean mIsCanceled;
private Handler mHandler;
public ExitTransitionCoordinator(Activity activity, ArrayList<String> names,
ArrayList<String> accepted, ArrayList<String> mapped, boolean isReturning) {
super(activity.getWindow(), names, accepted, mapped, activity.mTransitionListener);
mIsReturning = isReturning;
super(activity.getWindow(), names, accepted, mapped, getListener(activity, isReturning),
isReturning);
mIsBackgroundReady = !mIsReturning;
mActivity = activity;
}
private static SharedElementListener getListener(Activity activity, boolean isReturning) {
return isReturning ? activity.mExitTransitionListener : activity.mEnterTransitionListener;
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
switch (resultCode) {
@@ -271,13 +273,4 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator {
}
return -1;
}
@Override
protected Transition getViewsTransition() {
return getWindow().getExitTransition();
}
protected Transition getSharedElementTransition() {
return getWindow().getSharedElementExitTransition();
}
}

View File

@@ -22,15 +22,27 @@ import java.util.Map;
/**
* Listener provided in
* {@link Activity#setSharedElementListener(SharedElementListener)}
* to monitor the Activity transitions. The events can be used to customize or override Activity
* {@link Activity#setEnterSharedElementListener(SharedElementListener)} and
* {@link Activity#setExitSharedElementListener(SharedElementListener)}
* to monitor the Activity transitions. The events can be used to customize Activity
* Transition behavior.
*/
public class SharedElementListener {
public abstract class SharedElementListener {
static final SharedElementListener NULL_LISTENER = new SharedElementListener() {
};
/**
* Called to allow the listener to customize the start state of the shared element for
* the shared element entering transition. By default, the shared element is placed in
* the position and with the size of the shared element in the calling Activity or Fragment.
* Called to allow the listener to customize the start state of the shared element when
* transferring in shared element state.
* <p>
* The shared element will start at the size and position of the shared element
* in the launching Activity or Fragment. It will also transfer ImageView scaleType
* and imageMatrix if the shared elements in the calling and called Activities are
* ImageViews. Some applications may want to make additional changes, such as
* changing the clip bounds, scaling, or rotation if the shared element end state
* does not map well to the start state.
* </p>
*
* @param sharedElementNames The names of the shared elements that were accepted into
* the View hierarchy.
@@ -44,8 +56,17 @@ public class SharedElementListener {
List<View> sharedElements, List<View> sharedElementSnapshots) {}
/**
* Called to allow the listener to customize the end state of the shared element for
* the shared element entering transition.
* Called to allow the listener to customize the end state of the shared element when
* transferring in shared element state.
* <p>
* Any customization done in
* {@link #setSharedElementStart(java.util.List, java.util.List, java.util.List)}
* may need to be modified to the final state of the shared element if it is not
* automatically corrected by layout. For example, rotation or scale will not
* be affected by layout and if changed in {@link #setSharedElementStart(java.util.List,
* java.util.List, java.util.List)}, it will also have to be set here again to correct
* the end state.
* </p>
*
* @param sharedElementNames The names of the shared elements that were accepted into
* the View hierarchy.
@@ -59,13 +80,18 @@ public class SharedElementListener {
List<View> sharedElements, List<View> sharedElementSnapshots) {}
/**
* If nothing is done, all shared elements that were not accepted by
* {@link #remapSharedElements(java.util.List, java.util.Map)} will be Transitioned
* out of the entering scene automatically. Any elements removed from
* rejectedSharedElements must be handled by the ActivityTransitionListener.
* <p>Views in rejectedSharedElements will have their position and size set to the
* position of the calling shared element, relative to the Window decor View. This
* view may be safely added to the decor View's overlay to remain in position.</p>
* Called after {@link #remapSharedElements(java.util.List, java.util.Map)} when
* transferring shared elements in. Any shared elements that have no mapping will be in
* <var>rejectedSharedElements</var>. The elements remaining in
* <var>rejectedSharedElements</var> will be transitioned out of the Scene. If a
* View is removed from <var>rejectedSharedElements</var>, it must be handled by the
* <code>SharedElementListener</code>.
* <p>
* Views in rejectedSharedElements will have their position and size set to the
* position of the calling shared element, relative to the Window decor View and contain
* snapshots of the View from the calling Activity or Fragment. This
* view may be safely added to the decor View's overlay to remain in position.
* </p>
*
* @param rejectedSharedElements Views containing visual information of shared elements
* that are not part of the entering scene. These Views
@@ -78,6 +104,7 @@ public class SharedElementListener {
/**
* Lets the ActivityTransitionListener adjust the mapping of shared element names to
* Views.
*
* @param names The names of all shared elements transferred from the calling Activity
* to the started Activity.
* @param sharedElements The mapping of shared element names to Views. The best guess

View File

@@ -83,5 +83,4 @@
<item type="id" name="current_scene" />
<item type="id" name="scene_layoutid_cache" />
<item type="id" name="mask" />
<item type="id" name="shared_element" />
</resources>

View File

@@ -2186,7 +2186,6 @@
<public-padding type="id" name="l_resource_pad" end="0x01020040" />
<public type="id" name="mask" />
<public type="id" name="shared_element" />
<public-padding type="style" name="l_resource_pad" end="0x01030200" />