summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2015-05-04 20:26:47 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-05-04 20:26:48 +0000
commit61bab469a1529ef61cadb870ca4cc533a5510cfb (patch)
tree8b07f09073df94250f4c9fc0fbd8a237b4a31c78
parent394f9360c91c588fb1630f2d6af65fabe4c241a6 (diff)
parentfcfe531e742bd1731664080cb2ed3e66189d7f17 (diff)
downloadframeworks_base-61bab469a1529ef61cadb870ca4cc533a5510cfb.zip
frameworks_base-61bab469a1529ef61cadb870ca4cc533a5510cfb.tar.gz
frameworks_base-61bab469a1529ef61cadb870ca4cc533a5510cfb.tar.bz2
Merge "Fix Visibility not changing until Animator ends." into mnc-dev
-rw-r--r--core/java/android/transition/Visibility.java117
1 files changed, 81 insertions, 36 deletions
diff --git a/core/java/android/transition/Visibility.java b/core/java/android/transition/Visibility.java
index cd68fd1..ed7fd86 100644
--- a/core/java/android/transition/Visibility.java
+++ b/core/java/android/transition/Visibility.java
@@ -19,12 +19,17 @@ package android.transition;
import com.android.internal.R;
import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.Animator.AnimatorPauseListener;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.Animation.AnimationListener;
+
/**
* This transition tracks changes to the visibility of target views in the
* start and end scenes. Visibility is determined not just by the
@@ -286,6 +291,12 @@ public abstract class Visibility extends Transition {
return null;
}
}
+ final boolean isForcedVisibility = mForcedStartVisibility != -1 ||
+ mForcedEndVisibility != -1;
+ if (isForcedVisibility) {
+ // Make sure that we reverse the effect of onDisappear's setTransitionAlpha(0)
+ endValues.view.setTransitionAlpha(1);
+ }
return onAppear(sceneRoot, endValues.view, startValues, endValues);
}
@@ -418,9 +429,9 @@ public abstract class Visibility extends Transition {
sceneRoot.getOverlay().remove(overlayView);
} else {
final View finalOverlayView = overlayView;
- animator.addListener(new AnimatorListenerAdapter() {
+ addListener(new TransitionListenerAdapter() {
@Override
- public void onAnimationEnd(Animator animation) {
+ public void onTransitionEnd(Transition transition) {
finalSceneRoot.getOverlay().remove(finalOverlayView);
}
});
@@ -438,40 +449,10 @@ public abstract class Visibility extends Transition {
}
Animator animator = onDisappear(sceneRoot, viewToKeep, startValues, endValues);
if (animator != null) {
- final View finalViewToKeep = viewToKeep;
- animator.addListener(new AnimatorListenerAdapter() {
- boolean mCanceled = false;
-
- @Override
- public void onAnimationPause(Animator animation) {
- if (!mCanceled && !isForcedVisibility) {
- finalViewToKeep.setVisibility(finalVisibility);
- }
- }
-
- @Override
- public void onAnimationResume(Animator animation) {
- if (!mCanceled && !isForcedVisibility) {
- finalViewToKeep.setVisibility(View.VISIBLE);
- }
- }
-
- @Override
- public void onAnimationCancel(Animator animation) {
- mCanceled = true;
- }
-
- @Override
- public void onAnimationEnd(Animator animation) {
- if (!mCanceled) {
- if (isForcedVisibility) {
- finalViewToKeep.setTransitionAlpha(0);
- } else {
- finalViewToKeep.setVisibility(finalVisibility);
- }
- }
- }
- });
+ DisappearListener disappearListener = new DisappearListener(viewToKeep,
+ finalVisibility, isForcedVisibility);
+ animator.addListener(disappearListener);
+ addListener(disappearListener);
} else if (!isForcedVisibility) {
viewToKeep.setVisibility(originalVisibility);
}
@@ -517,4 +498,68 @@ public abstract class Visibility extends Transition {
TransitionValues endValues) {
return null;
}
+
+ private static class DisappearListener
+ extends TransitionListenerAdapter implements AnimatorListener, AnimatorPauseListener {
+ private final boolean mIsForcedVisibility;
+ private final View mView;
+ private final int mFinalVisibility;
+
+ boolean mCanceled = false;
+
+ public DisappearListener(View view, int finalVisibility, boolean isForcedVisibility) {
+ this.mView = view;
+ this.mIsForcedVisibility = isForcedVisibility;
+ this.mFinalVisibility = finalVisibility;
+ }
+
+ @Override
+ public void onAnimationPause(Animator animation) {
+ if (!mCanceled && !mIsForcedVisibility) {
+ mView.setVisibility(mFinalVisibility);
+ }
+ }
+
+ @Override
+ public void onAnimationResume(Animator animation) {
+ if (!mCanceled && !mIsForcedVisibility) {
+ mView.setVisibility(View.VISIBLE);
+ }
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCanceled = true;
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator animation) {
+
+ }
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ hideViewWhenNotCanceled();
+ }
+
+ @Override
+ public void onTransitionEnd(Transition transition) {
+ hideViewWhenNotCanceled();
+ }
+
+ private void hideViewWhenNotCanceled() {
+ if (!mCanceled) {
+ if (mIsForcedVisibility) {
+ mView.setTransitionAlpha(0);
+ } else {
+ mView.setVisibility(mFinalVisibility);
+ }
+ }
+ }
+ }
}