Fix PhysicalKeyboardSettings by merging it into InputMethodConfig.

Change-Id: I00deeda813f438f9eb2b7932e3b4d273be2e1ab8
This commit is contained in:
Chia-chi Yeh
2011-01-14 14:34:19 +08:00
parent 55b7d27936
commit 71966ce931
5 changed files with 81 additions and 149 deletions

View File

@@ -381,15 +381,6 @@
android:resource="@id/language_settings" />
</activity>
<activity android:name="PhysicalKeyboardSettings"
android:label="@string/builtin_keyboard_settings_title"
android:theme="@android:style/Theme.Holo.DialogWhenLarge">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="Settings$UserDictionarySettingsActivity"
android:theme="@android:style/Theme.Holo"
android:label="@string/user_dict_settings_titlebar"

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="hard_keyboard"
android:title="@string/builtin_keyboard_settings_title"
android:persistent="false">
<CheckBoxPreference
android:key="auto_replace"
android:title="@string/auto_replace"
android:summaryOn="@string/auto_replace_summary"
android:summaryOff="@string/auto_replace_summary"
android:persistent="false"/>
<CheckBoxPreference
android:key="auto_caps"
android:title="@string/auto_caps"
android:summaryOn="@string/auto_caps_summary"
android:summaryOff="@string/auto_caps_summary"
android:persistent="false"/>
<CheckBoxPreference
android:key="auto_punctuate"
android:title="@string/auto_punctuate"
android:summaryOn="@string/auto_punctuate_summary"
android:summaryOff="@string/auto_punctuate_summary"
android:persistent="false"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<CheckBoxPreference
android:key="auto_replace"
android:title="@string/auto_replace"
android:summaryOn="@string/auto_replace_summary"
android:summaryOff="@string/auto_replace_summary"
android:persistent="false"/>
<CheckBoxPreference
android:key="auto_caps"
android:title="@string/auto_caps"
android:summaryOn="@string/auto_caps_summary"
android:summaryOff="@string/auto_caps_summary"
android:persistent="false"/>
<CheckBoxPreference
android:key="auto_punctuate"
android:title="@string/auto_punctuate"
android:summaryOn="@string/auto_punctuate_summary"
android:summaryOff="@string/auto_punctuate_summary"
android:persistent="false"/>
</PreferenceScreen>

View File

@@ -1,83 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import android.content.ContentResolver;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.provider.Settings.System;
public class PhysicalKeyboardSettings extends SettingsPreferenceFragment {
private final String[] mSettingsUiKey = {
"auto_caps",
"auto_replace",
"auto_punctuate",
};
// Note: Order of this array should correspond to the order of the above array
private final String[] mSettingsSystemId = {
System.TEXT_AUTO_CAPS,
System.TEXT_AUTO_REPLACE,
System.TEXT_AUTO_PUNCTUATE,
};
// Note: Order of this array should correspond to the order of the above array
private final int[] mSettingsDefault = {
1,
1,
1,
};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.keyboard_settings);
}
@Override
public void onResume() {
super.onResume();
ContentResolver resolver = getContentResolver();
for (int i = 0; i < mSettingsUiKey.length; i++) {
CheckBoxPreference pref = (CheckBoxPreference) findPreference(mSettingsUiKey[i]);
pref.setChecked(System.getInt(resolver, mSettingsSystemId[i],
mSettingsDefault[i]) > 0);
}
}
@Override
public boolean onPreferenceTreeClick(
PreferenceScreen preferenceScreen, Preference preference) {
// Physical keyboard stuff
for (int i = 0; i < mSettingsUiKey.length; i++) {
if (mSettingsUiKey[i].equals(preference.getKey())) {
System.putInt(getContentResolver(), mSettingsSystemId[i],
((CheckBoxPreference)preference).isChecked()? 1 : 0);
return true;
}
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
}

View File

@@ -20,6 +20,7 @@ import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -31,6 +32,7 @@ import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.System;
import android.text.TextUtils;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -42,12 +44,17 @@ import java.util.List;
public class InputMethodConfig extends SettingsPreferenceFragment {
private static final String KEY_PHYSICALKEYBOARD_CATEGORY = "hardkeyboard_category";
private static final String PHYSICALKEYBOARD_SETTINGS_FRAGMENT
= "com.android.settings.PhysicalKeyboardSettings";
private static final String[] sSystemSettingNames = {
System.TEXT_AUTO_REPLACE, System.TEXT_AUTO_CAPS, System.TEXT_AUTO_PUNCTUATE,
};
private static final String[] sHardKeyboardKeys = {
"auto_replace", "auto_caps", "auto_punctuate",
};
private AlertDialog mDialog = null;
private boolean mHaveHardKeyboard;
private PreferenceCategory mHardKeyboardCategory;
// Map of imi and its preferences
final private HashMap<String, List<Preference>> mInputMethodPrefsMap =
new HashMap<String, List<Preference>>();
@@ -72,8 +79,18 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
@Override
public void onResume() {
super.onResume();
ContentResolver resolver = getContentResolver();
if (mHaveHardKeyboard) {
for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
CheckBoxPreference chkPref = (CheckBoxPreference)
mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i]);
chkPref.setChecked(System.getInt(resolver, sSystemSettingNames[i], 1) > 0);
}
}
InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(
this, getContentResolver(), mInputMethodProperties, mInputMethodPrefsMap);
this, resolver, mInputMethodProperties, mInputMethodPrefsMap);
updateActiveInputMethodsSummary();
}
@@ -133,6 +150,17 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
if (preference instanceof CheckBoxPreference) {
final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
if (mHaveHardKeyboard) {
for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
if (chkPref == mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i])) {
System.putInt(getContentResolver(), sSystemSettingNames[i],
chkPref.isChecked() ? 1 : 0);
return true;
}
}
}
final String imiId = chkPref.getKey();
if (chkPref.isChecked()) {
InputMethodInfo selImi = getInputMethodInfoFromImiId(imiId);
@@ -164,17 +192,6 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
}
}
private void addHardKeyboardPreference(PreferenceScreen root) {
PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(getActivity());
keyboardSettingsCategory.setTitle(R.string.builtin_keyboard_settings_title);
root.addPreference(keyboardSettingsCategory);
PreferenceScreen prefScreen = new PreferenceScreen(getActivity(), null);
prefScreen.setKey(KEY_PHYSICALKEYBOARD_CATEGORY);
prefScreen.setTitle(R.string.builtin_keyboard_settings_title);
prefScreen.setSummary(R.string.builtin_keyboard_settings_summary);
prefScreen.setFragment(PHYSICALKEYBOARD_SETTINGS_FRAGMENT);
}
private void addInputMethodPreference(PreferenceScreen root, InputMethodInfo imi,
final int imiSize) {
PreferenceCategory keyboardSettingsCategory = new PreferenceCategory(getActivity());
@@ -227,10 +244,13 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
}
private PreferenceScreen createPreferenceHierarchy() {
// Root
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(getActivity());
addPreferencesFromResource(R.xml.hard_keyboard_settings);
PreferenceScreen root = getPreferenceScreen();
if (mHaveHardKeyboard) {
addHardKeyboardPreference(root);
mHardKeyboardCategory = (PreferenceCategory) findPreference("hard_keyboard");
} else {
root.removeAll();
}
final int N = (mInputMethodProperties == null ? 0 : mInputMethodProperties.size());