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

Commit 9766bad9 authored by Olivier St-Onge's avatar Olivier St-Onge Committed by Android (Google) Code Review
Browse files

Merge "Don't animate brightness slider changes when triggered by keyboard" into main

parents 4a6c571b 73ac32eb
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ import java.util.concurrent.Executor;

public class BrightnessController implements ToggleSlider.Listener, MirroredBrightnessController {
    private static final String TAG = "CentralSurfaces.BrightnessController";
    private static final int SLIDER_ANIMATION_DURATION = 1000;
    private static final int SLIDER_ANIMATION_DURATION = 3000;

    private static final int MSG_UPDATE_SLIDER = 1;
    private static final int MSG_ATTACH_LISTENER = 2;
@@ -96,6 +96,7 @@ public class BrightnessController implements ToggleSlider.Listener, MirroredBrig
    };

    private volatile boolean mAutomatic;  // Brightness adjusted automatically using ambient light.
    private boolean mTrackingTouch = false; // Brightness adjusted via touch events.
    private volatile boolean mIsVrModeEnabled;
    private boolean mListening;
    private boolean mExternalChange;
@@ -330,6 +331,7 @@ public class BrightnessController implements ToggleSlider.Listener, MirroredBrig

    @Override
    public void onChanged(boolean tracking, int value, boolean stopTracking) {
        mTrackingTouch = tracking;
        if (mExternalChange) return;

        if (mSliderAnimator != null) {
@@ -396,6 +398,12 @@ public class BrightnessController implements ToggleSlider.Listener, MirroredBrig
        }
    }

    private boolean triggeredByBrightnessKey() {
        // When the brightness mode is manual and the user isn't changing the brightness via the
        // brightness slider, assume changes are coming from a brightness key.
        return !mAutomatic && !mTrackingTouch;
    }

    private void updateSlider(float brightnessValue, boolean inVrMode) {
        final float min = mBrightnessMin;
        final float max = mBrightnessMax;
@@ -417,12 +425,13 @@ public class BrightnessController implements ToggleSlider.Listener, MirroredBrig
    }

    private void animateSliderTo(int target) {
        if (!mControlValueInitialized || !mControl.isVisible()) {
        if (!mControlValueInitialized || !mControl.isVisible() || triggeredByBrightnessKey()) {
            // Don't animate the first value since its default state isn't meaningful to users.
            // We also don't want to animate slider if it's not visible - especially important when
            // two sliders are active at the same time in split shade (one in QS and one in QQS),
            // as this negatively affects transition between them and they share mirror slider -
            // animating it from two different sources causes janky motion
            // animating it from two different sources causes janky motion.
            // Don't animate if the value is changed via the brightness keys of a keyboard.
            mControl.setValue(target);
            mControlValueInitialized = true;
        }