1 /* 2 * Copyright (C) 2020 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 android.provider.Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED; 20 21 import static com.android.tv.settings.util.InstrumentationUtils.logToggleInteracted; 22 23 import android.app.tvsettings.TvSettingsEnums; 24 import android.os.Bundle; 25 import android.provider.Settings; 26 import android.text.TextUtils; 27 28 import androidx.annotation.Keep; 29 import androidx.preference.Preference; 30 import androidx.preference.SwitchPreference; 31 32 import com.android.tv.settings.R; 33 import com.android.tv.settings.SettingsPreferenceFragment; 34 35 /** 36 * The "Advanced display settings" screen in TV Settings. 37 */ 38 @Keep 39 public class AdvancedDisplayFragment extends SettingsPreferenceFragment { 40 private static final String KEY_GAME_MODE = "game_mode"; 41 42 @Override onCreatePreferences(Bundle bundle, String s)43 public void onCreatePreferences(Bundle bundle, String s) { 44 setPreferencesFromResource(R.xml.advanced_display, null); 45 SwitchPreference gameModePreference = findPreference(KEY_GAME_MODE); 46 gameModePreference.setChecked(getGameModeStatus() == 1); 47 } 48 49 @Override onPreferenceTreeClick(Preference preference)50 public boolean onPreferenceTreeClick(Preference preference) { 51 if (TextUtils.equals(preference.getKey(), KEY_GAME_MODE)) { 52 logToggleInteracted( 53 TvSettingsEnums.DISPLAY_SOUND_ADVANCED_DISPLAY_GAME_MODE, 54 ((SwitchPreference) preference).isChecked()); 55 setGameModeStatus(((SwitchPreference) preference).isChecked() ? 1 : 0); 56 } 57 return super.onPreferenceTreeClick(preference); 58 } 59 getGameModeStatus()60 private int getGameModeStatus() { 61 return Settings.Secure.getInt(getActivity().getContentResolver(), 62 MINIMAL_POST_PROCESSING_ALLOWED, 63 1); 64 } 65 setGameModeStatus(int state)66 private void setGameModeStatus(int state) { 67 Settings.Secure.putInt(getActivity().getContentResolver(), MINIMAL_POST_PROCESSING_ALLOWED, 68 state); 69 } 70 71 @Override getPageId()72 protected int getPageId() { 73 return TvSettingsEnums.DISPLAY_SOUND_ADVANCED_DISPLAY; 74 } 75 } 76