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

Commit 8e439499 authored by Catherine Liang's avatar Catherine Liang
Browse files

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
parent bf5b90d8
Loading
Loading
Loading
Loading
+72 −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.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"
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -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,
+10 −0
Original line number Diff line number Diff line
package com.android.customization.testing

import android.app.WallpaperColors
import android.content.Context
import android.content.res.Resources
import androidx.activity.ComponentActivity
import com.android.customization.model.color.ThemedWallpaperColorResources
import com.android.customization.model.color.WallpaperColorResources
import com.android.customization.module.CustomizationInjector
import com.android.customization.module.CustomizationPreferences
import com.android.customization.module.logging.ThemesUserEventLogger
@@ -49,6 +52,13 @@ constructor(
        throw UnsupportedOperationException("not implemented")
    }

    override fun getWallpaperColorResources(
        wallpaperColors: WallpaperColors,
        context: Context
    ): WallpaperColorResources {
        return ThemedWallpaperColorResources(wallpaperColors, context)
    }

    override fun getColorPickerInteractor(
        context: Context,
        wallpaperColorsRepository: WallpaperColorsRepository,