blob: b406df6d74ca439bdd63bebe41915ce48e407993 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
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
17package com.android.settings;
18
19import android.content.ContentResolver;
The Android Open Source Project1feaa852009-02-10 15:44:05 -080020import android.content.res.Configuration;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070021import android.os.Bundle;
22import android.preference.Preference;
23import android.preference.PreferenceActivity;
24import android.preference.PreferenceGroup;
25import android.preference.PreferenceScreen;
The Android Open Source Projecta578a6c2009-03-03 14:04:35 -080026import android.preference.CheckBoxPreference;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070027import android.provider.Settings.System;
28
29public class LanguageSettings extends PreferenceActivity {
30
31 private final String[] mSettingsUiKey = {
32 "auto_caps",
33 "auto_replace",
34 "auto_punctuate",
35 };
36
37 // Note: Order of this array should correspond to the order of the above array
38 private final String[] mSettingsSystemId = {
39 System.TEXT_AUTO_CAPS,
40 System.TEXT_AUTO_REPLACE,
41 System.TEXT_AUTO_PUNCTUATE,
42 };
43
44 // Note: Order of this array should correspond to the order of the above array
45 private final int[] mSettingsDefault = {
46 1,
47 1,
48 1,
49 };
50
51 @Override
52 protected void onCreate(Bundle icicle) {
53 super.onCreate(icicle);
54
55 addPreferencesFromResource(R.xml.language_settings);
56
57 if (getAssets().getLocales().length == 1) {
58 getPreferenceScreen().
59 removePreference(findPreference("language_category"));
60 }
61
The Android Open Source Project1feaa852009-02-10 15:44:05 -080062 Configuration config = getResources().getConfiguration();
63 if (config.keyboard != Configuration.KEYBOARD_QWERTY) {
64 getPreferenceScreen().removePreference(
65 getPreferenceScreen().findPreference("hardkeyboard_category"));
66 } else {
67 ContentResolver resolver = getContentResolver();
68 for (int i = 0; i < mSettingsUiKey.length; i++) {
69 CheckBoxPreference pref = (CheckBoxPreference) findPreference(mSettingsUiKey[i]);
70 pref.setChecked(System.getInt(resolver, mSettingsSystemId[i],
71 mSettingsDefault[i]) > 0);
72 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070073 }
The Android Open Source Project8a156092009-03-02 22:54:43 -080074 }
75
The Android Open Source Project8a156092009-03-02 22:54:43 -080076 @Override
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070077 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
78 for (int i = 0; i < mSettingsUiKey.length; i++) {
79 if (mSettingsUiKey[i].equals(preference.getKey())) {
80 System.putInt(getContentResolver(), mSettingsSystemId[i],
81 ((CheckBoxPreference)preference).isChecked()? 1 : 0);
82 return true;
83 }
84 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070085 return super.onPreferenceTreeClick(preferenceScreen, preference);
86 }
87
88}