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

Commit 23514122 authored by Catherine Liang's avatar Catherine Liang
Browse files

Format ThemePicker .kt files

1. kt-format existing .kt files with $ANDROID_BUILD_TOP/external/ktfmt/ktfmt.py <filepath>
2. Remove the exclusion of the files in ktfmt_includes.txt
Bug: 245751447
Test: Manual

Change-Id: Iad6e3ac101b59b521f535d72bdfe42a774bd7eaf
parent 7a45d741
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
+src/
+src_override/
+tests/
-src/com/android/customization/model/color/ColorProvider.kt
-src/com/android/customization/model/color/ColorUtils.kt
-src/com/android/customization/module/SysUiStatsLogger.kt
-src/com/android/customization/picker/clock/ClockSectionView.kt
+127 −106
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import android.app.WallpaperColors
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Resources
import android.text.TextUtils
import androidx.annotation.ColorInt
import androidx.core.graphics.ColorUtils.setAlphaComponent
import androidx.lifecycle.LifecycleOwner
@@ -29,8 +28,8 @@ import com.android.customization.model.ResourceConstants.COLOR_BUNDLES_ARRAY_NAM
import com.android.customization.model.ResourceConstants.COLOR_BUNDLE_MAIN_COLOR_PREFIX
import com.android.customization.model.ResourceConstants.COLOR_BUNDLE_NAME_PREFIX
import com.android.customization.model.ResourceConstants.COLOR_BUNDLE_STYLE_PREFIX
import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE
import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR
import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE
import com.android.customization.model.ResourcesApkProvider
import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_HOME
import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_LOCK
@@ -39,16 +38,15 @@ import com.android.systemui.monet.ColorScheme
import com.android.systemui.monet.Style
import com.android.wallpaper.compat.WallpaperManagerCompat
import com.android.wallpaper.module.InjectorProvider
import java.util.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.*

/**
 * Default implementation of {@link ColorOptionsProvider} that reads preset colors from
 * a stub APK.
 * Default implementation of {@link ColorOptionsProvider} that reads preset colors from a stub APK.
 */
