summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2019-06-19 21:30:40 -0700
committerSunny Goyal <sunnygoyal@google.com>2019-06-19 21:31:43 -0700
commitb80941bb24dbaa1b392d6d37bfff39cf3542aa6b (patch)
tree53cce57928bf419719d90b5fb9f4b1384b513b16 /src
parent676a795ebdec854554695c5f0ab1565d5745eff6 (diff)
downloadandroid_packages_apps_Trebuchet-b80941bb24dbaa1b392d6d37bfff39cf3542aa6b.tar.gz
android_packages_apps_Trebuchet-b80941bb24dbaa1b392d6d37bfff39cf3542aa6b.tar.bz2
android_packages_apps_Trebuchet-b80941bb24dbaa1b392d6d37bfff39cf3542aa6b.zip
Using FloatProperty for spring animation, instead of a interface
to allow easier generalization of animation definitions Change-Id: I37b1a604003ec007aa390eabdfe8c1ab733b7471
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/LauncherAnimUtils.java53
-rw-r--r--src/com/android/launcher3/ProgressInterface.java26
-rw-r--r--src/com/android/launcher3/allapps/AllAppsTransitionController.java16
-rw-r--r--src/com/android/launcher3/anim/SpringObjectAnimator.java46
4 files changed, 53 insertions, 88 deletions
diff --git a/src/com/android/launcher3/LauncherAnimUtils.java b/src/com/android/launcher3/LauncherAnimUtils.java
index 04f2b5276..74362ed5a 100644
--- a/src/com/android/launcher3/LauncherAnimUtils.java
+++ b/src/com/android/launcher3/LauncherAnimUtils.java
@@ -17,6 +17,7 @@
package com.android.launcher3;
import android.graphics.drawable.Drawable;
+import android.util.FloatProperty;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
@@ -47,15 +48,15 @@ public class LauncherAnimUtils {
}
};
- public static final Property<View, Float> SCALE_PROPERTY =
- new Property<View, Float>(Float.class, "scale") {
+ public static final FloatProperty<View> SCALE_PROPERTY =
+ new FloatProperty<View>("scale") {
@Override
public Float get(View view) {
return view.getScaleX();
}
@Override
- public void set(View view, Float scale) {
+ public void setValue(View view, float scale) {
view.setScaleX(scale);
view.setScaleY(scale);
}
@@ -92,23 +93,31 @@ public class LauncherAnimUtils {
}
};
- public static class ViewProgressProperty implements ProgressInterface {
- View mView;
- Property<View, Float> mProperty;
-
- public ViewProgressProperty(View view, Property<View, Float> property) {
- mView = view;
- mProperty = property;
- }
-
- @Override
- public void setProgress(float progress) {
- mProperty.set(mView, progress);
- }
-
- @Override
- public float getProgress() {
- return mProperty.get(mView);
- }
- }
+ public static final FloatProperty<View> VIEW_TRANSLATE_X =
+ View.TRANSLATION_X instanceof FloatProperty ? (FloatProperty) View.TRANSLATION_X
+ : new FloatProperty<View>("translateX") {
+ @Override
+ public void setValue(View view, float v) {
+ view.setTranslationX(v);
+ }
+
+ @Override
+ public Float get(View view) {
+ return view.getTranslationX();
+ }
+ };
+
+ public static final FloatProperty<View> VIEW_TRANSLATE_Y =
+ View.TRANSLATION_Y instanceof FloatProperty ? (FloatProperty) View.TRANSLATION_Y
+ : new FloatProperty<View>("translateY") {
+ @Override
+ public void setValue(View view, float v) {
+ view.setTranslationY(v);
+ }
+
+ @Override
+ public Float get(View view) {
+ return view.getTranslationY();
+ }
+ };
}
diff --git a/src/com/android/launcher3/ProgressInterface.java b/src/com/android/launcher3/ProgressInterface.java
deleted file mode 100644
index 663d8ba5e..000000000
--- a/src/com/android/launcher3/ProgressInterface.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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 a351b9ae1..3289d7d1d 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -16,8 +16,8 @@ import static com.android.launcher3.util.SystemUiController.UI_STATE_ALL_APPS;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
+import android.util.FloatProperty;
import android.util.Log;
-import android.util.Property;
import android.view.animation.Interpolator;
import com.android.launcher3.DeviceProfile;
@@ -26,7 +26,6 @@ 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;
@@ -46,14 +45,13 @@ import com.android.launcher3.views.ScrimView;
* 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,
- ProgressInterface {
+public class AllAppsTransitionController implements StateHandler, OnDeviceProfileChangeListener {
public static final float SPRING_DAMPING_RATIO = 0.9f;
public static final float SPRING_STIFFNESS = 600f;
- public static final Property<AllAppsTransitionController, Float> ALL_APPS_PROGRESS =
- new Property<AllAppsTransitionController, Float>(Float.class, "allAppsProgress") {
+ public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PROGRESS =
+ new FloatProperty<AllAppsTransitionController>("allAppsProgress") {
@Override
public Float get(AllAppsTransitionController controller) {
@@ -61,7 +59,7 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
}
@Override
- public void set(AllAppsTransitionController controller, Float progress) {
+ public void setValue(AllAppsTransitionController controller, float progress) {
controller.setProgress(progress);
}
};
@@ -121,7 +119,6 @@ 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);
@@ -149,7 +146,6 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
}
}
- @Override
public float getProgress() {
return mProgress;
}
@@ -192,7 +188,7 @@ 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, "allAppsSpringFromAATC", 1f / mShiftRange,
+ Animator anim = new SpringObjectAnimator<>(this, ALL_APPS_PROGRESS, 1f / mShiftRange,
SPRING_DAMPING_RATIO, SPRING_STIFFNESS, mProgress, targetProgress);
anim.setDuration(config.duration);
anim.setInterpolator(builder.getInterpolator(ANIM_VERTICAL_PROGRESS, interpolator));
diff --git a/src/com/android/launcher3/anim/SpringObjectAnimator.java b/src/com/android/launcher3/anim/SpringObjectAnimator.java
index b1395af89..395fed259 100644
--- a/src/com/android/launcher3/anim/SpringObjectAnimator.java
+++ b/src/com/android/launcher3/anim/SpringObjectAnimator.java
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.anim;
+import static androidx.dynamicanimation.animation.FloatPropertyCompat.createFloatPropertyCompat;
+
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
import android.animation.Animator;
@@ -24,15 +26,12 @@ import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.os.Handler;
import android.os.Looper;
+import android.util.FloatProperty;
import android.util.Log;
-import android.util.Property;
-
-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;
@@ -40,12 +39,11 @@ import androidx.dynamicanimation.animation.SpringForce;
* 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<T extends ProgressInterface> extends ValueAnimator {
+public class SpringObjectAnimator<T> extends ValueAnimator {
private static final String TAG = "SpringObjectAnimator";
private static boolean DEBUG = false;
- private T mObject;
private ObjectAnimator mObjectAnimator;
private float[] mValues;
@@ -57,29 +55,15 @@ public class SpringObjectAnimator<T extends ProgressInterface> extends ValueAnim
private boolean mAnimatorEnded = true;
private boolean mEnded = true;
- private static final FloatPropertyCompat<ProgressInterface> sFloatProperty =
- new FloatPropertyCompat<ProgressInterface>("springObjectAnimator") {
- @Override
- public float getValue(ProgressInterface object) {
- return object.getProgress();
- }
-
- @Override
- public void setValue(ProgressInterface object, float progress) {
- object.setProgress(progress);
- }
- };
-
- public SpringObjectAnimator(T object, String name, float minimumVisibleChange, float damping,
- float stiffness, float... values) {
- mObject = object;
- mSpring = new SpringAnimation(object, sFloatProperty);
+ public SpringObjectAnimator(T object, FloatProperty<T> property, float minimumVisibleChange,
+ float damping, float stiffness, float... values) {
+ mSpring = new SpringAnimation(object, createFloatPropertyCompat(property));
mSpring.setMinimumVisibleChange(minimumVisibleChange);
mSpring.setSpring(new SpringForce(0)
.setDampingRatio(damping)
.setStiffness(stiffness));
mSpring.setStartVelocity(0.01f);
- mProperty = new SpringProperty<T>(name, mSpring);
+ mProperty = new SpringProperty<>(property, mSpring);
mObjectAnimator = ObjectAnimator.ofFloat(object, mProperty, values);
mValues = values;
mListeners = new ArrayList<>();
@@ -285,13 +269,15 @@ public class SpringObjectAnimator<T extends ProgressInterface> extends ValueAnim
mObjectAnimator.setCurrentPlayTime(playTime);
}
- public static class SpringProperty<T extends ProgressInterface> extends Property<T, Float> {
+ public static class SpringProperty<T> extends FloatProperty<T> {
boolean useSpring = false;
+ final FloatProperty<T> mProperty;
final SpringAnimation mSpring;
- public SpringProperty(String name, SpringAnimation spring) {
- super(Float.class, name);
+ public SpringProperty(FloatProperty<T> property, SpringAnimation spring) {
+ super(property.getName());
+ mProperty = property;
mSpring = spring;
}
@@ -301,15 +287,15 @@ public class SpringObjectAnimator<T extends ProgressInterface> extends ValueAnim
@Override
public Float get(T object) {
- return object.getProgress();
+ return mProperty.get(object);
}
@Override
- public void set(T object, Float progress) {
+ public void setValue(T object, float progress) {
if (useSpring) {
mSpring.animateToFinalPosition(progress);
} else {
- object.setProgress(progress);
+ mProperty.setValue(object, progress);
}
}
}