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.settings.fuelgauge.batteryusage 17 18 import android.content.Context 19 import com.android.settings.R 20 import com.android.settings.display.BatteryPercentageSwitchPreference 21 import com.android.settings.flags.Flags 22 import com.android.settings.fuelgauge.BatteryHeaderPreference 23 import com.android.settingslib.metadata.PreferenceAvailabilityProvider 24 import com.android.settingslib.metadata.PreferenceIconProvider 25 import com.android.settingslib.metadata.ProvidePreferenceScreen 26 import com.android.settingslib.metadata.preferenceHierarchy 27 import com.android.settingslib.preference.PreferenceScreenCreator 28 import com.android.settingslib.widget.SettingsThemeHelper.isExpressiveTheme 29 30 @ProvidePreferenceScreen(PowerUsageSummaryScreen.KEY) 31 class PowerUsageSummaryScreen : 32 PreferenceScreenCreator, PreferenceAvailabilityProvider, PreferenceIconProvider { 33 override val key: String 34 get() = KEY 35 36 override val title: Int 37 get() = R.string.power_usage_summary_title 38 39 override val keywords: Int 40 get() = R.string.keywords_battery 41 isFlagEnablednull42 override fun isFlagEnabled(context: Context) = Flags.catalystPowerUsageSummaryScreen() 43 44 override fun hasCompleteHierarchy() = false 45 46 override fun fragmentClass() = PowerUsageSummary::class.java 47 48 override fun isAvailable(context: Context) = 49 context.resources.getBoolean(R.bool.config_show_top_level_battery) 50 51 override fun getIcon(context: Context) = 52 when { 53 isExpressiveTheme(context) -> R.drawable.ic_homepage_battery 54 Flags.homepageRevamp() -> R.drawable.ic_settings_battery_filled 55 else -> R.drawable.ic_settings_battery_white 56 } 57 getPreferenceHierarchynull58 override fun getPreferenceHierarchy(context: Context) = 59 preferenceHierarchy(context, this) { 60 +BatteryHeaderPreference() 61 +BatteryPercentageSwitchPreference() 62 } 63 64 companion object { 65 const val KEY = "power_usage_summary_screen" 66 } 67 } 68