From 5386fb337d3f2bd9b0ea673b5f60483246e5d0cd Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Wed, 3 Sep 2014 16:37:36 +0200 Subject: [PATCH] Tuned anti-falsing thresholds on the lockscreen Also added logic to provide nicer animations when falsing. In addition adapted the clock scale slightly if dragging in the void. Bug: 15433087 Change-Id: I4d8eb26cc81d22647ef4d2eca1e69b4994a7f1e2 --- packages/SystemUI/res/values/dimens.xml | 8 ++--- .../statusbar/KeyguardAffordanceView.java | 21 ++++++++---- .../phone/KeyguardAffordanceHelper.java | 33 ++++++++++--------- .../phone/NotificationPanelView.java | 17 ++++++++-- .../systemui/statusbar/phone/PanelView.java | 13 +++++++- 5 files changed, 62 insertions(+), 30 deletions(-) diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index d3cebd45345c7..31800eb4b01ed 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -286,13 +286,13 @@ 16dp - 100dp + 80dp - 60dp + 80dp - 100dp + 70dp 8dp @@ -312,7 +312,7 @@ 250dp - 85dp + 90dp 30dp diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java index 5878ae1b3c3b1..a4161f9563084 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java @@ -251,15 +251,19 @@ public class KeyguardAffordanceView extends ImageView { } public void setCircleRadius(float circleRadius) { - setCircleRadius(circleRadius, false); + setCircleRadius(circleRadius, false, false); + } + + public void setCircleRadius(float circleRadius, boolean slowAnimation) { + setCircleRadius(circleRadius, slowAnimation, false); } public void setCircleRadiusWithoutAnimation(float circleRadius) { cancelAnimator(mCircleAnimator); - setCircleRadius(circleRadius, true); + setCircleRadius(circleRadius, false ,true); } - private void setCircleRadius(float circleRadius, boolean noAnimation) { + private void setCircleRadius(float circleRadius, boolean slowAnimation, boolean noAnimation) { // Check if we need a new animation boolean radiusHidden = (mCircleAnimator != null && mCircleWillBeHidden) @@ -292,10 +296,13 @@ public class KeyguardAffordanceView extends ImageView { ? mDisappearInterpolator : mAppearInterpolator; animator.setInterpolator(interpolator); - float durationFactor = Math.abs(mCircleRadius - circleRadius) - / (float) mMinBackgroundRadius; - long duration = (long) (CIRCLE_APPEAR_DURATION * durationFactor); - duration = Math.min(duration, CIRCLE_DISAPPEAR_MAX_DURATION); + long duration = 250; + if (!slowAnimation) { + float durationFactor = Math.abs(mCircleRadius - circleRadius) + / (float) mMinBackgroundRadius; + duration = (long) (CIRCLE_APPEAR_DURATION * durationFactor); + duration = Math.min(duration, CIRCLE_DISAPPEAR_MAX_DURATION); + } animator.setDuration(duration); animator.start(); if (mPreviewView != null && mPreviewView.getVisibility() == View.VISIBLE) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java index eca8e6a89a5f3..a9c701ae107ae 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java @@ -20,8 +20,6 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.content.Context; -import android.os.PowerManager; -import android.os.SystemClock; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; @@ -85,9 +83,9 @@ public class KeyguardAffordanceHelper { mContext = context; mCallback = callback; initIcons(); - updateIcon(mLeftIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false); - updateIcon(mCenterIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false); - updateIcon(mRightIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false); + updateIcon(mLeftIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false, false); + updateIcon(mCenterIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false, false); + updateIcon(mRightIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false, false); initDimens(); } @@ -295,8 +293,7 @@ public class KeyguardAffordanceHelper { float vel = getCurrentVelocity(); // We snap back if the current translation is not far enough - boolean snapBack = Math.abs(mTranslation) < Math.abs(mTranslationOnDown) - + mMinTranslationAmount; + boolean snapBack = isBelowFalsingThreshold(); // or if the velocity is in the opposite direction. boolean velIsInWrongDirection = vel * mTranslation < 0; @@ -305,6 +302,11 @@ public class KeyguardAffordanceHelper { fling(vel, snapBack || forceSnapBack); } + private boolean isBelowFalsingThreshold() { + return Math.abs(mTranslation) < Math.abs(mTranslationOnDown) + + mMinTranslationAmount; + } + private void fling(float vel, final boolean snapBack) { float target = mTranslation < 0 ? -mCallback.getPageWidth() : mCallback.getPageWidth(); target = snapBack ? 0 : target; @@ -355,13 +357,14 @@ public class KeyguardAffordanceHelper { boolean animateIcons = isReset && animateReset; float radius = getRadiusFromTranslation(absTranslation); + boolean slowAnimation = isReset && isBelowFalsingThreshold(); if (!isReset) { - updateIcon(targetView, radius, alpha, false); + updateIcon(targetView, radius, alpha, false, false); } else { - updateIcon(targetView, 0.0f, fadeOutAlpha, animateIcons); + updateIcon(targetView, 0.0f, fadeOutAlpha, animateIcons, slowAnimation); } - updateIcon(otherView, 0.0f, fadeOutAlpha, animateIcons); - updateIcon(mCenterIcon, 0.0f, fadeOutAlpha, animateIcons); + updateIcon(otherView, 0.0f, fadeOutAlpha, animateIcons, slowAnimation); + updateIcon(mCenterIcon, 0.0f, fadeOutAlpha, animateIcons, slowAnimation); mTranslation = translation; } @@ -392,16 +395,16 @@ public class KeyguardAffordanceHelper { } public void animateHideLeftRightIcon() { - updateIcon(mRightIcon, 0f, 0f, true); - updateIcon(mLeftIcon, 0f, 0f, true); + updateIcon(mRightIcon, 0f, 0f, true, false); + updateIcon(mLeftIcon, 0f, 0f, true, false); } private void updateIcon(KeyguardAffordanceView view, float circleRadius, float alpha, - boolean animate) { + boolean animate, boolean slowRadiusAnimation) { if (view.getVisibility() != View.VISIBLE) { return; } - view.setCircleRadius(circleRadius); + view.setCircleRadius(circleRadius, slowRadiusAnimation); updateIconAlpha(view, alpha, animate); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java index d3c3f56b6f08d..4956f88a46306 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -551,7 +551,7 @@ public class NotificationPanelView extends PanelView implements } private boolean flingExpandsQs(float vel) { - if (!mQsTouchAboveFalsingThreshold && mStatusBarState == StatusBarState.KEYGUARD) { + if (isBelowFalsingThreshold()) { return false; } if (Math.abs(vel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) { @@ -561,6 +561,10 @@ public class NotificationPanelView extends PanelView implements } } + private boolean isBelowFalsingThreshold() { + return !mQsTouchAboveFalsingThreshold && mStatusBar.isFalsingThresholdNeeded(); + } + private float getQsExpansionFraction() { return Math.min(1f, (mQsExpansionHeight - mQsMinExpansionHeight) / (getTempQsMaxExpansion() - mQsMinExpansionHeight)); @@ -1125,9 +1129,16 @@ public class NotificationPanelView extends PanelView implements } return; } + boolean belowFalsingThreshold = isBelowFalsingThreshold(); + if (belowFalsingThreshold) { + vel = 0; + } mScrollView.setBlockFlinging(true); ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target); mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel); + if (belowFalsingThreshold) { + animator.setDuration(350); + } animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { @@ -1732,9 +1743,9 @@ public class NotificationPanelView extends PanelView implements } public void setEmptyDragAmount(float amount) { - float factor = 1f; + float factor = 0.8f; if (mNotificationStackScroller.getNotGoneChildCount() > 0) { - factor = 0.6f; + factor = 0.4f; } else if (!mStatusBar.hasActiveNotifications()) { factor = 0.4f; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java index e818d2350ddda..a31984f40382b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java @@ -479,7 +479,7 @@ public abstract class PanelView extends FrameLayout { * @return whether a fling should expands the panel; contracts otherwise */ protected boolean flingExpands(float vel, float vectorVel) { - if (!mTouchAboveFalsingThreshold && mStatusBar.isFalsingThresholdNeeded()) { + if (isBelowFalsingThreshold()) { return true; } if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) { @@ -489,6 +489,10 @@ public abstract class PanelView extends FrameLayout { } } + private boolean isBelowFalsingThreshold() { + return !mTouchAboveFalsingThreshold && mStatusBar.isFalsingThresholdNeeded(); + } + protected void fling(float vel, boolean expand) { cancelPeek(); float target = expand ? getMaxPanelHeight() : 0.0f; @@ -509,7 +513,14 @@ public abstract class PanelView extends FrameLayout { mOverExpandedBeforeFling = getOverExpansionAmount() > 0f; ValueAnimator animator = createHeightAnimator(target); if (expand) { + boolean belowFalsingThreshold = isBelowFalsingThreshold(); + if (belowFalsingThreshold) { + vel = 0; + } mFlingAnimationUtils.apply(animator, mExpandedHeight, target, vel, getHeight()); + if (belowFalsingThreshold) { + animator.setDuration(350); + } } else { mFlingAnimationUtils.applyDismissing(animator, mExpandedHeight, target, vel, getHeight());