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.settings.regionalpreferences; 18 19 import android.content.Context; 20 import android.util.Log; 21 22 import androidx.preference.PreferenceCategory; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.widget.PreferenceCategoryController; 26 27 /** Category preference controller for temperature preferences. */ 28 public class TemperatureUnitCategoryController extends PreferenceCategoryController { 29 30 private static final String LOG_TAG = "TemperatureUnitCategoryController"; 31 private static final String KEY_PREFERENCE_CATEGORY_TEMPERATURE_UNIT = 32 "temperature_unit_category"; 33 private static final String KEY_PREFERENCE_TEMPERATURE_UNIT = "temperature_unit_list"; 34 35 private PreferenceCategory mPreferenceCategory; 36 private TemperatureUnitListController mTemperatureUnitListController; 37 TemperatureUnitCategoryController(Context context, String key)38 public TemperatureUnitCategoryController(Context context, String key) { 39 super(context, key); 40 } 41 42 @Override getAvailabilityStatus()43 public int getAvailabilityStatus() { 44 return AVAILABLE; 45 } 46 47 @Override displayPreference(PreferenceScreen screen)48 public void displayPreference(PreferenceScreen screen) { 49 super.displayPreference(screen); 50 mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY_TEMPERATURE_UNIT); 51 if (mPreferenceCategory == null) { 52 Log.d(LOG_TAG, "displayPreference(), Can not find the category."); 53 return; 54 } 55 mPreferenceCategory.setVisible(isAvailable()); 56 mTemperatureUnitListController = new TemperatureUnitListController(mContext, 57 KEY_PREFERENCE_TEMPERATURE_UNIT); 58 mTemperatureUnitListController.displayPreference(screen); 59 } 60 } 61