Adding ThemeManager as a centralized place for controlling icon theming
Bug: 381897614 Flag: EXEMPT refactor Test: atest ThemeManagerTest Change-Id: Ib1dafdcc303f05f78cf586741c3d35243ab06e69
This commit is contained in:
@@ -22,9 +22,8 @@ import android.os.Process
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.LauncherPrefs.Companion.THEMED_ICONS
|
||||
import com.android.launcher3.LauncherPrefs.Companion.get
|
||||
import com.android.launcher3.graphics.PreloadIconDrawable
|
||||
import com.android.launcher3.graphics.ThemeManager
|
||||
import com.android.launcher3.icons.BitmapInfo
|
||||
import com.android.launcher3.icons.FastBitmapDrawable
|
||||
import com.android.launcher3.icons.IconCache
|
||||
@@ -71,6 +70,9 @@ class PreviewItemManagerTest {
|
||||
|
||||
private var defaultThemedIcons = false
|
||||
|
||||
private val themeManager: ThemeManager
|
||||
get() = ThemeManager.INSTANCE.get(context)
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
modelHelper = LauncherModelHelper()
|
||||
@@ -126,19 +128,19 @@ class PreviewItemManagerTest {
|
||||
folderItems[3].bitmap.withFlags(profileFlagOp(UserIconInfo.TYPE_WORK))
|
||||
folderItems[3].bitmap.themedBitmap = null
|
||||
|
||||
defaultThemedIcons = get(context).get(THEMED_ICONS)
|
||||
defaultThemedIcons = themeManager.isMonoThemeEnabled
|
||||
}
|
||||
|
||||
@After
|
||||
@Throws(Exception::class)
|
||||
fun tearDown() {
|
||||
get(context).put(THEMED_ICONS, defaultThemedIcons)
|
||||
themeManager.isMonoThemeEnabled = defaultThemedIcons
|
||||
modelHelper.destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkThemedIconWithThemingOn_iconShouldBeThemed() {
|
||||
get(context).put(THEMED_ICONS, true)
|
||||
themeManager.isMonoThemeEnabled = true
|
||||
val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
|
||||
previewItemManager.setDrawable(drawingParams, folderItems[0])
|
||||
@@ -148,7 +150,7 @@ class PreviewItemManagerTest {
|
||||
|
||||
@Test
|
||||
fun checkThemedIconWithThemingOff_iconShouldNotBeThemed() {
|
||||
get(context).put(THEMED_ICONS, false)
|
||||
themeManager.isMonoThemeEnabled = false
|
||||
val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
|
||||
previewItemManager.setDrawable(drawingParams, folderItems[0])
|
||||
@@ -158,7 +160,7 @@ class PreviewItemManagerTest {
|
||||
|
||||
@Test
|
||||
fun checkUnthemedIconWithThemingOn_iconShouldNotBeThemed() {
|
||||
get(context).put(THEMED_ICONS, true)
|
||||
themeManager.isMonoThemeEnabled = true
|
||||
val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
|
||||
previewItemManager.setDrawable(drawingParams, folderItems[1])
|
||||
@@ -168,7 +170,7 @@ class PreviewItemManagerTest {
|
||||
|
||||
@Test
|
||||
fun checkUnthemedIconWithThemingOff_iconShouldNotBeThemed() {
|
||||
get(context).put(THEMED_ICONS, false)
|
||||
themeManager.isMonoThemeEnabled = false
|
||||
val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
|
||||
previewItemManager.setDrawable(drawingParams, folderItems[1])
|
||||
@@ -178,7 +180,7 @@ class PreviewItemManagerTest {
|
||||
|
||||
@Test
|
||||
fun checkThemedIconWithBadgeWithThemingOn_iconAndBadgeShouldBeThemed() {
|
||||
get(context).put(THEMED_ICONS, true)
|
||||
themeManager.isMonoThemeEnabled = true
|
||||
val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
|
||||
previewItemManager.setDrawable(drawingParams, folderItems[2])
|
||||
@@ -191,7 +193,7 @@ class PreviewItemManagerTest {
|
||||
|
||||
@Test
|
||||
fun checkUnthemedIconWithBadgeWithThemingOn_badgeShouldBeThemed() {
|
||||
get(context).put(THEMED_ICONS, true)
|
||||
themeManager.isMonoThemeEnabled = true
|
||||
val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
|
||||
previewItemManager.setDrawable(drawingParams, folderItems[3])
|
||||
@@ -204,7 +206,7 @@ class PreviewItemManagerTest {
|
||||
|
||||
@Test
|
||||
fun checkUnthemedIconWithBadgeWithThemingOff_iconAndBadgeShouldNotBeThemed() {
|
||||
get(context).put(THEMED_ICONS, false)
|
||||
themeManager.isMonoThemeEnabled = false
|
||||
val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
|
||||
previewItemManager.setDrawable(drawingParams, folderItems[3])
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.launcher3.graphics
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.launcher3.FakeLauncherPrefs
|
||||
import com.android.launcher3.dagger.LauncherAppComponent
|
||||
import com.android.launcher3.dagger.LauncherAppModule
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.util.Executors.MAIN_EXECUTOR
|
||||
import com.android.launcher3.util.SandboxApplication
|
||||
import com.android.launcher3.util.TestUtil
|
||||
import dagger.Component
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ThemeManagerTest {
|
||||
|
||||
@get:Rule val context = SandboxApplication()
|
||||
|
||||
lateinit var themeManager: ThemeManager
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
context.initDaggerComponent(DaggerThemeManagerComponent.builder())
|
||||
themeManager = ThemeManager.INSTANCE[context]
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isMonoThemeEnabled get and set`() {
|
||||
themeManager.isMonoThemeEnabled = true
|
||||
TestUtil.runOnExecutorSync(MAIN_EXECUTOR) {}
|
||||
assertTrue(themeManager.isMonoThemeEnabled)
|
||||
assertTrue(themeManager.iconState.isMonoTheme)
|
||||
|
||||
themeManager.isMonoThemeEnabled = false
|
||||
TestUtil.runOnExecutorSync(MAIN_EXECUTOR) {}
|
||||
assertFalse(themeManager.isMonoThemeEnabled)
|
||||
assertFalse(themeManager.iconState.isMonoTheme)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `callback called on theme change`() {
|
||||
themeManager.isMonoThemeEnabled = false
|
||||
|
||||
var callbackCalled = false
|
||||
themeManager.addChangeListener { callbackCalled = true }
|
||||
themeManager.isMonoThemeEnabled = true
|
||||
TestUtil.runOnExecutorSync(MAIN_EXECUTOR) {}
|
||||
|
||||
assertTrue(callbackCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `iconState changes with theme`() {
|
||||
themeManager.isMonoThemeEnabled = false
|
||||
TestUtil.runOnExecutorSync(MAIN_EXECUTOR) {}
|
||||
val disabledIconState = themeManager.iconState
|
||||
|
||||
themeManager.isMonoThemeEnabled = true
|
||||
TestUtil.runOnExecutorSync(MAIN_EXECUTOR) {}
|
||||
assertNotEquals(disabledIconState, themeManager.iconState)
|
||||
|
||||
themeManager.isMonoThemeEnabled = false
|
||||
TestUtil.runOnExecutorSync(MAIN_EXECUTOR) {}
|
||||
assertEquals(disabledIconState, themeManager.iconState)
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAppSingleton
|
||||
@Component(modules = [LauncherAppModule::class])
|
||||
interface ThemeManagerComponent : LauncherAppComponent {
|
||||
|
||||
override fun getLauncherPrefs(): FakeLauncherPrefs
|
||||
|
||||
@Component.Builder
|
||||
interface Builder : LauncherAppComponent.Builder {
|
||||
|
||||
override fun build(): ThemeManagerComponent
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user