diff options
author | Catherine Liang <cathliang@google.com> | 2023-11-21 22:05:58 +0000 |
---|---|---|
committer | Catherine Liang <cathliang@google.com> | 2023-11-29 22:59:42 +0000 |
commit | 8e43949902bf9cce76525366d7cc9e41ce725b45 (patch) | |
tree | 69487ff368656120d7ae79887963916748cf7825 /src/com | |
parent | bf5b90d8042f37f8c90098949e750174d4777334 (diff) | |
download | ThemePicker-8e43949902bf9cce76525366d7cc9e41ce725b45.tar.gz |
Fix color in the preview fragment (2/2)
Colors were inconsistent between the preview fragment and the actual
wallpaper colors set, because the style was not accounted for.
Adjust to account for style when changing the colors of the preview
fragment UI. Style-related changes are included in ThemePicker while
PreviewFragment changes are in WallpaperPicker2.
Flag: NONE
Bug: 308947090
Bug: 308946897
Test: manually verified with different wallpapers
Change-Id: I1897ae1e18113fdbfa573676111ccf3b1daee82f
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/customization/model/color/ThemedWallpaperColorResources.kt | 72 | ||||
-rw-r--r-- | src/com/android/customization/module/ThemePickerInjector.kt | 10 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/com/android/customization/model/color/ThemedWallpaperColorResources.kt b/src/com/android/customization/model/color/ThemedWallpaperColorResources.kt new file mode 100644 index 00000000..906d9020 --- /dev/null +++ b/src/com/android/customization/model/color/ThemedWallpaperColorResources.kt @@ -0,0 +1,72 @@ +/* + * 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.customization.model.color + +import android.R +import android.app.WallpaperColors +import android.content.Context +import android.provider.Settings +import android.util.Log +import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_THEME_STYLE +import com.android.systemui.monet.ColorScheme +import com.android.systemui.monet.Style +import org.json.JSONException +import org.json.JSONObject + +class ThemedWallpaperColorResources(wallpaperColors: WallpaperColors, context: Context) : + WallpaperColorResources(wallpaperColors) { + + init { + val wallpaperColorScheme = + ColorScheme( + wallpaperColors = wallpaperColors, + darkTheme = false, + style = fetchThemeStyleFromSetting(context) + ) + addOverlayColor(wallpaperColorScheme.neutral1, R.color.system_neutral1_10) + addOverlayColor(wallpaperColorScheme.neutral2, R.color.system_neutral2_10) + addOverlayColor(wallpaperColorScheme.accent1, R.color.system_accent1_10) + addOverlayColor(wallpaperColorScheme.accent2, R.color.system_accent2_10) + addOverlayColor(wallpaperColorScheme.accent3, R.color.system_accent3_10) + } + + private fun fetchThemeStyleFromSetting(context: Context): Style { + val overlayPackageJson = + Settings.Secure.getString( + context.contentResolver, + Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, + ) + return if (!overlayPackageJson.isNullOrEmpty()) { + try { + val jsonObject = JSONObject(overlayPackageJson) + Style.valueOf(jsonObject.getString(OVERLAY_CATEGORY_THEME_STYLE)) + } catch (e: (JSONException)) { + Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e) + Style.TONAL_SPOT + } catch (e: IllegalArgumentException) { + Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e) + Style.TONAL_SPOT + } + } else { + Style.TONAL_SPOT + } + } + + companion object { + private const val TAG = "ThemedWallpaperColorResources" + } +} diff --git a/src/com/android/customization/module/ThemePickerInjector.kt b/src/com/android/customization/module/ThemePickerInjector.kt index e01fa44e..0ae9600b 100644 --- a/src/com/android/customization/module/ThemePickerInjector.kt +++ b/src/com/android/customization/module/ThemePickerInjector.kt @@ -17,6 +17,7 @@ package com.android.customization.module import android.app.Activity import android.app.UiModeManager +import android.app.WallpaperColors import android.app.WallpaperManager import android.content.Context import android.content.Intent @@ -29,6 +30,8 @@ import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ViewModelProvider import com.android.customization.model.color.ColorCustomizationManager import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_PRESET +import com.android.customization.model.color.ThemedWallpaperColorResources +import com.android.customization.model.color.WallpaperColorResources import com.android.customization.model.grid.GridOptionsManager import com.android.customization.model.mode.DarkModeSnapshotRestorer import com.android.customization.model.theme.OverlayManagerCompat @@ -399,6 +402,13 @@ internal constructor( } } + override fun getWallpaperColorResources( + wallpaperColors: WallpaperColors, + context: Context + ): WallpaperColorResources { + return ThemedWallpaperColorResources(wallpaperColors, context) + } + override fun getColorPickerInteractor( context: Context, wallpaperColorsRepository: WallpaperColorsRepository, |