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

Commit 9688ad33 authored by Matt Pietal's avatar Matt Pietal
Browse files

[DO NOT MERGE] Allow a settings override for double-line clock

This setting allows users to always show a single-line format clock,
regardless of notification status.

Fixes: 194905512
Test: atest KeyguardClockSwitchControllerTest
Change-Id: I77269988447fc5732ff6b8774654ce4bf9c026de
parent 7d75b594
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -9603,6 +9603,14 @@ public final class Settings {
         */
        public static final String LOCKSCREEN_SHOW_WALLET = "lockscreen_show_wallet";
        /**
         * Whether to use the lockscreen double-line clock
         *
         * @hide
         */
        public static final String LOCKSCREEN_USE_DOUBLE_LINE_CLOCK =
                "lockscreen_use_double_line_clock";
        /**
         * Specifies whether the web action API is enabled.
         *
+1 −0
Original line number Diff line number Diff line
@@ -191,5 +191,6 @@ public class SecureSettings {
        Settings.Secure.LOCATION_TIME_ZONE_DETECTION_ENABLED,
        Settings.Secure.LOCKSCREEN_SHOW_CONTROLS,
        Settings.Secure.LOCKSCREEN_SHOW_WALLET,
        Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK,
    };
}
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.POWER_MENU_LOCKED_SHOW_CONTENT, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.LOCKSCREEN_SHOW_CONTROLS, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.LOCKSCREEN_SHOW_WALLET, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.DOZE_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.DOZE_ALWAYS_ON, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.DOZE_PICK_UP_GESTURE, BOOLEAN_VALIDATOR);
+7 −17
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

@@ -89,7 +88,6 @@ public class KeyguardClockSwitch extends RelativeLayout {

    private int mClockSwitchYAmount;
    @VisibleForTesting boolean mChildrenAreLaidOut = false;
    private OnPreDrawListener mPreDrawListener;

    public KeyguardClockSwitch(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -284,30 +282,21 @@ public class KeyguardClockSwitch extends RelativeLayout {
        // translate them properly
        if (mChildrenAreLaidOut) {
            animateClockChange(clockSize == LARGE);
            mDisplayedClockSize = clockSize;
        } else if (mPreDrawListener == null) {
            mPreDrawListener = () -> {
                switchToClock(clockSize);
                getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener);
                mPreDrawListener = null;
                return true;
            };
            getViewTreeObserver().addOnPreDrawListener(mPreDrawListener);
        }

        mDisplayedClockSize = clockSize;
        return true;
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        mChildrenAreLaidOut = true;
    }

    void onViewDetached() {
        if (mPreDrawListener != null) {
            getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener);
            mPreDrawListener = null;
        if (mDisplayedClockSize != null && !mChildrenAreLaidOut) {
            animateClockChange(mDisplayedClockSize == LARGE);
        }

        mChildrenAreLaidOut = true;
    }

    public Paint getPaint() {
@@ -368,5 +357,6 @@ public class KeyguardClockSwitch extends RelativeLayout {
        pw.println("  mDarkAmount: " + mDarkAmount);
        pw.println("  mSupportsDarkText: " + mSupportsDarkText);
        pw.println("  mColorPalette: " + Arrays.toString(mColorPalette));
        pw.println("  mDisplayedClockSize: " + mDisplayedClockSize);
    }
}
+40 −2
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static com.android.keyguard.KeyguardClockSwitch.LARGE;

import android.app.WallpaperManager;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
@@ -49,11 +51,13 @@ import com.android.systemui.statusbar.phone.NotificationIconAreaController;
import com.android.systemui.statusbar.phone.NotificationIconContainer;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.settings.SecureSettings;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.Executor;

import javax.inject.Inject;

@@ -72,6 +76,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    private final BatteryController mBatteryController;
    private final LockscreenSmartspaceController mSmartspaceController;
    private final Resources mResources;
    private final SecureSettings mSecureSettings;

    /**
     * Clock for both small and large sizes
@@ -109,6 +114,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    private SmartspaceTransitionController mSmartspaceTransitionController;

    private boolean mOnlyClock = false;
    private Executor mUiExecutor;
    private boolean mCanShowDoubleLineClock = true;
    private ContentObserver mDoubleLineClockObserver = new ContentObserver(null) {
        @Override
        public void onChange(boolean change) {
            updateDoubleLineClock();
        }
    };

    @Inject
    public KeyguardClockSwitchController(
@@ -125,6 +138,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
            LockscreenSmartspaceController smartspaceController,
            KeyguardUnlockAnimationController keyguardUnlockAnimationController,
            SmartspaceTransitionController smartspaceTransitionController,
            SecureSettings secureSettings,
            @Main Executor uiExecutor,
            @Main Resources resources) {
        super(keyguardClockSwitch);
        mStatusBarStateController = statusBarStateController;
@@ -138,7 +153,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        mBypassController = bypassController;
        mSmartspaceController = smartspaceController;
        mResources = resources;

        mSecureSettings = secureSettings;
        mUiExecutor = uiExecutor;
        mKeyguardUnlockAnimationController = keyguardUnlockAnimationController;
        mSmartspaceTransitionController = smartspaceTransitionController;
    }
@@ -223,6 +239,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
            updateClockLayout();
            mSmartspaceTransitionController.setLockscreenSmartspace(mSmartspaceView);
        }

        mSecureSettings.registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK),
                false, /* notifyForDescendants */
                mDoubleLineClockObserver
        );

        updateDoubleLineClock();
    }

    int getNotificationIconAreaHeight() {
@@ -236,7 +260,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        }
        mColorExtractor.removeOnColorsChangedListener(mColorsListener);
        mView.setClockPlugin(null, mStatusBarStateController.getState());
        mView.onViewDetached();

        mSecureSettings.unregisterContentObserver(mDoubleLineClockObserver);
    }

    /**
@@ -268,6 +293,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
     * hidden.
     */
    public void displayClock(@KeyguardClockSwitch.ClockSize int clockSize) {
        if (!mCanShowDoubleLineClock && clockSize == KeyguardClockSwitch.LARGE) {
            return;
        }

        boolean appeared = mView.switchToClock(clockSize);
        if (appeared && clockSize == LARGE) {
            mLargeClockViewController.animateAppear();
@@ -410,4 +439,13 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    private int getCurrentLayoutDirection() {
        return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault());
    }

    private void updateDoubleLineClock() {
        mCanShowDoubleLineClock = mSecureSettings.getInt(
            Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, 1) != 0;

        if (!mCanShowDoubleLineClock) {
            mUiExecutor.execute(() -> displayClock(KeyguardClockSwitch.SMALL));
        }
    }
}
Loading