@@ -86,7 +86,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
8686 public static final int SCROLL_STATE_SETTLING = 2 ;
8787 public static final int SCROLL_STATE_FADING = 3 ;
8888
89- private static final int CHALLENGE_FADE_DURATION = 70 ;
89+ private static final int CHALLENGE_FADE_OUT_DURATION = 100 ;
90+ private static final int CHALLENGE_FADE_IN_DURATION = 160 ;
9091
9192 private static final int MAX_SETTLE_DURATION = 600 ; // ms
9293
@@ -442,9 +443,7 @@ void animateChallengeTo(int y, int velocity) {
442443 return ;
443444 }
444445
445- if (mFader != null ) {
446- mFader .cancel ();
447- }
446+ cancelTransitionsInProgress ();
448447
449448 mChallengeInteractiveInternal = false ;
450449 mChallengeView .setLayerType (LAYER_TYPE_HARDWARE , null );
@@ -984,6 +983,83 @@ public void computeScroll() {
984983 }
985984 }
986985
986+ private void cancelTransitionsInProgress () {
987+ if (!mScroller .isFinished ()) {
988+ mScroller .abortAnimation ();
989+ completeChallengeScroll ();
990+ }
991+ if (mFader != null ) {
992+ mFader .cancel ();
993+ }
994+ }
995+
996+ public void fadeInChallenge () {
997+ fadeChallenge (true );
998+ }
999+
1000+ public void fadeOutChallenge () {
1001+ fadeChallenge (false );
1002+ }
1003+
1004+ public void fadeChallenge (final boolean show ) {
1005+ if (mChallengeView != null ) {
1006+
1007+ cancelTransitionsInProgress ();
1008+ float alpha = show ? 1f : 0f ;
1009+ int duration = show ? CHALLENGE_FADE_IN_DURATION : CHALLENGE_FADE_OUT_DURATION ;
1010+ mFader = ObjectAnimator .ofFloat (mChallengeView , "alpha" , alpha );
1011+ mFader .addListener (new AnimatorListenerAdapter () {
1012+ @ Override
1013+ public void onAnimationStart (Animator animation ) {
1014+ onFadeStart (show );
1015+ }
1016+ @ Override
1017+ public void onAnimationEnd (Animator animation ) {
1018+ onFadeEnd (show );
1019+ }
1020+ });
1021+ mFader .setDuration (duration );
1022+ mFader .start ();
1023+ }
1024+ }
1025+
1026+ private int getMaxChallengeBottom () {
1027+ if (mChallengeView == null ) return 0 ;
1028+ final int layoutBottom = getLayoutBottom ();
1029+ final int challengeHeight = mChallengeView .getMeasuredHeight ();
1030+
1031+ return (layoutBottom + challengeHeight - mChallengeBottomBound );
1032+ }
1033+
1034+ private int getMinChallengeBottom () {
1035+ return getLayoutBottom ();
1036+ }
1037+
1038+
1039+ private void onFadeStart (boolean show ) {
1040+ mChallengeInteractiveInternal = false ;
1041+ mChallengeView .setLayerType (LAYER_TYPE_HARDWARE , null );
1042+
1043+ if (show ) {
1044+ moveChallengeTo (getMinChallengeBottom ());
1045+ }
1046+
1047+ setScrollState (SCROLL_STATE_FADING );
1048+ }
1049+
1050+ private void onFadeEnd (boolean show ) {
1051+ mChallengeInteractiveInternal = true ;
1052+ setChallengeShowing (show );
1053+
1054+ if (!show ) {
1055+ moveChallengeTo (getMaxChallengeBottom ());
1056+ }
1057+
1058+ mChallengeView .setLayerType (LAYER_TYPE_NONE , null );
1059+ mFader = null ;
1060+ setScrollState (SCROLL_STATE_IDLE );
1061+ }
1062+
9871063 public int getMaxChallengeTop () {
9881064 if (mChallengeView == null ) return 0 ;
9891065
@@ -1009,8 +1085,8 @@ private boolean moveChallengeTo(int bottom) {
10091085 final int layoutBottom = getLayoutBottom ();
10101086 final int challengeHeight = mChallengeView .getHeight ();
10111087
1012- bottom = Math .max (layoutBottom ,
1013- Math .min (bottom , layoutBottom + challengeHeight - mChallengeBottomBound ));
1088+ bottom = Math .max (getMinChallengeBottom () ,
1089+ Math .min (bottom , getMaxChallengeBottom () ));
10141090
10151091 float offset = 1.f - (float ) (bottom - layoutBottom ) /
10161092 (challengeHeight - mChallengeBottomBound );
@@ -1064,45 +1140,6 @@ public void showChallenge(boolean show) {
10641140 }
10651141 }
10661142
1067- public void dismissChallengeWithFade () {
1068- if (mChallengeView != null ) {
1069- if (!mScroller .isFinished ()) {
1070- mScroller .abortAnimation ();
1071- completeChallengeScroll ();
1072- }
1073-
1074- mFader = ObjectAnimator .ofFloat (mChallengeView , "alpha" , 0f );
1075- mFader .addListener (new AnimatorListenerAdapter () {
1076- @ Override
1077- public void onAnimationStart (Animator animation ) {
1078- onFadeStart ();
1079- }
1080- @ Override
1081- public void onAnimationEnd (Animator animation ) {
1082- onFadeEnd ();
1083- }
1084- });
1085- mFader .setDuration (CHALLENGE_FADE_DURATION );
1086- mFader .start ();
1087- }
1088- }
1089-
1090- private void onFadeStart () {
1091- mChallengeInteractiveInternal = false ;
1092- mChallengeView .setLayerType (LAYER_TYPE_HARDWARE , null );
1093- setScrollState (SCROLL_STATE_FADING );
1094- }
1095-
1096- private void onFadeEnd () {
1097- mChallengeInteractiveInternal = true ;
1098- setChallengeShowing (false );
1099- moveChallengeTo (getLayoutBottom () + mChallengeView .getMeasuredHeight ());
1100- mChallengeView .setAlpha (1f );
1101- mChallengeView .setLayerType (LAYER_TYPE_NONE , null );
1102- mFader = null ;
1103- setScrollState (SCROLL_STATE_IDLE );
1104- }
1105-
11061143 private void showChallenge (int velocity ) {
11071144 boolean show = false ;
11081145 if (Math .abs (velocity ) > mMinVelocity ) {
0 commit comments