1 /* 2 * Copyright (C) 2024 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 package com.android.permissioncontroller.wear.permission.components.theme 17 18 import android.content.Context 19 import android.os.SystemProperties 20 import androidx.annotation.ColorRes 21 import androidx.annotation.DimenRes 22 import androidx.annotation.DoNotInline 23 import androidx.annotation.StringRes 24 import androidx.compose.ui.graphics.Color 25 26 object ResourceHelper { 27 28 private const val MATERIAL3_ENABLED_SYSPROP = "persist.cw_build.bluechip.enabled" 29 30 /* This controls in app permission controller experience. */ 31 private val material3Enabled: Boolean 32 get() { 33 return SystemProperties.getBoolean(MATERIAL3_ENABLED_SYSPROP, false) 34 } 35 36 val materialUIVersionInApp: WearPermissionMaterialUIVersion = 37 if (material3Enabled) { 38 WearPermissionMaterialUIVersion.MATERIAL3 39 } else { 40 WearPermissionMaterialUIVersion.MATERIAL2_5 41 } 42 43 /* 44 This is to control the permission controller screens in settings. 45 Currently it is set as false. We will either use the flag or a common property from settings 46 based on settings implementation when we are ready" */ 47 private val material3EnabledInSettings: Boolean 48 get() { 49 return false 50 } 51 52 val materialUIVersionInSettings: WearPermissionMaterialUIVersion = 53 if (material3EnabledInSettings) { 54 WearPermissionMaterialUIVersion.MATERIAL3 55 } else { 56 WearPermissionMaterialUIVersion.MATERIAL2_5 57 } 58 59 @DoNotInline getColornull60 fun getColor(context: Context, @ColorRes id: Int): Color? { 61 return try { 62 val colorInt = context.resources.getColor(id, context.theme) 63 Color(colorInt) 64 } catch (_: Exception) { 65 null 66 } 67 } 68 69 @DoNotInline getStringnull70 fun getString(context: Context, @StringRes id: Int): String? { 71 return try { 72 context.resources.getString(id) 73 } catch (_: Exception) { 74 null 75 } 76 } 77 78 @DoNotInline getDimennull79 fun getDimen(context: Context, @DimenRes id: Int): Float? { 80 return try { 81 context.resources.getDimension(id) / context.resources.displayMetrics.density 82 } catch (_: Exception) { 83 null 84 } 85 } 86 } 87