summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon Miranda <jonmiranda@google.com>2019-01-16 15:01:03 -0800
committerJon Miranda <jonmiranda@google.com>2019-01-16 15:15:56 -0800
commit60adc3fb83484b656c24950429fb2f2cf2ecebc2 (patch)
tree5740d70558af2cad328514e8c66f393a3b327ad4 /src
parent982ff0714f44ab33554c07f8c50eb3d4c124c17f (diff)
downloadandroid_packages_apps_Trebuchet-60adc3fb83484b656c24950429fb2f2cf2ecebc2.tar.gz
android_packages_apps_Trebuchet-60adc3fb83484b656c24950429fb2f2cf2ecebc2.tar.bz2
android_packages_apps_Trebuchet-60adc3fb83484b656c24950429fb2f2cf2ecebc2.zip
Generalize SpringObjectAnimator.
This is in preparation for adding more springs to the state transitions. Bug: 111698021 Change-Id: I32cd7894e940dae00895799280b244d68400d374
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/ProgressInterface.java26
-rw-r--r--src/com/android/launcher3/allapps/AllAppsTransitionController.java46
-rw-r--r--src/com/android/launcher3/anim/SpringObjectAnimator.java47
3 files changed, 66 insertions, 53 deletions
diff --git a/src/com/android/launcher3/ProgressInterface.java b/src/com/android/launcher3/ProgressInterface.java
new file mode 100644
index 000000000..663d8ba5e
--- /dev/null
+++ b/src/com/android/launcher3/ProgressInterface.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2019 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.launcher3;
+
+/**
+ * Progress is defined as a value with range [0, 1], and is specific to each implementor.
+ * It is used when there is a transition from one state of the UI to another.
+ */
+public interface ProgressInterface {
+ void setProgress(float progress);
+ float getProgress();
+} \ No newline at end of file
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 962c25bf5..e8e93febb 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -23,17 +23,16 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager.AnimationConfig;
import com.android.launcher3.LauncherStateManager.StateHandler;
+import com.android.launcher3.ProgressInterface;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.anim.SpringObjectAnimator;
import com.android.launcher3.anim.PropertySetter;
-import com.android.launcher3.anim.SpringObjectAnimator.SpringProperty;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ScrimView;
import androidx.dynamicanimation.animation.FloatPropertyCompat;
-import androidx.dynamicanimation.animation.SpringAnimation;
/**
* Handles AllApps view transition.
@@ -45,7 +44,8 @@ import androidx.dynamicanimation.animation.SpringAnimation;
* If release velocity < THRES1, snap according to either top or bottom depending on whether it's
* closer to top or closer to the page indicator.
*/
-public class AllAppsTransitionController implements StateHandler, OnDeviceProfileChangeListener {
+public class AllAppsTransitionController implements StateHandler, OnDeviceProfileChangeListener,
+ ProgressInterface {
public static final Property<AllAppsTransitionController, Float> ALL_APPS_PROGRESS =
new Property<AllAppsTransitionController, Float>(Float.class, "allAppsProgress") {
@@ -74,40 +74,6 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
}
};
- /**
- * Property that either sets the progress directly or animates the progress via a spring.
- */
- public static class AllAppsSpringProperty extends
- SpringProperty<AllAppsTransitionController, Float> {
-
- SpringAnimation mSpring;
- boolean useSpring = false;
-
- public AllAppsSpringProperty(SpringAnimation spring) {
- super(Float.class, "allAppsSpringProperty");
- mSpring = spring;
- }
-
- @Override
- public Float get(AllAppsTransitionController controller) {
- return controller.getProgress();
- }
-
- @Override
- public void set(AllAppsTransitionController controller, Float progress) {
- if (useSpring) {
- mSpring.animateToFinalPosition(progress);
- } else {
- controller.setProgress(progress);
- }
- }
-
- @Override
- public void switchToSpring() {
- useSpring = true;
- }
- }
-
private AllAppsContainerView mAppsView;
private ScrimView mScrimView;
@@ -161,6 +127,7 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
* @see #setState(LauncherState)
* @see #setStateWithAnimation(LauncherState, AnimatorSetBuilder, AnimationConfig)
*/
+ @Override
public void setProgress(float progress) {
mProgress = progress;
mScrimView.setProgress(progress);
@@ -185,6 +152,7 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
}
}
+ @Override
public float getProgress() {
return mProgress;
}
@@ -223,8 +191,8 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
Interpolator interpolator = config.userControlled ? LINEAR : toState == OVERVIEW
? builder.getInterpolator(ANIM_OVERVIEW_SCALE, FAST_OUT_SLOW_IN)
: FAST_OUT_SLOW_IN;
- Animator anim = new SpringObjectAnimator(this, 1f / mShiftRange, mProgress,
- targetProgress);
+ Animator anim = new SpringObjectAnimator<>(this, ALL_APPS_PROGRESS_SPRING,
+ "allAppsSpringFromAATC", 1f / mShiftRange, mProgress, targetProgress);
anim.setDuration(config.duration);
anim.setInterpolator(builder.getInterpolator(ANIM_VERTICAL_PROGRESS, interpolator));
anim.addListener(getProgressAnimatorListener());
diff --git a/src/com/android/launcher3/anim/SpringObjectAnimator.java b/src/com/android/launcher3/anim/SpringObjectAnimator.java
index 4f037efa6..4ece909c0 100644
--- a/src/com/android/launcher3/anim/SpringObjectAnimator.java
+++ b/src/com/android/launcher3/anim/SpringObjectAnimator.java
@@ -23,12 +23,12 @@ import android.animation.ValueAnimator;
import android.util.Log;
import android.util.Property;
-import com.android.launcher3.allapps.AllAppsTransitionController;
-import com.android.launcher3.allapps.AllAppsTransitionController.AllAppsSpringProperty;
+import com.android.launcher3.ProgressInterface;
import java.util.ArrayList;
import androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener;
+import androidx.dynamicanimation.animation.FloatPropertyCompat;
import androidx.dynamicanimation.animation.SpringAnimation;
import androidx.dynamicanimation.animation.SpringForce;
@@ -38,17 +38,17 @@ import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
* This animator allows for an object's property to be be controlled by an {@link ObjectAnimator} or
* a {@link SpringAnimation}. It extends ValueAnimator so it can be used in an AnimatorSet.
*/
-public class SpringObjectAnimator extends ValueAnimator {
+public class SpringObjectAnimator<T extends ProgressInterface> extends ValueAnimator {
private static final String TAG = "SpringObjectAnimator";
private static boolean DEBUG = false;
- private AllAppsTransitionController mObject;
+ private T mObject;
private ObjectAnimator mObjectAnimator;
private float[] mValues;
private SpringAnimation mSpring;
- private AllAppsSpringProperty mProperty;
+ private SpringProperty<T> mProperty;
private ArrayList<AnimatorListener> mListeners;
private boolean mSpringEnded = false;
@@ -58,16 +58,16 @@ public class SpringObjectAnimator extends ValueAnimator {
private static final float SPRING_DAMPING_RATIO = 0.9f;
private static final float SPRING_STIFFNESS = 600f;
- public SpringObjectAnimator(AllAppsTransitionController object, float minimumVisibleChange,
- float... values) {
+ public SpringObjectAnimator(T object, FloatPropertyCompat<T> floatProperty,
+ String name, float minimumVisibleChange, float... values) {
mObject = object;
- mSpring = new SpringAnimation(object, AllAppsTransitionController.ALL_APPS_PROGRESS_SPRING);
+ mSpring = new SpringAnimation(object, floatProperty);
mSpring.setMinimumVisibleChange(minimumVisibleChange);
mSpring.setSpring(new SpringForce(0)
.setDampingRatio(SPRING_DAMPING_RATIO)
.setStiffness(SPRING_STIFFNESS));
mSpring.setStartVelocity(0.01f);
- mProperty = new AllAppsSpringProperty(mSpring);
+ mProperty = new SpringProperty<T>(name, mSpring);
mObjectAnimator = ObjectAnimator.ofFloat(object, mProperty, values);
mValues = values;
mListeners = new ArrayList<>();
@@ -261,13 +261,32 @@ public class SpringObjectAnimator extends ValueAnimator {
mObjectAnimator.setCurrentPlayTime(playTime);
}
- public static abstract class SpringProperty<T, V> extends Property<T, V> {
+ public static class SpringProperty<T extends ProgressInterface> extends Property<T, Float> {
- public SpringProperty(Class<V> type, String name) {
- super(type, name);
+ boolean useSpring = false;
+ final SpringAnimation mSpring;
+
+ public SpringProperty(String name, SpringAnimation spring) {
+ super(Float.class, name);
+ mSpring = spring;
}
- abstract public void switchToSpring();
- }
+ public void switchToSpring() {
+ useSpring = true;
+ }
+
+ @Override
+ public Float get(T object) {
+ return object.getProgress();
+ }
+ @Override
+ public void set(T object, Float progress) {
+ if (useSpring) {
+ mSpring.animateToFinalPosition(progress);
+ } else {
+ object.setProgress(progress);
+ }
+ }
+ }
}