class ColorProvider(context: Context, stubPackageName: String) :
    ResourcesApkProvider(context, stubPackageName), ColorOptionsProvider {
@@ -64,11 +62,13 @@ class ColorProvider(context: Context, stubPackageName: String) :

    private val monetEnabled = ColorUtils.isMonetEnabled(context)
    // TODO(b/202145216): Use style method to fetch the list of style.
    private var styleList = if (themeStyleEnabled) arrayOf(
        Style.TONAL_SPOT, Style.SPRITZ, Style.VIBRANT, Style.EXPRESSIVE
    ) else arrayOf(Style.TONAL_SPOT)
    private var styleList =
        if (themeStyleEnabled)
            arrayOf(Style.TONAL_SPOT, Style.SPRITZ, Style.VIBRANT, Style.EXPRESSIVE)
        else arrayOf(Style.TONAL_SPOT)

    private val scope = if (mContext is LifecycleOwner) {
    private val scope =
        if (mContext is LifecycleOwner) {
            mContext.lifecycleScope
        } else {
            CoroutineScope(Dispatchers.Default + SupervisorJob())
@@ -79,16 +79,19 @@ class ColorProvider(context: Context, stubPackageName: String) :
    private var homeWallpaperColors: WallpaperColors? = null
    private var lockWallpaperColors: WallpaperColors? = null


    override fun isAvailable(): Boolean {
        return monetEnabled && super.isAvailable() && colorsAvailable
    }

    override fun fetch(callback: OptionsFetchedListener<ColorOption>?, reload: Boolean,
    override fun fetch(
        callback: OptionsFetchedListener<ColorOption>?,
        reload: Boolean,
        homeWallpaperColors: WallpaperColors?,
                       lockWallpaperColors: WallpaperColors?) {
        val wallpaperColorsChanged = this.homeWallpaperColors != homeWallpaperColors
                || this.lockWallpaperColors != lockWallpaperColors
        lockWallpaperColors: WallpaperColors?
    ) {
        val wallpaperColorsChanged =
            this.homeWallpaperColors != homeWallpaperColors ||
                this.lockWallpaperColors != lockWallpaperColors
        if (wallpaperColorsChanged) {
            this.homeWallpaperColors = homeWallpaperColors
            this.lockWallpaperColors = lockWallpaperColors
@@ -122,12 +125,15 @@ class ColorProvider(context: Context, stubPackageName: String) :
            manager.getWallpaperId(WallpaperManagerCompat.FLAG_SYSTEM)
    }

    private fun loadSeedColors(homeWallpaperColors: WallpaperColors?,
                               lockWallpaperColors: WallpaperColors?) {
    private fun loadSeedColors(
        homeWallpaperColors: WallpaperColors?,
        lockWallpaperColors: WallpaperColors?
    ) {
        if (homeWallpaperColors == null) return

        val bundles: MutableList<ColorOption> = ArrayList()
        val colorsPerSource = if (lockWallpaperColors == null) {
        val colorsPerSource =
            if (lockWallpaperColors == null) {
                MAX_SEED_COLORS
            } else {
                MAX_SEED_COLORS / 2
@@ -141,14 +147,16 @@ class ColorProvider(context: Context, stubPackageName: String) :
                colorsPerSource,
                if (shouldLockColorsGoFirst) COLOR_SOURCE_LOCK else COLOR_SOURCE_HOME,
                true,
                    bundles)
                bundles
            )
            // Second half of the colors
            buildColorSeeds(
                if (shouldLockColorsGoFirst) homeWallpaperColors else lockWallpaperColors,
                MAX_SEED_COLORS - bundles.size / styleSize,
                if (shouldLockColorsGoFirst) COLOR_SOURCE_HOME else COLOR_SOURCE_LOCK,
                false,
                    bundles)
                bundles
            )
        } else {
            buildColorSeeds(homeWallpaperColors, colorsPerSource, COLOR_SOURCE_HOME, true, bundles)
        }
@@ -157,8 +165,13 @@ class ColorProvider(context: Context, stubPackageName: String) :
        colorBundles = bundles
    }

    private fun buildColorSeeds(wallpaperColors: WallpaperColors, maxColors: Int, source: String,
                                containsDefault: Boolean, bundles: MutableList<ColorOption>) {
    private fun buildColorSeeds(
        wallpaperColors: WallpaperColors,
        maxColors: Int,
        source: String,
        containsDefault: Boolean,
        bundles: MutableList<ColorOption>
    ) {
        val seedColors = ColorScheme.getSeedColors(wallpaperColors)
        val defaultSeed = seedColors.first()
        buildBundle(defaultSeed, 0, containsDefault, source, bundles)
@@ -167,19 +180,27 @@ class ColorProvider(context: Context, stubPackageName: String) :
        }
    }

    private fun buildBundle(colorInt: Int, i: Int, isDefault: Boolean, source: String,
                            bundles: MutableList<ColorOption>) {
    private fun buildBundle(
        colorInt: Int,
        i: Int,
        isDefault: Boolean,
        source: String,
        bundles: MutableList<ColorOption>
    ) {
        // TODO(b/202145216): Measure time cost in the loop.
        for (style in styleList) {
            val builder = ColorSeedOption.Builder()
            val lightColorScheme = ColorScheme(colorInt, /* darkTheme= */ false, style)
            val darkColorScheme = ColorScheme(colorInt, /* darkTheme= */ true, style)
            builder.setLightColors(lightColorScheme.getLightColorPreview())
            builder
                .setLightColors(lightColorScheme.getLightColorPreview())
                .setDarkColors(darkColorScheme.getDarkColorPreview())
                .addOverlayPackage(OVERLAY_CATEGORY_SYSTEM_PALETTE,
                .addOverlayPackage(
                    OVERLAY_CATEGORY_SYSTEM_PALETTE,
                    if (isDefault) "" else toColorString(colorInt)
                )
                .addOverlayPackage(OVERLAY_CATEGORY_COLOR,
                .addOverlayPackage(
                    OVERLAY_CATEGORY_COLOR,
                    if (isDefault) "" else toColorString(colorInt)
                )
                .setSource(source)
@@ -194,37 +215,31 @@ class ColorProvider(context: Context, stubPackageName: String) :
    }

    /**
     * Returns the colors for the light theme version of the preview of a ColorScheme
     * based on this order:
     * |-------|
     * | 0 | 1 |
     * |---+---|
     * | 2 | 3 |
     * |-------|
     * Returns the colors for the light theme version of the preview of a ColorScheme based on this
     * order: |-------| | 0 | 1 | |---+---| | 2 | 3 | |-------|
     */
    @ColorInt
    private fun ColorScheme.getLightColorPreview(): IntArray {
        return intArrayOf(setAlphaComponent(this.accent1[2], ALPHA_MASK),
        return intArrayOf(
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            ColorStateList.valueOf(this.accent3[6]).withLStar(85f).colors[0],
                setAlphaComponent(this.accent1[6], ALPHA_MASK))
            setAlphaComponent(this.accent1[6], ALPHA_MASK)
        )
    }

    /**
     * Returns the color for the dark theme version of the preview of a ColorScheme
     * based on this order:
     * |-------|
     * | 0 | 1 |
     * |---+---|
     * | 2 | 3 |
     * |-------|
     * Returns the color for the dark theme version of the preview of a ColorScheme based on this
     * order: |-------| | 0 | 1 | |---+---| | 2 | 3 | |-------|
     */
    @ColorInt
    private fun ColorScheme.getDarkColorPreview(): IntArray {
        return intArrayOf(setAlphaComponent(this.accent1[2], ALPHA_MASK),
        return intArrayOf(
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            ColorStateList.valueOf(this.accent3[6]).withLStar(85f).colors[0],
                setAlphaComponent(this.accent1[6], ALPHA_MASK))
            setAlphaComponent(this.accent1[6], ALPHA_MASK)
        )
    }

    private fun ColorScheme.getPresetColorPreview(seed: Int): IntArray {
@@ -235,7 +250,8 @@ class ColorProvider(context: Context, stubPackageName: String) :
        }
    }

    private suspend fun loadPreset() = withContext(Dispatchers.IO) {
    private suspend fun loadPreset() =
        withContext(Dispatchers.IO) {
            val extractor = ColorBundlePreviewExtractor(mContext)
            val bundles: MutableList<ColorOption> = ArrayList()

@@ -251,24 +267,29 @@ class ColorProvider(context: Context, stubPackageName: String) :
                extractor.addPrimaryColor(builder, colorFromStub)
                extractor.addSecondaryColor(builder, colorFromStub)
                if (themeStyleEnabled) {
                val styleName = try {
                    val styleName =
                        try {
                            getItemStringFromStub(COLOR_BUNDLE_STYLE_PREFIX, bundleName)
                        } catch (e: Resources.NotFoundException) {
                            null
                        }
                    extractor.addColorStyle(builder, styleName)
                val style = try {
                    val style =
                        try {
                            if (styleName != null) Style.valueOf(styleName) else Style.TONAL_SPOT
                        } catch (e: IllegalArgumentException) {
                            Style.TONAL_SPOT
                        }

                val darkColors = ColorScheme(colorFromStub, true, style)
                        .getPresetColorPreview(colorFromStub)
                val lightColors = ColorScheme(colorFromStub, false, style)
                    val darkColors =
                        ColorScheme(colorFromStub, true, style).getPresetColorPreview(colorFromStub)
                    val lightColors =
                        ColorScheme(colorFromStub, false, style)
                            .getPresetColorPreview(colorFromStub)
                    builder.setColorPrimaryDark(darkColors[0]).setColorSecondaryDark(darkColors[1])
                builder.setColorPrimaryLight(lightColors[0]).setColorSecondaryLight(lightColors[1])
                    builder
                        .setColorPrimaryLight(lightColors[0])
                        .setColorSecondaryLight(lightColors[1])
                }

                bundles.add(builder.build(mContext))
+11 −11
Original line number Diff line number Diff line
@@ -22,18 +22,14 @@ import android.os.SystemProperties
import android.util.Log
import androidx.annotation.ColorInt

/**
 * Utility to wrap Monet's color extraction
 */
/** Utility to wrap Monet's color extraction */
object ColorUtils {
    private const val TAG = "ColorUtils"
    private const val MONET_FLAG = "flag_monet"
    private var sSysuiRes: Resources? = null
    private var sFlagId = 0

    /**
     * Returns true if color extraction is enabled in systemui.
     */
    /** Returns true if color extraction is enabled in systemui. */
    @JvmStatic
    fun isMonetEnabled(context: Context): Boolean {
        var monetEnabled = SystemProperties.getBoolean("persist.systemui.flag_monet", false)
@@ -41,8 +37,11 @@ object ColorUtils {
            if (sSysuiRes == null) {
                try {
                    val pm = context.packageManager
                    val sysUIInfo = pm.getApplicationInfo("com.android.systemui",
                            PackageManager.GET_META_DATA or PackageManager.MATCH_SYSTEM_ONLY)
                    val sysUIInfo =
                        pm.getApplicationInfo(
                            "com.android.systemui",
                            PackageManager.GET_META_DATA or PackageManager.MATCH_SYSTEM_ONLY
                        )
                    if (sysUIInfo != null) {
                        sSysuiRes = pm.getResourcesForApplication(sysUIInfo)
                    }
@@ -51,8 +50,9 @@ object ColorUtils {
                }
            }
            if (sFlagId == 0) {
                sFlagId = if (sSysuiRes == null) 0 else sSysuiRes!!.getIdentifier(
                        MONET_FLAG, "bool", "com.android.systemui")
                sFlagId =
                    if (sSysuiRes == null) 0
                    else sSysuiRes!!.getIdentifier(MONET_FLAG, "bool", "com.android.systemui")
            }
            if (sFlagId > 0) {
                monetEnabled = sSysuiRes!!.getBoolean(sFlagId)
+50 −46
Original line number Diff line number Diff line
@@ -19,9 +19,7 @@ import android.stats.style.StyleEnums
import com.android.systemui.shared.system.SysUiStatsLog
import com.android.systemui.shared.system.SysUiStatsLog.STYLE_UI_CHANGED

/**
 * The builder for [SysUiStatsLog].
 */
/** The builder for [SysUiStatsLog]. */
class SysUiStatsLogger {

    private var atom = STYLE_UI_CHANGED
@@ -46,67 +44,73 @@ class SysUiStatsLogger {
    private var appLaunchCount = 0
    private var colorVariant = 0

    fun setAction(action: Int) =
        apply { this.action = action }
    fun setAction(action: Int) = apply { this.action = action }

    fun setColorPackageHash(color_package_hash: Int) =
        apply { this.colorPackageHash = color_package_hash }
    fun setColorPackageHash(color_package_hash: Int) = apply {
        this.colorPackageHash = color_package_hash
    }

    fun setFontPackageHash(font_package_hash: Int) =
        apply { this.fontPackageHash = font_package_hash }
    fun setFontPackageHash(font_package_hash: Int) = apply {
        this.fontPackageHash = font_package_hash
    }

    fun setShapePackageHash(shape_package_hash: Int) =
        apply { this.shapePackageHash = shape_package_hash }
    fun setShapePackageHash(shape_package_hash: Int) = apply {
        this.shapePackageHash = shape_package_hash
    }

    fun setClockPackageHash(clock_package_hash: Int) =
        apply { this.clockPackageHash = clock_package_hash }
    fun setClockPackageHash(clock_package_hash: Int) = apply {
        this.clockPackageHash = clock_package_hash
    }

    fun setLauncherGrid(launcher_grid: Int) =
        apply { this.launcherGrid = launcher_grid }
    fun setLauncherGrid(launcher_grid: Int) = apply { this.launcherGrid = launcher_grid }

    fun setWallpaperCategoryHash(wallpaper_category_hash: Int) =
        apply { this.wallpaperCategoryHash = wallpaper_category_hash }
    fun setWallpaperCategoryHash(wallpaper_category_hash: Int) = apply {
        this.wallpaperCategoryHash = wallpaper_category_hash
    }

    fun setWallpaperIdHash(wallpaper_id_hash: Int) =
        apply { this.wallpaperIdHash = wallpaper_id_hash }
    fun setWallpaperIdHash(wallpaper_id_hash: Int) = apply {
        this.wallpaperIdHash = wallpaper_id_hash
    }

    fun setColorPreference(color_preference: Int) =
        apply { this.colorPreference = color_preference }
    fun setColorPreference(color_preference: Int) = apply {
        this.colorPreference = color_preference
    }

    fun setLocationPreference(location_preference: Int) =
        apply { this.locationPreference = location_preference }
    fun setLocationPreference(location_preference: Int) = apply {
        this.locationPreference = location_preference
    }

    fun setDatePreference(date_preference: Int) =
        apply { this.datePreference = date_preference }
    fun setDatePreference(date_preference: Int) = apply { this.datePreference = date_preference }

    fun setLaunchedPreference(launched_preference: Int) =
        apply { this.launchedPreference = launched_preference }
    fun setLaunchedPreference(launched_preference: Int) = apply {
        this.launchedPreference = launched_preference
    }

    fun setEffectPreference(effect_preference: Int) =
        apply { this.effectPreference = effect_preference }
    fun setEffectPreference(effect_preference: Int) = apply {
        this.effectPreference = effect_preference
    }

    fun setEffectIdHash(effect_id_hash: Int) =
        apply { this.effectIdHash = effect_id_hash }
    fun setEffectIdHash(effect_id_hash: Int) = apply { this.effectIdHash = effect_id_hash }

    fun setLockWallpaperCategoryHash(lock_wallpaper_category_hash: Int) =
        apply { this.lockWallpaperCategoryHash = lock_wallpaper_category_hash }
    fun setLockWallpaperCategoryHash(lock_wallpaper_category_hash: Int) = apply {
        this.lockWallpaperCategoryHash = lock_wallpaper_category_hash
    }

    fun setLockWallpaperIdHash(lock_wallpaper_id_hash: Int) =
        apply { this.lockWallpaperIdHash = lock_wallpaper_id_hash }
    fun setLockWallpaperIdHash(lock_wallpaper_id_hash: Int) = apply {
        this.lockWallpaperIdHash = lock_wallpaper_id_hash
    }

    fun setFirstLaunchDateSinceSetup(first_launch_date_since_setup: Int) =
        apply { this.firstLaunchDateSinceSetup = first_launch_date_since_setup }
    fun setFirstLaunchDateSinceSetup(first_launch_date_since_setup: Int) = apply {
        this.firstLaunchDateSinceSetup = first_launch_date_since_setup
    }

    fun setFirstWallpaperApplyDateSinceSetup(first_wallpaper_apply_date_since_setup: Int) =
        apply {
    fun setFirstWallpaperApplyDateSinceSetup(first_wallpaper_apply_date_since_setup: Int) = apply {
        this.firstWallpaperApplyDateSinceSetup = first_wallpaper_apply_date_since_setup
    }

    fun setAppLaunchCount(app_launch_count: Int) =
        apply { this.appLaunchCount = app_launch_count }
    fun setAppLaunchCount(app_launch_count: Int) = apply { this.appLaunchCount = app_launch_count }

    fun setColorVariant(color_variant: Int) =
        apply { this.colorVariant = color_variant }
    fun setColorVariant(color_variant: Int) = apply { this.colorVariant = color_variant }

    fun log() {
        SysUiStatsLog.write(
+2 −2

File changed.

Contains only whitespace changes.