QC scrim opacity depends on scroll position
Scrim opacity depends on scroll position after the initial
entrance animation.
This is the last CL needed for b/16683381. Also, this is the
last feature-requestish ui-tweak I plan on doing before
LMP (I promised this one to UX a while ago).
Bug: 16683381
Change-Id: I8a62ff1eda6f2174b50f71f54c4301c111182b7f
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index faa7e41..82b3970 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -9,6 +9,8 @@
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
@@ -163,6 +165,10 @@
void onStartScrollOffBottom();
+ void onTransparentViewHeightChange(float ratio);
+
+ void onEntranceAnimationDone();
+
void onEnterFullscreen();
void onExitFullscreen();
@@ -560,6 +566,19 @@
}
}
+ /**
+ * Return ratio of non-transparent:viewgroup-height for this viewgroup at the starting position.
+ */
+ public float getStartingTransparentHeightRatio() {
+ return getTransparentHeightRatio(mTransparentStartHeight);
+ }
+
+ private float getTransparentHeightRatio(int transparentHeight) {
+ final float heightRatio = (float) transparentHeight / getHeight();
+ // Clamp between [0, 1] in case this is called before height is initialized.
+ return 1.0f - Math.max(Math.min(1.0f, heightRatio), 0f);
+ }
+
public void scrollOffBottom() {
final Interpolator interpolator = new AcceleratingFlingInterpolator(
EXIT_FLING_ANIMATION_DURATION_MS, getCurrentVelocity(),
@@ -588,10 +607,19 @@
- (getHeight() - getTransparentViewHeight()) + 1;
final Interpolator interpolator = AnimationUtils.loadInterpolator(getContext(),
android.R.interpolator.linear_out_slow_in);
+ final int desiredValue = currentPosition + (scrollToCurrentPosition ? currentPosition
+ : getTransparentViewHeight());
final ObjectAnimator animator = ObjectAnimator.ofInt(this, "scroll", bottomScrollPosition,
- currentPosition + (scrollToCurrentPosition ? currentPosition
- : getTransparentViewHeight()));
+ desiredValue);
animator.setInterpolator(interpolator);
+ animator.addUpdateListener(new AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ if (animation.getAnimatedValue().equals(desiredValue) && mListener != null) {
+ mListener.onEntranceAnimationDone();
+ }
+ }
+ });
animator.start();
}
@@ -614,6 +642,10 @@
} else if (!wasFullscreen && isFullscreen) {
mListener.onEnterFullscreen();
}
+ if (!isFullscreen || !wasFullscreen) {
+ mListener.onTransparentViewHeightChange(
+ getTransparentHeightRatio(getTransparentViewHeight()));
+ }
}
}