Loading packages/SystemUI/src/com/android/systemui/statusbar/FlingAnimationUtils.java→libs/WindowManager/Shell/src/com/android/wm/shell/animation/FlingAnimationUtils.java +71 −63 Original line number Diff line number Diff line Loading @@ -11,10 +11,10 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License * limitations under the License. */ package com.android.systemui.statusbar; package com.android.wm.shell.animation; import android.animation.Animator; import android.util.DisplayMetrics; Loading @@ -23,11 +23,6 @@ import android.view.ViewPropertyAnimator; import android.view.animation.Interpolator; import android.view.animation.PathInterpolator; import com.android.systemui.Interpolators; import com.android.systemui.statusbar.notification.NotificationUtils; import javax.inject.Inject; /** * Utility class to calculate general fling animation when the finger is released. */ Loading Loading @@ -77,8 +72,8 @@ public class FlingAnimationUtils { * @param speedUpFactor a factor from 0 to 1 how much the slow down should be shifted towards * the end of the animation. 0 means it's at the beginning and no * acceleration will take place. * @param x2 the x value to take for the second point of the bezier spline. If a value below 0 * is provided, the value is automatically calculated. * @param x2 the x value to take for the second point of the bezier spline. If a * value below 0 is provided, the value is automatically calculated. * @param y2 the y value to take for the second point of the bezier spline */ public FlingAnimationUtils(DisplayMetrics displayMetrics, float maxLengthSeconds, Loading @@ -86,7 +81,7 @@ public class FlingAnimationUtils { mMaxLengthSeconds = maxLengthSeconds; mSpeedUpFactor = speedUpFactor; if (x2 < 0) { mLinearOutSlowInX2 = NotificationUtils.interpolate(LINEAR_OUT_SLOW_IN_X2, mLinearOutSlowInX2 = interpolate(LINEAR_OUT_SLOW_IN_X2, LINEAR_OUT_SLOW_IN_X2_MAX, mSpeedUpFactor); } else { Loading Loading @@ -140,8 +135,8 @@ public class FlingAnimationUtils { float maxDistance) { AnimatorProperties properties = getProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } /** Loading @@ -159,8 +154,8 @@ public class FlingAnimationUtils { float velocity, float maxDistance) { AnimatorProperties properties = getProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } private AnimatorProperties getProperties(float currValue, Loading @@ -171,28 +166,28 @@ public class FlingAnimationUtils { float velAbs = Math.abs(velocity); float velocityFactor = mSpeedUpFactor == 0.0f ? 1.0f : Math.min(velAbs / HIGH_VELOCITY_DP_PER_SECOND, 1.0f); float startGradient = NotificationUtils.interpolate(LINEAR_OUT_SLOW_IN_START_GRADIENT, float startGradient = interpolate(LINEAR_OUT_SLOW_IN_START_GRADIENT, mY2 / mLinearOutSlowInX2, velocityFactor); float durationSeconds = startGradient * diff / velAbs; Interpolator slowInInterpolator = getInterpolator(startGradient, velocityFactor); if (durationSeconds <= maxLengthSeconds) { mAnimatorProperties.interpolator = slowInInterpolator; mAnimatorProperties.mInterpolator = slowInInterpolator; } else if (velAbs >= mMinVelocityPxPerSecond) { // Cross fade between fast-out-slow-in and linear interpolator with current velocity. durationSeconds = maxLengthSeconds; VelocityInterpolator velocityInterpolator = new VelocityInterpolator(durationSeconds, velAbs, diff); VelocityInterpolator velocityInterpolator = new VelocityInterpolator( durationSeconds, velAbs, diff); InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator( velocityInterpolator, slowInInterpolator, Interpolators.LINEAR_OUT_SLOW_IN); mAnimatorProperties.interpolator = superInterpolator; mAnimatorProperties.mInterpolator = superInterpolator; } else { // Just use a normal interpolator which doesn't take the velocity into account. durationSeconds = maxLengthSeconds; mAnimatorProperties.interpolator = Interpolators.FAST_OUT_SLOW_IN; mAnimatorProperties.mInterpolator = Interpolators.FAST_OUT_SLOW_IN; } mAnimatorProperties.duration = (long) (durationSeconds * 1000); mAnimatorProperties.mDuration = (long) (durationSeconds * 1000); return mAnimatorProperties; } Loading Loading @@ -236,8 +231,8 @@ public class FlingAnimationUtils { float velocity, float maxDistance) { AnimatorProperties properties = getDismissingProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } /** Loading @@ -256,8 +251,8 @@ public class FlingAnimationUtils { float velocity, float maxDistance) { AnimatorProperties properties = getDismissingProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } private AnimatorProperties getDismissingProperties(float currValue, float endValue, Loading @@ -272,24 +267,24 @@ public class FlingAnimationUtils { Interpolator mLinearOutFasterIn = new PathInterpolator(0, 0, LINEAR_OUT_FASTER_IN_X2, y2); float durationSeconds = startGradient * diff / velAbs; if (durationSeconds <= maxLengthSeconds) { mAnimatorProperties.interpolator = mLinearOutFasterIn; mAnimatorProperties.mInterpolator = mLinearOutFasterIn; } else if (velAbs >= mMinVelocityPxPerSecond) { // Cross fade between linear-out-faster-in and linear interpolator with current // velocity. durationSeconds = maxLengthSeconds; VelocityInterpolator velocityInterpolator = new VelocityInterpolator(durationSeconds, velAbs, diff); VelocityInterpolator velocityInterpolator = new VelocityInterpolator( durationSeconds, velAbs, diff); InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator( velocityInterpolator, mLinearOutFasterIn, Interpolators.LINEAR_OUT_SLOW_IN); mAnimatorProperties.interpolator = superInterpolator; mAnimatorProperties.mInterpolator = superInterpolator; } else { // Just use a normal interpolator which doesn't take the velocity into account. durationSeconds = maxLengthSeconds; mAnimatorProperties.interpolator = Interpolators.FAST_OUT_LINEAR_IN; mAnimatorProperties.mInterpolator = Interpolators.FAST_OUT_LINEAR_IN; } mAnimatorProperties.duration = (long) (durationSeconds * 1000); mAnimatorProperties.mDuration = (long) (durationSeconds * 1000); return mAnimatorProperties; } Loading Loading @@ -361,10 +356,11 @@ public class FlingAnimationUtils { } private static class AnimatorProperties { Interpolator interpolator; long duration; Interpolator mInterpolator; long mDuration; } /** Builder for {@link #FlingAnimationUtils}. */ public static class Builder { private final DisplayMetrics mDisplayMetrics; float mMaxLengthSeconds; Loading @@ -372,32 +368,39 @@ public class FlingAnimationUtils { float mX2; float mY2; @Inject public Builder(DisplayMetrics displayMetrics) { mDisplayMetrics = displayMetrics; reset(); } /** Sets the longest duration an animation can become in seconds. */ public Builder setMaxLengthSeconds(float maxLengthSeconds) { mMaxLengthSeconds = maxLengthSeconds; return this; } /** * Sets the factor for how much the slow down should be shifted towards the end of the * animation. */ public Builder setSpeedUpFactor(float speedUpFactor) { mSpeedUpFactor = speedUpFactor; return this; } /** Sets the x value to take for the second point of the bezier spline. */ public Builder setX2(float x2) { mX2 = x2; return this; } /** Sets the y value to take for the second point of the bezier spline. */ public Builder setY2(float y2) { mY2 = y2; return this; } /** Resets all parameters of the builder. */ public Builder reset() { mMaxLengthSeconds = 0; mSpeedUpFactor = 0.0f; Loading @@ -407,9 +410,14 @@ public class FlingAnimationUtils { return this; } /** Builds {@link #FlingAnimationUtils}. */ public FlingAnimationUtils build() { return new FlingAnimationUtils(mDisplayMetrics, mMaxLengthSeconds, mSpeedUpFactor, mX2, mY2); } } private static float interpolate(float start, float end, float amount) { return start * (1.0f - amount) + end * amount; } } libs/WindowManager/Shell/src/com/android/wm/shell/animation/Interpolators.java 0 → 100644 +45 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.wm.shell.animation; import android.view.animation.Interpolator; import android.view.animation.PathInterpolator; /** * Common interpolators used in wm shell library. */ public class Interpolators { /** * Interpolator for fast out linear in animation. */ public static final Interpolator FAST_OUT_LINEAR_IN = new PathInterpolator(0.4f, 0f, 1f, 1f); /** * Interpolator for fast out slow in animation. */ public static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f); /** * Interpolator for linear out slow in animation. */ public static final Interpolator LINEAR_OUT_SLOW_IN = new PathInterpolator(0f, 0f, 0.2f, 1f); /** * Interpolator to be used when animating a move based on a click. Pair with enough duration. */ public static final Interpolator TOUCH_RESPONSE = new PathInterpolator(0.3f, 0f, 0.1f, 1f); } packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java +1 −1 Original line number Diff line number Diff line Loading @@ -54,8 +54,8 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dagger.qualifiers.UiBackground; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.FlingAnimationUtils; import com.android.systemui.statusbar.StatusBarState; import com.android.wm.shell.animation.FlingAnimationUtils; import java.util.concurrent.Executor; Loading packages/CarSystemUI/src/com/android/systemui/car/window/OverlayPanelViewController.java +1 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ import androidx.annotation.CallSuper; import com.android.systemui.R; import com.android.systemui.car.CarDeviceProvisionedController; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.statusbar.FlingAnimationUtils; import com.android.wm.shell.animation.FlingAnimationUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading packages/CarSystemUI/tests/src/com/android/systemui/car/window/OverlayPanelViewControllerTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -40,8 +40,8 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.car.CarDeviceProvisionedController; import com.android.systemui.car.CarSystemUiTest; import com.android.systemui.statusbar.FlingAnimationUtils; import com.android.systemui.tests.R; import com.android.wm.shell.animation.FlingAnimationUtils; import org.junit.Before; import org.junit.Test; Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/FlingAnimationUtils.java→libs/WindowManager/Shell/src/com/android/wm/shell/animation/FlingAnimationUtils.java +71 −63 Original line number Diff line number Diff line Loading @@ -11,10 +11,10 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License * limitations under the License. */ package com.android.systemui.statusbar; package com.android.wm.shell.animation; import android.animation.Animator; import android.util.DisplayMetrics; Loading @@ -23,11 +23,6 @@ import android.view.ViewPropertyAnimator; import android.view.animation.Interpolator; import android.view.animation.PathInterpolator; import com.android.systemui.Interpolators; import com.android.systemui.statusbar.notification.NotificationUtils; import javax.inject.Inject; /** * Utility class to calculate general fling animation when the finger is released. */ Loading Loading @@ -77,8 +72,8 @@ public class FlingAnimationUtils { * @param speedUpFactor a factor from 0 to 1 how much the slow down should be shifted towards * the end of the animation. 0 means it's at the beginning and no * acceleration will take place. * @param x2 the x value to take for the second point of the bezier spline. If a value below 0 * is provided, the value is automatically calculated. * @param x2 the x value to take for the second point of the bezier spline. If a * value below 0 is provided, the value is automatically calculated. * @param y2 the y value to take for the second point of the bezier spline */ public FlingAnimationUtils(DisplayMetrics displayMetrics, float maxLengthSeconds, Loading @@ -86,7 +81,7 @@ public class FlingAnimationUtils { mMaxLengthSeconds = maxLengthSeconds; mSpeedUpFactor = speedUpFactor; if (x2 < 0) { mLinearOutSlowInX2 = NotificationUtils.interpolate(LINEAR_OUT_SLOW_IN_X2, mLinearOutSlowInX2 = interpolate(LINEAR_OUT_SLOW_IN_X2, LINEAR_OUT_SLOW_IN_X2_MAX, mSpeedUpFactor); } else { Loading Loading @@ -140,8 +135,8 @@ public class FlingAnimationUtils { float maxDistance) { AnimatorProperties properties = getProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } /** Loading @@ -159,8 +154,8 @@ public class FlingAnimationUtils { float velocity, float maxDistance) { AnimatorProperties properties = getProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } private AnimatorProperties getProperties(float currValue, Loading @@ -171,28 +166,28 @@ public class FlingAnimationUtils { float velAbs = Math.abs(velocity); float velocityFactor = mSpeedUpFactor == 0.0f ? 1.0f : Math.min(velAbs / HIGH_VELOCITY_DP_PER_SECOND, 1.0f); float startGradient = NotificationUtils.interpolate(LINEAR_OUT_SLOW_IN_START_GRADIENT, float startGradient = interpolate(LINEAR_OUT_SLOW_IN_START_GRADIENT, mY2 / mLinearOutSlowInX2, velocityFactor); float durationSeconds = startGradient * diff / velAbs; Interpolator slowInInterpolator = getInterpolator(startGradient, velocityFactor); if (durationSeconds <= maxLengthSeconds) { mAnimatorProperties.interpolator = slowInInterpolator; mAnimatorProperties.mInterpolator = slowInInterpolator; } else if (velAbs >= mMinVelocityPxPerSecond) { // Cross fade between fast-out-slow-in and linear interpolator with current velocity. durationSeconds = maxLengthSeconds; VelocityInterpolator velocityInterpolator = new VelocityInterpolator(durationSeconds, velAbs, diff); VelocityInterpolator velocityInterpolator = new VelocityInterpolator( durationSeconds, velAbs, diff); InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator( velocityInterpolator, slowInInterpolator, Interpolators.LINEAR_OUT_SLOW_IN); mAnimatorProperties.interpolator = superInterpolator; mAnimatorProperties.mInterpolator = superInterpolator; } else { // Just use a normal interpolator which doesn't take the velocity into account. durationSeconds = maxLengthSeconds; mAnimatorProperties.interpolator = Interpolators.FAST_OUT_SLOW_IN; mAnimatorProperties.mInterpolator = Interpolators.FAST_OUT_SLOW_IN; } mAnimatorProperties.duration = (long) (durationSeconds * 1000); mAnimatorProperties.mDuration = (long) (durationSeconds * 1000); return mAnimatorProperties; } Loading Loading @@ -236,8 +231,8 @@ public class FlingAnimationUtils { float velocity, float maxDistance) { AnimatorProperties properties = getDismissingProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } /** Loading @@ -256,8 +251,8 @@ public class FlingAnimationUtils { float velocity, float maxDistance) { AnimatorProperties properties = getDismissingProperties(currValue, endValue, velocity, maxDistance); animator.setDuration(properties.duration); animator.setInterpolator(properties.interpolator); animator.setDuration(properties.mDuration); animator.setInterpolator(properties.mInterpolator); } private AnimatorProperties getDismissingProperties(float currValue, float endValue, Loading @@ -272,24 +267,24 @@ public class FlingAnimationUtils { Interpolator mLinearOutFasterIn = new PathInterpolator(0, 0, LINEAR_OUT_FASTER_IN_X2, y2); float durationSeconds = startGradient * diff / velAbs; if (durationSeconds <= maxLengthSeconds) { mAnimatorProperties.interpolator = mLinearOutFasterIn; mAnimatorProperties.mInterpolator = mLinearOutFasterIn; } else if (velAbs >= mMinVelocityPxPerSecond) { // Cross fade between linear-out-faster-in and linear interpolator with current // velocity. durationSeconds = maxLengthSeconds; VelocityInterpolator velocityInterpolator = new VelocityInterpolator(durationSeconds, velAbs, diff); VelocityInterpolator velocityInterpolator = new VelocityInterpolator( durationSeconds, velAbs, diff); InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator( velocityInterpolator, mLinearOutFasterIn, Interpolators.LINEAR_OUT_SLOW_IN); mAnimatorProperties.interpolator = superInterpolator; mAnimatorProperties.mInterpolator = superInterpolator; } else { // Just use a normal interpolator which doesn't take the velocity into account. durationSeconds = maxLengthSeconds; mAnimatorProperties.interpolator = Interpolators.FAST_OUT_LINEAR_IN; mAnimatorProperties.mInterpolator = Interpolators.FAST_OUT_LINEAR_IN; } mAnimatorProperties.duration = (long) (durationSeconds * 1000); mAnimatorProperties.mDuration = (long) (durationSeconds * 1000); return mAnimatorProperties; } Loading Loading @@ -361,10 +356,11 @@ public class FlingAnimationUtils { } private static class AnimatorProperties { Interpolator interpolator; long duration; Interpolator mInterpolator; long mDuration; } /** Builder for {@link #FlingAnimationUtils}. */ public static class Builder { private final DisplayMetrics mDisplayMetrics; float mMaxLengthSeconds; Loading @@ -372,32 +368,39 @@ public class FlingAnimationUtils { float mX2; float mY2; @Inject public Builder(DisplayMetrics displayMetrics) { mDisplayMetrics = displayMetrics; reset(); } /** Sets the longest duration an animation can become in seconds. */ public Builder setMaxLengthSeconds(float maxLengthSeconds) { mMaxLengthSeconds = maxLengthSeconds; return this; } /** * Sets the factor for how much the slow down should be shifted towards the end of the * animation. */ public Builder setSpeedUpFactor(float speedUpFactor) { mSpeedUpFactor = speedUpFactor; return this; } /** Sets the x value to take for the second point of the bezier spline. */ public Builder setX2(float x2) { mX2 = x2; return this; } /** Sets the y value to take for the second point of the bezier spline. */ public Builder setY2(float y2) { mY2 = y2; return this; } /** Resets all parameters of the builder. */ public Builder reset() { mMaxLengthSeconds = 0; mSpeedUpFactor = 0.0f; Loading @@ -407,9 +410,14 @@ public class FlingAnimationUtils { return this; } /** Builds {@link #FlingAnimationUtils}. */ public FlingAnimationUtils build() { return new FlingAnimationUtils(mDisplayMetrics, mMaxLengthSeconds, mSpeedUpFactor, mX2, mY2); } } private static float interpolate(float start, float end, float amount) { return start * (1.0f - amount) + end * amount; } }
libs/WindowManager/Shell/src/com/android/wm/shell/animation/Interpolators.java 0 → 100644 +45 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.wm.shell.animation; import android.view.animation.Interpolator; import android.view.animation.PathInterpolator; /** * Common interpolators used in wm shell library. */ public class Interpolators { /** * Interpolator for fast out linear in animation. */ public static final Interpolator FAST_OUT_LINEAR_IN = new PathInterpolator(0.4f, 0f, 1f, 1f); /** * Interpolator for fast out slow in animation. */ public static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f); /** * Interpolator for linear out slow in animation. */ public static final Interpolator LINEAR_OUT_SLOW_IN = new PathInterpolator(0f, 0f, 0.2f, 1f); /** * Interpolator to be used when animating a move based on a click. Pair with enough duration. */ public static final Interpolator TOUCH_RESPONSE = new PathInterpolator(0.3f, 0f, 0.1f, 1f); }
packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java +1 −1 Original line number Diff line number Diff line Loading @@ -54,8 +54,8 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dagger.qualifiers.UiBackground; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.FlingAnimationUtils; import com.android.systemui.statusbar.StatusBarState; import com.android.wm.shell.animation.FlingAnimationUtils; import java.util.concurrent.Executor; Loading
packages/CarSystemUI/src/com/android/systemui/car/window/OverlayPanelViewController.java +1 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ import androidx.annotation.CallSuper; import com.android.systemui.R; import com.android.systemui.car.CarDeviceProvisionedController; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.statusbar.FlingAnimationUtils; import com.android.wm.shell.animation.FlingAnimationUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading
packages/CarSystemUI/tests/src/com/android/systemui/car/window/OverlayPanelViewControllerTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -40,8 +40,8 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.car.CarDeviceProvisionedController; import com.android.systemui.car.CarSystemUiTest; import com.android.systemui.statusbar.FlingAnimationUtils; import com.android.systemui.tests.R; import com.android.wm.shell.animation.FlingAnimationUtils; import org.junit.Before; import org.junit.Test; Loading