• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Révisionbfd75517c8403b7b983e63c1858d090aebe4c9f3 (tree)
l'heure2012-06-27 05:02:58
AuteurStefan Seidel <android@stef...>
CommiterStefan Seidel

Message de Log

[2/2] change hardware keyboard layout on the fly

This change will allow reconfiguration of the layout of the hardware keyboard.
These are the UI changes.

Parts of this code were inspired by the work of Christopher-Eyk Hrabia
(https://github.com/cehberlin).

Change Summary

Modification

--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -602,6 +602,24 @@
602602 <item>Always use HDCP checking</item>
603603 </string-array>
604604
605+ <!-- Titles for hardware keyboard layout preference. -->
606+ <string-array name="hardware_keyboard_layout_titles">
607+ <item>Use system language</item>
608+ <item>English</item>
609+ <item>French</item>
610+ <item>German</item>
611+ <item>Russian</item>
612+ </string-array>
613+
614+ <!-- Values for hardware keyboard layout preference. -->
615+ <string-array name="hardware_keyboard_layout_keys" translatable="false" >
616+ <item>sys</item>
617+ <item>en</item>
618+ <item>fr</item>
619+ <item>de</item>
620+ <item>ru</item>
621+ </string-array>
622+
605623 <!-- Titles for window animation scale preference. [CHAR LIMIT=35] -->
606624 <string-array name="window_animation_scale_entries">
607625 <item>Animation off</item>
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2566,6 +2566,12 @@ found in the list of installed apps.</string>
25662566 <string name="hardkeyboard_category">Physical keyboard settings</string>
25672567 <!-- On Text & language settings screen, setting summary for the Auto-punctuate setting. -->
25682568 <string name="auto_punctuate_summary">Press Space key twice to insert \u0022.\u0022</string>
2569+ <!-- On Text & language settings screen, option for physical keyboard layout -->
2570+ <string name="hardware_keyboard_layout_title">Physical keyboard layout</string>
2571+ <!-- On Text & language settings screen, title for physical keyboard layout selection dialog -->
2572+ <string name="hardware_keyboard_layout_dialog_title">Select physical keyboard layout</string>
2573+ <!-- On Text & language settings screen, option for physical keyboard layout -->
2574+ <string name="hardware_keyboard_layout_changed">Physical keyboard layout has been changed. This change is NOT effective for previously started apps. It is recommended to restart your device to fully apply the new layout.</string>
25692575 <!-- On Security & location settings screen, setting check box name. Title of the checkbox to set whether password edit fields will show the most recent character typed and then hide it, or just hide it right away. By hide, I mean mask it out. -->
25702576 <string name="show_password">Make passwords visible</string>
25712577 <!-- On Security & location settings screen, setting check box summary. Summary for the visible passwords setting. -->
--- a/res/xml/hard_keyboard_settings.xml
+++ b/res/xml/hard_keyboard_settings.xml
@@ -39,5 +39,12 @@
3939 android:summaryOn="@string/auto_punctuate_summary"
4040 android:summaryOff="@string/auto_punctuate_summary"
4141 android:persistent="false"/>
42+
43+ <ListPreference
44+ android:key="hardware_keyboard_layout_selector"
45+ android:title="@string/hardware_keyboard_layout_title"
46+ android:dialogTitle="@string/hardware_keyboard_layout_dialog_title"
47+ android:entries="@array/hardware_keyboard_layout_titles"
48+ android:entryValues="@array/hardware_keyboard_layout_keys" />
4249 </PreferenceCategory>
4350 </PreferenceScreen>
--- a/res/xml/language_settings.xml
+++ b/res/xml/language_settings.xml
@@ -58,6 +58,12 @@
5858 android:summaryOn="@string/auto_punctuate_summary"
5959 android:summaryOff="@string/auto_punctuate_summary"
6060 android:persistent="false"/>
61+ <ListPreference
62+ android:key="hardware_keyboard_layout_selector"
63+ android:title="@string/hardware_keyboard_layout_title"
64+ android:dialogTitle="@string/hardware_keyboard_layout_dialog_title"
65+ android:entries="@array/hardware_keyboard_layout_titles"
66+ android:entryValues="@array/hardware_keyboard_layout_keys" />
6167 </PreferenceCategory>
6268
6369 <PreferenceCategory android:key="voice_category"
--- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
+++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
@@ -31,6 +31,7 @@ import android.content.res.Configuration;
3131 import android.database.ContentObserver;
3232 import android.os.Bundle;
3333 import android.os.Handler;
34+import android.os.SystemProperties;
3435 import android.preference.CheckBoxPreference;
3536 import android.preference.ListPreference;
3637 import android.preference.Preference;
@@ -42,6 +43,7 @@ import android.provider.Settings.System;
4243 import android.text.TextUtils;
4344 import android.view.inputmethod.InputMethodInfo;
4445 import android.view.inputmethod.InputMethodManager;
46+import android.widget.Toast;
4547
4648 import java.util.ArrayList;
4749 import java.util.Collections;
@@ -58,6 +60,10 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
5860 // false: on ICS or later
5961 private static final boolean SHOW_INPUT_METHOD_SWITCHER_SETTINGS = false;
6062
63+ private static final String KEY_HARDWARE_KEYBOARD_LAYOUT_SELECTOR =
64+ "hardware_keyboard_layout_selector";
65+ private static final String PROP_HARDWARE_KEYBOARD_LAYOUT = "persist.sys.keyboard.locale";
66+
6167 private static final String[] sSystemSettingNames = {
6268 System.TEXT_AUTO_REPLACE, System.TEXT_AUTO_CAPS, System.TEXT_AUTO_PUNCTUATE,
6369 };
@@ -73,6 +79,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
7379 new ArrayList<InputMethodPreference>();
7480 private boolean mHaveHardKeyboard;
7581 private PreferenceCategory mHardKeyboardCategory;
82+ private ListPreference mHardKeyboardLayoutSelectorPref;
7683 private InputMethodManager mImm;
7784 private List<InputMethodInfo> mImis;
7885 private boolean mIsOnlyImeSettings;
@@ -196,6 +203,8 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
196203 chkPref.setChecked(
197204 System.getInt(getContentResolver(), sSystemSettingNames[i], 1) > 0);
198205 }
206+
207+ updateHardKeyboardLayout(SystemProperties.get(PROP_HARDWARE_KEYBOARD_LAYOUT));
199208 }
200209
201210 // IME
@@ -259,6 +268,25 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
259268 mDefaultInputMethodSelectorVisibility);
260269 }
261270
271+ private void updateHardKeyboardLayout(String value) {
272+ // selector of hardware keyboard layout
273+ mHardKeyboardLayoutSelectorPref = (ListPreference) mHardKeyboardCategory.findPreference(
274+ KEY_HARDWARE_KEYBOARD_LAYOUT_SELECTOR);
275+ int index = 0; // defaults to "follow system language"
276+ String[] values = getResources().getStringArray(R.array.hardware_keyboard_layout_keys);
277+ String[] summaries = getResources().getStringArray(
278+ R.array.hardware_keyboard_layout_titles);
279+ for (int i = 0; i < values.length; i++) {
280+ if (value.equals(values[i])) {
281+ index = i;
282+ break;
283+ }
284+ }
285+ mHardKeyboardLayoutSelectorPref.setValue(values[index]);
286+ mHardKeyboardLayoutSelectorPref.setSummary(summaries[index]);
287+ mHardKeyboardLayoutSelectorPref.setOnPreferenceChangeListener(this);
288+ }
289+
262290 @Override
263291 public boolean onPreferenceChange(Preference preference, Object value) {
264292 if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
@@ -268,6 +296,14 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
268296 }
269297 }
270298 }
299+ if (preference == mHardKeyboardLayoutSelectorPref) {
300+ SystemProperties.set(PROP_HARDWARE_KEYBOARD_LAYOUT, value.toString());
301+ Settings.System.putString(getContentResolver(), Settings.System.HARD_KEYBOARD_LAYOUT,
302+ value.toString());
303+ Toast.makeText(getActivity(), R.string.hardware_keyboard_layout_changed,
304+ Toast.LENGTH_LONG).show();
305+ updateHardKeyboardLayout(value.toString());
306+ }
271307 return false;
272308 }
273309