1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 package com.android.customization.model.color 18 19 import android.content.Context 20 import android.stats.style.StyleEnums 21 import android.view.View 22 import androidx.annotation.ColorInt 23 import com.android.customization.model.color.ColorOptionsProvider.ColorSource 24 import com.android.customization.picker.color.shared.model.ColorType 25 import com.android.systemui.monet.Style 26 import com.android.themepicker.R 27 28 /** 29 * Represents a color option in the revamped UI, it can be used for both wallpaper and preset colors 30 */ 31 class ColorOptionImpl( 32 title: String?, 33 overlayPackages: Map<String, String?>, 34 isDefault: Boolean, 35 private val source: String?, 36 style: Style, 37 index: Int, 38 private val previewInfo: PreviewInfo, 39 val type: ColorType, 40 ) : ColorOption(title, overlayPackages, isDefault, style, index) { 41 42 class PreviewInfo( 43 @ColorInt val lightColors: IntArray, 44 @ColorInt val darkColors: IntArray, 45 ) : ColorOption.PreviewInfo { 46 @ColorInt resolveColorsnull47 fun resolveColors(darkTheme: Boolean): IntArray { 48 return if (darkTheme) darkColors else lightColors 49 } 50 } 51 bindThumbnailTilenull52 override fun bindThumbnailTile(view: View?) { 53 // Do nothing. This function will no longer be used in the Revamped UI 54 } 55 getLayoutResIdnull56 override fun getLayoutResId(): Int { 57 return R.layout.color_option 58 } 59 getPreviewInfonull60 override fun getPreviewInfo(): PreviewInfo { 61 return previewInfo 62 } 63 getContentDescriptionnull64 override fun getContentDescription(context: Context): CharSequence? { 65 return title 66 } 67 getSourcenull68 override fun getSource(): String? { 69 return source 70 } 71 getSourceForLoggingnull72 override fun getSourceForLogging(): Int { 73 return when (getSource()) { 74 ColorOptionsProvider.COLOR_SOURCE_PRESET -> StyleEnums.COLOR_SOURCE_PRESET_COLOR 75 ColorOptionsProvider.COLOR_SOURCE_HOME -> StyleEnums.COLOR_SOURCE_HOME_SCREEN_WALLPAPER 76 ColorOptionsProvider.COLOR_SOURCE_LOCK -> StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER 77 else -> StyleEnums.COLOR_SOURCE_UNSPECIFIED 78 } 79 } 80 getStyleForLoggingnull81 override fun getStyleForLogging(): Int = style.toString().hashCode() 82 83 class Builder { 84 var title: String? = null 85 86 @ColorInt var lightColors: IntArray = intArrayOf() 87 88 @ColorInt var darkColors: IntArray = intArrayOf() 89 90 @ColorSource var source: String? = null 91 var isDefault = false 92 var style = Style.TONAL_SPOT 93 var index = 0 94 var packages: MutableMap<String, String?> = HashMap() 95 var type = ColorType.WALLPAPER_COLOR 96 97 fun build(): ColorOptionImpl { 98 return ColorOptionImpl( 99 title, 100 packages, 101 isDefault, 102 source, 103 style, 104 index, 105 createPreviewInfo(), 106 type 107 ) 108 } 109 110 private fun createPreviewInfo(): PreviewInfo { 111 return PreviewInfo(lightColors, darkColors) 112 } 113 114 fun addOverlayPackage(category: String?, packageName: String?): ColorOptionImpl.Builder { 115 category?.let { packages[category] = packageName } 116 return this 117 } 118 } 119 } 120