1 /* 2 * Copyright (C) 2021 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.tv.settings.device.displaysound; 18 19 import static com.android.tv.settings.library.PreferenceCompat.STATUS_OFF; 20 import static com.android.tv.settings.library.PreferenceCompat.STATUS_ON; 21 22 import android.os.Bundle; 23 24 import androidx.annotation.Keep; 25 import androidx.preference.PreferenceGroup; 26 27 import com.android.tv.settings.R; 28 import com.android.tv.settings.compat.HasKeys; 29 import com.android.tv.settings.compat.RenderUtil; 30 import com.android.tv.settings.library.ManagerUtil; 31 import com.android.tv.settings.library.PreferenceCompat; 32 33 /** 34 * The fragment compat for advanced volume screen in TV settings. 35 */ 36 @Keep 37 public class AdvancedVolumeFragmentCompat extends RadioPreferencesFragmentCompat { 38 private static final String KEY_ADVANCED_SOUND_OPTION = "advanced_sound_settings_option"; 39 private static final String KEY_FORMAT_INFO = "surround_sound_format_info"; 40 private static final String KEY_FORMAT_INFO_ON_MANUAL = "surround_sound_format_info_on_manual"; 41 42 @Override onCreatePreferences(Bundle bundle, String s)43 public void onCreatePreferences(Bundle bundle, String s) { 44 setPreferencesFromResource(R.xml.advanced_volume_compat, null); 45 mPrefGroup = findPreference(KEY_ADVANCED_SOUND_OPTION); 46 } 47 48 @Override updatePref(PreferenceCompat preferenceCompat)49 public HasKeys updatePref(PreferenceCompat preferenceCompat) { 50 if (preferenceCompat != null && preferenceCompat.getKey().length == 1) { 51 String categoryKey = preferenceCompat.getKey()[0]; 52 switch (categoryKey) { 53 case KEY_ADVANCED_SOUND_OPTION: 54 return super.updatePref(preferenceCompat); 55 case KEY_FORMAT_INFO: 56 case KEY_FORMAT_INFO_ON_MANUAL: 57 if (preferenceCompat.getVisible() == STATUS_OFF) { 58 findPreference(categoryKey).setVisible(false); 59 } else if (preferenceCompat.getVisible() == STATUS_ON) { 60 findPreference(categoryKey).setVisible(true); 61 } 62 RenderUtil.updatePreferenceGroup( 63 ((PreferenceGroup) findPreference(categoryKey)), 64 preferenceCompat.getChildPrefCompats()); 65 return null; 66 default: 67 return null; 68 } 69 } 70 return super.updatePref(preferenceCompat); 71 } 72 73 @Override getStateIdentifier()74 public int getStateIdentifier() { 75 return ManagerUtil.STATE_ADVANCED_VOLUME; 76 } 77 } 78