Fix STATE_DEPTH stuck at 1 after setting wallpaper
- Made BaseDepthController.setDepth/mDepth private, all get/set should be done through STATE_DEPTH or WIDGET_DEPTH
- Generified ClampedDepthProperty into Utilities.ClampedProperty to apply on STATE_DEPTH
Bug: 240580498
Test: Go to walppaper&style, set new wallpaper, then go to widget picker, wallpaper depth should transition smoothly
Change-Id: I53cdedf970fd7ffba6a952c4edf4b34251b01f07
diff --git a/src/com/android/launcher3/LauncherAnimUtils.java b/src/com/android/launcher3/LauncherAnimUtils.java
index b858d1a..4e80d41 100644
--- a/src/com/android/launcher3/LauncherAnimUtils.java
+++ b/src/com/android/launcher3/LauncherAnimUtils.java
@@ -218,4 +218,32 @@
}
};
}
+
+ /**
+ * A property that updates the specified property within a given range of values (ie. even if
+ * the animator goes beyond 0..1, the interpolated value will still be bounded).
+ * @param <T> the specified property
+ */
+ public static class ClampedProperty<T> extends FloatProperty<T> {
+ private final FloatProperty<T> mProperty;
+ private final float mMinValue;
+ private final float mMaxValue;
+
+ public ClampedProperty(FloatProperty<T> property, float minValue, float maxValue) {
+ super(property.getName() + "Clamped");
+ mProperty = property;
+ mMinValue = minValue;
+ mMaxValue = maxValue;
+ }
+
+ @Override
+ public void setValue(T t, float v) {
+ mProperty.set(t, Utilities.boundToRange(v, mMinValue, mMaxValue));
+ }
+
+ @Override
+ public Float get(T t) {
+ return mProperty.get(t);
+ }
+ }
}
diff --git a/src/com/android/launcher3/util/MultiPropertyFactory.java b/src/com/android/launcher3/util/MultiPropertyFactory.java
index e7a7785..43daf08 100644
--- a/src/com/android/launcher3/util/MultiPropertyFactory.java
+++ b/src/com/android/launcher3/util/MultiPropertyFactory.java
@@ -107,12 +107,9 @@
@Override
public Float get(T object) {
- // The scale of the view should match mLastAggregatedValue. Still, if it has been
- // changed without using this property, it can differ. As this get method is usually
- // used to set the starting point on an animation, this would result in some jumps
- // when the view scale is different than the last aggregated value. To stay on the
- // safe side, let's return the real view scale.
- return mProperty.get(object);
+ // Callers of MultiProperty should only care about the sub-property that it sets. If
+ // the overall value is needed, mProperty.get should be called directly.
+ return mValue;
}
@Override