1 /* 2 * Copyright (C) 2025 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.settings.communal; 18 19 import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_CHARGING; 20 import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_CHARGING_UPRIGHT; 21 import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_DOCKED; 22 import static android.provider.Settings.Secure.GLANCEABLE_HUB_START_NEVER; 23 import static android.provider.Settings.Secure.WHEN_TO_START_GLANCEABLE_HUB; 24 25 import android.annotation.StringRes; 26 import android.content.Context; 27 import android.provider.Settings; 28 29 import androidx.preference.Preference; 30 31 import com.android.settings.R; 32 import com.android.settings.core.BasePreferenceController; 33 import com.android.settings.core.PreferenceControllerMixin; 34 35 /** 36 * A preference controller that is responsible for showing the "when to auto start hub" setting in 37 * hub settings. 38 */ 39 public class WhenToStartHubPreferenceController extends BasePreferenceController implements 40 PreferenceControllerMixin { WhenToStartHubPreferenceController(Context context, String preferenceKey)41 public WhenToStartHubPreferenceController(Context context, String preferenceKey) { 42 super(context, preferenceKey); 43 } 44 45 @Override updateState(Preference preference)46 public void updateState(Preference preference) { 47 super.updateState(preference); 48 49 preference.setSummary(getSummaryResId()); 50 } 51 52 @Override getAvailabilityStatus()53 public int getAvailabilityStatus() { 54 return AVAILABLE; 55 } 56 57 @Override getSummary()58 public CharSequence getSummary() { 59 return mContext.getString(getSummaryResId()); 60 } 61 62 @StringRes getSummaryResId()63 private int getSummaryResId() { 64 final int setting = Settings.Secure.getInt( 65 mContext.getContentResolver(), 66 WHEN_TO_START_GLANCEABLE_HUB, 67 GLANCEABLE_HUB_START_NEVER); 68 69 switch (setting) { 70 case GLANCEABLE_HUB_START_CHARGING: 71 return R.string.when_to_show_hubmode_charging; 72 case GLANCEABLE_HUB_START_DOCKED: 73 return R.string.when_to_show_hubmode_docked; 74 case GLANCEABLE_HUB_START_CHARGING_UPRIGHT: 75 return R.string.when_to_show_hubmode_charging_and_upright; 76 case GLANCEABLE_HUB_START_NEVER: 77 default: 78 return R.string.when_to_show_hubmode_never; 79 } 80 } 81 } 82