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

Commit f2091c41 authored by George Lin's avatar George Lin Committed by Android (Google) Code Review
Browse files

Merge "Clock customization screen (1/3)" into main

parents 814c6f10 be70fb8b
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2024 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.
  -->
<com.android.customization.picker.clock.ui.view.ClockHostView2
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/clock_host_view"
    android:importantForAccessibility="noHideDescendants"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center" />
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@
            android:paddingHorizontal="@dimen/floating_sheet_content_horizontal_padding">

            <LinearLayout
                android:id="@+id/clock_size_option_dynamic"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
@@ -150,6 +151,7 @@
            </LinearLayout>

            <LinearLayout
                android:id="@+id/clock_size_option_small"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
+19 −39
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import com.android.customization.module.logging.ThemesUserEventLogger
import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor
import com.android.customization.picker.clock.domain.interactor.ClockPickerSnapshotRestorer
import com.android.customization.picker.clock.ui.view.ClockViewFactory
import com.android.customization.picker.clock.ui.view.ClockViewFactoryImpl
import com.android.customization.picker.clock.ui.view.ThemePickerClockViewFactory
import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewModel
import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel
import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor
@@ -72,7 +72,6 @@ import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInt
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.picker.di.modules.MainDispatcher
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer
import com.android.wallpaper.util.ScreenSizeCalculator
import dagger.Lazy
import javax.inject.Inject
import javax.inject.Singleton
@@ -172,9 +171,7 @@ constructor(
        return fragmentFactory ?: ThemePickerFragmentFactory().also { fragmentFactory }
    }

    override fun getSnapshotRestorers(
        context: Context,
    ): Map<Int, SnapshotRestorer> {
    override fun getSnapshotRestorers(context: Context): Map<Int, SnapshotRestorer> {
        return super<WallpaperPicker2Injector>.getSnapshotRestorers(context).toMutableMap().apply {
            this[KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER] =
                keyguardQuickAffordanceSnapshotRestorer.get()
@@ -220,7 +217,7 @@ constructor(
    }

    fun getNotificationSectionViewModelFactory(
        context: Context,
        context: Context
    ): NotificationSectionViewModel.Factory {
        return notificationSectionViewModelFactory
            ?: NotificationSectionViewModel.Factory(
@@ -230,9 +227,7 @@ constructor(
                .also { notificationSectionViewModelFactory = it }
    }

    private fun getNotificationsInteractor(
        context: Context,
    ): NotificationSettingsInteractor {
    private fun getNotificationsInteractor(context: Context): NotificationSettingsInteractor {
        return notificationSettingsInteractor
            ?: NotificationSettingsInteractor(
                    repository =
@@ -241,7 +236,7 @@ constructor(
                            backgroundDispatcher = bgDispatcher,
                            secureSettingsRepository = secureSettingsRepository.get(),
                            systemSettingsRepository = systemSettingsRepository.get(),
                        ),
                        )
                )
                .also { notificationSettingsInteractor = it }
    }
@@ -249,10 +244,7 @@ constructor(
    private fun getNotificationsSnapshotRestorer(context: Context): NotificationsSnapshotRestorer {
        return notificationsSnapshotRestorer
            ?: NotificationsSnapshotRestorer(
                    interactor =
                        getNotificationsInteractor(
                            context = context,
                        ),
                    interactor = getNotificationsInteractor(context = context),
                    backgroundScope = bgScope,
                )
                .also { notificationsSnapshotRestorer = it }
@@ -276,10 +268,8 @@ constructor(

    override fun getClockViewFactory(activity: ComponentActivity): ClockViewFactory {
        return clockViewFactory
            ?: ClockViewFactoryImpl(
                    activity.applicationContext,
                    ScreenSizeCalculator.getInstance()
                        .getScreenSize(activity.windowManager.defaultDisplay),
            ?: ThemePickerClockViewFactory(
                    activity,
                    WallpaperManager.getInstance(activity.applicationContext),
                    clockRegistry.get(),
                )
@@ -299,7 +289,7 @@ constructor(

    override fun getWallpaperColorResources(
        wallpaperColors: WallpaperColors,
        context: Context
        context: Context,
    ): WallpaperColorResources {
        return ThemedWallpaperColorResources(wallpaperColors, secureSettingsRepository.get())
    }
@@ -321,9 +311,7 @@ constructor(
            }
    }

    fun getDarkModeSnapshotRestorer(
        context: Context,
    ): DarkModeSnapshotRestorer {
    fun getDarkModeSnapshotRestorer(context: Context): DarkModeSnapshotRestorer {
        val appContext = context.applicationContext
        return darkModeSnapshotRestorer
            ?: DarkModeSnapshotRestorer(
@@ -334,9 +322,7 @@ constructor(
                .also { darkModeSnapshotRestorer = it }
    }

    protected fun getThemedIconSnapshotRestorer(
        context: Context,
    ): ThemedIconSnapshotRestorer {
    protected fun getThemedIconSnapshotRestorer(context: Context): ThemedIconSnapshotRestorer {
        val optionProvider = ThemedIconSwitchProvider.getInstance(context)
        return themedIconSnapshotRestorer
            ?: ThemedIconSnapshotRestorer(
@@ -351,10 +337,9 @@ constructor(

    protected fun getThemedIconInteractor(): ThemedIconInteractor {
        return themedIconInteractor
            ?: ThemedIconInteractor(
                    repository = ThemeIconRepository(),
                )
                .also { themedIconInteractor = it }
            ?: ThemedIconInteractor(repository = ThemeIconRepository()).also {
                themedIconInteractor = it
            }
    }

    override fun getClockSettingsViewModelFactory(
@@ -375,9 +360,7 @@ constructor(
                .also { clockSettingsViewModelFactory = it }
    }

    fun getGridScreenViewModelFactory(
        context: Context,
    ): ViewModelProvider.Factory {
    fun getGridScreenViewModelFactory(context: Context): ViewModelProvider.Factory {
        return gridScreenViewModelFactory
            ?: GridScreenViewModel.Factory(
                    context = context,
@@ -404,14 +387,11 @@ constructor(
                .also { gridInteractor = it }
    }

    private fun getGridSnapshotRestorer(
        context: Context,
    ): GridSnapshotRestorer {
    private fun getGridSnapshotRestorer(context: Context): GridSnapshotRestorer {
        return gridSnapshotRestorer
            ?: GridSnapshotRestorer(
                    interactor = getGridInteractor(context),
                )
                .also { gridSnapshotRestorer = it }
            ?: GridSnapshotRestorer(interactor = getGridInteractor(context)).also {
                gridSnapshotRestorer = it
            }
    }

    override fun isCurrentSelectedColorPreset(context: Context): Boolean {
+19 −1
Original line number Diff line number Diff line
@@ -84,6 +84,24 @@ constructor(
        setClockOption(ClockSnapshotModel(clockSize = size))
    }

    suspend fun applyClock(
        clockId: String?,
        size: ClockSize?,
        selectedColorId: String?,
        @IntRange(from = 0, to = 100) colorToneProgress: Int?,
        @ColorInt seedColor: Int?,
    ) {
        setClockOption(
            ClockSnapshotModel(
                clockId = clockId,
                clockSize = size,
                selectedColorId = selectedColorId,
                colorToneProgress = colorToneProgress,
                seedColor = seedColor,
            )
        )
    }

    private suspend fun setClockOption(clockSnapshotModel: ClockSnapshotModel) {
        // [ClockCarouselViewModel] is monitoring the [ClockPickerInteractor.setSelectedClock] job,
        // so it needs to finish last.
@@ -94,7 +112,7 @@ constructor(
            repository.setClockColor(
                selectedColorId = clockSnapshotModel.selectedColorId,
                colorToneProgress = clockSnapshotModel.colorToneProgress,
                seedColor = clockSnapshotModel.seedColor
                seedColor = clockSnapshotModel.seedColor,
            )
        }
        clockSnapshotModel.clockId?.let { repository.setSelectedClock(it) }
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.customization.picker.clock.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.View.MeasureSpec.EXACTLY
import android.widget.FrameLayout
import com.android.customization.picker.clock.shared.ClockSize
import com.android.wallpaper.util.ScreenSizeCalculator

/**
 * Parent view for the clock view. We will calculate the current display size and the preview size
 * and scale down the clock view to fit in the preview.
 */
class ClockHostView2(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {

    var clockSize: ClockSize = ClockSize.DYNAMIC
        set(value) {
            if (field != value) {
                field = value
                updatePivotAndScale()
                invalidate()
            }
        }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        updatePivotAndScale()
    }

    override fun measureChildWithMargins(
        child: View?,
        parentWidthMeasureSpec: Int,
        widthUsed: Int,
        parentHeightMeasureSpec: Int,
        heightUsed: Int,
    ) {
        val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display)
        super.measureChildWithMargins(
            child,
            MeasureSpec.makeMeasureSpec(screenSize.x, EXACTLY),
            widthUsed,
            MeasureSpec.makeMeasureSpec(screenSize.y, EXACTLY),
            heightUsed,
        )
    }

    private fun updatePivotAndScale() {
        when (clockSize) {
            ClockSize.DYNAMIC -> {
                pivotX = (width / 2).toFloat()
                pivotY = (height / 2).toFloat()
            }
            ClockSize.SMALL -> {
                pivotX = getCenteredHostViewPivotX(this)
                pivotY = 0F
            }
        }
        val screenSize = ScreenSizeCalculator.getInstance().getScreenSize(display)
        val ratio = measuredWidth / screenSize.x.toFloat()
        scaleX = ratio
        scaleY = ratio
    }

    companion object {
        fun getCenteredHostViewPivotX(hostView: View): Float {
            return if (hostView.isLayoutRtl) hostView.width.toFloat() else 0F
        }
    }
}
Loading