Makes spring variable dynamic resources so that they can be changed via plugin
Bug: 147302669 Change-Id: Ia4e74ff46a4d8338a56ea75ed826b69102c42d93
This commit is contained in:
1 parent
acaf0749b3
commit
7edcd7803f
10 files changed
+103
-26
No files matched your search
@@ -32,8 +32,10 @@ import com.android.launcher3.anim.AnimationSuccessListener;
|
||||
import com.android.launcher3.anim.AnimatorSetBuilder;
|
||||
import com.android.launcher3.anim.PropertySetter;
|
||||
import com.android.launcher3.anim.SpringObjectAnimator;
|
||||
import com.android.launcher3.util.DynamicResource;
|
||||
import com.android.launcher3.util.Themes;
|
||||
import com.android.launcher3.views.ScrimView;
|
||||
import com.android.systemui.plugins.ResourceProvider;
|
||||
|
||||
/**
|
||||
* Handles AllApps view transition.
|
||||
@@ -47,9 +49,6 @@ import com.android.launcher3.views.ScrimView;
|
||||
*/
|
||||
public class AllAppsTransitionController implements StateHandler, OnDeviceProfileChangeListener {
|
||||
|
||||
private static final float SPRING_DAMPING_RATIO = 0.75f;
|
||||
private static final float SPRING_STIFFNESS = 600f;
|
||||
|
||||
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PROGRESS =
|
||||
new FloatProperty<AllAppsTransitionController>("allAppsProgress") {
|
||||
|
||||
@@ -187,8 +186,12 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
|
||||
|
||||
public Animator createSpringAnimation(float... progressValues) {
|
||||
if (UNSTABLE_SPRINGS.get()) {
|
||||
ResourceProvider rp = DynamicResource.provider(mLauncher);
|
||||
float damping = rp.getFloat(R.dimen.all_apps_spring_damping_ratio);
|
||||
float stiffness = rp.getFloat(R.dimen.all_apps_spring_stiffness);
|
||||
|
||||
return new SpringObjectAnimator<>(this, ALL_APPS_PROGRESS, 1f / mShiftRange,
|
||||
SPRING_DAMPING_RATIO, SPRING_STIFFNESS, progressValues);
|
||||
damping, stiffness, progressValues);
|
||||
}
|
||||
return ObjectAnimator.ofFloat(this, ALL_APPS_PROGRESS, progressValues);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,11 @@ public class DynamicResource implements ResourceProvider, PluginListener<Resourc
|
||||
return mContext.getResources().getColor(resId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(@DimenRes int resId) {
|
||||
return mContext.getResources().getFloat(resId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginConnected(ResourceProvider plugin, Context context) {
|
||||
mPlugin = plugin;
|
||||
|
||||
@@ -26,11 +26,13 @@ import android.view.ViewConfiguration;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import androidx.dynamicanimation.animation.DynamicAnimation;
|
||||
import androidx.dynamicanimation.animation.FloatPropertyCompat;
|
||||
import androidx.dynamicanimation.animation.SpringAnimation;
|
||||
import androidx.dynamicanimation.animation.SpringForce;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.systemui.plugins.ResourceProvider;
|
||||
|
||||
/**
|
||||
* Based on {@link android.widget.OverScroller} supporting only 1-d scrolling and with more
|
||||
* customization options.
|
||||
@@ -425,6 +427,7 @@ public class OverScroller {
|
||||
// Current state of the animation.
|
||||
private int mState = SPLINE;
|
||||
|
||||
private Context mContext;
|
||||
private SpringAnimation mSpring;
|
||||
|
||||
// Constant gravity value, used in the deceleration phase.
|
||||
@@ -500,6 +503,7 @@ public class OverScroller {
|
||||
}
|
||||
|
||||
SplineOverScroller(Context context) {
|
||||
mContext = context;
|
||||
mFinished = true;
|
||||
final float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
|
||||
mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2)
|
||||
@@ -560,9 +564,12 @@ public class OverScroller {
|
||||
}
|
||||
mSpring = new SpringAnimation(this, SPRING_PROPERTY);
|
||||
|
||||
ResourceProvider rp = DynamicResource.provider(mContext);
|
||||
float stiffness = rp.getFloat(R.dimen.horizontal_spring_stiffness);
|
||||
float damping = rp.getFloat(R.dimen.horizontal_spring_damping_ratio);
|
||||
mSpring.setSpring(new SpringForce(mFinal)
|
||||
.setStiffness(SpringForce.STIFFNESS_LOW)
|
||||
.setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY));
|
||||
.setStiffness(stiffness)
|
||||
.setDampingRatio(damping));
|
||||
mSpring.setStartVelocity(velocity);
|
||||
mSpring.animateToFinalPosition(mFinal);
|
||||
mSpring.addEndListener((animation, canceled, value, velocity1) -> {
|
||||
|
||||
Reference in new issue
Block a user