packages/apps/Settings
Revisión | bfd75517c8403b7b983e63c1858d090aebe4c9f3 (tree) |
---|---|
Tiempo | 2012-06-27 05:02:58 |
Autor | Stefan Seidel <android@stef...> |
Commiter | Stefan Seidel |
[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).
@@ -602,6 +602,24 @@ | ||
602 | 602 | <item>Always use HDCP checking</item> |
603 | 603 | </string-array> |
604 | 604 | |
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 | + | |
605 | 623 | <!-- Titles for window animation scale preference. [CHAR LIMIT=35] --> |
606 | 624 | <string-array name="window_animation_scale_entries"> |
607 | 625 | <item>Animation off</item> |
@@ -2566,6 +2566,12 @@ found in the list of installed apps.</string> | ||
2566 | 2566 | <string name="hardkeyboard_category">Physical keyboard settings</string> |
2567 | 2567 | <!-- On Text & language settings screen, setting summary for the Auto-punctuate setting. --> |
2568 | 2568 | <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> | |
2569 | 2575 | <!-- 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. --> |
2570 | 2576 | <string name="show_password">Make passwords visible</string> |
2571 | 2577 | <!-- On Security & location settings screen, setting check box summary. Summary for the visible passwords setting. --> |
@@ -39,5 +39,12 @@ | ||
39 | 39 | android:summaryOn="@string/auto_punctuate_summary" |
40 | 40 | android:summaryOff="@string/auto_punctuate_summary" |
41 | 41 | 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" /> | |
42 | 49 | </PreferenceCategory> |
43 | 50 | </PreferenceScreen> |
@@ -58,6 +58,12 @@ | ||
58 | 58 | android:summaryOn="@string/auto_punctuate_summary" |
59 | 59 | android:summaryOff="@string/auto_punctuate_summary" |
60 | 60 | 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" /> | |
61 | 67 | </PreferenceCategory> |
62 | 68 | |
63 | 69 | <PreferenceCategory android:key="voice_category" |
@@ -31,6 +31,7 @@ import android.content.res.Configuration; | ||
31 | 31 | import android.database.ContentObserver; |
32 | 32 | import android.os.Bundle; |
33 | 33 | import android.os.Handler; |
34 | +import android.os.SystemProperties; | |
34 | 35 | import android.preference.CheckBoxPreference; |
35 | 36 | import android.preference.ListPreference; |
36 | 37 | import android.preference.Preference; |
@@ -42,6 +43,7 @@ import android.provider.Settings.System; | ||
42 | 43 | import android.text.TextUtils; |
43 | 44 | import android.view.inputmethod.InputMethodInfo; |
44 | 45 | import android.view.inputmethod.InputMethodManager; |
46 | +import android.widget.Toast; | |
45 | 47 | |
46 | 48 | import java.util.ArrayList; |
47 | 49 | import java.util.Collections; |
@@ -58,6 +60,10 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment | ||
58 | 60 | // false: on ICS or later |
59 | 61 | private static final boolean SHOW_INPUT_METHOD_SWITCHER_SETTINGS = false; |
60 | 62 | |
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 | + | |
61 | 67 | private static final String[] sSystemSettingNames = { |
62 | 68 | System.TEXT_AUTO_REPLACE, System.TEXT_AUTO_CAPS, System.TEXT_AUTO_PUNCTUATE, |
63 | 69 | }; |
@@ -73,6 +79,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment | ||
73 | 79 | new ArrayList<InputMethodPreference>(); |
74 | 80 | private boolean mHaveHardKeyboard; |
75 | 81 | private PreferenceCategory mHardKeyboardCategory; |
82 | + private ListPreference mHardKeyboardLayoutSelectorPref; | |
76 | 83 | private InputMethodManager mImm; |
77 | 84 | private List<InputMethodInfo> mImis; |
78 | 85 | private boolean mIsOnlyImeSettings; |
@@ -196,6 +203,8 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment | ||
196 | 203 | chkPref.setChecked( |
197 | 204 | System.getInt(getContentResolver(), sSystemSettingNames[i], 1) > 0); |
198 | 205 | } |
206 | + | |
207 | + updateHardKeyboardLayout(SystemProperties.get(PROP_HARDWARE_KEYBOARD_LAYOUT)); | |
199 | 208 | } |
200 | 209 | |
201 | 210 | // IME |
@@ -259,6 +268,25 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment | ||
259 | 268 | mDefaultInputMethodSelectorVisibility); |
260 | 269 | } |
261 | 270 | |
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 | + | |
262 | 290 | @Override |
263 | 291 | public boolean onPreferenceChange(Preference preference, Object value) { |
264 | 292 | if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) { |
@@ -268,6 +296,14 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment | ||
268 | 296 | } |
269 | 297 | } |
270 | 298 | } |
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 | + } | |
271 | 307 | return false; |
272 | 308 | } |
273 | 309 |