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

Commit d5364cec authored by George Lin's avatar George Lin Committed by Automerger Merge Worker
Browse files

Merge "Support small clock for the lock screen preview" into udc-dev am: b03c480d

parents 18ec3bf9 b03c480d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@

    <!-- additional offset for clock switch area items -->
    <dimen name="small_clock_height">114dp</dimen>
    <dimen name="small_clock_padding_top">28dp</dimen>
    <dimen name="clock_padding_start">28dp</dimen>
    <dimen name="below_clock_padding_start">32dp</dimen>
    <dimen name="below_clock_padding_end">16dp</dimen>
+13 −7
Original line number Diff line number Diff line
@@ -66,6 +66,17 @@ public class KeyguardClockSwitch extends RelativeLayout {
                top + targetHeight);
    }

    /** Returns a region for the small clock to position itself, based on the given parent. */
    public static Rect getSmallClockRegion(ViewGroup parent) {
        int targetHeight = parent.getResources()
                .getDimensionPixelSize(R.dimen.small_clock_text_size);
        return new Rect(
                parent.getLeft(),
                parent.getTop(),
                parent.getRight(),
                parent.getTop() + targetHeight);
    }

    /**
     * Frame for small/large clocks
     */
@@ -172,13 +183,8 @@ public class KeyguardClockSwitch extends RelativeLayout {
    void updateClockTargetRegions() {
        if (mClock != null) {
            if (mSmallClockFrame.isLaidOut()) {
                int targetHeight =  getResources()
                        .getDimensionPixelSize(R.dimen.small_clock_text_size);
                mClock.getSmallClock().getEvents().onTargetRegionChanged(new Rect(
                        mSmallClockFrame.getLeft(),
                        mSmallClockFrame.getTop(),
                        mSmallClockFrame.getRight(),
                        mSmallClockFrame.getTop() + targetHeight));
                Rect targetRegion = getSmallClockRegion(mSmallClockFrame);
                mClock.getSmallClock().getEvents().onTargetRegionChanged(targetRegion);
            }

            if (mLargeClockFrame.isLaidOut()) {
+65 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.data.repository

import android.os.UserHandle
import android.provider.Settings
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext

@SysUISingleton
class KeyguardClockRepository
@Inject
constructor(
    private val secureSettings: SecureSettings,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
) {

    val selectedClockSize: Flow<SettingsClockSize> =
        secureSettings
            .observerFlow(
                names = arrayOf(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK),
                userId = UserHandle.USER_SYSTEM,
            )
            .onStart { emit(Unit) } // Forces an initial update.
            .map { getClockSize() }

    private suspend fun getClockSize(): SettingsClockSize {
        return withContext(backgroundDispatcher) {
            if (
                secureSettings.getIntForUser(
                    Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK,
                    1,
                    UserHandle.USER_CURRENT
                ) == 1
            ) {
                SettingsClockSize.DYNAMIC
            } else {
                SettingsClockSize.SMALL
            }
        }
    }
}
+34 −0
Original line number Diff line number Diff line
/*
 *  Copyright (C) 2023 The Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.android.systemui.keyguard.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.data.repository.KeyguardClockRepository
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow

/** Encapsulates business-logic related to the keyguard clock. */
@SysUISingleton
class KeyguardClockInteractor
@Inject
constructor(
    repository: KeyguardClockRepository,
) {
    val selectedClockSize: Flow<SettingsClockSize> = repository.selectedClockSize
}
+23 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.android.systemui.keyguard.shared.model

enum class SettingsClockSize {
    DYNAMIC,
    SMALL,
}
Loading