Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c38fa1f6 authored by Chet Haase's avatar Chet Haase
Browse files

Add Developer Option setting for Animator scaling.

This new setting allows users to set a scale factor for the
duration and startDelay of all Animator-based animations. This
setting is very similar to the Transition animation scale and
Window animation scale settings, except this one applies specifically
to Animator animations. The property is only accessible by users
through the Settings UI, not programmatically. The value applies
system-wide and is picked up per-process at the time of the first
ValueAnimator construction.

This is an update to a previous CL; this approach uses the WindowManager
to store the animator scale settings, instead of SystemProperties.

Change-Id: I8295fab060aa6d597ae507ded8f9c9d6077be966
parent 26daa02b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17583,6 +17583,7 @@ package android.provider {
    field public static final java.lang.String ALARM_ALERT = "alarm_alert";
    field public static final java.lang.String ALWAYS_FINISH_ACTIVITIES = "always_finish_activities";
    field public static final deprecated java.lang.String ANDROID_ID = "android_id";
    field public static final java.lang.String ANIMATOR_DURATION_SCALE = "animator_duration_scale";
    field public static final java.lang.String APPEND_FOR_LAST_AUDIBLE = "_last_audible";
    field public static final java.lang.String AUTO_TIME = "auto_time";
    field public static final java.lang.String AUTO_TIME_ZONE = "auto_time_zone";
+9 −11
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ public class ValueAnimator extends Animator {
     * Internal constants
     */
    private static float sDurationScale = 1.0f;
    private static boolean sDurationScaleInitialized = false;

    /**
     * Messages sent to timing handler: START is sent when an animation first begins.
@@ -161,7 +160,7 @@ public class ValueAnimator extends Animator {
    //

    // How long the animation should last in ms
    private long mDuration = 300;
    private long mDuration = (long)(300 * sDurationScale);
    private long mUnscaledDuration = 300;

    // The amount of time in ms to delay starting the animation after start() is called
@@ -222,21 +221,20 @@ public class ValueAnimator extends Animator {
     */
    public static final int INFINITE = -1;


    /**
     * @hide
     */
    public static void setDurationScale(float durationScale) {
        sDurationScale = durationScale;
    }

    /**
     * Creates a new ValueAnimator object. This default constructor is primarily for
     * use internally; the factory methods which take parameters are more generally
     * useful.
     */
    public ValueAnimator() {
        if (!sDurationScaleInitialized) {
            // Scale value initialized per-process when first animator is constructed
            String scaleString = SystemProperties.get("persist.sys.ui.animation");
            if (!scaleString.isEmpty()) {
                sDurationScale = Float.parseFloat(scaleString);
            }
            sDurationScaleInitialized = true;
        }
        mDuration *= sDurationScale;
    }

    /**
+7 −0
Original line number Diff line number Diff line
@@ -1677,6 +1677,13 @@ public final class Settings {
         */
        public static final String TRANSITION_ANIMATION_SCALE = "transition_animation_scale";

        /**
         * Scaling factor for Animator-based animations. This affects both the start delay and
         * duration of all such animations. Setting to 0 will cause animations to end immediately.
         * The default value is 1.
         */
        public static final String ANIMATOR_DURATION_SCALE = "animator_duration_scale";

        /**
         * Scaling factor for normal window animations. Setting to 0 will disable window
         * animations.
+5 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.view;

import android.Manifest;
import android.animation.LayoutTransition;
import android.animation.ValueAnimator;
import android.app.ActivityManagerNative;
import android.content.ClipDescription;
import android.content.ComponentCallbacks;
@@ -323,8 +324,11 @@ public final class ViewRootImpl extends Handler implements ViewParent,
            if (!mInitialized) {
                try {
                    InputMethodManager imm = InputMethodManager.getInstance(mainLooper);
                    sWindowSession = Display.getWindowManager().openSession(
                    IWindowManager windowManager = Display.getWindowManager();
                    sWindowSession = windowManager.openSession(
                            imm.getClient(), imm.getInputContext());
                    float animatorScale = windowManager.getAnimationScale(2);
                    ValueAnimator.setDurationScale(animatorScale);
                    mInitialized = true;
                } catch (RemoteException e) {
                }
+13 −1
Original line number Diff line number Diff line
@@ -559,6 +559,7 @@ public class WindowManagerService extends IWindowManager.Stub

    float mWindowAnimationScale = 1.0f;
    float mTransitionAnimationScale = 1.0f;
    float mAnimatorDurationScale = 1.0f;

    final InputManager mInputManager;

@@ -774,6 +775,8 @@ public class WindowManagerService extends IWindowManager.Stub
                Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
        mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
                Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
        mAnimatorDurationScale = Settings.System.getFloat(context.getContentResolver(),
                Settings.System.ANIMATOR_DURATION_SCALE, mTransitionAnimationScale);

        // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
        IntentFilter filter = new IntentFilter();
@@ -4657,6 +4660,7 @@ public class WindowManagerService extends IWindowManager.Stub
        switch (which) {
            case 0: mWindowAnimationScale = fixScale(scale); break;
            case 1: mTransitionAnimationScale = fixScale(scale); break;
            case 2: mAnimatorDurationScale = fixScale(scale); break;
        }

        // Persist setting
@@ -4676,6 +4680,9 @@ public class WindowManagerService extends IWindowManager.Stub
            if (scales.length >= 2) {
                mTransitionAnimationScale = fixScale(scales[1]);
            }
            if (scales.length >= 3) {
                mAnimatorDurationScale = fixScale(scales[2]);
            }
        }

        // Persist setting
@@ -4686,12 +4693,14 @@ public class WindowManagerService extends IWindowManager.Stub
        switch (which) {
            case 0: return mWindowAnimationScale;
            case 1: return mTransitionAnimationScale;
            case 2: return mAnimatorDurationScale;
        }
        return 0;
    }

    public float[] getAnimationScales() {
        return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
        return new float[] { mWindowAnimationScale, mTransitionAnimationScale,
                mAnimatorDurationScale };
    }

    public int getSwitchState(int sw) {
@@ -6825,6 +6834,8 @@ public class WindowManagerService extends IWindowManager.Stub
                            Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
                    Settings.System.putFloat(mContext.getContentResolver(),
                            Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
                    Settings.System.putFloat(mContext.getContentResolver(),
                            Settings.System.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale);
                    break;
                }

@@ -9762,6 +9773,7 @@ public class WindowManagerService extends IWindowManager.Stub
            pw.print("  mAnimationPending="); pw.print(mAnimationPending);
                    pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
                    pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
                    pw.print(" mAnimatorDurationScale="); pw.println(mAnimatorDurationScale);
            pw.print("  mNextAppTransition=0x");
                    pw.print(Integer.toHexString(mNextAppTransition));
                    pw.print(" mAppTransitionReady="); pw.println(mAppTransitionReady);