Add IN/OUT flag for all Visibility transitions.
Bug 15758206
Change-Id: If9b1871117a6808c87adc84ab9215b913ebd2704
diff --git a/core/java/android/transition/Visibility.java b/core/java/android/transition/Visibility.java
index 947e1a7..aa9f04e 100644
--- a/core/java/android/transition/Visibility.java
+++ b/core/java/android/transition/Visibility.java
@@ -43,6 +43,20 @@
private static final String PROPNAME_PARENT = "android:visibility:parent";
private static final String PROPNAME_SCREEN_LOCATION = "android:visibility:screenLocation";
+ /**
+ * Mode used in {@link #setMode(int)} to make the transition
+ * operate on targets that are appearing. Maybe be combined with
+ * {@link #OUT} to target Visibility changes both in and out.
+ */
+ public static final int IN = 0x1;
+
+ /**
+ * Mode used in {@link #setMode(int)} to make the transition
+ * operate on targets that are disappearing. Maybe be combined with
+ * {@link #IN} to target Visibility changes both in and out.
+ */
+ public static final int OUT = 0x2;
+
private static final String[] sTransitionProperties = {
PROPNAME_VISIBILITY,
PROPNAME_PARENT,
@@ -58,6 +72,22 @@
ViewGroup endParent;
}
+ private int mMode = IN | OUT;
+
+ /**
+ * Changes the transition to support appearing and/or disappearing Views, depending
+ * on <code>mode</code>.
+ *
+ * @param mode The behavior supported by this transition, a combination of
+ * {@link #IN} and {@link #OUT}.
+ */
+ public void setMode(int mode) {
+ if ((mode & ~(IN | OUT)) != 0) {
+ throw new IllegalArgumentException("Only IN and OUT flags are allowed");
+ }
+ mMode = mode;
+ }
+
@Override
public String[] getTransitionProperties() {
return sTransitionProperties;
@@ -200,6 +230,9 @@
public Animator onAppear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
+ if ((mMode & IN) != IN || endValues == null) {
+ return null;
+ }
return onAppear(sceneRoot, endValues.view, startValues, endValues);
}
@@ -260,6 +293,10 @@
public Animator onDisappear(ViewGroup sceneRoot,
TransitionValues startValues, int startVisibility,
TransitionValues endValues, int endVisibility) {
+ if ((mMode & OUT) != OUT) {
+ return null;
+ }
+
View startView = (startValues != null) ? startValues.view : null;
View endView = (endValues != null) ? endValues.view : null;
View overlayView = null;