1 /* 2 * Copyright (C) 2009 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; 18 19 import android.content.ContentResolver; 20 import android.os.Bundle; 21 import android.preference.CheckBoxPreference; 22 import android.preference.Preference; 23 import android.preference.PreferenceActivity; 24 import android.preference.PreferenceScreen; 25 import android.provider.Settings.System; 26 27 public class PhysicalKeyboardSettings extends PreferenceActivity { 28 29 private final String[] mSettingsUiKey = { 30 "auto_caps", 31 "auto_replace", 32 "auto_punctuate", 33 }; 34 35 // Note: Order of this array should correspond to the order of the above array 36 private final String[] mSettingsSystemId = { 37 System.TEXT_AUTO_CAPS, 38 System.TEXT_AUTO_REPLACE, 39 System.TEXT_AUTO_PUNCTUATE, 40 }; 41 42 // Note: Order of this array should correspond to the order of the above array 43 private final int[] mSettingsDefault = { 44 1, 45 1, 46 1, 47 }; 48 49 @Override onCreate(Bundle icicle)50 protected void onCreate(Bundle icicle) { 51 super.onCreate(icicle); 52 53 addPreferencesFromResource(R.xml.keyboard_settings); 54 } 55 56 @Override onResume()57 protected void onResume() { 58 super.onResume(); 59 ContentResolver resolver = getContentResolver(); 60 for (int i = 0; i < mSettingsUiKey.length; i++) { 61 CheckBoxPreference pref = (CheckBoxPreference) findPreference(mSettingsUiKey[i]); 62 pref.setChecked(System.getInt(resolver, mSettingsSystemId[i], 63 mSettingsDefault[i]) > 0); 64 } 65 } 66 67 68 @Override onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)69 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 70 71 // Physical keyboard stuff 72 for (int i = 0; i < mSettingsUiKey.length; i++) { 73 if (mSettingsUiKey[i].equals(preference.getKey())) { 74 System.putInt(getContentResolver(), mSettingsSystemId[i], 75 ((CheckBoxPreference)preference).isChecked()? 1 : 0); 76 return true; 77 } 78 } 79 80 return super.onPreferenceTreeClick(preferenceScreen, preference); 81 } 82 83 } 84