1 /* 2 * Copyright (C) 2015 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.quicksettings; 18 19 import android.content.Context; 20 import android.content.SharedPreferences; 21 import android.content.res.Resources; 22 import android.text.TextUtils; 23 24 public class PresetSettingsListener implements SharedPreferences.OnSharedPreferenceChangeListener { 25 26 private final Context mContext; 27 28 PresetSettingsListener(Context context) { 29 mContext = context; 30 } 31 32 @Override 33 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 34 if (!TextUtils.equals(key, "preset")) { 35 return; 36 } 37 final String preset = sharedPreferences.getString(key, "standard"); 38 final Resources res = mContext.getResources(); 39 final int[] newValues; 40 switch (preset) { 41 case "standard": 42 newValues = res.getIntArray(R.array.standard_setting_values); 43 break; 44 case "cinema": 45 newValues = res.getIntArray(R.array.cinema_setting_values); 46 break; 47 case "vivid": 48 newValues = res.getIntArray(R.array.vivid_setting_values); 49 break; 50 case "game": 51 newValues = res.getIntArray(R.array.game_setting_values); 52 break; 53 default: 54 case "custom": 55 return; 56 } 57 final String[] keys = res.getStringArray(R.array.setting_keys); 58 59 final SharedPreferences.Editor prefs = sharedPreferences.edit(); 60 try { 61 for (int i = 0; i < keys.length; i++) { 62 prefs.putInt(keys[i], newValues[i]); 63 } 64 } finally { 65 prefs.apply(); 66 } 67 68 } 69 } 70