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