packages/apps/Settings
Révision | e988a213419c1f4d3f4def78ba598043e2a03b68 (tree) |
---|---|
l'heure | 2011-08-05 15:37:50 |
Auteur | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
KeyboardPicker: refine the keyboard layout list to be more extendable
Other improvements:
* use ISO 639-1 language code for layout names.
* add Japanese, Swedish and United Kingdom to the list.
* add license notice.
@@ -1,19 +1,38 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2009 The Android-x86 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 | + | |
1 | 17 | package com.android.settings; |
2 | 18 | |
3 | 19 | import java.util.ArrayList; |
4 | 20 | import java.util.List; |
21 | +import java.util.TreeMap; | |
5 | 22 | |
6 | 23 | import android.app.ListActivity; |
7 | 24 | import android.os.Bundle; |
8 | 25 | import android.os.SystemProperties; |
9 | -import android.util.Log; | |
10 | 26 | import android.view.View; |
11 | 27 | import android.widget.ArrayAdapter; |
12 | 28 | import android.widget.ListView; |
13 | 29 | import android.widget.Toast; |
14 | 30 | |
15 | -public class KeyboardPicker extends ListActivity{ | |
16 | - int getContentView() { | |
31 | +public class KeyboardPicker extends ListActivity { | |
32 | + private List<String> mKeyboardList; | |
33 | + private TreeMap<String,String> mKeyboardLayouts; | |
34 | + | |
35 | + int getContentView() { | |
17 | 36 | return R.layout.keyboard_picker; |
18 | 37 | } |
19 | 38 |
@@ -23,46 +42,28 @@ public class KeyboardPicker extends ListActivity{ | ||
23 | 42 | setContentView(getContentView()); |
24 | 43 | int layoutId = R.layout.keyboard_picker_item; |
25 | 44 | int fieldId = R.id.keyboard; |
26 | - List<String> mKeyboardLayout = new ArrayList<String>(); | |
27 | - mKeyboardLayout.add("American(Standard keyboard)"); | |
28 | - mKeyboardLayout.add("Finnish"); | |
29 | - mKeyboardLayout.add("French"); | |
30 | - mKeyboardLayout.add("German"); | |
31 | - mKeyboardLayout.add("Ireland"); | |
32 | - mKeyboardLayout.add("Russia"); | |
33 | - mKeyboardLayout.add("Spanish(Latin America)"); | |
34 | - | |
45 | + mKeyboardLayouts = new TreeMap<String,String>(); | |
46 | + mKeyboardLayouts.put("American(Standard keyboard)", "qwerty"); | |
47 | + mKeyboardLayouts.put("Finnish", "fn"); | |
48 | + mKeyboardLayouts.put("French", "fr"); | |
49 | + mKeyboardLayouts.put("German", "de"); | |
50 | + mKeyboardLayouts.put("Ireland", "uk"); | |
51 | + mKeyboardLayouts.put("Japanese", "jp"); | |
52 | + mKeyboardLayouts.put("Russian", "ru"); | |
53 | + mKeyboardLayouts.put("Spanish(Latin America)", "es_latin"); | |
54 | + mKeyboardLayouts.put("Swedish", "fn"); | |
55 | + mKeyboardLayouts.put("United Kingdom", "uk"); | |
35 | 56 | |
57 | + mKeyboardList = new ArrayList<String>(mKeyboardLayouts.keySet()); | |
36 | 58 | ArrayAdapter<String> adapter = |
37 | - new ArrayAdapter<String>(this, layoutId, fieldId, mKeyboardLayout); | |
59 | + new ArrayAdapter<String>(this, layoutId, fieldId, mKeyboardList); | |
38 | 60 | getListView().setAdapter(adapter); |
39 | 61 | } |
40 | 62 | @Override |
41 | 63 | protected void onListItemClick(ListView l, View v, int position, long id) { |
42 | - switch(position){ | |
43 | - case 1: | |
44 | - SystemProperties.set("persist.sys.keylayout","fn"); | |
45 | - break; | |
46 | - case 2: | |
47 | - SystemProperties.set("persist.sys.keylayout","fr"); | |
48 | - break; | |
49 | - case 3: | |
50 | - SystemProperties.set("persist.sys.keylayout","de"); | |
51 | - break; | |
52 | - case 4: | |
53 | - SystemProperties.set("persist.sys.keylayout","Ireland"); | |
54 | - break; | |
55 | - case 5: | |
56 | - SystemProperties.set("persist.sys.keylayout","ru"); | |
57 | - break; | |
58 | - case 6: | |
59 | - SystemProperties.set("persist.sys.keylayout","spanish_latin"); | |
60 | - break; | |
61 | - default: | |
62 | - SystemProperties.set("persist.sys.keylayout","qwerty"); | |
63 | - break; | |
64 | - } | |
65 | - | |
66 | - Toast.makeText(this, "Please reboot your machine to enable the new keyboard layout.", Toast.LENGTH_LONG).show(); | |
64 | + String kb = mKeyboardList.get(position); | |
65 | + SystemProperties.set("persist.sys.keylayout", mKeyboardLayouts.get(kb)); | |
66 | + Toast.makeText(this, "Set keyboard layout to " + kb + | |
67 | + ".\nPlease reboot your machine to enable the new keyboard layout.", Toast.LENGTH_LONG).show(); | |
67 | 68 | } |
68 | 69 | } |