summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2013-08-26 14:20:16 -0700
committerChet Haase <chet@google.com>2013-09-04 14:46:38 -0700
commitd82c8ac4db7091d2e976af4c89a1734465d20cd2 (patch)
treea3ccb4d7a4325582dfe028030e4ca2d38ba4c2be /core/java
parent2a59f3f24076d96cbb10e1c00c3264dec43f19b1 (diff)
downloadframeworks_base-d82c8ac4db7091d2e976af4c89a1734465d20cd2.zip
frameworks_base-d82c8ac4db7091d2e976af4c89a1734465d20cd2.tar.gz
frameworks_base-d82c8ac4db7091d2e976af4c89a1734465d20cd2.tar.bz2
Transition API changes from API council recommendations
Issue #10460684 KLP API Review: android.view.transition and android.animation Issue #10570740 Transitions: inflate transition targets from xml Change-Id: I7a3f6d3aece2fcafc5efd555d033f79e86635c98
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/animation/Animator.java16
-rw-r--r--core/java/android/animation/PropertyValuesHolder.java2
-rw-r--r--core/java/android/transition/AutoTransition.java (renamed from core/java/android/view/transition/AutoTransition.java)16
-rw-r--r--core/java/android/transition/ChangeBounds.java (renamed from core/java/android/view/transition/Move.java)37
-rw-r--r--core/java/android/transition/Crossfade.java (renamed from core/java/android/view/transition/Crossfade.java)49
-rw-r--r--core/java/android/transition/Fade.java (renamed from core/java/android/view/transition/Fade.java)50
-rw-r--r--core/java/android/transition/Recolor.java (renamed from core/java/android/view/transition/Recolor.java)29
-rw-r--r--core/java/android/transition/Rotate.java (renamed from core/java/android/view/transition/Rotate.java)15
-rw-r--r--core/java/android/transition/Scene.java (renamed from core/java/android/view/transition/Scene.java)85
-rw-r--r--core/java/android/transition/Slide.java (renamed from core/java/android/view/transition/Slide.java)8
-rw-r--r--core/java/android/transition/TextChange.java (renamed from core/java/android/view/transition/TextChange.java)45
-rw-r--r--core/java/android/transition/Transition.java (renamed from core/java/android/view/transition/Transition.java)377
-rw-r--r--core/java/android/transition/TransitionInflater.java (renamed from core/java/android/view/transition/TransitionInflater.java)156
-rw-r--r--core/java/android/transition/TransitionManager.java (renamed from core/java/android/view/transition/TransitionManager.java)112
-rw-r--r--core/java/android/transition/TransitionSet.java (renamed from core/java/android/view/transition/TransitionGroup.java)218
-rw-r--r--core/java/android/transition/TransitionValues.java (renamed from core/java/android/view/transition/TransitionValues.java)6
-rw-r--r--core/java/android/transition/TransitionValuesMaps.java (renamed from core/java/android/view/transition/TransitionValuesMaps.java)2
-rw-r--r--core/java/android/transition/Visibility.java (renamed from core/java/android/view/transition/Visibility.java)80
-rw-r--r--core/java/android/transition/package.html (renamed from core/java/android/view/transition/package.html)11
-rw-r--r--core/java/android/view/View.java29
20 files changed, 787 insertions, 556 deletions
diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java
index 89accbb..129e52c 100644
--- a/core/java/android/animation/Animator.java
+++ b/core/java/android/animation/Animator.java
@@ -280,19 +280,9 @@ public abstract class Animator implements Cloneable {
}
/**
- * Gets the set of {@link AnimatorPauseListener} objects that are currently
- * listening for pause/resume events on this animator.
- *
- * @return ArrayList<AnimatorListener> The set of pause listeners.
- */
- public ArrayList<AnimatorPauseListener> getPauseListeners() {
- return mPauseListeners;
- }
-
- /**
- * Removes all listeners from this object. This is equivalent to calling
- * {@link #getListeners()} and {@link #getPauseListeners()} followed by calling
- * {@link ArrayList#clear()} on the returned lists of listeners.
+ * Removes all {@link #addListener(android.animation.Animator.AnimatorListener) listeners}
+ * and {@link #addPauseListener(android.animation.Animator.AnimatorPauseListener)
+ * pauseListeners} from this object.
*/
public void removeAllListeners() {
if (mListeners != null) {
diff --git a/core/java/android/animation/PropertyValuesHolder.java b/core/java/android/animation/PropertyValuesHolder.java
index 5b1a7cf..43014ad 100644
--- a/core/java/android/animation/PropertyValuesHolder.java
+++ b/core/java/android/animation/PropertyValuesHolder.java
@@ -636,7 +636,7 @@ public class PropertyValuesHolder implements Cloneable {
}
/**
- * The TypeEvaluator will the automatically determined based on the type of values
+ * The TypeEvaluator will be automatically determined based on the type of values
* supplied to PropertyValuesHolder. The evaluator can be manually set, however, if so
* desired. This may be important in cases where either the type of the values supplied
* do not match the way that they should be interpolated between, or if the values
diff --git a/core/java/android/view/transition/AutoTransition.java b/core/java/android/transition/AutoTransition.java
index 7ddac7e..6e46021 100644
--- a/core/java/android/view/transition/AutoTransition.java
+++ b/core/java/android/transition/AutoTransition.java
@@ -14,22 +14,28 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
/**
* Utility class for creating a default transition that automatically fades,
* moves, and resizes views during a scene change.
+ *
+ * <p>An AutoTransition can be described in a resource file by using the
+ * tag <code>autoTransition</code>, along with the other standard
+ * attributes of {@link android.R.styleable#Transition}.</p>
*/
-public class AutoTransition extends TransitionGroup {
+public class AutoTransition extends TransitionSet {
/**
- * Constructs an AutoTransition object, which is a TransitionGroup which
+ * Constructs an AutoTransition object, which is a TransitionSet which
* first fades out disappearing targets, then moves and resizes existing
* targets, and finally fades in appearing targets.
*
*/
public AutoTransition() {
- setOrdering(SEQUENTIALLY);
- addTransitions(new Fade(Fade.OUT), new Move(), new Fade(Fade.IN));
+ setOrdering(ORDERING_SEQUENTIAL);
+ addTransition(new Fade(Fade.OUT)).
+ addTransition(new ChangeBounds()).
+ addTransition(new Fade(Fade.IN));
}
}
diff --git a/core/java/android/view/transition/Move.java b/core/java/android/transition/ChangeBounds.java
index fda0cd2..8053bff 100644
--- a/core/java/android/view/transition/Move.java
+++ b/core/java/android/transition/ChangeBounds.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -33,13 +33,17 @@ import java.util.Map;
/**
* This transition captures the layout bounds of target views before and after
* the scene change and animates those changes during the transition.
+ *
+ * <p>A ChangeBounds transition can be described in a resource file by using the
+ * tag <code>changeBounds</code>, along with the other standard
+ * attributes of {@link android.R.styleable#Transition}.</p>
*/
-public class Move extends Transition {
+public class ChangeBounds extends Transition {
- private static final String PROPNAME_BOUNDS = "android:move:bounds";
- private static final String PROPNAME_PARENT = "android:move:parent";
- private static final String PROPNAME_WINDOW_X = "android:move:windowX";
- private static final String PROPNAME_WINDOW_Y = "android:move:windowY";
+ private static final String PROPNAME_BOUNDS = "android:changeBounds:bounds";
+ private static final String PROPNAME_PARENT = "android:changeBounds:parent";
+ private static final String PROPNAME_WINDOW_X = "android:changeBounds:windowX";
+ private static final String PROPNAME_WINDOW_Y = "android:changeBounds:windowY";
private static final String[] sTransitionProperties = {
PROPNAME_BOUNDS,
PROPNAME_PARENT,
@@ -50,7 +54,7 @@ public class Move extends Transition {
int[] tempLocation = new int[2];
boolean mResizeClip = false;
boolean mReparent = false;
- private static final String LOG_TAG = "Move";
+ private static final String LOG_TAG = "ChangeBounds";
private static RectEvaluator sRectEvaluator = new RectEvaluator();
@@ -64,7 +68,7 @@ public class Move extends Transition {
}
/**
- * Setting this flag tells Move to track the before/after parent
+ * Setting this flag tells ChangeBounds to track the before/after parent
* of every view using this transition. The flag is not enabled by
* default because it requires the parent instances to be the same
* in the two scenes or else all parents must use ids to allow
@@ -77,8 +81,7 @@ public class Move extends Transition {
mReparent = reparent;
}
- @Override
- protected void captureValues(TransitionValues values, boolean start) {
+ private void captureValues(TransitionValues values) {
View view = values.view;
values.values.put(PROPNAME_BOUNDS, new Rect(view.getLeft(), view.getTop(),
view.getRight(), view.getBottom()));
@@ -89,7 +92,17 @@ public class Move extends Transition {
}
@Override
- protected Animator play(final ViewGroup sceneRoot, TransitionValues startValues,
+ public void captureStartValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
+ @Override
+ public void captureEndValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
+ @Override
+ public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;
@@ -105,7 +118,7 @@ public class Move extends Transition {
boolean parentsEqual = (startParent == endParent) ||
(startParent.getId() == endParent.getId());
// TODO: Might want reparenting to be separate/subclass transition, or at least
- // triggered by a property on Move. Otherwise, we're forcing the requirement that
+ // triggered by a property on ChangeBounds. Otherwise, we're forcing the requirement that
// all parents in layouts have IDs to avoid layout-inflation resulting in a side-effect
// of reparenting the views.
if (!mReparent || parentsEqual) {
diff --git a/core/java/android/view/transition/Crossfade.java b/core/java/android/transition/Crossfade.java
index 18bb57f..69ce872 100644
--- a/core/java/android/view/transition/Crossfade.java
+++ b/core/java/android/transition/Crossfade.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -24,10 +24,8 @@ import android.animation.RectEvaluator;
import android.animation.ValueAnimator;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.SurfaceView;
import android.view.TextureView;
@@ -43,6 +41,8 @@ import java.util.Map;
*
* <p>Note: This transition is not compatible with {@link TextureView}
* or {@link SurfaceView}.</p>
+ *
+ * @hide
*/
public class Crossfade extends Transition {
// TODO: Add a hook that lets a Transition call user code to query whether it should run on
@@ -121,12 +121,19 @@ public class Crossfade extends Transition {
* @param fadeBehavior The type of fading animation to use when this
* transition is run.
*/
- public void setFadeBehavior(int fadeBehavior) {
+ public Crossfade setFadeBehavior(int fadeBehavior) {
if (fadeBehavior >= FADE_BEHAVIOR_CROSSFADE && fadeBehavior <= FADE_BEHAVIOR_OUT_IN) {
mFadeBehavior = fadeBehavior;
}
+ return this;
}
+ /**
+ * Returns the fading behavior of the animation.
+ *
+ * @return This crossfade object.
+ * @see #setFadeBehavior(int)
+ */
public int getFadeBehavior() {
return mFadeBehavior;
}
@@ -139,18 +146,25 @@ public class Crossfade extends Transition {
* @param resizeBehavior The type of resizing behavior to use when this
* transition is run.
*/
- public void setResizeBehavior(int resizeBehavior) {
+ public Crossfade setResizeBehavior(int resizeBehavior) {
if (resizeBehavior >= RESIZE_BEHAVIOR_NONE && resizeBehavior <= RESIZE_BEHAVIOR_SCALE) {
mResizeBehavior = resizeBehavior;
}
+ return this;
}
+ /**
+ * Returns the resizing behavior of the animation.
+ *
+ * @return This crossfade object.
+ * @see #setResizeBehavior(int)
+ */
public int getResizeBehavior() {
return mResizeBehavior;
}
@Override
- protected Animator play(ViewGroup sceneRoot, TransitionValues startValues,
+ public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;
@@ -243,18 +257,16 @@ public class Crossfade extends Transition {
}
}
- @Override
- protected void captureValues(TransitionValues values, boolean start) {
- View view = values.view;
+ private void captureValues(TransitionValues transitionValues) {
+ View view = transitionValues.view;
Rect bounds = new Rect(0, 0, view.getWidth(), view.getHeight());
if (mFadeBehavior != FADE_BEHAVIOR_REVEAL) {
bounds.offset(view.getLeft(), view.getTop());
}
- values.values.put(PROPNAME_BOUNDS, bounds);
+ transitionValues.values.put(PROPNAME_BOUNDS, bounds);
if (Transition.DBG) {
- Log.d(LOG_TAG, "Captured bounds " + values.values.get(PROPNAME_BOUNDS) + ": start = " +
- start);
+ Log.d(LOG_TAG, "Captured bounds " + transitionValues.values.get(PROPNAME_BOUNDS));
}
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
Bitmap.Config.ARGB_8888);
@@ -264,12 +276,21 @@ public class Crossfade extends Transition {
Canvas c = new Canvas(bitmap);
view.draw(c);
}
- values.values.put(PROPNAME_BITMAP, bitmap);
+ transitionValues.values.put(PROPNAME_BITMAP, bitmap);
// TODO: I don't have resources, can't call the non-deprecated method?
BitmapDrawable drawable = new BitmapDrawable(bitmap);
// TODO: lrtb will be wrong if the view has transXY set
drawable.setBounds(bounds);
- values.values.put(PROPNAME_DRAWABLE, drawable);
+ transitionValues.values.put(PROPNAME_DRAWABLE, drawable);
}
+ @Override
+ public void captureStartValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
+ @Override
+ public void captureEndValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
}
diff --git a/core/java/android/view/transition/Fade.java b/core/java/android/transition/Fade.java
index 45c21d8..12e0d73 100644
--- a/core/java/android/view/transition/Fade.java
+++ b/core/java/android/transition/Fade.java
@@ -14,12 +14,11 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
-import android.animation.ValueAnimator;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -30,6 +29,12 @@ import android.view.ViewGroup;
* or non-visible. Visibility is determined by both the
* {@link View#setVisibility(int)} state of the view as well as whether it
* is parented in the current view hierarchy.
+ *
+ * <p>A Fade transition can be described in a resource file by using the
+ * tag <code>fade</code>, along with the standard
+ * attributes of {@link android.R.styleable#Fade} and
+ * {@link android.R.styleable#Transition}.</p>
+
*/
public class Fade extends Visibility {
@@ -93,21 +98,31 @@ public class Fade extends Visibility {
return anim;
}
- @Override
- protected void captureValues(TransitionValues values, boolean start) {
- super.captureValues(values, start);
- float alpha = values.view.getAlpha();
- values.values.put(PROPNAME_ALPHA, alpha);
+ private void captureValues(TransitionValues transitionValues) {
+ float alpha = transitionValues.view.getAlpha();
+ transitionValues.values.put(PROPNAME_ALPHA, alpha);
int[] loc = new int[2];
- values.view.getLocationOnScreen(loc);
- values.values.put(PROPNAME_SCREEN_X, loc[0]);
- values.values.put(PROPNAME_SCREEN_Y, loc[1]);
+ transitionValues.view.getLocationOnScreen(loc);
+ transitionValues.values.put(PROPNAME_SCREEN_X, loc[0]);
+ transitionValues.values.put(PROPNAME_SCREEN_Y, loc[1]);
+ }
+
+ @Override
+ public void captureStartValues(TransitionValues transitionValues) {
+ super.captureStartValues(transitionValues);
+ captureValues(transitionValues);
+ }
+
+
+ @Override
+ public void captureEndValues(TransitionValues transitionValues) {
+ super.captureEndValues(transitionValues);
}
@Override
- protected Animator play(ViewGroup sceneRoot, TransitionValues startValues,
+ public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
- Animator animator = super.play(sceneRoot, startValues, endValues);
+ Animator animator = super.createAnimator(sceneRoot, startValues, endValues);
if (animator == null && startValues != null && endValues != null) {
boolean endVisible = isVisible(endValues);
final View endView = endValues.view;
@@ -122,13 +137,18 @@ public class Fade extends Visibility {
}
@Override
- protected Animator appear(ViewGroup sceneRoot,
+ public Animator onAppear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
if ((mFadingMode & IN) != IN || endValues == null) {
return null;
}
final View endView = endValues.view;
+ if (DBG) {
+ View startView = (startValues != null) ? startValues.view : null;
+ Log.d(LOG_TAG, "Fade.onDisappear: startView, startVis, endView, endVis = " +
+ startView + ", " + startVisibility + ", " + endView + ", " + endVisibility);
+ }
// if alpha < 1, just fade it in from the current value
if (endView.getAlpha() == 1.0f) {
endView.setAlpha(0);
@@ -137,7 +157,7 @@ public class Fade extends Visibility {
}
@Override
- protected Animator disappear(ViewGroup sceneRoot,
+ public Animator onDisappear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
if ((mFadingMode & OUT) != OUT) {
@@ -147,7 +167,7 @@ public class Fade extends Visibility {
View startView = (startValues != null) ? startValues.view : null;
View endView = (endValues != null) ? endValues.view : null;
if (DBG) {
- Log.d(LOG_TAG, "Fade.predisappear: startView, startVis, endView, endVis = " +
+ Log.d(LOG_TAG, "Fade.onDisappear: startView, startVis, endView, endVis = " +
startView + ", " + startVisibility + ", " + endView + ", " + endVisibility);
}
View overlayView = null;
diff --git a/core/java/android/view/transition/Recolor.java b/core/java/android/transition/Recolor.java
index e4858c4..70111d1 100644
--- a/core/java/android/view/transition/Recolor.java
+++ b/core/java/android/transition/Recolor.java
@@ -14,20 +14,17 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
-import android.util.ArrayMap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
-import java.util.Map;
-
/**
* This transition tracks changes during scene changes to the
* {@link View#setBackground(android.graphics.drawable.Drawable) background}
@@ -36,22 +33,34 @@ import java.util.Map;
* {@link TextView#setTextColor(android.content.res.ColorStateList)
* color} of the text for target TextViews. If the color changes between
* scenes, the color change is animated.
+ *
+ * @hide
*/
public class Recolor extends Transition {
private static final String PROPNAME_BACKGROUND = "android:recolor:background";
private static final String PROPNAME_TEXT_COLOR = "android:recolor:textColor";
- @Override
- protected void captureValues(TransitionValues values, boolean start) {
- values.values.put(PROPNAME_BACKGROUND, values.view.getBackground());
- if (values.view instanceof TextView) {
- values.values.put(PROPNAME_TEXT_COLOR, ((TextView)values.view).getCurrentTextColor());
+ private void captureValues(TransitionValues transitionValues) {
+ transitionValues.values.put(PROPNAME_BACKGROUND, transitionValues.view.getBackground());
+ if (transitionValues.view instanceof TextView) {
+ transitionValues.values.put(PROPNAME_TEXT_COLOR,
+ ((TextView)transitionValues.view).getCurrentTextColor());
}
}
@Override
- protected Animator play(ViewGroup sceneRoot, TransitionValues startValues,
+ public void captureStartValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
+ @Override
+ public void captureEndValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
+ @Override
+ public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;
diff --git a/core/java/android/view/transition/Rotate.java b/core/java/android/transition/Rotate.java
index d35a6dc7..ad1720c 100644
--- a/core/java/android/view/transition/Rotate.java
+++ b/core/java/android/transition/Rotate.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.ObjectAnimator;
@@ -24,18 +24,25 @@ import android.view.ViewGroup;
/**
* This transition captures the rotation property of targets before and after
* the scene change and animates any changes.
+ *
+ * @hide
*/
public class Rotate extends Transition {
private static final String PROPNAME_ROTATION = "android:rotate:rotation";
@Override
- protected void captureValues(TransitionValues values, boolean start) {
- values.values.put(PROPNAME_ROTATION, values.view.getRotation());
+ public void captureStartValues(TransitionValues transitionValues) {
+ transitionValues.values.put(PROPNAME_ROTATION, transitionValues.view.getRotation());
+ }
+
+ @Override
+ public void captureEndValues(TransitionValues transitionValues) {
+ transitionValues.values.put(PROPNAME_ROTATION, transitionValues.view.getRotation());
}
@Override
- protected Animator play(ViewGroup sceneRoot, TransitionValues startValues,
+ public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;
diff --git a/core/java/android/view/transition/Scene.java b/core/java/android/transition/Scene.java
index cf3eadb..f81eeef 100644
--- a/core/java/android/view/transition/Scene.java
+++ b/core/java/android/transition/Scene.java
@@ -14,10 +14,12 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.content.Context;
+import android.util.SparseArray;
import android.view.LayoutInflater;
+import android.view.View;
import android.view.ViewGroup;
/**
@@ -34,6 +36,37 @@ public final class Scene {
private ViewGroup mSceneRoot;
private ViewGroup mLayout; // alternative to layoutId
Runnable mEnterAction, mExitAction;
+ private static ThreadLocal<SparseArray<Scene>> sScenes = new ThreadLocal<SparseArray<Scene>>();
+
+ /**
+ * Returns a Scene described by the resource file associated with the given
+ * <code>layoutId</code> parameter. If such a Scene has already been created,
+ * that same Scene will be returned. This caching of layoutId-based scenes enables
+ * sharing of common scenes between those created in code and those referenced
+ * by {@link TransitionManager} XML resource files.
+ *
+ * @param sceneRoot The root of the hierarchy in which scene changes
+ * and transitions will take place.
+ * @param layoutId The id of a standard layout resource file.
+ * @param context The context used in the process of inflating
+ * the layout resource.
+ * @return
+ */
+ public static Scene getSceneForLayout(ViewGroup sceneRoot, int layoutId, Context context) {
+ SparseArray<Scene> scenes = sScenes.get();
+ if (scenes == null) {
+ scenes = new SparseArray<Scene>();
+ sScenes.set(scenes);
+ }
+ Scene scene = scenes.get(layoutId);
+ if (scene != null) {
+ return scene;
+ } else {
+ scene = new Scene(sceneRoot, layoutId, context);
+ scenes.put(layoutId, scene);
+ return scene;
+ }
+ }
/**
* Constructs a Scene with no information about how values will change
@@ -54,6 +87,9 @@ public final class Scene {
* children from the sceneRoot container and will inflate and add
* the hierarchy specified by the layoutId resource file.
*
+ * <p>This method is hidden because layoutId-based scenes should be
+ * created by the caching factory method {@link Scene#getCurrentScene(View)}.</p>
+ *
* @param sceneRoot The root of the hierarchy in which scene changes
* and transitions will take place.
* @param layoutId The id of a resource file that defines the view
@@ -61,7 +97,7 @@ public final class Scene {
* @param context The context used in the process of inflating
* the layout resource.
*/
- public Scene(ViewGroup sceneRoot, int layoutId, Context context) {
+ private Scene(ViewGroup sceneRoot, int layoutId, Context context) {
mContext = context;
mSceneRoot = sceneRoot;
mLayoutId = layoutId;
@@ -74,7 +110,7 @@ public final class Scene {
*
* @param sceneRoot The root of the hierarchy in which scene changes
* and transitions will take place.
- * @param layout The view hiearrchy of this scene, added as a child
+ * @param layout The view hierarchy of this scene, added as a child
* of sceneRoot when this scene is entered.
*/
public Scene(ViewGroup sceneRoot, ViewGroup layout) {
@@ -94,19 +130,14 @@ public final class Scene {
}
/**
- * Exits this scene, if it is the {@link ViewGroup#getCurrentScene()
- * currentScene} on the scene's {@link #getSceneRoot() scene root}.
- * Exiting a scene involves removing the layout added if the scene
- * has either a layoutId or layout view group (set at construction
- * time) and running the {@link #setExitAction(Runnable) exit action}
+ * Exits this scene, if it is the current scene
+ * on the scene's {@link #getSceneRoot() scene root}. The current scene is
+ * set when {@link #enter() entering} a scene.
+ * Exiting a scene runs the {@link #setExitAction(Runnable) exit action}
* if there is one.
*/
public void exit() {
- if (mSceneRoot.getCurrentScene() == this) {
- if (mLayoutId >= 0 || mLayout != null) {
- // Undo layout change caused by entering this scene
- getSceneRoot().removeAllViews();
- }
+ if (getCurrentScene(mSceneRoot) == this) {
if (mExitAction != null) {
mExitAction.run();
}
@@ -127,8 +158,7 @@ public final class Scene {
// Apply layout change, if any
if (mLayoutId >= 0 || mLayout != null) {
- // redundant with exit() action of previous scene, but must
- // empty out that parent container before adding to it
+ // empty out parent container before adding to it
getSceneRoot().removeAllViews();
if (mLayoutId >= 0) {
@@ -143,7 +173,30 @@ public final class Scene {
mEnterAction.run();
}
- mSceneRoot.setCurrentScene(this );
+ setCurrentScene(mSceneRoot, this);
+ }
+
+ /**
+ * Set the scene that the given view is in. The current scene is set only
+ * on the root view of a scene, not for every view in that hierarchy. This
+ * information is used by Scene to determine whether there is a previous
+ * scene which should be exited before the new scene is entered.
+ *
+ * @param view The view on which the current scene is being set
+ */
+ static void setCurrentScene(View view, Scene scene) {
+ view.setTagInternal(com.android.internal.R.id.current_scene, scene);
+ }
+
+ /**
+ * Gets the current {@link Scene} set on the given view. A scene is set on a view
+ * only if that view is the scene root.
+ *
+ * @return The current Scene set on this view. A value of null indicates that
+ * no Scene is currently set.
+ */
+ static Scene getCurrentScene(View view) {
+ return (Scene) view.getTag(com.android.internal.R.id.current_scene);
}
/**
diff --git a/core/java/android/view/transition/Slide.java b/core/java/android/transition/Slide.java
index b2f5db5..b38973c 100644
--- a/core/java/android/view/transition/Slide.java
+++ b/core/java/android/transition/Slide.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.ObjectAnimator;
@@ -28,6 +28,8 @@ import android.view.animation.DecelerateInterpolator;
* This transition captures the visibility of target objects before and
* after a scene change and animates any changes by sliding the target
* objects into or out of place.
+ *
+ * @hide
*/
public class Slide extends Visibility {
@@ -37,7 +39,7 @@ public class Slide extends Visibility {
private static final TimeInterpolator sDecelerator = new DecelerateInterpolator();
@Override
- protected Animator appear(ViewGroup sceneRoot,
+ public Animator onAppear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
View endView = (endValues != null) ? endValues.view : null;
@@ -49,7 +51,7 @@ public class Slide extends Visibility {
}
@Override
- protected Animator disappear(ViewGroup sceneRoot,
+ public Animator onDisappear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
View startView = (startValues != null) ? startValues.view : null;
diff --git a/core/java/android/view/transition/TextChange.java b/core/java/android/transition/TextChange.java
index 7973c97..1b26942 100644
--- a/core/java/android/view/transition/TextChange.java
+++ b/core/java/android/transition/TextChange.java
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.graphics.Color;
-import android.util.ArrayMap;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -33,6 +32,8 @@ import java.util.Map;
* starting text stays until the transition ends, at which point it changes
* to the end text. This is useful in situations where you want to resize a
* text view to its new size before displaying the text that goes there.
+ *
+ * @hide
*/
public class TextChange extends Transition {
private static final String PROPNAME_TEXT = "android:textchange:text";
@@ -84,15 +85,18 @@ public class TextChange extends Transition {
/**
* Sets the type of changing animation that will be run, one of
- * {@link #CHANGE_BEHAVIOR_KEEP} and {@link #CHANGE_BEHAVIOR_OUT_IN}.
+ * {@link #CHANGE_BEHAVIOR_KEEP}, {@link #CHANGE_BEHAVIOR_OUT},
+ * {@link #CHANGE_BEHAVIOR_IN}, and {@link #CHANGE_BEHAVIOR_OUT_IN}.
*
* @param changeBehavior The type of fading animation to use when this
* transition is run.
+ * @return this textChange object.
*/
- public void setChangeBehavior(int changeBehavior) {
+ public TextChange setChangeBehavior(int changeBehavior) {
if (changeBehavior >= CHANGE_BEHAVIOR_KEEP && changeBehavior <= CHANGE_BEHAVIOR_OUT_IN) {
mChangeBehavior = changeBehavior;
}
+ return this;
}
@Override
@@ -100,19 +104,38 @@ public class TextChange extends Transition {
return sTransitionProperties;
}
- @Override
- protected void captureValues(TransitionValues values, boolean start) {
- if (values.view instanceof TextView) {
- TextView textview = (TextView) values.view;
- values.values.put(PROPNAME_TEXT, textview.getText());
+ /**
+ * Returns the type of changing animation that will be run.
+ *
+ * @return either {@link #CHANGE_BEHAVIOR_KEEP}, {@link #CHANGE_BEHAVIOR_OUT},
+ * {@link #CHANGE_BEHAVIOR_IN}, or {@link #CHANGE_BEHAVIOR_OUT_IN}.
+ */
+ public int getChangeBehavior() {
+ return mChangeBehavior;
+ }
+
+ private void captureValues(TransitionValues transitionValues) {
+ if (transitionValues.view instanceof TextView) {
+ TextView textview = (TextView) transitionValues.view;
+ transitionValues.values.put(PROPNAME_TEXT, textview.getText());
if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
- values.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
+ transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
}
}
}
@Override
- protected Animator play(ViewGroup sceneRoot, TransitionValues startValues,
+ public void captureStartValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
+ @Override
+ public void captureEndValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
+ @Override
+ public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
if (startValues == null || endValues == null || !(endValues.view instanceof TextView)) {
return null;
diff --git a/core/java/android/view/transition/Transition.java b/core/java/android/transition/Transition.java
index a66fa52..59df183 100644
--- a/core/java/android/view/transition/Transition.java
+++ b/core/java/android/transition/Transition.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -31,11 +31,12 @@ import android.view.ViewOverlay;
import android.widget.ListView;
import java.util.ArrayList;
+import java.util.List;
/**
* A Transition holds information about animations that will be run on its
* targets during a scene change. Subclasses of this abstract class may
- * choreograph several child transitions ({@link TransitionGroup} or they may
+ * choreograph several child transitions ({@link TransitionSet} or they may
* perform custom animations themselves. Any Transition has two main jobs:
* (1) capture property values, and (2) play animations based on changes to
* captured property values. A custom transition knows what property values
@@ -50,9 +51,42 @@ import java.util.ArrayList;
* a non-UI thread, so changes to the view due to transitions (such as moving
* and resizing the view) may be out of sync with the display inside those bounds.
* TextureView is more compatible with transitions in general, but some
- * specific transitions (such as {@link Crossfade}) may not be compatible
+ * specific transitions (such as {@link Fade}) may not be compatible
* with TextureView because they rely on {@link ViewOverlay} functionality,
* which does not currently work with TextureView.</p>
+ *
+ * <p>Transitions can be declared in XML resource files inside the <code>res/transition</code>
+ * directory. Transition resources consist of a tag name for one of the Transition
+ * subclasses along with attributes to define some of the attributes of that transition.
+ * For example, here is a minimal resource file that declares a {@link ChangeBounds} transition:</p>
+ *
+ * {@sample development/samples/ApiDemos/res/transition/changebounds.xml ChangeBounds}
+ *
+ * <p>Note that attributes for the transition are not required, just as they are
+ * optional when declared in code; Transitions created from XML resources will use
+ * the same defaults as their code-created equivalents. Here is a slightly more
+ * elaborate example which declares a {@link TransitionSet} transition with
+ * {@link ChangeBounds} and {@link Fade} child transitions:</p>
+ *
+ * {@sample
+ * development/samples/ApiDemos/res/transition/changebounds_fadeout_sequential.xml TransitionSet}
+ *
+ * <p>In this example, the transitionOrdering attribute is used on the TransitionSet
+ * object to change from the default {@link TransitionSet#ORDERING_TOGETHER} behavior
+ * to be {@link TransitionSet#ORDERING_SEQUENTIAL} instead. Also, the {@link Fade}
+ * transition uses a fadingMode of {@link Fade#OUT} instead of the default
+ * out-in behavior. Finally, note the use of the <code>targets</code> sub-tag, which
+ * takes a set of {@link android.R.styleable#TransitionTarget target} tags, each
+ * of which lists a specific <code>targetId</code> which this transition acts upon.
+ * Use of targets is optional, but can be used to either limit the time spent checking
+ * attributes on unchanging views, or limiting the types of animations run on specific views.
+ * In this case, we know that only the <code>grayscaleContainer</code> will be
+ * disappearing, so we choose to limit the {@link Fade} transition to only that view.</p>
+ *
+ * Further information on XML resource descriptions for transitions can be found for
+ * {@link android.R.styleable#Transition}, {@link android.R.styleable#TransitionSet},
+ * {@link android.R.styleable#TransitionTarget}, and {@link android.R.styleable#Fade}.
+ *
*/
public abstract class Transition implements Cloneable {
@@ -64,17 +98,17 @@ public abstract class Transition implements Cloneable {
long mStartDelay = -1;
long mDuration = -1;
TimeInterpolator mInterpolator = null;
- int[] mTargetIds;
- View[] mTargets;
+ ArrayList<Integer> mTargetIds = new ArrayList<Integer>();
+ ArrayList<View> mTargets = new ArrayList<View>();
private TransitionValuesMaps mStartValues = new TransitionValuesMaps();
private TransitionValuesMaps mEndValues = new TransitionValuesMaps();
- TransitionGroup mParent = null;
+ TransitionSet mParent = null;
// Per-animator information used for later canceling when future transitions overlap
private static ThreadLocal<ArrayMap<Animator, AnimationInfo>> sRunningAnimators =
new ThreadLocal<ArrayMap<Animator, AnimationInfo>>();
- // Scene Root is set at play() time in the cloned Transition
+ // Scene Root is set at createAnimator() time in the cloned Transition
ViewGroup mSceneRoot = null;
// Track all animators in use in case the transition gets canceled and needs to
@@ -91,14 +125,15 @@ public abstract class Transition implements Cloneable {
// The set of listeners to be sent transition lifecycle events.
ArrayList<TransitionListener> mListeners = null;
- // The set of animators collected from calls to play(), to be run in runAnimations()
+ // The set of animators collected from calls to createAnimator(),
+ // to be run in runAnimators()
ArrayList<Animator> mAnimators = new ArrayList<Animator>();
/**
* Constructs a Transition object with no target objects. A transition with
* no targets defaults to running on all target objects in the scene hierarchy
- * (if the transition is not contained in a TransitionGroup), or all target
- * objects passed down from its parent (if it is in a TransitionGroup).
+ * (if the transition is not contained in a TransitionSet), or all target
+ * objects passed down from its parent (if it is in a TransitionSet).
*/
public Transition() {}
@@ -110,6 +145,7 @@ public abstract class Transition implements Cloneable {
*
* @param duration The length of the animation, in milliseconds.
* @return This transition object.
+ * @attr ref android.R.styleable#Transition_duration
*/
public Transition setDuration(long duration) {
mDuration = duration;
@@ -121,8 +157,8 @@ public abstract class Transition implements Cloneable {
* the returned value will be negative, indicating that resulting animators will
* retain their own durations.
*
- * @return The duration set on this transition, if one has been set, otherwise
- * returns a negative number.
+ * @return The duration set on this transition, in milliseconds, if one has been
+ * set, otherwise returns a negative number.
*/
public long getDuration() {
return mDuration;
@@ -135,9 +171,12 @@ public abstract class Transition implements Cloneable {
* Transition is set, that delay will override the Animator delay.
*
* @param startDelay The length of the delay, in milliseconds.
+ * @return This transition object.
+ * @attr ref android.R.styleable#Transition_startDelay
*/
- public void setStartDelay(long startDelay) {
+ public Transition setStartDelay(long startDelay) {
mStartDelay = startDelay;
+ return this;
}
/**
@@ -145,8 +184,8 @@ public abstract class Transition implements Cloneable {
* the returned value will be negative, indicating that resulting animators will
* retain their own startDelays.
*
- * @return The startDealy set on this transition, if one has been set, otherwise
- * returns a negative number.
+ * @return The startDelay set on this transition, in milliseconds, if one has
+ * been set, otherwise returns a negative number.
*/
public long getStartDelay() {
return mStartDelay;
@@ -159,9 +198,12 @@ public abstract class Transition implements Cloneable {
* Transition is set, that interpolator will override the Animator interpolator.
*
* @param interpolator The time interpolator used by the transition
+ * @return This transition object.
+ * @attr ref android.R.styleable#Transition_interpolator
*/
- public void setInterpolator(TimeInterpolator interpolator) {
+ public Transition setInterpolator(TimeInterpolator interpolator) {
mInterpolator = interpolator;
+ return this;
}
/**
@@ -178,7 +220,7 @@ public abstract class Transition implements Cloneable {
/**
* Returns the set of property names used stored in the {@link TransitionValues}
- * object passed into {@link #captureValues(TransitionValues, boolean)} that
+ * object passed into {@link #captureStartValues(TransitionValues)} that
* this transition cares about for the purposes of canceling overlapping animations.
* When any transition is started on a given scene root, all transitions
* currently running on that same scene root are checked to see whether the
@@ -202,11 +244,17 @@ public abstract class Transition implements Cloneable {
}
/**
- * This method is called by the transition's parent (all the way up to the
+ * This method creates an animation that will be run for this transition
+ * given the information in the startValues and endValues structures captured
+ * earlier for the start and end scenes. Subclasses of Transition should override
+ * this method. The method should only be called by the transition system; it is
+ * not intended to be called from external classes.
+ *
+ * <p>This method is called by the transition's parent (all the way up to the
* topmost Transition in the hierarchy) with the sceneRoot and start/end
* values that the transition may need to set up initial target values
* and construct an appropriate animation. For example, if an overall
- * Transition is a {@link TransitionGroup} consisting of several
+ * Transition is a {@link TransitionSet} consisting of several
* child transitions in sequence, then some of the child transitions may
* want to set initial values on target views prior to the overall
* Transition commencing, to put them in an appropriate state for the
@@ -216,14 +264,13 @@ public abstract class Transition implements Cloneable {
* actually starting the animation. This is necessary because the scene
* change that triggers the Transition will automatically set the end-scene
* on all target views, so a Transition that wants to animate from a
- * different value should set that value prior to returning from this method.
+ * different value should set that value prior to returning from this method.</p>
*
* <p>Additionally, a Transition can perform logic to determine whether
* the transition needs to run on the given target and start/end values.
* For example, a transition that resizes objects on the screen may wish
* to avoid running for views which are not present in either the start
- * or end scenes. A return value of <code>null</code> indicates that
- * no animation should run. The default implementation returns null.</p>
+ * or end scenes.</p>
*
* <p>If there is an animator created and returned from this method, the
* transition mechanism will apply any applicable duration, startDelay,
@@ -234,31 +281,34 @@ public abstract class Transition implements Cloneable {
* <p>The method is called for every applicable target object, which is
* stored in the {@link TransitionValues#view} field.</p>
*
- * @param sceneRoot
- * @param startValues
- * @param endValues
- * @return A non-null Animator to be started at the appropriate time in the
- * overall transition for this scene change, null otherwise.
+ *
+ * @param sceneRoot The root of the transition hierarchy.
+ * @param startValues The values for a specific target in the start scene.
+ * @param endValues The values for the target in the end scene.
+ * @return A Animator to be started at the appropriate time in the
+ * overall transition for this scene change. A null value means no animation
+ * should be run.
*/
- protected Animator play(ViewGroup sceneRoot, TransitionValues startValues,
+ public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
return null;
}
/**
- * This version of play() is called with the entire set of start/end
+ * This method, essentially a wrapper around all calls to createAnimator for all
+ * possible target views, is called with the entire set of start/end
* values. The implementation in Transition iterates through these lists
- * and calls {@link #play(ViewGroup, TransitionValues, TransitionValues)}
+ * and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
* with each set of start/end values on this transition. The
- * TransitionGroup subclass overrides this method and delegates it to
+ * TransitionSet subclass overrides this method and delegates it to
* each of its children in succession.
*
* @hide
*/
- protected void play(ViewGroup sceneRoot, TransitionValuesMaps startValues,
+ protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
TransitionValuesMaps endValues) {
if (DBG) {
- Log.d(LOG_TAG, "play() for " + this);
+ Log.d(LOG_TAG, "createAnimators() for " + this);
}
ArrayMap<View, TransitionValues> endCopy =
new ArrayMap<View, TransitionValues>(endValues.viewValues);
@@ -392,7 +442,7 @@ public abstract class Transition implements Cloneable {
}
}
// TODO: what to do about targetIds and itemIds?
- Animator animator = play(sceneRoot, start, end);
+ Animator animator = createAnimator(sceneRoot, start, end);
if (animator != null) {
// Save animation info for future cancellation purposes
View view = null;
@@ -450,19 +500,19 @@ public abstract class Transition implements Cloneable {
* views are ignored and only the ids are used).
*/
boolean isValidTarget(View target, long targetId) {
- if (mTargetIds == null && mTargets == null) {
+ if (mTargetIds.size() == 0 && mTargets.size() == 0) {
return true;
}
- if (mTargetIds != null) {
- for (int i = 0; i < mTargetIds.length; ++i) {
- if (mTargetIds[i] == targetId) {
+ if (mTargetIds.size() > 0) {
+ for (int i = 0; i < mTargetIds.size(); ++i) {
+ if (mTargetIds.get(i) == targetId) {
return true;
}
}
}
- if (target != null && mTargets != null) {
- for (int i = 0; i < mTargets.length; ++i) {
- if (mTargets[i] == target) {
+ if (target != null && mTargets.size() > 0) {
+ for (int i = 0; i < mTargets.size(); ++i) {
+ if (mTargets.get(i) == target) {
return true;
}
}
@@ -485,13 +535,13 @@ public abstract class Transition implements Cloneable {
*
* @hide
*/
- protected void runAnimations() {
+ protected void runAnimators() {
if (DBG) {
- Log.d(LOG_TAG, "runAnimations() on " + this);
+ Log.d(LOG_TAG, "runAnimators() on " + this);
}
start();
ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
- // Now start every Animator that was previously created for this transition in play()
+ // Now start every Animator that was previously created for this transition
for (Animator anim : mAnimators) {
if (DBG) {
Log.d(LOG_TAG, " anim: " + anim);
@@ -525,17 +575,49 @@ public abstract class Transition implements Cloneable {
}
/**
- * Captures the current scene of values for the properties that this
- * transition monitors. These values can be either the start or end
- * values used in a subsequent call to
- * {@link #play(ViewGroup, TransitionValues, TransitionValues)}, as indicated by
- * <code>start</code>. The main concern for an implementation is what the
+ * Captures the values in the start scene for the properties that this
+ * transition monitors. These values are then passed as the startValues
+ * structure in a later call to
+ * {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}.
+ * The main concern for an implementation is what the
+ * properties are that the transition cares about and what the values are
+ * for all of those properties. The start and end values will be compared
+ * later during the
+ * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)}
+ * method to determine what, if any, animations, should be run.
+ *
+ * <p>Subclasses must implement this method. The method should only be called by the
+ * transition system; it is not intended to be called from external classes.</p>
+ *
+ * @param transitionValues The holder for any values that the Transition
+ * wishes to store. Values are stored in the <code>values</code> field
+ * of this TransitionValues object and are keyed from
+ * a String value. For example, to store a view's rotation value,
+ * a transition might call
+ * <code>transitionValues.values.put("appname:transitionname:rotation",
+ * view.getRotation())</code>. The target view will already be stored in
+ * the transitionValues structure when this method is called.
+ *
+ * @see #captureEndValues(TransitionValues)
+ * @see #createAnimator(ViewGroup, TransitionValues, TransitionValues)
+ */
+ public abstract void captureStartValues(TransitionValues transitionValues);
+
+ /**
+ * Captures the values in the end scene for the properties that this
+ * transition monitors. These values are then passed as the endValues
+ * structure in a later call to
+ * {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}.
+ * The main concern for an implementation is what the
* properties are that the transition cares about and what the values are
* for all of those properties. The start and end values will be compared
* later during the
- * {@link #play(android.view.ViewGroup, TransitionValues, TransitionValues)}
+ * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)}
* method to determine what, if any, animations, should be run.
*
+ * <p>Subclasses must implement this method. The method should only be called by the
+ * transition system; it is not intended to be called from external classes.</p>
+ *
* @param transitionValues The holder for any values that the Transition
* wishes to store. Values are stored in the <code>values</code> field
* of this TransitionValues object and are keyed from
@@ -544,29 +626,51 @@ public abstract class Transition implements Cloneable {
* <code>transitionValues.values.put("appname:transitionname:rotation",
* view.getRotation())</code>. The target view will already be stored in
* the transitionValues structure when this method is called.
+ *
+ * @see #captureStartValues(TransitionValues)
+ * @see #createAnimator(ViewGroup, TransitionValues, TransitionValues)
*/
- protected abstract void captureValues(TransitionValues transitionValues, boolean start);
+ public abstract void captureEndValues(TransitionValues transitionValues);
/**
- * Sets the ids of target views that this Transition is interested in
+ * Adds the id of a target view that this Transition is interested in
* animating. By default, there are no targetIds, and a Transition will
* listen for changes on every view in the hierarchy below the sceneRoot
- * of the Scene being transitioned into. Setting targetIDs constrains
+ * of the Scene being transitioned into. Setting targetIds constrains
* the Transition to only listen for, and act on, views with these IDs.
* Views with different IDs, or no IDs whatsoever, will be ignored.
*
+ * <p>Note that using ids to specify targets implies that ids should be unique
+ * within the view hierarchy underneat the scene root.</p>
+ *
* @see View#getId()
- * @param targetIds A list of IDs which specify the set of Views on which
- * the Transition will act.
- * @return Transition The Transition on which the targetIds have been set.
+ * @param targetId The id of a target view, must be a positive number.
+ * @return The Transition to which the targetId is added.
+ * Returning the same object makes it easier to chain calls during
+ * construction, such as
+ * <code>transitionSet.addTransitions(new Fade()).addTargetId(someId);</code>
+ */
+ public Transition addTargetId(int targetId) {
+ if (targetId > 0) {
+ mTargetIds.add(targetId);
+ }
+ return this;
+ }
+
+ /**
+ * Removes the given targetId from the list of ids that this Transition
+ * is interested in animating.
+ *
+ * @param targetId The id of a target view, must be a positive number.
+ * @return The Transition from which the targetId is removed.
* Returning the same object makes it easier to chain calls during
* construction, such as
- * <code>transitionGroup.addTransitions(new Fade()).setTargetIds(someId);</code>
+ * <code>transitionSet.addTransitions(new Fade()).removeTargetId(someId);</code>
*/
- public Transition setTargetIds(int... targetIds) {
- int numTargets = targetIds.length;
- mTargetIds = new int[numTargets];
- System.arraycopy(targetIds, 0, mTargetIds, 0, numTargets);
+ public Transition removeTargetId(int targetId) {
+ if (targetId > 0) {
+ mTargetIds.remove(targetId);
+ }
return this;
}
@@ -578,28 +682,43 @@ public abstract class Transition implements Cloneable {
* the Transition to only listen for, and act on, these views.
* All other views will be ignored.
*
- * <p>The target list is like the {@link #setTargetIds(int...) targetId}
+ * <p>The target list is like the {@link #addTargetId(int) targetId}
* list except this list specifies the actual View instances, not the ids
* of the views. This is an important distinction when scene changes involve
* view hierarchies which have been inflated separately; different views may
* share the same id but not actually be the same instance. If the transition
- * should treat those views as the same, then seTargetIds() should be used
- * instead of setTargets(). If, on the other hand, scene changes involve
+ * should treat those views as the same, then {@link #addTargetId(int)} should be used
+ * instead of {@link #addTarget(View)}. If, on the other hand, scene changes involve
* changes all within the same view hierarchy, among views which do not
- * necessary have ids set on them, then the target list may be more
+ * necessarily have ids set on them, then the target list of views may be more
* convenient.</p>
*
- * @see #setTargetIds(int...)
- * @param targets A list of Views on which the Transition will act.
- * @return Transition The Transition on which the targets have been set.
+ * @see #addTargetId(int)
+ * @param target A View on which the Transition will act, must be non-null.
+ * @return The Transition to which the target is added.
+ * Returning the same object makes it easier to chain calls during
+ * construction, such as
+ * <code>transitionSet.addTransitions(new Fade()).addTarget(someView);</code>
+ */
+ public Transition addTarget(View target) {
+ mTargets.add(target);
+ return this;
+ }
+
+ /**
+ * Removes the given target from the list of targets that this Transition
+ * is interested in animating.
+ *
+ * @param target The target view, must be non-null.
+ * @return Transition The Transition from which the target is removed.
* Returning the same object makes it easier to chain calls during
* construction, such as
- * <code>transitionGroup.addTransitions(new Fade()).setTargets(someView);</code>
+ * <code>transitionSet.addTransitions(new Fade()).removeTarget(someView);</code>
*/
- public Transition setTargets(View... targets) {
- int numTargets = targets.length;
- mTargets = new View[numTargets];
- System.arraycopy(targets, 0, mTargets, 0, numTargets);
+ public Transition removeTarget(View target) {
+ if (target != null) {
+ mTargets.remove(target);
+ }
return this;
}
@@ -612,7 +731,7 @@ public abstract class Transition implements Cloneable {
*
* @return the list of target IDs
*/
- public int[] getTargetIds() {
+ public List<Integer> getTargetIds() {
return mTargetIds;
}
@@ -625,7 +744,7 @@ public abstract class Transition implements Cloneable {
*
* @return the list of target views
*/
- public View[] getTargets() {
+ public List<View> getTargets() {
return mTargets;
}
@@ -646,16 +765,19 @@ public abstract class Transition implements Cloneable {
mEndValues.idValues.clear();
mEndValues.itemIdValues.clear();
}
- if (mTargetIds != null && mTargetIds.length > 0 ||
- mTargets != null && mTargets.length > 0) {
- if (mTargetIds != null) {
- for (int i = 0; i < mTargetIds.length; ++i) {
- int id = mTargetIds[i];
+ if (mTargetIds.size() > 0 || mTargets.size() > 0) {
+ if (mTargetIds.size() > 0) {
+ for (int i = 0; i < mTargetIds.size(); ++i) {
+ int id = mTargetIds.get(i);
View view = sceneRoot.findViewById(id);
if (view != null) {
TransitionValues values = new TransitionValues();
values.view = view;
- captureValues(values, start);
+ if (start) {
+ captureStartValues(values);
+ } else {
+ captureEndValues(values);
+ }
if (start) {
mStartValues.viewValues.put(view, values);
if (id >= 0) {
@@ -670,13 +792,17 @@ public abstract class Transition implements Cloneable {
}
}
}
- if (mTargets != null) {
- for (int i = 0; i < mTargets.length; ++i) {
- View view = mTargets[i];
+ if (mTargets.size() > 0) {
+ for (int i = 0; i < mTargets.size(); ++i) {
+ View view = mTargets.get(i);
if (view != null) {
TransitionValues values = new TransitionValues();
values.view = view;
- captureValues(values, start);
+ if (start) {
+ captureStartValues(values);
+ } else {
+ captureEndValues(values);
+ }
if (start) {
mStartValues.viewValues.put(view, values);
} else {
@@ -723,7 +849,7 @@ public abstract class Transition implements Cloneable {
}
TransitionValues values = new TransitionValues();
values.view = view;
- captureValues(values, start);
+ captureStartValues(values);
if (start) {
if (!isListViewItem) {
mStartValues.viewValues.put(view, values);
@@ -757,7 +883,7 @@ public abstract class Transition implements Cloneable {
* necessary, for example, to query the before/after state of related views
* for a given transition.
*/
- protected TransitionValues getTransitionValues(View view, boolean start) {
+ public TransitionValues getTransitionValues(View view, boolean start) {
if (mParent != null) {
return mParent.getTransitionValues(view, start);
}
@@ -834,7 +960,7 @@ public abstract class Transition implements Cloneable {
/**
* Called by TransitionManager to play the transition. This calls
- * play() to set things up and create all of the animations and then
+ * createAnimators() to set things up and create all of the animations and then
* runAnimations() to actually start the animations.
*/
void playTransition(ViewGroup sceneRoot) {
@@ -889,11 +1015,8 @@ public abstract class Transition implements Cloneable {
}
}
- // setup() must be called on entire transition hierarchy and set of views
- // before calling play() on anything; every transition needs a chance to set up
- // target views appropriately before transitions begin running
- play(sceneRoot, mStartValues, mEndValues);
- runAnimations();
+ createAnimators(sceneRoot, mStartValues, mEndValues);
+ runAnimators();
}
/**
@@ -933,7 +1056,7 @@ public abstract class Transition implements Cloneable {
/**
* This method is called automatically by the transition and
- * TransitionGroup classes prior to a Transition subclass starting;
+ * TransitionSet classes prior to a Transition subclass starting;
* subclasses should not need to call it directly.
*
* @hide
@@ -954,9 +1077,9 @@ public abstract class Transition implements Cloneable {
/**
* This method is called automatically by the Transition and
- * TransitionGroup classes when a transition finishes, either because
+ * TransitionSet classes when a transition finishes, either because
* a transition did nothing (returned a null Animator from
- * {@link Transition#play(ViewGroup, TransitionValues,
+ * {@link Transition#createAnimator(ViewGroup, TransitionValues,
* TransitionValues)}) or because the transition returned a valid
* Animator and end() was called in the onAnimationEnd()
* callback of the AnimatorListener.
@@ -993,11 +1116,10 @@ public abstract class Transition implements Cloneable {
/**
* This method cancels a transition that is currently running.
- * Implementation TBD.
+ *
+ * @hide
*/
protected void cancel() {
- // TODO: how does this work with instances?
- // TODO: this doesn't actually do *anything* yet
int numAnimators = mCurrentAnimators.size();
for (int i = numAnimators - 1; i >= 0; i--) {
Animator animator = mCurrentAnimators.get(i);
@@ -1019,12 +1141,14 @@ public abstract class Transition implements Cloneable {
*
* @param listener the listener to be added to the current set of listeners
* for this animation.
+ * @return This transition object.
*/
- public void addListener(TransitionListener listener) {
+ public Transition addListener(TransitionListener listener) {
if (mListeners == null) {
mListeners = new ArrayList<TransitionListener>();
}
mListeners.add(listener);
+ return this;
}
/**
@@ -1032,29 +1156,22 @@ public abstract class Transition implements Cloneable {
*
* @param listener the listener to be removed from the current set of
* listeners for this transition.
+ * @return This transition object.
*/
- public void removeListener(TransitionListener listener) {
+ public Transition removeListener(TransitionListener listener) {
if (mListeners == null) {
- return;
+ return this;
}
mListeners.remove(listener);
if (mListeners.size() == 0) {
mListeners = null;
}
+ return this;
}
- /**
- * Gets the set of {@link TransitionListener} objects that are currently
- * listening for events on this <code>Transition</code> object.
- *
- * @return ArrayList<TransitionListener> The set of listeners.
- */
- public ArrayList<TransitionListener> getListeners() {
- return mListeners;
- }
-
- void setSceneRoot(ViewGroup sceneRoot) {
+ Transition setSceneRoot(ViewGroup sceneRoot) {
mSceneRoot = sceneRoot;
+ return this;
}
@Override
@@ -1076,9 +1193,9 @@ public abstract class Transition implements Cloneable {
/**
* Returns the name of this Transition. This name is used internally to distinguish
* between different transitions to determine when interrupting transitions overlap.
- * For example, a Move running on the same target view as another Move should determine
- * whether the old transition is animating to different end values and should be
- * canceled in favor of the new transition.
+ * For example, a ChangeBounds running on the same target view as another ChangeBounds
+ * should determine whether the old transition is animating to different end values
+ * and should be canceled in favor of the new transition.
*
* <p>By default, a Transition's name is simply the value of {@link Class#getName()},
* but subclasses are free to override and return something different.</p>
@@ -1101,22 +1218,22 @@ public abstract class Transition implements Cloneable {
if (mInterpolator != null) {
result += "interp(" + mInterpolator + ") ";
}
- if (mTargetIds != null || mTargets != null) {
+ if (mTargetIds.size() > 0 || mTargets.size() > 0) {
result += "tgts(";
- if (mTargetIds != null) {
- for (int i = 0; i < mTargetIds.length; ++i) {
+ if (mTargetIds.size() > 0) {
+ for (int i = 0; i < mTargetIds.size(); ++i) {
if (i > 0) {
result += ", ";
}
- result += mTargetIds[i];
+ result += mTargetIds.get(i);
}
}
- if (mTargets != null) {
- for (int i = 0; i < mTargets.length; ++i) {
+ if (mTargets.size() > 0) {
+ for (int i = 0; i < mTargets.size(); ++i) {
if (i > 0) {
result += ", ";
}
- result += mTargets[i];
+ result += mTargets.get(i);
}
}
result += ")";
@@ -1149,11 +1266,11 @@ public abstract class Transition implements Cloneable {
/**
* Notification about the cancellation of the transition.
- * Note that cancel() may be called by a parent {@link TransitionGroup} on
+ * Note that cancel may be called by a parent {@link TransitionSet} on
* a child transition which has not yet started. This allows the child
* transition to restore state on target objects which was set at
- * {@link #play(android.view.ViewGroup, TransitionValues, TransitionValues)
- * play()} time.
+ * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)
+ * createAnimator()} time.
*
* @param transition The transition which was canceled.
*/
@@ -1161,11 +1278,11 @@ public abstract class Transition implements Cloneable {
/**
* Notification when a transition is paused.
- * Note that play() may be called by a parent {@link TransitionGroup} on
+ * Note that createAnimator() may be called by a parent {@link TransitionSet} on
* a child transition which has not yet started. This allows the child
* transition to restore state on target objects which was set at
- * {@link #play(android.view.ViewGroup, TransitionValues, TransitionValues)
- * play()} time.
+ * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)
+ * createAnimator()} time.
*
* @param transition The transition which was paused.
*/
@@ -1173,7 +1290,7 @@ public abstract class Transition implements Cloneable {
/**
* Notification when a transition is resumed.
- * Note that resume() may be called by a parent {@link TransitionGroup} on
+ * Note that resume() may be called by a parent {@link TransitionSet} on
* a child transition which has not yet started. This allows the child
* transition to restore state which may have changed in an earlier call
* to {@link #onTransitionPause(Transition)}.
diff --git a/core/java/android/view/transition/TransitionInflater.java b/core/java/android/transition/TransitionInflater.java
index be658af..ebedeeb 100644
--- a/core/java/android/view/transition/TransitionInflater.java
+++ b/core/java/android/transition/TransitionInflater.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.content.Context;
import android.content.res.Resources;
@@ -35,6 +35,11 @@ import java.util.ArrayList;
/**
* This class inflates scenes and transitions from resource files.
+ *
+ * Information on XML resource descriptions for transitions can be found for
+ * {@link android.R.styleable#Transition}, {@link android.R.styleable#TransitionSet},
+ * {@link android.R.styleable#TransitionTarget}, {@link android.R.styleable#Fade},
+ * and {@link android.R.styleable#TransitionManager}.
*/
public class TransitionInflater {
@@ -121,46 +126,12 @@ public class TransitionInflater {
}
}
- /**
- * Loads a {@link Scene} object from a resource
- *
- * @param resource The resource id of the scene to load
- * @return The loaded Scene object
- * @throws android.content.res.Resources.NotFoundException when the scene
- * cannot be loaded
- */
- public Scene inflateScene(int resource, ViewGroup parent) {
- Scene scene = mScenes.get(resource);
- if (scene != null) {
- return scene;
- }
- XmlResourceParser parser = mContext.getResources().getXml(resource);
- try {
- scene = createSceneFromXml(parser, Xml.asAttributeSet(parser), parent);
- mScenes.put(resource, scene);
- return scene;
- } catch (XmlPullParserException e) {
- InflateException ex = new InflateException(e.getMessage());
- ex.initCause(e);
- throw ex;
- } catch (IOException e) {
- InflateException ex = new InflateException(
- parser.getPositionDescription()
- + ": " + e.getMessage());
- ex.initCause(e);
- throw ex;
- } finally {
- parser.close();
- }
- }
-
-
//
// Transition loading
//
private Transition createTransitionFromXml(XmlPullParser parser,
- AttributeSet attrs, TransitionGroup transitionGroup)
+ AttributeSet attrs, TransitionSet transitionSet)
throws XmlPullParserException, IOException {
Transition transition = null;
@@ -180,10 +151,14 @@ public class TransitionInflater {
String name = parser.getName();
if ("fade".equals(name)) {
- transition = new Fade();
+ TypedArray a = mContext.obtainStyledAttributes(attrs,
+ com.android.internal.R.styleable.Fade);
+ int fadingMode = a.getInt(com.android.internal.R.styleable.Fade_fadingMode,
+ Fade.IN | Fade.OUT);
+ transition = new Fade(fadingMode);
newTransition = true;
- } else if ("move".equals(name)) {
- transition = new Move();
+ } else if ("changeBounds".equals(name)) {
+ transition = new ChangeBounds();
newTransition = true;
} else if ("slide".equals(name)) {
transition = new Slide();
@@ -194,24 +169,31 @@ public class TransitionInflater {
} else if ("recolor".equals(name)) {
transition = new Recolor();
newTransition = true;
- } else if ("transitionGroup".equals(name)) {
- transition = new TransitionGroup();
- createTransitionFromXml(parser, attrs, ((TransitionGroup) transition));
+ } else if ("set".equals(name)) {
+ transition = new TransitionSet();
+ TypedArray a = mContext.obtainStyledAttributes(attrs,
+ com.android.internal.R.styleable.TransitionSet);
+ int ordering = a.getInt(
+ com.android.internal.R.styleable.TransitionSet_transitionOrdering,
+ TransitionSet.ORDERING_TOGETHER);
+ ((TransitionSet) transition).setOrdering(ordering);
+ createTransitionFromXml(parser, attrs, ((TransitionSet) transition));
+ a.recycle();
newTransition = true;
} else if ("targets".equals(name)) {
if (parser.getDepth() - 1 > depth && transition != null) {
// We're inside the child tag - add targets to the child
- getTargetIDs(parser, attrs, transition);
- } else if (parser.getDepth() - 1 == depth && transitionGroup != null) {
- // add targets to the group
- getTargetIDs(parser, attrs, transitionGroup);
+ getTargetIds(parser, attrs, transition);
+ } else if (parser.getDepth() - 1 == depth && transitionSet != null) {
+ // add targets to the set
+ getTargetIds(parser, attrs, transitionSet);
}
}
if (transition != null || "targets".equals(name)) {
if (newTransition) {
loadTransition(transition, attrs);
- if (transitionGroup != null) {
- transitionGroup.addTransitions(transition);
+ if (transitionSet != null) {
+ transitionSet.addTransition(transition);
}
}
} else {
@@ -222,7 +204,7 @@ public class TransitionInflater {
return transition;
}
- private void getTargetIDs(XmlPullParser parser,
+ private void getTargetIds(XmlPullParser parser,
AttributeSet attrs, Transition transition) throws XmlPullParserException, IOException {
// Make sure we are on a start tag.
@@ -240,8 +222,9 @@ public class TransitionInflater {
String name = parser.getName();
if (name.equals("target")) {
TypedArray a = mContext.obtainStyledAttributes(attrs,
- com.android.internal.R.styleable.Transition);
- int id = a.getResourceId(com.android.internal.R.styleable.Transition_targetID, -1);
+ com.android.internal.R.styleable.TransitionTarget);
+ int id = a.getResourceId(
+ com.android.internal.R.styleable.TransitionTarget_targetId, -1);
if (id >= 0) {
targetIds.add(id);
}
@@ -251,11 +234,9 @@ public class TransitionInflater {
}
int numTargets = targetIds.size();
if (numTargets > 0) {
- int[] targetsArray = new int[numTargets];
- for (int i = 0; i < targetIds.size(); ++i) {
- targetsArray[i] = targetIds.get(i);
+ for (int i = 0; i < numTargets; ++i) {
+ transition.addTargetId(targetIds.get(i));
}
- transition.setTargetIds(targetsArray);
}
}
@@ -268,9 +249,9 @@ public class TransitionInflater {
if (duration >= 0) {
transition.setDuration(duration);
}
- long startOffset = a.getInt(com.android.internal.R.styleable.Transition_startOffset, -1);
- if (startOffset > 0) {
- transition.setStartDelay(startOffset);
+ long startDelay = a.getInt(com.android.internal.R.styleable.Transition_startDelay, -1);
+ if (startDelay > 0) {
+ transition.setStartDelay(startDelay);
}
final int resID =
a.getResourceId(com.android.internal.R.styleable.Animator_interpolator, 0);
@@ -313,20 +294,19 @@ public class TransitionInflater {
}
private void loadTransition(AttributeSet attrs, ViewGroup sceneRoot,
- TransitionManager transitionManager)
- throws Resources.NotFoundException {
+ TransitionManager transitionManager) throws Resources.NotFoundException {
TypedArray a = mContext.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.TransitionManager);
- int transitionId = attrs.getAttributeResourceValue(
+ int transitionId = a.getResourceId(
com.android.internal.R.styleable.TransitionManager_transition, -1);
Scene fromScene = null, toScene = null;
- int fromId = attrs.getAttributeResourceValue(
+ int fromId = a.getResourceId(
com.android.internal.R.styleable.TransitionManager_fromScene, -1);
- if (fromId >= 0) fromScene = inflateScene(fromId, sceneRoot);
- int toId = attrs.getAttributeResourceValue(
+ if (fromId >= 0) fromScene = Scene.getSceneForLayout(sceneRoot, fromId, mContext);
+ int toId = a.getResourceId(
com.android.internal.R.styleable.TransitionManager_toScene, -1);
- if (toId >= 0) toScene = inflateScene(toId, sceneRoot);
+ if (toId >= 0) toScene = Scene.getSceneForLayout(sceneRoot, toId, mContext);
if (transitionId >= 0) {
Transition transition = inflateTransition(transitionId);
if (transition != null) {
@@ -344,50 +324,4 @@ public class TransitionInflater {
}
a.recycle();
}
-
- //
- // Scene loading
- //
-
- private Scene createSceneFromXml(XmlPullParser parser, AttributeSet attrs, ViewGroup parent)
- throws XmlPullParserException, IOException {
- Scene scene = null;
-
- // Make sure we are on a start tag.
- int type;
- int depth = parser.getDepth();
-
- while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
- && type != XmlPullParser.END_DOCUMENT) {
-
- if (type != XmlPullParser.START_TAG) {
- continue;
- }
-
- String name = parser.getName();
- if (name.equals("scene")) {
- scene = loadScene(attrs, parent);
- } else {
- throw new RuntimeException("Unknown scene name: " + parser.getName());
- }
- }
-
- return scene;
- }
-
- private Scene loadScene(AttributeSet attrs, ViewGroup parent)
- throws Resources.NotFoundException {
-
- Scene scene;
- TypedArray a = mContext.obtainStyledAttributes(attrs,
- com.android.internal.R.styleable.Scene);
- int layoutId = a.getResourceId(com.android.internal.R.styleable.Scene_layout, -1);
- if (layoutId >= 0) {
- scene = new Scene(parent, layoutId, mContext);
- } else {
- scene = new Scene(parent);
- }
- a.recycle();
- return scene;
- }
}
diff --git a/core/java/android/view/transition/TransitionManager.java b/core/java/android/transition/TransitionManager.java
index bde891d..9904413 100644
--- a/core/java/android/view/transition/TransitionManager.java
+++ b/core/java/android/transition/TransitionManager.java
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
+import android.content.Context;
import android.util.ArrayMap;
import android.util.Log;
-import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
@@ -34,14 +34,36 @@ import java.util.ArrayList;
* situations. Specifying other transitions for particular scene changes is
* only necessary if the application wants different transition behavior
* in these situations.
+ *
+ * <p>TransitionManagers can be declared in XML resource files inside the
+ * <code>res/transition</code> directory. TransitionManager resources consist of
+ * the <code>transitionManager</code>tag name, containing one or more
+ * <code>transition</code> tags, each of which describe the relationship of
+ * that transition to the from/to scene information in that tag.
+ * For example, here is a resource file that declares several scene
+ * transitions:</p>
+ *
+ * {@sample development/samples/ApiDemos/res/transition/transitions_mgr.xml TransitionManager}
+ *
+ * <p>For each of the <code>fromScene</code> and <code>toScene</code> attributes,
+ * there is a reference to a standard XML layout file. This is equivalent to
+ * creating a scene from a layout in code by calling
+ * {@link Scene#getSceneForLayout(ViewGroup, int, Context)}. For the
+ * <code>transition</code> attribute, there is a reference to a resource
+ * file in the <code>res/transition</code> directory which describes that
+ * transition.</p>
+ *
+ * Information on XML resource descriptions for transitions can be found for
+ * {@link android.R.styleable#Transition}, {@link android.R.styleable#TransitionSet},
+ * {@link android.R.styleable#TransitionTarget}, {@link android.R.styleable#Fade},
+ * and {@link android.R.styleable#TransitionManager}.
*/
public class TransitionManager {
// TODO: how to handle enter/exit?
private static String LOG_TAG = "TransitionManager";
- private static final Transition sDefaultTransition = new AutoTransition();
- private Transition mDefaultTransition = new AutoTransition();
+ private static Transition sDefaultTransition = new AutoTransition();
ArrayMap<Scene, Transition> mSceneTransitions = new ArrayMap<Scene, Transition>();
ArrayMap<Scene, ArrayMap<Scene, Transition>> mScenePairTransitions =
@@ -59,7 +81,7 @@ public class TransitionManager {
* @param transition The default transition to be used for scene changes.
*/
public void setDefaultTransition(Transition transition) {
- mDefaultTransition = transition;
+ sDefaultTransition = transition;
}
/**
@@ -69,8 +91,8 @@ public class TransitionManager {
* @return The current default transition.
* @see #setDefaultTransition(Transition)
*/
- public Transition getDefaultTransition() {
- return mDefaultTransition;
+ public static Transition getDefaultTransition() {
+ return sDefaultTransition;
}
/**
@@ -80,7 +102,7 @@ public class TransitionManager {
* transition to run.
* @param transition The transition that will play when the given scene is
* entered. A value of null will result in the default behavior of
- * using {@link AutoTransition}.
+ * using the {@link #getDefaultTransition() default transition} instead.
*/
public void setTransition(Scene scene, Transition transition) {
mSceneTransitions.put(scene, transition);
@@ -96,7 +118,7 @@ public class TransitionManager {
* be run
* @param transition The transition that will play when the given scene is
* entered. A value of null will result in the default behavior of
- * using {@link AutoTransition}.
+ * using the {@link #getDefaultTransition() default transition} instead.
*/
public void setTransition(Scene fromScene, Scene toScene, Transition transition) {
ArrayMap<Scene, Transition> sceneTransitionMap = mScenePairTransitions.get(toScene);
@@ -114,15 +136,15 @@ public class TransitionManager {
*
* @param scene The scene being entered
* @return The Transition to be used for the given scene change. If no
- * Transition was specified for this scene change, {@link AutoTransition}
- * will be used instead.
+ * Transition was specified for this scene change, the {@link #getDefaultTransition()
+ * default transition} will be used instead.
*/
private Transition getTransition(Scene scene) {
Transition transition = null;
ViewGroup sceneRoot = scene.getSceneRoot();
if (sceneRoot != null) {
// TODO: cached in Scene instead? long-term, cache in View itself
- Scene currScene = sceneRoot.getCurrentScene();
+ Scene currScene = Scene.getCurrentScene(sceneRoot);
if (currScene != null) {
ArrayMap<Scene, Transition> sceneTransitionMap = mScenePairTransitions.get(scene);
if (sceneTransitionMap != null) {
@@ -134,7 +156,7 @@ public class TransitionManager {
}
}
transition = mSceneTransitions.get(scene);
- return (transition != null) ? transition : new AutoTransition();
+ return (transition != null) ? transition : sDefaultTransition;
}
/**
@@ -234,7 +256,7 @@ public class TransitionManager {
}
// Notify previous scene that it is being exited
- Scene previousScene = sceneRoot.getCurrentScene();
+ Scene previousScene = Scene.getCurrentScene(sceneRoot);
if (previousScene != null) {
previousScene.exit();
}
@@ -256,7 +278,7 @@ public class TransitionManager {
}
/**
- * Static utility method to simply change to the given scene using
+ * Convenience method to simply change to the given scene using
* the default transition for TransitionManager.
*
* @param scene The Scene to change to
@@ -266,15 +288,14 @@ public class TransitionManager {
}
/**
- * Static utility method to simply change to the given scene using
+ * Convenience method to simply change to the given scene using
* the given transition.
*
* <p>Passing in <code>null</code> for the transition parameter will
* result in the scene changing without any transition running, and is
* equivalent to calling {@link Scene#exit()} on the scene root's
- * {@link ViewGroup#getCurrentScene() current scene}, followed by
- * {@link Scene#enter()} on the scene specified by the <code>scene</code>
- * parameter.</p>
+ * current scene, followed by {@link Scene#enter()} on the scene
+ * specified by the <code>scene</code> parameter.</p>
*
* @param scene The Scene to change to
* @param transition The transition to use for this scene change. A
@@ -285,55 +306,20 @@ public class TransitionManager {
}
/**
- * Static utility method to simply change to a scene defined by the
- * code in the given runnable, which will be executed after
- * the current values have been captured for the transition.
- * This is equivalent to creating a Scene and calling {@link
- * Scene#setEnterAction(Runnable)} with the runnable, then calling
- * {@link #go(Scene, Transition)}. The transition used will be the
- * default provided by TransitionManager.
- *
- * @param sceneRoot The root of the View hierarchy used when this scene
- * runs a transition automatically.
- * @param action The runnable whose {@link Runnable#run() run()} method will
- * be called.
- */
- public static void go(ViewGroup sceneRoot, Runnable action) {
- Scene scene = new Scene(sceneRoot);
- scene.setEnterAction(action);
- changeScene(scene, sDefaultTransition);
- }
-
- /**
- * Static utility method to simply change to a scene defined by the
- * code in the given runnable, which will be executed after
- * the current values have been captured for the transition.
- * This is equivalent to creating a Scene and calling {@link
- * Scene#setEnterAction(Runnable)} with the runnable, then calling
- * {@link #go(Scene, Transition)}. The given transition will be
- * used to animate the changes.
- *
- * <p>Passing in <code>null</code> for the transition parameter will
- * result in the scene changing without any transition running, and is
- * equivalent to calling {@link Scene#exit()} on the scene root's
- * {@link ViewGroup#getCurrentScene() current scene}, followed by
- * {@link Scene#enter()} on a new scene specified by the
- * <code>action</code> parameter.</p>
+ * Convenience method to animate, using the default transition,
+ * to a new scene defined by all changes within the given scene root between
+ * calling this method and the next rendering frame.
+ * Equivalent to calling {@link #beginDelayedTransition(ViewGroup, Transition)}
+ * with a value of <code>null</code> for the <code>transition</code> parameter.
*
* @param sceneRoot The root of the View hierarchy to run the transition on.
- * @param action The runnable whose {@link Runnable#run() run()} method will
- * be called.
- * @param transition The transition to use for this change. A
- * value of null causes the change to happen with no transition.
*/
- public static void go(ViewGroup sceneRoot, Runnable action, Transition transition) {
- Scene scene = new Scene(sceneRoot);
- scene.setEnterAction(action);
- changeScene(scene, transition);
+ public static void beginDelayedTransition(final ViewGroup sceneRoot) {
+ beginDelayedTransition(sceneRoot, null);
}
/**
- * Static utility method to animate to a new scene defined by all changes within
+ * Convenience method to animate to a new scene defined by all changes within
* the given scene root between calling this method and the next rendering frame.
* Calling this method causes TransitionManager to capture current values in the
* scene root and then post a request to run a transition on the next frame.
@@ -367,7 +353,7 @@ public class TransitionManager {
}
final Transition finalTransition = transition.clone();
sceneChangeSetup(sceneRoot, transition);
- sceneRoot.setCurrentScene(null);
+ Scene.setCurrentScene(sceneRoot, null);
sceneChangeRunTransition(sceneRoot, finalTransition);
}
}
diff --git a/core/java/android/view/transition/TransitionGroup.java b/core/java/android/transition/TransitionSet.java
index b3bacde..1972c2a 100644
--- a/core/java/android/view/transition/TransitionGroup.java
+++ b/core/java/android/transition/TransitionSet.java
@@ -14,22 +14,24 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
+import android.animation.TimeInterpolator;
import android.util.AndroidRuntimeException;
+import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
/**
- * A TransitionGroup is a parent of child transitions (including other
- * TransitionGroups). Using TransitionGroups enables more complex
- * choreography of transitions, where some groups play {@link #TOGETHER} and
- * others play {@link #SEQUENTIALLY}. For example, {@link AutoTransition}
- * uses a TransitionGroup to sequentially play a Fade(Fade.OUT), followed by
- * a {@link Move}, followed by a Fade(Fade.OUT) transition.
+ * A TransitionSet is a parent of child transitions (including other
+ * TransitionSets). Using TransitionSets enables more complex
+ * choreography of transitions, where some sets play {@link #ORDERING_TOGETHER} and
+ * others play {@link #ORDERING_SEQUENTIAL}. For example, {@link AutoTransition}
+ * uses a TransitionSet to sequentially play a Fade(Fade.OUT), followed by
+ * a {@link ChangeBounds}, followed by a Fade(Fade.OUT) transition.
*/
-public class TransitionGroup extends Transition {
+public class TransitionSet extends Transition {
ArrayList<Transition> mTransitions = new ArrayList<Transition>();
private boolean mPlayTogether = true;
@@ -37,88 +39,96 @@ public class TransitionGroup extends Transition {
boolean mStarted = false;
/**
- * A flag used to indicate that the child transitions of this group
+ * A flag used to indicate that the child transitions of this set
* should all start at the same time.
*/
- public static final int TOGETHER = 0;
+ public static final int ORDERING_TOGETHER = 0;
/**
- * A flag used to indicate that the child transitions of this group should
+ * A flag used to indicate that the child transitions of this set should
* play in sequence; when one child transition ends, the next child
* transition begins. Note that a transition does not end until all
* instances of it (which are playing on all applicable targets of the
* transition) end.
*/
- public static final int SEQUENTIALLY = 1;
+ public static final int ORDERING_SEQUENTIAL = 1;
/**
- * Constructs an empty transition group. Add child transitions to the
- * group by calling to {@link #addTransitions(Transition...)} )}. By default,
- * child transitions will play {@link #TOGETHER}.
+ * Constructs an empty transition set. Add child transitions to the
+ * set by calling {@link #addTransition(Transition)} )}. By default,
+ * child transitions will play {@link #ORDERING_TOGETHER together}.
*/
- public TransitionGroup() {
+ public TransitionSet() {
}
/**
- * Constructs an empty transition group with the specified ordering.
+ * Sets the play order of this set's child transitions.
*
- * @param ordering {@link #TOGETHER} to start this group's child
- * transitions together, {@link #SEQUENTIALLY} to play the child
- * transitions in sequence.
- * @see #setOrdering(int)
- */
- public TransitionGroup(int ordering) {
- setOrdering(ordering);
- }
-
- /**
- * Sets the play order of this group's child transitions.
- *
- * @param ordering {@link #TOGETHER} to start this group's child
- * transitions together, {@link #SEQUENTIALLY} to play the child
+ * @param ordering {@link #ORDERING_TOGETHER} to play this set's child
+ * transitions together, {@link #ORDERING_SEQUENTIAL} to play the child
* transitions in sequence.
+ * @return This transitionSet object.
*/
- public void setOrdering(int ordering) {
+ public TransitionSet setOrdering(int ordering) {
switch (ordering) {
- case SEQUENTIALLY:
+ case ORDERING_SEQUENTIAL:
mPlayTogether = false;
break;
- case TOGETHER:
+ case ORDERING_TOGETHER:
mPlayTogether = true;
break;
default:
- throw new AndroidRuntimeException("Invalid parameter for TransitionGroup " +
+ throw new AndroidRuntimeException("Invalid parameter for TransitionSet " +
"ordering: " + ordering);
}
+ return this;
}
/**
- * Adds child transitions to this group. The order of the child transitions
- * passed in determines the order in which they are started.
+ * Returns the ordering of this TransitionSet. By default, the value is
+ * {@link #ORDERING_TOGETHER}.
+ *
+ * @return {@link #ORDERING_TOGETHER} if child transitions will play at the same
+ * time, {@link #ORDERING_SEQUENTIAL} if they will play in sequence.
*
- * @param transitions A list of child transition to be added to this group.
+ * @see #setOrdering(int)
*/
- public void addTransitions(Transition... transitions) {
- if (transitions != null) {
- int numTransitions = transitions.length;
- for (int i = 0; i < numTransitions; ++i) {
- mTransitions.add(transitions[i]);
- transitions[i].mParent = this;
- if (mDuration >= 0) {
- transitions[i].setDuration(mDuration);
- }
+ public int getOrdering() {
+ return mPlayTogether ? ORDERING_TOGETHER : ORDERING_SEQUENTIAL;
+ }
+
+ /**
+ * Adds child transition to this set. The order in which this child transition
+ * is added relative to other child transitions that are added, in addition to
+ * the {@link #getOrdering() ordering} property, determines the
+ * order in which the transitions are started.
+ *
+ * <p>If this transitionSet has a {@link #getDuration() duration} set on it, the
+ * child transition will inherit that duration. Transitions are assumed to have
+ * a maximum of one transitionSet parent.</p>
+ *
+ * @param transition A non-null child transition to be added to this set.
+ * @return This transitionSet object.
+ */
+ public TransitionSet addTransition(Transition transition) {
+ if (transition != null) {
+ mTransitions.add(transition);
+ transition.mParent = this;
+ if (mDuration >= 0) {
+ transition.setDuration(mDuration);
}
}
+ return this;
}
/**
- * Setting a non-negative duration on a TransitionGroup causes all of the child
+ * Setting a non-negative duration on a TransitionSet causes all of the child
* transitions (current and future) to inherit this duration.
*
* @param duration The length of the animation, in milliseconds.
- * @return This transitionGroup object.
+ * @return This transitionSet object.
*/
@Override
- public Transition setDuration(long duration) {
+ public TransitionSet setDuration(long duration) {
super.setDuration(duration);
if (mDuration >= 0) {
int numTransitions = mTransitions.size();
@@ -129,23 +139,65 @@ public class TransitionGroup extends Transition {
return this;
}
+ @Override
+ public TransitionSet setStartDelay(long startDelay) {
+ return (TransitionSet) super.setStartDelay(startDelay);
+ }
+
+ @Override
+ public TransitionSet setInterpolator(TimeInterpolator interpolator) {
+ return (TransitionSet) super.setInterpolator(interpolator);
+ }
+
+ @Override
+ public TransitionSet addTarget(View target) {
+ return (TransitionSet) super.addTarget(target);
+ }
+
+ @Override
+ public TransitionSet addTargetId(int targetId) {
+ return (TransitionSet) super.addTargetId(targetId);
+ }
+
+ @Override
+ public TransitionSet addListener(TransitionListener listener) {
+ return (TransitionSet) super.addListener(listener);
+ }
+
+ @Override
+ public TransitionSet removeTargetId(int targetId) {
+ return (TransitionSet) super.removeTargetId(targetId);
+ }
+
+ @Override
+ public TransitionSet removeTarget(View target) {
+ return (TransitionSet) super.removeTarget(target);
+ }
+
+ @Override
+ public TransitionSet removeListener(TransitionListener listener) {
+ return (TransitionSet) super.removeListener(listener);
+ }
+
/**
- * Removes the specified child transition from this group.
+ * Removes the specified child transition from this set.
*
* @param transition The transition to be removed.
+ * @return This transitionSet object.
*/
- public void removeTransition(Transition transition) {
+ public TransitionSet removeTransition(Transition transition) {
mTransitions.remove(transition);
transition.mParent = null;
+ return this;
}
/**
* Sets up listeners for each of the child transitions. This is used to
- * determine when this transition group is finished (all child transitions
+ * determine when this transition set is finished (all child transitions
* must finish first).
*/
private void setupStartEndListeners() {
- TransitionGroupListener listener = new TransitionGroupListener(this);
+ TransitionSetListener listener = new TransitionSetListener(this);
for (Transition childTransition : mTransitions) {
childTransition.addListener(listener);
}
@@ -154,28 +206,28 @@ public class TransitionGroup extends Transition {
/**
* This listener is used to detect when all child transitions are done, at
- * which point this transition group is also done.
+ * which point this transition set is also done.
*/
- static class TransitionGroupListener extends TransitionListenerAdapter {
- TransitionGroup mTransitionGroup;
- TransitionGroupListener(TransitionGroup transitionGroup) {
- mTransitionGroup = transitionGroup;
+ static class TransitionSetListener extends TransitionListenerAdapter {
+ TransitionSet mTransitionSet;
+ TransitionSetListener(TransitionSet transitionSet) {
+ mTransitionSet = transitionSet;
}
@Override
public void onTransitionStart(Transition transition) {
- if (!mTransitionGroup.mStarted) {
- mTransitionGroup.start();
- mTransitionGroup.mStarted = true;
+ if (!mTransitionSet.mStarted) {
+ mTransitionSet.start();
+ mTransitionSet.mStarted = true;
}
}
@Override
public void onTransitionEnd(Transition transition) {
- --mTransitionGroup.mCurrentListeners;
- if (mTransitionGroup.mCurrentListeners == 0) {
+ --mTransitionSet.mCurrentListeners;
+ if (mTransitionSet.mCurrentListeners == 0) {
// All child trans
- mTransitionGroup.mStarted = false;
- mTransitionGroup.end();
+ mTransitionSet.mStarted = false;
+ mTransitionSet.end();
}
transition.removeListener(this);
}
@@ -185,10 +237,10 @@ public class TransitionGroup extends Transition {
* @hide
*/
@Override
- protected void play(ViewGroup sceneRoot, TransitionValuesMaps startValues,
+ protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
TransitionValuesMaps endValues) {
for (Transition childTransition : mTransitions) {
- childTransition.play(sceneRoot, startValues, endValues);
+ childTransition.createAnimators(sceneRoot, startValues, endValues);
}
}
@@ -196,7 +248,7 @@ public class TransitionGroup extends Transition {
* @hide
*/
@Override
- protected void runAnimations() {
+ protected void runAnimators() {
setupStartEndListeners();
if (!mPlayTogether) {
// Setup sequence with listeners
@@ -207,28 +259,38 @@ public class TransitionGroup extends Transition {
previousTransition.addListener(new TransitionListenerAdapter() {
@Override
public void onTransitionEnd(Transition transition) {
- nextTransition.runAnimations();
+ nextTransition.runAnimators();
transition.removeListener(this);
}
});
}
Transition firstTransition = mTransitions.get(0);
if (firstTransition != null) {
- firstTransition.runAnimations();
+ firstTransition.runAnimators();
}
} else {
for (Transition childTransition : mTransitions) {
- childTransition.runAnimations();
+ childTransition.runAnimators();
}
}
}
@Override
- protected void captureValues(TransitionValues transitionValues, boolean start) {
+ public void captureStartValues(TransitionValues transitionValues) {
int targetId = transitionValues.view.getId();
for (Transition childTransition : mTransitions) {
if (childTransition.isValidTarget(transitionValues.view, targetId)) {
- childTransition.captureValues(transitionValues, start);
+ childTransition.captureStartValues(transitionValues);
+ }
+ }
+ }
+
+ @Override
+ public void captureEndValues(TransitionValues transitionValues) {
+ int targetId = transitionValues.view.getId();
+ for (Transition childTransition : mTransitions) {
+ if (childTransition.isValidTarget(transitionValues.view, targetId)) {
+ childTransition.captureEndValues(transitionValues);
}
}
}
@@ -253,6 +315,7 @@ public class TransitionGroup extends Transition {
}
}
+ /** @hide */
@Override
protected void cancel() {
super.cancel();
@@ -263,12 +326,13 @@ public class TransitionGroup extends Transition {
}
@Override
- void setSceneRoot(ViewGroup sceneRoot) {
+ TransitionSet setSceneRoot(ViewGroup sceneRoot) {
super.setSceneRoot(sceneRoot);
int numTransitions = mTransitions.size();
for (int i = 0; i < numTransitions; ++i) {
mTransitions.get(i).setSceneRoot(sceneRoot);
}
+ return (TransitionSet) this;
}
@Override
@@ -281,8 +345,8 @@ public class TransitionGroup extends Transition {
}
@Override
- public TransitionGroup clone() {
- TransitionGroup clone = (TransitionGroup) super.clone();
+ public TransitionSet clone() {
+ TransitionSet clone = (TransitionSet) super.clone();
clone.mTransitions = new ArrayList<Transition>();
int numTransitions = mTransitions.size();
for (int i = 0; i < numTransitions; ++i) {
diff --git a/core/java/android/view/transition/TransitionValues.java b/core/java/android/transition/TransitionValues.java
index 6e5d3d3..8989f89 100644
--- a/core/java/android/view/transition/TransitionValues.java
+++ b/core/java/android/transition/TransitionValues.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.util.ArrayMap;
import android.view.View;
@@ -33,11 +33,11 @@ import java.util.Map;
* "Fader" as "android:fader:alpha".
*
* <p>These values are cached during the
- * {@link Transition#captureValues(TransitionValues, boolean)}
+ * {@link Transition#captureStartValues(TransitionValues)}
* capture} phases of a scene change, once when the start values are captured
* and again when the end values are captured. These start/end values are then
* passed into the transitions via the
- * for {@link Transition#play(ViewGroup, TransitionValues, TransitionValues)}
+ * for {@link Transition#createAnimator(ViewGroup, TransitionValues, TransitionValues)}
* method.</p>
*/
public class TransitionValues {
diff --git a/core/java/android/view/transition/TransitionValuesMaps.java b/core/java/android/transition/TransitionValuesMaps.java
index 4cfce4d..131596b 100644
--- a/core/java/android/view/transition/TransitionValuesMaps.java
+++ b/core/java/android/transition/TransitionValuesMaps.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.util.ArrayMap;
import android.util.LongSparseArray;
diff --git a/core/java/android/view/transition/Visibility.java b/core/java/android/transition/Visibility.java
index 348dcfb..75d3e7c 100644
--- a/core/java/android/view/transition/Visibility.java
+++ b/core/java/android/transition/Visibility.java
@@ -14,13 +14,11 @@
* limitations under the License.
*/
-package android.view.transition;
+package android.transition;
import android.animation.Animator;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewOverlay;
-import android.view.ViewParent;
/**
* This transition tracks changes to the visibility of target views in the
@@ -30,13 +28,13 @@ import android.view.ViewParent;
* utility for subclasses such as {@link Fade}, which use this visibility
* information to determine the specific animations to run when visibility
* changes occur. Subclasses should implement one or both of the methods
- * {@link #appear(ViewGroup, TransitionValues, int, TransitionValues, int), and
- * {@link #disappear(ViewGroup, TransitionValues, int, TransitionValues, int)}.
+ * {@link #onAppear(ViewGroup, TransitionValues, int, TransitionValues, int)},
+ * {@link #onDisappear(ViewGroup, TransitionValues, int, TransitionValues, int)},
*
* <p>Note that a view's visibility change is determined by both whether the view
* itself is changing and whether its parent hierarchy's visibility is changing.
* That is, a view that appears in the end scene will only trigger a call to
- * {@link #appear(android.view.ViewGroup, TransitionValues, int, TransitionValues, int)
+ * {@link #onAppear(android.view.ViewGroup, TransitionValues, int, TransitionValues, int)
* appear()} if its parent hierarchy was stable between the start and end scenes.
* This is done to avoid causing a visibility transition on every node in a hierarchy
* when only the top-most node is the one that should be transitioned in/out.
@@ -75,11 +73,20 @@ public abstract class Visibility extends Transition {
return sTransitionProperties;
}
+ private void captureValues(TransitionValues transitionValues) {
+ int visibility = transitionValues.view.getVisibility();
+ transitionValues.values.put(PROPNAME_VISIBILITY, visibility);
+ transitionValues.values.put(PROPNAME_PARENT, transitionValues.view.getParent());
+ }
+
+ @Override
+ public void captureStartValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
+ }
+
@Override
- protected void captureValues(TransitionValues values, boolean start) {
- int visibility = values.view.getVisibility();
- values.values.put(PROPNAME_VISIBILITY, visibility);
- values.values.put(PROPNAME_PARENT, values.view.getParent());
+ public void captureEndValues(TransitionValues transitionValues) {
+ captureValues(transitionValues);
}
/**
@@ -87,7 +94,7 @@ public abstract class Visibility extends Transition {
* object. This is determined by testing the same properties in the values
* object that are used to determine whether the object is appearing or
* disappearing in the {@link
- * #play(android.view.ViewGroup, TransitionValues, TransitionValues)}
+ * Transition#createAnimator(ViewGroup, TransitionValues, TransitionValues)}
* method. This method can be called by, for example, subclasses that want
* to know whether the object is visible in the same way that Visibility
* determines it for the actual animation.
@@ -207,14 +214,14 @@ public abstract class Visibility extends Transition {
}
@Override
- protected Animator play(ViewGroup sceneRoot, TransitionValues startValues,
+ public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
VisibilityInfo visInfo = getVisibilityChangeInfo(startValues, endValues);
if (visInfo.visibilityChange) {
// Only transition views that are either targets of this transition
// or whose parent hierarchies remain stable between scenes
boolean isTarget = false;
- if (mTargets != null || mTargetIds != null) {
+ if (mTargets.size() > 0 || mTargetIds.size() > 0) {
View startView = startValues != null ? startValues.view : null;
View endView = endValues != null ? endValues.view : null;
int startId = startView != null ? startView.getId() : -1;
@@ -225,10 +232,10 @@ public abstract class Visibility extends Transition {
!isHierarchyVisibilityChanging(sceneRoot,
visInfo.startParent, visInfo.endParent))) {
if (visInfo.fadeIn) {
- return appear(sceneRoot, startValues, visInfo.startVisibility,
+ return onAppear(sceneRoot, startValues, visInfo.startVisibility,
endValues, visInfo.endVisibility);
} else {
- return disappear(sceneRoot, startValues, visInfo.startVisibility,
+ return onDisappear(sceneRoot, startValues, visInfo.startVisibility,
endValues, visInfo.endVisibility
);
}
@@ -239,17 +246,20 @@ public abstract class Visibility extends Transition {
/**
* The default implementation of this method does nothing. Subclasses
- * should override if they need to set up anything prior to the
- * transition starting.
+ * should override if they need to create an Animator when targets appear.
+ * The method should only be called by the Visibility class; it is
+ * not intended to be called from external classes.
*
- * @param sceneRoot
- * @param startValues
- * @param startVisibility
- * @param endValues
- * @param endVisibility
- * @return
+ * @param sceneRoot The root of the transition hierarchy
+ * @param startValues The target values in the start scene
+ * @param startVisibility The target visibility in the start scene
+ * @param endValues The target values in the end scene
+ * @param endVisibility The target visibility in the end scene
+ * @return An Animator to be started at the appropriate time in the
+ * overall transition for this scene change. A null value means no animation
+ * should be run.
*/
- protected Animator appear(ViewGroup sceneRoot,
+ public Animator onAppear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
return null;
@@ -257,17 +267,21 @@ public abstract class Visibility extends Transition {
/**
* The default implementation of this method does nothing. Subclasses
- * should override if they need to set up anything prior to the
- * transition starting.
+ * should override if they need to create an Animator when targets disappear.
+ * The method should only be called by the Visibility class; it is
+ * not intended to be called from external classes.
+ *
*
- * @param sceneRoot
- * @param startValues
- * @param startVisibility
- * @param endValues
- * @param endVisibility
- * @return
+ * @param sceneRoot The root of the transition hierarchy
+ * @param startValues The target values in the start scene
+ * @param startVisibility The target visibility in the start scene
+ * @param endValues The target values in the end scene
+ * @param endVisibility The target visibility in the end scene
+ * @return An Animator to be started at the appropriate time in the
+ * overall transition for this scene change. A null value means no animation
+ * should be run.
*/
- protected Animator disappear(ViewGroup sceneRoot,
+ public Animator onDisappear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
return null;
diff --git a/core/java/android/view/transition/package.html b/core/java/android/transition/package.html
index 37dc0ec..f357d34 100644
--- a/core/java/android/view/transition/package.html
+++ b/core/java/android/transition/package.html
@@ -3,15 +3,15 @@
<p>The classes in this package enable "scenes & transitions" functionality for
view hiearchies.</p>
-<p>A <b>Scene</b> is an encapsulation of the state of a view hiearchy,
+<p>A <b>Scene</b> is an encapsulation of the state of a view hierarchy,
including the views in that hierarchy and the various values (layout-related
-and otherwise) that those views have. A scene be defined by a layout hierarchy
-directly or some code which sets up the scene dynamically as it is entered.</p>
+and otherwise) that those views have. A scene can be defined by a layout hierarchy
+directly or by code which sets up the scene dynamically as it is entered.</p>
<p>A <b>Transition</b> is a mechanism to automatically animate changes that occur
when a new scene is entered. Some transition capabilities are automatic. That
is, entering a scene may cause animations to run which fade out views that
-go away, move and resize existing views that change, and fade in views that
+go away, changeBounds and resize existing views that change, and fade in views that
become visible. There are additional transitions that can animate other
attributes, such as color changes, and which can optionally be specified
to take place during particular scene changes. Finally, developers can
@@ -19,7 +19,8 @@ define their own Transition subclasses which monitor particular property
changes and which run custom animations when those properties change values.</p>
<p><b>TransitionManager</b> is used to specify custom transitions for particular
-scene changes, and to cause scene changes with transitions to take place.</p>
+scene changes, and to cause scene changes with specific transitions to
+take place.</p>
</body>
</html>
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 7b69a81..f2b3e89 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -74,7 +74,6 @@ import android.view.animation.Transformation;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
-import android.view.transition.Scene;
import android.widget.ScrollBarDrawable;
import static android.os.Build.VERSION_CODES.*;
@@ -1575,8 +1574,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
protected Object mTag;
- private Scene mCurrentScene = null;
-
// for mPrivateFlags:
/** {@hide} */
static final int PFLAG_WANTS_FOCUS = 0x00000001;
@@ -12189,7 +12186,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
cleanupDraw();
mCurrentAnimation = null;
- mCurrentScene = null;
}
private void cleanupDraw() {
@@ -18102,31 +18098,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
- * Set the current Scene that this view is in. The current scene is set only
- * on the root view of a scene, not for every view in that hierarchy. This
- * information is used by Scene to determine whether there is a previous
- * scene which should be exited before the new scene is entered.
- *
- * @param scene The new scene being set on the view
- *
- * @hide
- */
- public void setCurrentScene(Scene scene) {
- mCurrentScene = scene;
- }
-
- /**
- * Gets the current {@link Scene} set on this view. A scene is set on a view
- * only if that view is the scene root.
- *
- * @return The current Scene set on this view. A value of null indicates that
- * no Scene is current set.
- */
- public Scene getCurrentScene() {
- return mCurrentScene;
- }
-
- /**
* Interface definition for a callback to be invoked when a hardware key event is
* dispatched to this view. The callback will be invoked before the key event is
* given to the view. This is only useful for hardware keyboards; a software input