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

Commit 27e2efee authored by Beverly's avatar Beverly
Browse files

Forward fix/revert of clock detached state on keyguard visibility

This reverts most of ag/14554008. The keyguard visibility state isn't
updated immediatly when dozing begins, so we need to make sure we're
still registered for the StatusBarStateControllerListener for dozing
state so that the clock is in the correct state when entering AOD.

Test: manual, enter AOD from the home screen on timeout
Fixes: 188592929
Change-Id: Idf19bc86b11e3423ffdf1ed6e12ef52ea68d8881
parent 85cf59de
Loading
Loading
Loading
Loading
+18 −32
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
    private boolean mIsDozing;
    private boolean mIsCharging;
    private float mDozeAmount;
    boolean mKeyguardShowing;
    private Locale mLocale;
    private boolean mAttached; // if keyguard isn't showing, mAttached = false

    private final NumberFormat mBurmeseNf = NumberFormat.getInstance(Locale.forLanguageTag("my"));
    private final String mBurmeseNumerals;
@@ -85,11 +85,15 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
                R.dimen.keyguard_clock_line_spacing_scale);
    }

    private void reset() {
        mView.animateDoze(mIsDozing, false);
    }

    private final BatteryController.BatteryStateChangeCallback mBatteryCallback =
            new BatteryController.BatteryStateChangeCallback() {
        @Override
        public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
            if (!mIsCharging && charging) {
            if (mKeyguardShowing && !mIsCharging && charging) {
                mView.animateCharge(mIsDozing);
            }
            mIsCharging = charging;
@@ -103,21 +107,6 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
        }
    };

    private final KeyguardUpdateMonitorCallback mKeyguardPersistentCallback =
            new KeyguardUpdateMonitorCallback() {
        @Override
        public void onKeyguardVisibilityChanged(boolean showing) {
            // call attached/detached methods on visibility changes. benefits include:
            //  - no animations when keyguard/clock view aren't visible
            //  - resets state when keyguard is visible again (ie: font weight)
            if (showing) {
                onViewAttached();
            } else {
                onViewDetached();
            }
        }
    };

    private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
            new KeyguardUpdateMonitorCallback() {
        @Override
@@ -128,44 +117,41 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
                mView.animateDisappear();
            }
        }

        @Override
        public void onKeyguardVisibilityChanged(boolean showing) {
            mKeyguardShowing = showing;
            if (!mKeyguardShowing) {
                // reset state (ie: after animateDisappear)
                reset();
            }
        }
    };

    @Override
    protected void onViewAttached() {
        if (mAttached) {
            return;
        }
        mAttached = true;
        updateLocale();
        mBroadcastDispatcher.registerReceiver(mLocaleBroadcastReceiver,
                new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
        mStatusBarStateController.addCallback(mStatusBarStateListener);

        mIsDozing = mStatusBarStateController.isDozing();
        mDozeAmount = mStatusBarStateController.getDozeAmount();
        mBatteryController.addCallback(mBatteryCallback);
        mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);

        mKeyguardUpdateMonitor.removeCallback(mKeyguardPersistentCallback);
        mKeyguardUpdateMonitor.registerCallback(mKeyguardPersistentCallback);
        mKeyguardShowing = true;

        refreshTime();
        initColors();
        mView.animateDoze(mIsDozing, false);
    }

    @Override
    protected void onViewDetached() {
        if (!mAttached) {
            return;
        }

        mAttached = false;
        mBroadcastDispatcher.unregisterReceiver(mLocaleBroadcastReceiver);
        mStatusBarStateController.removeCallback(mStatusBarStateListener);
        mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateMonitorCallback);
        mBatteryController.removeCallback(mBatteryCallback);
        if (!mView.isAttachedToWindow()) {
            mKeyguardUpdateMonitor.removeCallback(mKeyguardPersistentCallback);
        }
    }

    /** Animate the clock appearance */