OSDN Git Service

Nico/Bellレイアウトの整理
[nicownn/NicoWnn.git] / src / com / hiroshica / android / input / nicownn2 / JAJP / DefaultSoftKeyboardJAJP.java
1 /*
2  * Copyright (C) 2008,2009  OMRON SOFTWARE Co., Ltd.
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  * test message
17  */
18
19 package com.hiroshica.android.input.nicownn2.JAJP;
20
21 import android.view.KeyEvent;
22 import android.view.inputmethod.EditorInfo;
23 import android.view.inputmethod.InputConnection;
24 import android.inputmethodservice.Keyboard;
25 import android.util.Log;
26 import android.view.View;
27 import android.content.SharedPreferences;
28 import android.content.Intent;
29 import android.os.*;
30 import android.app.Activity;
31
32 import android.inputmethodservice.InputMethodService;
33 import android.view.WindowManager;
34 import android.content.Context;
35 import android.view.View;
36 import android.view.KeyEvent;
37 import android.content.SharedPreferences;
38 import android.preference.PreferenceManager;
39 import android.content.pm.PackageManager;
40 import android.util.Log;
41 import android.os.*;
42 import android.view.inputmethod.*;
43 import android.content.res.Configuration;
44 import android.graphics.*;
45 import android.graphics.drawable.*;
46 import android.view.MotionEvent;
47 import android.app.Activity;
48 import android.content.Intent;
49
50
51 import java.lang.Object;
52 import java.util.HashMap;
53 import java.util.Locale;
54 import java.util.List;
55 import java.lang.Math;
56
57 import com.hiroshica.android.input.nicownn2.*;
58
59 /**
60  * The default Software Keyboard class for Japanese IME.
61  *
62  * @author Copyright (C) 2009 OMRON SOFTWARE CO., LTD.  All Rights Reserved.
63  */
64 public class DefaultSoftKeyboardJAJP extends DefaultSoftKeyboard {
65         private static final String GETACTION_INTERCEPT = "com.hiroshica.android.input.nicownn2.ACTION_INTERCEPT";
66         private static final String REPLACE_KEY = "replace_key";
67         private static final String INPUTCONNECTION_KEY = "inputconnection_key";
68
69         /** Enable English word prediction on half-width alphabet mode */
70         private static final boolean USE_ENGLISH_PREDICT = true;
71
72         /** Key code for switching to full-width HIRAGANA mode */
73         private static final int KEYCODE_SWITCH_FULL_HIRAGANA = -301;
74
75         /** Key code for switching to full-width KATAKANA mode */
76         private static final int KEYCODE_SWITCH_FULL_KATAKANA = -302;
77
78         /** Key code for switching to full-width alphabet mode */
79         private static final int KEYCODE_SWITCH_FULL_ALPHABET = -303;
80
81         /** Key code for switching to full-width number mode */
82         private static final int KEYCODE_SWITCH_FULL_NUMBER = -304;
83
84         /** Key code for switching to half-width KATAKANA mode */
85         private static final int KEYCODE_SWITCH_HALF_KATAKANA = -306;
86
87         /** Key code for switching to half-width alphabet mode */
88         private static final int KEYCODE_SWITCH_HALF_ALPHABET = -307;
89
90         /** Key code for switching to half-width number mode */
91         private static final int KEYCODE_SWITCH_HALF_NUMBER = -308;
92
93         /** Key code for case toggle key */
94         private static final int KEYCODE_SELECT_CASE = -309;
95
96         /** Key code for EISU-KANA conversion */
97         private static final int KEYCODE_EISU_KANA = -305;
98
99         /** Key code for switching to full-width Nikotouch mode */
100         private static final int KEYCODE_SWITCH_FULL_NIKO = -400;
101
102         /** Key code for NOP (no-operation) */
103         private static final int KEYCODE_NOP = -310;
104
105
106         /** Input mode toggle cycle table */
107         private static final int[] JP_MODE_CYCLE_TABLE = {
108                 KEYMODE_JA_FULL_NIKO, KEYMODE_JA_FULL_HIRAGANA, KEYMODE_JA_HALF_ALPHABET, KEYMODE_JA_HALF_NUMBER,
109         };
110
111         /** Definition for {@code mInputType} (toggle) */
112         private static final int INPUT_TYPE_TOGGLE = 1;
113
114         /** Definition for {@code mInputType} (commit instantly) */
115         private static final int INPUT_TYPE_INSTANT = 2;
116
117         /** Max key number of the 12 key keyboard (depends on the definition of keyboards) */
118         private static final int KEY_NUMBER_12KEY = 20;
119
120         /** Toggle cycle table for full-width HIRAGANA */
121         private static final String[][] JP_FULL_HIRAGANA_CYCLE_TABLE = {
122                 {"\u3042", "\u3044", "\u3046", "\u3048", "\u304a", "\u3041", "\u3043", "\u3045", "\u3047", "\u3049"},
123                 {"\u304b", "\u304d", "\u304f", "\u3051", "\u3053"},
124                 {"\u3055", "\u3057", "\u3059", "\u305b", "\u305d"},
125                 {"\u305f", "\u3061", "\u3064", "\u3066", "\u3068", "\u3063"},
126                 {"\u306a", "\u306b", "\u306c", "\u306d", "\u306e"},
127                 {"\u306f", "\u3072", "\u3075", "\u3078", "\u307b"},
128                 {"\u307e", "\u307f", "\u3080", "\u3081", "\u3082"},
129                 {"\u3084", "\u3086", "\u3088", "\u3083", "\u3085", "\u3087"},
130                 {"\u3089", "\u308a", "\u308b", "\u308c", "\u308d"},
131                 {"\u308f", "\u3092", "\u3093", "\u308e", "\u30fc"},
132                 {"\u3001", "\u3002", "\uff1f", "\uff01", "\u30fb", "\u3000"},
133         };
134
135         /** Replace table for full-width HIRAGANA */
136         private static final HashMap<String, String> JP_FULL_HIRAGANA_REPLACE_TABLE = new HashMap<String, String>() {{
137                         put("\u3042", "\u3041"); put("\u3044", "\u3043"); put("\u3046", "\u3045"); put("\u3048", "\u3047"); put("\u304a", "\u3049");
138                         put("\u3041", "\u3042"); put("\u3043", "\u3044"); put("\u3045", "\u30f4"); put("\u3047", "\u3048"); put("\u3049", "\u304a");
139                         put("\u304b", "\u304c"); put("\u304d", "\u304e"); put("\u304f", "\u3050"); put("\u3051", "\u3052"); put("\u3053", "\u3054");
140                         put("\u304c", "\u304b"); put("\u304e", "\u304d"); put("\u3050", "\u304f"); put("\u3052", "\u3051"); put("\u3054", "\u3053");
141                         put("\u3055", "\u3056"); put("\u3057", "\u3058"); put("\u3059", "\u305a"); put("\u305b", "\u305c"); put("\u305d", "\u305e");
142                         put("\u3056", "\u3055"); put("\u3058", "\u3057"); put("\u305a", "\u3059"); put("\u305c", "\u305b"); put("\u305e", "\u305d");
143                         put("\u305f", "\u3060"); put("\u3061", "\u3062"); put("\u3064", "\u3063"); put("\u3066", "\u3067"); put("\u3068", "\u3069");
144                         put("\u3060", "\u305f"); put("\u3062", "\u3061"); put("\u3063", "\u3065"); put("\u3067", "\u3066"); put("\u3069", "\u3068");
145                         put("\u3065", "\u3064"); put("\u30f4", "\u3046");
146                         put("\u306f", "\u3070"); put("\u3072", "\u3073"); put("\u3075", "\u3076"); put("\u3078", "\u3079"); put("\u307b", "\u307c");
147                         put("\u3070", "\u3071"); put("\u3073", "\u3074"); put("\u3076", "\u3077"); put("\u3079", "\u307a"); put("\u307c", "\u307d");
148                         put("\u3071", "\u306f"); put("\u3074", "\u3072"); put("\u3077", "\u3075"); put("\u307a", "\u3078"); put("\u307d", "\u307b");
149                         put("\u3084", "\u3083"); put("\u3086", "\u3085"); put("\u3088", "\u3087");
150                         put("\u3083", "\u3084"); put("\u3085", "\u3086"); put("\u3087", "\u3088");
151                         put("\u308f", "\u308e");
152                         put("\u308e", "\u308f");
153                         put("\u309b", "\u309c");
154                         put("\u309c", "\u309b");
155                 }};
156
157         /** Toggle cycle table for full-width KATAKANA */
158         private static final String[][] JP_FULL_KATAKANA_CYCLE_TABLE = {
159                 {"\u30a2", "\u30a4", "\u30a6", "\u30a8", "\u30aa", "\u30a1", "\u30a3",
160                  "\u30a5", "\u30a7", "\u30a9"},
161                 {"\u30ab", "\u30ad", "\u30af", "\u30b1", "\u30b3"},
162                 {"\u30b5", "\u30b7", "\u30b9", "\u30bb", "\u30bd"},
163                 {"\u30bf", "\u30c1", "\u30c4", "\u30c6", "\u30c8", "\u30c3"},
164                 {"\u30ca", "\u30cb", "\u30cc", "\u30cd", "\u30ce"},
165                 {"\u30cf", "\u30d2", "\u30d5", "\u30d8", "\u30db"},
166                 {"\u30de", "\u30df", "\u30e0", "\u30e1", "\u30e2"},
167                 {"\u30e4", "\u30e6", "\u30e8", "\u30e3", "\u30e5", "\u30e7"},
168                 {"\u30e9", "\u30ea", "\u30eb", "\u30ec", "\u30ed"},
169                 {"\u30ef", "\u30f2", "\u30f3", "\u30ee", "\u30fc"},
170                 {"\u3001", "\u3002", "\uff1f", "\uff01", "\u30fb", "\u3000"}
171         };
172
173         /** Replace table for full-width KATAKANA */
174         private static final HashMap<String,String> JP_FULL_KATAKANA_REPLACE_TABLE = new HashMap<String,String>() {{
175                         put("\u30a2", "\u30a1"); put("\u30a4", "\u30a3"); put("\u30a6", "\u30a5"); put("\u30a8", "\u30a7"); put("\u30aa", "\u30a9");
176                         put("\u30a1", "\u30a2"); put("\u30a3", "\u30a4"); put("\u30a5", "\u30f4"); put("\u30a7", "\u30a8"); put("\u30a9", "\u30aa");
177                         put("\u30ab", "\u30ac"); put("\u30ad", "\u30ae"); put("\u30af", "\u30b0"); put("\u30b1", "\u30b2"); put("\u30b3", "\u30b4");
178                         put("\u30ac", "\u30ab"); put("\u30ae", "\u30ad"); put("\u30b0", "\u30af"); put("\u30b2", "\u30b1"); put("\u30b4", "\u30b3");
179                         put("\u30b5", "\u30b6"); put("\u30b7", "\u30b8"); put("\u30b9", "\u30ba"); put("\u30bb", "\u30bc"); put("\u30bd", "\u30be");
180                         put("\u30b6", "\u30b5"); put("\u30b8", "\u30b7"); put("\u30ba", "\u30b9"); put("\u30bc", "\u30bb"); put("\u30be", "\u30bd");
181                         put("\u30bf", "\u30c0"); put("\u30c1", "\u30c2"); put("\u30c4", "\u30c3"); put("\u30c6", "\u30c7"); put("\u30c8", "\u30c9");
182                         put("\u30c0", "\u30bf"); put("\u30c2", "\u30c1"); put("\u30c3", "\u30c5"); put("\u30c7", "\u30c6"); put("\u30c9", "\u30c8");
183                         put("\u30c5", "\u30c4"); put("\u30f4", "\u30a6");
184                         put("\u30cf", "\u30d0"); put("\u30d2", "\u30d3"); put("\u30d5", "\u30d6"); put("\u30d8", "\u30d9"); put("\u30db", "\u30dc");
185                         put("\u30d0", "\u30d1"); put("\u30d3", "\u30d4"); put("\u30d6", "\u30d7"); put("\u30d9", "\u30da"); put("\u30dc", "\u30dd");
186                         put("\u30d1", "\u30cf"); put("\u30d4", "\u30d2"); put("\u30d7", "\u30d5"); put("\u30da", "\u30d8"); put("\u30dd", "\u30db");
187                         put("\u30e4", "\u30e3"); put("\u30e6", "\u30e5"); put("\u30e8", "\u30e7");
188                         put("\u30e3", "\u30e4"); put("\u30e5", "\u30e6"); put("\u30e7", "\u30e8");
189                         put("\u30ef", "\u30ee");
190                         put("\u30ee", "\u30ef");
191                 }};
192
193         /** Toggle cycle table for half-width KATAKANA */
194         private static final String[][] JP_HALF_KATAKANA_CYCLE_TABLE = {
195                 {"\uff71", "\uff72", "\uff73", "\uff74", "\uff75", "\uff67", "\uff68", "\uff69", "\uff6a", "\uff6b"},
196                 {"\uff76", "\uff77", "\uff78", "\uff79", "\uff7a"},
197                 {"\uff7b", "\uff7c", "\uff7d", "\uff7e", "\uff7f"},
198                 {"\uff80", "\uff81", "\uff82", "\uff83", "\uff84", "\uff6f"},
199                 {"\uff85", "\uff86", "\uff87", "\uff88", "\uff89"},
200                 {"\uff8a", "\uff8b", "\uff8c", "\uff8d", "\uff8e"},
201                 {"\uff8f", "\uff90", "\uff91", "\uff92", "\uff93"},
202                 {"\uff94", "\uff95", "\uff96", "\uff6c", "\uff6d", "\uff6e"},
203                 {"\uff97", "\uff98", "\uff99", "\uff9a", "\uff9b"},
204                 {"\uff9c", "\uff66", "\uff9d", "\uff70"},
205                 {"\uff64", "\uff61", "?", "!", "\uff65", " "},
206         };
207
208         /** Replace table for half-width KATAKANA */
209         private static final HashMap<String,String> JP_HALF_KATAKANA_REPLACE_TABLE = new HashMap<String,String>() {{
210                         put("\uff71", "\uff67");  put("\uff72", "\uff68");  put("\uff73", "\uff69");  put("\uff74", "\uff6a");  put("\uff75", "\uff6b");
211                         put("\uff67", "\uff71");  put("\uff68", "\uff72");  put("\uff69", "\uff73\uff9e");  put("\uff6a", "\uff74");  put("\uff6b", "\uff75");
212                         put("\uff76", "\uff76\uff9e"); put("\uff77", "\uff77\uff9e"); put("\uff78", "\uff78\uff9e"); put("\uff79", "\uff79\uff9e"); put("\uff7a", "\uff7a\uff9e");
213                         put("\uff76\uff9e", "\uff76"); put("\uff77\uff9e", "\uff77"); put("\uff78\uff9e", "\uff78"); put("\uff79\uff9e", "\uff79"); put("\uff7a\uff9e", "\uff7a");
214                         put("\uff7b", "\uff7b\uff9e"); put("\uff7c", "\uff7c\uff9e"); put("\uff7d", "\uff7d\uff9e"); put("\uff7e", "\uff7e\uff9e"); put("\uff7f", "\uff7f\uff9e");
215                         put("\uff7b\uff9e", "\uff7b"); put("\uff7c\uff9e", "\uff7c"); put("\uff7d\uff9e", "\uff7d"); put("\uff7e\uff9e", "\uff7e"); put("\uff7f\uff9e", "\uff7f");
216                         put("\uff80", "\uff80\uff9e"); put("\uff81", "\uff81\uff9e"); put("\uff82", "\uff6f");  put("\uff83", "\uff83\uff9e"); put("\uff84", "\uff84\uff9e");
217                         put("\uff80\uff9e", "\uff80"); put("\uff81\uff9e", "\uff81"); put("\uff6f", "\uff82\uff9e"); put("\uff83\uff9e", "\uff83"); put("\uff84\uff9e", "\uff84");
218                         put("\uff82\uff9e", "\uff82");
219                         put("\uff8a", "\uff8a\uff9e"); put("\uff8b", "\uff8b\uff9e"); put("\uff8c", "\uff8c\uff9e"); put("\uff8d", "\uff8d\uff9e"); put("\uff8e", "\uff8e\uff9e");
220                         put("\uff8a\uff9e", "\uff8a\uff9f");put("\uff8b\uff9e", "\uff8b\uff9f");put("\uff8c\uff9e", "\uff8c\uff9f");put("\uff8d\uff9e", "\uff8d\uff9f");put("\uff8e\uff9e", "\uff8e\uff9f");
221                         put("\uff8a\uff9f", "\uff8a"); put("\uff8b\uff9f", "\uff8b"); put("\uff8c\uff9f", "\uff8c"); put("\uff8d\uff9f", "\uff8d"); put("\uff8e\uff9f", "\uff8e");
222                         put("\uff94", "\uff6c");  put("\uff95", "\uff6d");  put("\uff96", "\uff6e");
223                         put("\uff6c", "\uff94");  put("\uff6d", "\uff95");  put("\uff6e", "\uff96");
224                         put("\uff9c", "\uff9c"); put("\uff73\uff9e", "\uff73");
225                 }};
226
227         /** Toggle cycle table for full-width alphabet */
228         private static final String[][] JP_FULL_ALPHABET_CYCLE_TABLE = {
229                 {"\uff0e", "\uff20", "\uff0d", "\uff3f", "\uff0f", "\uff1a", "\uff5e", "\uff11"},
230                 {"\uff41", "\uff42", "\uff43", "\uff21", "\uff22", "\uff23", "\uff12"},
231                 {"\uff44", "\uff45", "\uff46", "\uff24", "\uff25", "\uff26", "\uff13"},
232                 {"\uff47", "\uff48", "\uff49", "\uff27", "\uff28", "\uff29", "\uff14"},
233                 {"\uff4a", "\uff4b", "\uff4c", "\uff2a", "\uff2b", "\uff2c", "\uff15"},
234                 {"\uff4d", "\uff4e", "\uff4f", "\uff2d", "\uff2e", "\uff2f", "\uff16"},
235                 {"\uff50", "\uff51", "\uff52", "\uff53", "\uff30", "\uff31", "\uff32", "\uff33", "\uff17"},
236                 {"\uff54", "\uff55", "\uff56", "\uff34", "\uff35", "\uff36", "\uff18"},
237                 {"\uff57", "\uff58", "\uff59", "\uff5a", "\uff37", "\uff38", "\uff39", "\uff3a", "\uff19"},
238                 {"\uff0d", "\uff10"},
239                 {"\uff0c", "\uff0e", "\uff1f", "\uff01", "\u30fb", "\u3000"}
240         };
241
242         /** Replace table for full-width alphabet */
243         private static final HashMap<String,String> JP_FULL_ALPHABET_REPLACE_TABLE = new HashMap<String,String>() {{
244                         put("\uff21", "\uff41"); put("\uff22", "\uff42"); put("\uff23", "\uff43"); put("\uff24", "\uff44"); put("\uff25", "\uff45"); 
245                         put("\uff41", "\uff21"); put("\uff42", "\uff22"); put("\uff43", "\uff23"); put("\uff44", "\uff24"); put("\uff45", "\uff25"); 
246                         put("\uff26", "\uff46"); put("\uff27", "\uff47"); put("\uff28", "\uff48"); put("\uff29", "\uff49"); put("\uff2a", "\uff4a"); 
247                         put("\uff46", "\uff26"); put("\uff47", "\uff27"); put("\uff48", "\uff28"); put("\uff49", "\uff29"); put("\uff4a", "\uff2a"); 
248                         put("\uff2b", "\uff4b"); put("\uff2c", "\uff4c"); put("\uff2d", "\uff4d"); put("\uff2e", "\uff4e"); put("\uff2f", "\uff4f"); 
249                         put("\uff4b", "\uff2b"); put("\uff4c", "\uff2c"); put("\uff4d", "\uff2d"); put("\uff4e", "\uff2e"); put("\uff4f", "\uff2f"); 
250                         put("\uff30", "\uff50"); put("\uff31", "\uff51"); put("\uff32", "\uff52"); put("\uff33", "\uff53"); put("\uff34", "\uff54"); 
251                         put("\uff50", "\uff30"); put("\uff51", "\uff31"); put("\uff52", "\uff32"); put("\uff53", "\uff33"); put("\uff54", "\uff34"); 
252                         put("\uff35", "\uff55"); put("\uff36", "\uff56"); put("\uff37", "\uff57"); put("\uff38", "\uff58"); put("\uff39", "\uff59"); 
253                         put("\uff55", "\uff35"); put("\uff56", "\uff36"); put("\uff57", "\uff37"); put("\uff58", "\uff38"); put("\uff59", "\uff39"); 
254                         put("\uff3a", "\uff5a"); 
255                         put("\uff5a", "\uff3a"); 
256                 }};
257
258         /** Toggle cycle table for half-width alphabet */
259         private static final String[][] JP_HALF_ALPHABET_CYCLE_TABLE = {
260                 {".", "@", "-", "_", "/", ":", "~", "1"},
261                 {"a", "b", "c", "A", "B", "C", "2"},
262                 {"d", "e", "f", "D", "E", "F", "3"},
263                 {"g", "h", "i", "G", "H", "I", "4"},
264                 {"j", "k", "l", "J", "K", "L", "5"},
265                 {"m", "n", "o", "M", "N", "O", "6"},
266                 {"p", "q", "r", "s", "P", "Q", "R", "S", "7"},
267                 {"t", "u", "v", "T", "U", "V", "8"},
268                 {"w", "x", "y", "z", "W", "X", "Y", "Z", "9"},
269                 {"-", "0"},
270                 {",", ".", "?", "!", ";", " "}
271         };
272
273         /** Replace table for half-width alphabet */
274         private static final HashMap<String,String> JP_HALF_ALPHABET_REPLACE_TABLE = new HashMap<String,String>() {{
275                         put("A", "a"); put("B", "b"); put("C", "c"); put("D", "d"); put("E", "e"); 
276                         put("a", "A"); put("b", "B"); put("c", "C"); put("d", "D"); put("e", "E"); 
277                         put("F", "f"); put("G", "g"); put("H", "h"); put("I", "i"); put("J", "j"); 
278                         put("f", "F"); put("g", "G"); put("h", "H"); put("i", "I"); put("j", "J"); 
279                         put("K", "k"); put("L", "l"); put("M", "m"); put("N", "n"); put("O", "o"); 
280                         put("k", "K"); put("l", "L"); put("m", "M"); put("n", "N"); put("o", "O"); 
281                         put("P", "p"); put("Q", "q"); put("R", "r"); put("S", "s"); put("T", "t"); 
282                         put("p", "P"); put("q", "Q"); put("r", "R"); put("s", "S"); put("t", "T"); 
283                         put("U", "u"); put("V", "v"); put("W", "w"); put("X", "x"); put("Y", "y"); 
284                         put("u", "U"); put("v", "V"); put("w", "W"); put("x", "X"); put("y", "Y"); 
285                         put("Z", "z"); 
286                         put("z", "Z"); 
287                 }};
288
289         /** Toggle cycle table for full-width Nikotouch */
290         private static final String[][] JP_FULL_NIKO_CYCLE_TABLE = {
291                 {"\u3042"}, {"\u3044"}, {"\u3046"}, {"\u3048"}, {"\u304a"},      {"."},      {"-"},      {"@"},      {"_"}, {"1"},
292                 {"\u304b"}, {"\u304d"}, {"\u304f"}, {"\u3051"}, {"\u3053"},      {" "},      {"a"},      {"b"},      {"c"}, {"2"},
293                 {"\u3055"}, {"\u3057"}, {"\u3059"}, {"\u305b"}, {"\u305d"},      {"/"},      {"d"},      {"e"},      {"f"}, {"3"},
294                 {"\u305f"}, {"\u3061"}, {"\u3064"}, {"\u3066"}, {"\u3068"}, {"\u3063"},      {"g"},      {"h"},      {"i"}, {"4"},
295                 {"\u306a"}, {"\u306b"}, {"\u306c"}, {"\u306d"}, {"\u306e"},      {"("},      {"j"},      {"k"},      {"l"}, {"5"},
296                 {"\u306f"}, {"\u3072"}, {"\u3075"}, {"\u3078"}, {"\u307b"},      {")"},      {"m"},      {"n"},      {"o"}, {"6"},
297                 {"\u307e"}, {"\u307f"}, {"\u3080"}, {"\u3081"}, {"\u3082"},      {"p"},      {"q"},      {"r"},      {"s"}, {"7"},
298                 {"\u3084"}, {"\u3086"}, {"\u3088"}, {"\u3083"}, {"\u3085"}, {"\u3087"},      {"t"},      {"u"},      {"v"}, {"8"},
299                 {"\u3089"}, {"\u308a"}, {"\u308b"}, {"\u308c"}, {"\u308d"},      {"w"},      {"x"},      {"y"},      {"z"}, {"9"},
300                 {"\u308f"}, {"\u3092"}, {"\u3093"}, {"\u3001"}, {"\u3002"}, {"\u30fc"}, {"\u30fb"}, {"\uff01"}, {"\uff1f"}, {"0"},
301         };
302         /** Toggle cycle table for full-width belltouch */
303         private static final String[][] JP_FULL_BELL_CYCLE_TABLE = {
304                 {"\u3042"}, {"\u3044"}, {"\u3046"}, {"\u3048"}, {"\u304a"},      {"a"},      {"b"},      {"c"},      {"d"}, {"e"},
305                 {"\u304b"}, {"\u304d"}, {"\u304f"}, {"\u3051"}, {"\u3053"},      {"f"},      {"g"},      {"h"},      {"i"}, {"j"},
306                 {"\u3055"}, {"\u3057"}, {"\u3059"}, {"\u305b"}, {"\u305d"},      {"k"},      {"l"},      {"m"},      {"n"}, {"o"},
307                 {"\u305f"}, {"\u3061"}, {"\u3064"}, {"\u3066"}, {"\u3068"},      {"p"},      {"q"},      {"r"},      {"s"}, {"t"},
308                 {"\u306a"}, {"\u306b"}, {"\u306c"}, {"\u306d"}, {"\u306e"},      {"u"},      {"v"},      {"w"},      {"x"}, {"y"},
309                 {"\u306f"}, {"\u3072"}, {"\u3075"}, {"\u3078"}, {"\u307b"},      {"z"},      {" "},      {" "},      {" "}, {" "},
310                 {"\u307e"}, {"\u307f"}, {"\u3080"}, {"\u3081"}, {"\u3082"},      {" "},      {" "},      {" "},      {" "}, {" "},
311                 {"\u3084"},      {" "}, {"\u3086"},      {" "}, {"\u3088"}, {"\u30fc"}, {"\u30fb"}, {"\uff01"}, {"\uff1f"}, {" "},
312                 {"\u3089"}, {"\u308a"}, {"\u308b"}, {"\u308c"}, {"\u308d"},      {"1"},      {"2"},      {"3"},      {"4"}, {"5"},
313                 {"\u308f"}, {"\u3092"}, {"\u3093"}, {"\u3001"}, {"\u3002"},      {"6"},      {"7"},      {"8"},      {"9"}, {"0"},
314         };
315
316         /** Toggle cycle table for full-width Nikotouch */
317         private static final String[][] JP_FULL_NIKO_CYCLE_TABLE_BIG = {
318                 {"\u3042"}, {"\u3044"}, {"\u3046"}, {"\u3048"}, {"\u304a"},      {"."},      {"-"},      {"@"},      {"_"}, {"1"},
319                 {"\u304b"}, {"\u304d"}, {"\u304f"}, {"\u3051"}, {"\u3053"},      {" "},      {"A"},      {"B"},      {"C"}, {"2"},
320                 {"\u3055"}, {"\u3057"}, {"\u3059"}, {"\u305b"}, {"\u305d"},      {"/"},      {"D"},      {"E"},      {"F"}, {"3"},
321                 {"\u305f"}, {"\u3061"}, {"\u3064"}, {"\u3066"}, {"\u3068"}, {"\u3063"},      {"G"},      {"H"},      {"I"}, {"4"},
322                 {"\u306a"}, {"\u306b"}, {"\u306c"}, {"\u306d"}, {"\u306e"},      {"("},      {"J"},      {"K"},      {"L"}, {"5"},
323                 {"\u306f"}, {"\u3072"}, {"\u3075"}, {"\u3078"}, {"\u307b"},      {")"},      {"M"},      {"N"},      {"O"}, {"6"},
324                 {"\u307e"}, {"\u307f"}, {"\u3080"}, {"\u3081"}, {"\u3082"},      {"P"},      {"Q"},      {"R"},      {"S"}, {"7"},
325                 {"\u3084"}, {"\u3086"}, {"\u3088"}, {"\u3083"}, {"\u3085"}, {"\u3087"},      {"T"},      {"U"},      {"V"}, {"8"},
326                 {"\u3089"}, {"\u308a"}, {"\u308b"}, {"\u308c"}, {"\u308d"},      {"W"},      {"X"},      {"Y"},      {"Z"}, {"9"},
327                 {"\u308f"}, {"\u3092"}, {"\u3093"}, {"\u3001"}, {"\u3002"}, {"\u30fc"}, {"\u30fb"}, {"\uff01"}, {"\uff1f"}, {"0"},
328         };
329         /** Toggle cycle table for full-width belltouch */
330         private static final String[][] JP_FULL_BELL_CYCLE_TABLE_BIG = {
331                 {"\u3042"}, {"\u3044"}, {"\u3046"}, {"\u3048"}, {"\u304a"},      {"A"},      {"B"},      {"C"},      {"D"}, {"E"},
332                 {"\u304b"}, {"\u304d"}, {"\u304f"}, {"\u3051"}, {"\u3053"},      {"F"},      {"G"},      {"H"},      {"I"}, {"J"},
333                 {"\u3055"}, {"\u3057"}, {"\u3059"}, {"\u305b"}, {"\u305d"},      {"K"},      {"L"},      {"M"},      {"N"}, {"O"},
334                 {"\u305f"}, {"\u3061"}, {"\u3064"}, {"\u3066"}, {"\u3068"},      {"P"},      {"Q"},      {"R"},      {"S"}, {"T"},
335                 {"\u306a"}, {"\u306b"}, {"\u306c"}, {"\u306d"}, {"\u306e"},      {"U"},      {"V"},      {"W"},      {"X"}, {"Y"},
336                 {"\u306f"}, {"\u3072"}, {"\u3075"}, {"\u3078"}, {"\u307b"},      {"Z"},      {" "},      {" "},      {" "}, {" "},
337                 {"\u307e"}, {"\u307f"}, {"\u3080"}, {"\u3081"}, {"\u3082"},      {" "},      {" "},      {" "},      {" "}, {" "},
338                 {"\u3084"},      {" "}, {"\u3086"},      {" "}, {"\u3088"}, {"\u30fc"}, {"\u30fb"}, {"\uff01"}, {"\uff1f"}, {" "},
339                 {"\u3089"}, {"\u308a"}, {"\u308b"}, {"\u308c"}, {"\u308d"},      {"1"},      {"2"},      {"3"},      {"4"}, {"5"},
340                 {"\u308f"}, {"\u3092"}, {"\u3093"}, {"\u3001"}, {"\u3002"},      {"6"},      {"7"},      {"8"},      {"9"}, {"0"},
341         };
342
343         /** Replace table for full-width Nikotouch */
344         private static final HashMap<String, String> JP_FULL_NIKO_REPLACE_TABLE = new HashMap<String, String>() {{
345                         put("\u3042", "\u3041"); put("\u3044", "\u3043"); put("\u3046", "\u3045"); put("\u3048", "\u3047"); put("\u304a", "\u3049"); // A
346                         put("\u3041", "\u3042"); put("\u3043", "\u3044"); put("\u3045", "\u30f4"); put("\u3047", "\u3048"); put("\u3049", "\u304a"); // a
347                         put("\u304b", "\u304c"); put("\u304d", "\u304e"); put("\u304f", "\u3050"); put("\u3051", "\u3052"); put("\u3053", "\u3054"); // K
348                         put("\u304c", "\u304b"); put("\u304e", "\u304d"); put("\u3050", "\u304f"); put("\u3052", "\u3051"); put("\u3054", "\u3053"); // k
349                         put("\u3055", "\u3056"); put("\u3057", "\u3058"); put("\u3059", "\u305a"); put("\u305b", "\u305c"); put("\u305d", "\u305e"); // S
350                         put("\u3056", "\u3055"); put("\u3058", "\u3057"); put("\u305a", "\u3059"); put("\u305c", "\u305b"); put("\u305e", "\u305d"); // s
351                         put("\u305f", "\u3060"); put("\u3061", "\u3062"); put("\u3064", "\u3065"); put("\u3066", "\u3067"); put("\u3068", "\u3069"); // T
352                         put("\u3060", "\u305f"); put("\u3062", "\u3061"); put("\u3065", "\u3063"); put("\u3067", "\u3066"); put("\u3069", "\u3068"); // t
353                         put("\u3063", "\u3064"); put("\u30f4", "\u3046");
354                         put("\u306f", "\u3070"); put("\u3072", "\u3073"); put("\u3075", "\u3076"); put("\u3078", "\u3079"); put("\u307b", "\u307c"); // H
355                         put("\u3070", "\u3071"); put("\u3073", "\u3074"); put("\u3076", "\u3077"); put("\u3079", "\u307a"); put("\u307c", "\u307d"); // h
356                         put("\u3071", "\u306f"); put("\u3074", "\u3072"); put("\u3077", "\u3075"); put("\u307a", "\u3078"); put("\u307d", "\u307b"); // h.
357                         put("\u3084", "\u3083"); put("\u3086", "\u3085"); put("\u3088", "\u3087"); // Y
358                         put("\u3083", "\u3084"); put("\u3085", "\u3086"); put("\u3087", "\u3088"); // y
359                         put("\u308f", "\u308e");
360                         put("\u308e", "\u308f");
361                         put("\u309b", "\u309c");
362                         put("\u309c", "\u309b");
363
364                         put("a", "A"); put("b", "B"); put("c", "C"); put("d", "D"); put("e", "E"); put("f", "F"); put("g", "G"); put("h", "H"); put("i", "I"); put("j", "J");
365                         put("k", "K"); put("l", "L"); put("m", "M"); put("n", "N"); put("o", "O"); put("p", "P"); put("q", "Q"); put("r", "R"); put("s", "S"); put("t", "T");
366                         put("u", "U"); put("v", "V"); put("w", "W"); put("x", "X"); put("y", "Y"); put("z", "Z");
367                         put("A", "a"); put("B", "b"); put("C", "c"); put("D", "d"); put("E", "e"); put("F", "f"); put("G", "g"); put("H", "h"); put("I", "i"); put("J", "j");
368                         put("K", "k"); put("L", "l"); put("M", "m"); put("N", "n"); put("O", "o"); put("P", "p"); put("Q", "q"); put("R", "r"); put("S", "s"); put("T", "t");
369                         put("U", "u"); put("V", "v"); put("W", "w"); put("X", "x"); put("Y", "y"); put("Z", "z");
370
371                         put("1", "\uff11"); put("2", "\uff12"); put("3", "\uff13"); put("4", "\uff14"); put("5", "\uff15");
372                         put("6", "\uff16"); put("7", "\uff17"); put("8", "\uff18"); put("9", "\uff19"); put("0", "\uff10");
373                         put("\uff11", "1"); put("\uff12", "2"); put("\uff13", "3"); put("\uff14", "4"); put("\uff15", "5");
374                         put("\uff16", "6"); put("\uff17", "7"); put("\uff18", "8"); put("\uff19", "9"); put("\uff10", "0");
375
376                         put(".", "\uff0e"); put("-", "\u2015"); put("@", "\uff20"); put("_", "\uff3f");
377                         put("\uff0e", "."); put("\u2015", "-"); put("\uff20", "@"); put("\uff3f", "_");
378
379                         put("\uff01", "!"); put("\uff1f", "?");
380                         put("!", "\uff01"); put("?", "\uff1f");
381
382                         put("\u3000", " "); put(" ", "\u3000");
383
384                         put("(", "["); put("[", "\u300c"); put("\u300c", "\u300e"); put("\u300e", "\u3010"); put("\u3010", "(");
385                         put(")", "]"); put("]", "\u300d"); put("\u300d", "\u300f"); put("\u300f", "\u3011"); put("\u3011", ")");
386                 }};
387         
388
389         
390         /** Character table for full-width number */
391         private static final char[] INSTANT_CHAR_CODE_FULL_NUMBER = 
392                 "\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19\uff10\uff03\uff0a".toCharArray();
393
394         /** Character table for half-width number */
395         private static final char[] INSTANT_CHAR_CODE_HALF_NUMBER = 
396                 "1234567890#*".toCharArray();
397
398         /** The constant for mFixedKeyMode. It means that input mode is not fixed. */
399         private static final int INVALID_KEYMODE = -1;
400
401         /** KeyIndex of "Moji" key on 12 keyboard (depends on the definition of keyboards) */
402         private static final int KEY_INDEX_CHANGE_MODE_12KEY = 15;
403     
404         /** KeyIndex of "Moji" key on QWERTY keyboard (depends on the definition of keyboards) */
405         private static final int KEY_INDEX_CHANGE_MODE_QWERTY = 29;
406
407         /** Type of input mode */
408         private int mInputType = INPUT_TYPE_TOGGLE;
409
410         /** Previous input character code */
411         private int mPrevInputKeyCode = 0;
412
413         /** flick nicoinput **/
414         private static final int NICOFLICK_NONE       = 0;
415         private static final int NICOFLICK_1STROKE    = 1;
416         private static final int NICOFLICK_NICOSTROKE = 2;
417
418         private int mFlickNicoInput = 0;
419         private boolean mNicoFlick = false;
420         private static final HashMap<String, Integer> flickModeTable = new HashMap<String, Integer>() {{
421                         put("none_flick", 0);
422                         put("normal_stroke", 1);
423                         put("nico_stroke", 2);
424                 }};
425
426         /** **/
427         private int mFlickLimitX;
428         private int mFlickLimitY;
429         
430
431         private static final NicoWnnEvent mEventTouchOtherKey    = new NicoWnnEvent(NicoWnnEvent.TOUCH_OTHER_KEY);
432         private static final NicoWnnEvent mEventCommitText       = new NicoWnnEvent(NicoWnnEvent.COMMIT_COMPOSING_TEXT);
433         private static final NicoWnnEvent mEventConvert          = new NicoWnnEvent(NicoWnnEvent.CONVERT);
434
435         private static final NicoWnnEvent mEventChangeMode12Key    = new NicoWnnEvent(NicoWnnEvent.CHANGE_MODE, NicoWnnJAJP.ENGINE_MODE_OPT_TYPE_12KEY);
436         private static final NicoWnnEvent mEventChangeModeQwerty   = new NicoWnnEvent(NicoWnnEvent.CHANGE_MODE, NicoWnnJAJP.ENGINE_MODE_OPT_TYPE_QWERTY);
437         private static final NicoWnnEvent mEventChangeModeSymbol   = new NicoWnnEvent(NicoWnnEvent.CHANGE_MODE, NicoWnnJAJP.ENGINE_MODE_SYMBOL);
438         private static final NicoWnnEvent mEventChangeModeDocomo   = new NicoWnnEvent(NicoWnnEvent.CHANGE_MODE, NicoWnnJAJP.ENGINE_MODE_DOCOMOSYMBOL);
439         private static final NicoWnnEvent mEventChangeModeEisuKana = new NicoWnnEvent(NicoWnnEvent.CHANGE_MODE, NicoWnnJAJP.ENGINE_MODE_EISU_KANA);
440
441         private static final NicoWnnEvent mEventInputShiftLeft   = new NicoWnnEvent(NicoWnnEvent.INPUT_SOFT_KEY, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
442
443         private static final NicoWnnEvent mEventInputKeyDel      = new NicoWnnEvent(NicoWnnEvent.INPUT_SOFT_KEY, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
444         private static final NicoWnnEvent mEventInputEnter       = new NicoWnnEvent(NicoWnnEvent.INPUT_SOFT_KEY, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
445         private static final NicoWnnEvent mEventInputBack        = new NicoWnnEvent(NicoWnnEvent.INPUT_KEY, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
446         private static final NicoWnnEvent mEventInputDpadLeft    = new NicoWnnEvent(NicoWnnEvent.INPUT_SOFT_KEY, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT));
447         private static final NicoWnnEvent mEventInputDpadRight   = new NicoWnnEvent(NicoWnnEvent.INPUT_SOFT_KEY, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT));
448
449
450         /**
451          * Character table to input when mInputType becomes INPUT_TYPE_INSTANT.
452          * (Either INSTANT_CHAR_CODE_FULL_NUMBER or INSTANT_CHAR_CODE_HALF_NUMBER)
453          */
454         private char[] mCurrentInstantTable = null;
455
456         /** Input mode that is not able to be changed. If ENABLE_CHANGE_KEYMODE is set, input mode can change. */
457         private int[] mLimitedKeyMode = null;
458
459         /** Input mode that is given the first priority. If ENABLE_CHANGE_KEYMODE is set, input mode can change. */
460         private int mPreferenceKeyMode = INVALID_KEYMODE;
461
462         /** The last input type */
463         private int mLastInputType = 0;
464
465         /** Auto caps mode */
466         private boolean mEnableAutoCaps = true;
467
468         /** PopupResId of "Moji" key (this is used for canceling long-press) */
469         private int mPopupResId = 0;
470     
471         /** Whether the InputType is null */
472         private boolean mIsInputTypeNull = false;
473     
474         /** {@code SharedPreferences} for save the keyboard type */
475         private SharedPreferences.Editor mPrefEditor = null;
476     
477         /** "Moji" key (this is used for canceling long-press) */
478         private Keyboard.Key mChangeModeKey = null;
479     
480         private boolean mNikoFirst = false;
481
482         private static final int KEYBOARD_NICO = 0;
483         private static final int KEYBOARD_BELL = 1;
484         private static final int KEYBOARD_MAX  = 2;
485         private int mNicoBellKeyboardMode = 0;
486
487         private Keyboard[][][] mNicoBellKeyboard;
488
489         //private Keyboard[][] mNicoKeyboard;
490         //private Keyboard[][] mBellKeyboard;
491
492         private boolean mGetNoFlipScreen = false;
493         private boolean mNoFlipScreen = false;
494
495         /** option keyboard type */
496         private int     mHookStockKeyType;
497
498         /** change keitai skip **/
499         private boolean mOnOffKeitaiMode = false;
500         /** change eisu change mode **/
501         private boolean mChange12keyQwertyMode = false;
502         private final int[] m12keyTable = {
503                 KEYBOARD_12KEY,  KEYBOARD_12KEY, KEYBOARD_QWERTY, KEYBOARD_QWERTY,  KEYBOARD_12KEY, KEYBOARD_QWERTY, KEYBOARD_QWERTY,  KEYBOARD_12KEY,  KEYBOARD_12KEY
504         };
505         /** option bell type **/
506         private boolean mChangeBellMode = false;
507         private boolean mChangeAlphaBigMode = false;
508
509         /** Default constructor */
510         public DefaultSoftKeyboardJAJP() {
511                 mCurrentLanguage     = LANG_JA;
512                 mCurrentKeyboardType = KEYBOARD_12KEY;
513                 mHookStockKeyType    = KEYBOARD_12KEY;
514                 mShiftOn             = KEYBOARD_SHIFT_OFF;
515                 mCurrentKeyMode      = KEYMODE_JA_FULL_NIKO;
516                 mCurrentSlide        = NIKO_SLIDE_MODE_TOP;
517         }
518
519         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#createKeyboards */
520         @Override protected void createKeyboards(NicoWnn parent) {
521
522                 /* Keyboard[# of Languages][portrait/landscape][# of keyboard type][shift off/on][max # of key-modes][noinput/input] */
523                 mKeyboard = new Keyboard[3][2][4][2][9][2];
524
525                 SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(parent);
526                 mChange12keyQwertyMode = pref.getBoolean("change_12key_qwerty", false);
527                 mChangeBellMode        = pref.getBoolean("change_bellmode", false);
528                 mChangeAlphaBigMode    = pref.getBoolean("change_alphamode", false);
529                 mGetNoFlipScreen       = pref.getBoolean("no_flip_screen", false);
530                 mFlickNicoInput        = flickModeTable.get(pref.getString("nicoflick_mode", "none_flick"));
531                 //if ((true == mGetNoFlipScreen) && (NICOFLICK_NONE != mFlickNicoInput)) {
532                 if (true == mGetNoFlipScreen) {
533                         mNoFlipScreen = true;
534                 }
535                 else{
536                         mNoFlipScreen = false;
537                 }
538                 if (false == mChangeBellMode) {
539                         mNicoBellKeyboardMode = KEYBOARD_NICO;
540                 }
541                 else{
542                         mNicoBellKeyboardMode = KEYBOARD_BELL;
543                 }
544                 
545                 /* Create the suitable keyboard object */
546                 if (mDisplayMode == DefaultSoftKeyboard.PORTRAIT) {
547                         //mCurrentKeyboardType = KEYBOARD_12KEY;
548                         createKeyboardsPortrait(parent);
549                         mFlickLimitX = 24;
550                         mFlickLimitY = 24;
551                 } else {
552                         //mCurrentKeyboardType = KEYBOARD_QWERTY;
553                         createKeyboardsLandscape(parent);
554                         mFlickLimitX = 24;
555                         mFlickLimitY = 20;
556                 }
557                         
558                 if (mCurrentKeyboardType == KEYBOARD_12KEY) {
559                         mWnn.onEvent(mEventChangeMode12Key);
560                 } else {
561                         mWnn.onEvent(mEventChangeModeQwerty);
562                 }
563         }
564
565         /**
566          * Commit the pre-edit string for committing operation that is not explicit
567          * (ex. when a candidate is selected)
568          */
569         private void commitText() {
570                 if (!mNoInput) {
571                         mWnn.onEvent(mEventCommitText);
572                 }
573         }
574
575         /**
576          * Change input mode
577          * <br>
578          * @param keyMode   The type of input mode
579          */
580         public void changeKeyMode(int keyMode) {
581                 int targetMode = filterKeyMode(keyMode);
582                 if (targetMode == INVALID_KEYMODE) {
583                         return;
584                 }
585         
586                 commitText();
587
588                 if (mCapsLock) {
589                         mWnn.onEvent(mEventInputShiftLeft);
590                         mCapsLock = false;
591                 }
592                 mShiftOn = KEYBOARD_SHIFT_OFF;
593                 Keyboard kbd = getModeChangeKeyboard(targetMode);
594                 mCurrentKeyMode = targetMode;
595                 mPrevInputKeyCode = 0;
596                 mCurrentSlide = 0;
597         
598                 int mode = NicoWnnEvent.Mode.DIRECT;
599         
600                 switch (targetMode) {
601                 case KEYMODE_JA_FULL_HIRAGANA:
602                         mInputType = INPUT_TYPE_TOGGLE;
603                         mode = NicoWnnEvent.Mode.DEFAULT;
604                         break;
605             
606                 case KEYMODE_JA_HALF_ALPHABET:
607                         if (USE_ENGLISH_PREDICT) {
608                                 mInputType = INPUT_TYPE_TOGGLE;
609                                 mode = NicoWnnEvent.Mode.NO_LV1_CONV;
610                         } else {
611                                 mInputType = INPUT_TYPE_TOGGLE;
612                                 mode = NicoWnnEvent.Mode.DIRECT;
613                         }
614                         break;
615             
616                 case KEYMODE_JA_FULL_NUMBER:
617                         mInputType = INPUT_TYPE_INSTANT;
618                         mode = NicoWnnEvent.Mode.DIRECT;
619                         mCurrentInstantTable = INSTANT_CHAR_CODE_FULL_NUMBER;
620                         break;
621             
622                 case KEYMODE_JA_HALF_NUMBER:
623                         mInputType = INPUT_TYPE_INSTANT;
624                         mode = NicoWnnEvent.Mode.DIRECT;
625                         mCurrentInstantTable = INSTANT_CHAR_CODE_HALF_NUMBER;
626                         break;
627             
628                 case KEYMODE_JA_FULL_KATAKANA:
629                         mInputType = INPUT_TYPE_TOGGLE;
630                         mode = NicoWnnJAJP.ENGINE_MODE_FULL_KATAKANA;
631                         break;
632             
633                 case KEYMODE_JA_FULL_ALPHABET:
634                         mInputType = INPUT_TYPE_TOGGLE;
635                         mode = NicoWnnEvent.Mode.DIRECT;
636                         break;
637             
638                 case KEYMODE_JA_HALF_KATAKANA:
639                         mInputType = INPUT_TYPE_TOGGLE;
640                         mode = NicoWnnJAJP.ENGINE_MODE_HALF_KATAKANA;
641                         break;
642             
643                 case KEYMODE_JA_FULL_NIKO:
644                         mInputType = INPUT_TYPE_TOGGLE;
645                         mode = NicoWnnEvent.Mode.DEFAULT;
646                         mNikoFirst = false;
647                         mNicoFlick = false;
648                         break;
649
650                 default:
651                         break;
652                 }
653         
654                 setStatusIcon();
655                 changeKeyboard(kbd);
656                 mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.CHANGE_MODE, mode));
657                 if (mChange12keyQwertyMode == true) {
658                         changeKeyboardType(m12keyTable[targetMode]);
659                 }
660         }
661
662         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#initView */
663         @Override public View initView(NicoWnn parent, int width, int height) {
664                 View view = super.initView(parent, width, height);
665                 SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(parent);
666
667                 changeKeyboard(mKeyboard[mCurrentLanguage][mDisplayMode][mCurrentKeyboardType][mShiftOn][mCurrentKeyMode][0]);
668                 return view;
669         }
670
671         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#changeKeyboard */
672         @Override protected boolean changeKeyboard(Keyboard keyboard) {
673
674                 if (keyboard != null) {
675                         if (mIsInputTypeNull) {
676                                 mChangeModeKey.popupResId = mPopupResId;
677                         }
678
679                         List<Keyboard.Key> keys = keyboard.getKeys();
680                         int keyIndex = (KEY_NUMBER_12KEY < keys.size())
681                                 ? KEY_INDEX_CHANGE_MODE_QWERTY : KEY_INDEX_CHANGE_MODE_12KEY;
682                         mChangeModeKey = keys.get(keyIndex);
683
684                         if (mIsInputTypeNull) {
685                                 mPopupResId = mChangeModeKey.popupResId;
686                                 mChangeModeKey.popupResId = 0;
687                         }
688                 }
689                 return super.changeKeyboard(keyboard);
690         }
691
692         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#changeKeyboardType */
693         @Override public void changeKeyboardType(int type) {
694                 commitText();
695                 Keyboard kbd = getTypeChangeKeyboard(type);
696                 if (kbd != null) {
697                         mCurrentKeyboardType = type;
698                         mPrefEditor.putBoolean("opt_enable_qwerty", type == KEYBOARD_QWERTY);
699                         mPrefEditor.commit();
700                         changeKeyboard(kbd);
701                 }
702                 if (type == KEYBOARD_12KEY) {
703                         mWnn.onEvent(mEventChangeMode12Key);
704                 } else {
705                         mWnn.onEvent(mEventChangeModeQwerty);
706                 }
707         }
708         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#setPreferences */
709         @Override public void setPreferences(SharedPreferences pref, EditorInfo editor) {
710                 mPrefEditor = pref.edit();
711                 boolean isQwerty = pref.getBoolean("opt_enable_qwerty", false);
712                 if (isQwerty && (mCurrentKeyboardType != KEYBOARD_QWERTY)) {
713                         changeKeyboardType(KEYBOARD_QWERTY);
714                 }
715
716                 super.setPreferences(pref, editor);
717
718                 int inputType = editor.inputType;
719                 if (mHardKeyboardHidden) {
720                         if (inputType == EditorInfo.TYPE_NULL) {
721                                 if (!mIsInputTypeNull) {
722                                         mIsInputTypeNull = true;
723                                         mPopupResId = mChangeModeKey.popupResId;
724                                         mChangeModeKey.popupResId = 0;
725                                 }
726                                 return;
727                         }
728             
729                         if (mIsInputTypeNull) {
730                                 mIsInputTypeNull = false;
731                                 mChangeModeKey.popupResId = mPopupResId;
732                         }
733                 }
734
735                 mEnableAutoCaps = pref.getBoolean("auto_caps", true);
736                 mLimitedKeyMode = null;
737                 mPreferenceKeyMode = INVALID_KEYMODE;
738                 mNoInput = true;
739                 mDisableKeyInput = false;
740                 mCapsLock = false;
741
742                 mOnOffKeitaiMode = pref.getBoolean("change_keitaimode", false);
743                 if (true == mOnOffKeitaiMode) {
744                         // off keitai hiragana mode
745                         mLimitedKeyMode = new int[] {KEYMODE_JA_FULL_NIKO, KEYMODE_JA_HALF_ALPHABET, KEYMODE_JA_HALF_NUMBER};
746                 }
747                 switch (inputType & EditorInfo.TYPE_MASK_CLASS) {
748
749                 case EditorInfo.TYPE_CLASS_NUMBER:
750                 case EditorInfo.TYPE_CLASS_DATETIME:
751                         mPreferenceKeyMode = KEYMODE_JA_HALF_NUMBER;
752                         break;
753
754                 case EditorInfo.TYPE_CLASS_PHONE:
755                         if (mHardKeyboardHidden) {
756                                 //mLimitedKeyMode = new int[] {KEYMODE_JA_FULL_NIKO};
757                                 mPreferenceKeyMode = KEYMODE_JA_FULL_NIKO;
758                         } else {
759                                 //mLimitedKeyMode = new int[] {KEYMODE_JA_HALF_ALPHABET};
760                                 mPreferenceKeyMode = KEYMODE_JA_FULL_NIKO;
761                         }
762                         break;
763
764                 case EditorInfo.TYPE_CLASS_TEXT:
765                         switch (inputType & EditorInfo.TYPE_MASK_VARIATION) {
766
767                         case EditorInfo.TYPE_TEXT_VARIATION_PASSWORD:
768                                 //mLimitedKeyMode = new int[] {KEYMODE_JA_HALF_ALPHABET, KEYMODE_JA_HALF_NUMBER};
769                                 break;
770
771                         case EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
772                                 //mLimitedKeyMode = new int[] {KEYMODE_JA_HALF_ALPHABET, KEYMODE_JA_HALF_NUMBER};
773                                 break;
774                         case EditorInfo.TYPE_TEXT_VARIATION_URI:
775                                 //mPreferenceKeyMode = KEYMODE_JA_HALF_ALPHABET;
776                                 mPreferenceKeyMode = KEYMODE_JA_FULL_NIKO;
777                                 break;
778
779                         default:
780                                 break;
781                         }
782                         break;
783
784                 default:
785                         break;
786                 }
787
788                 boolean restartkey = false;
789                 boolean old12keyqwerty = mChange12keyQwertyMode;
790                 boolean oldnicobell    = mChangeBellMode;
791
792                 mChange12keyQwertyMode = pref.getBoolean("change_12key_qwerty", false);
793                 mChangeBellMode        = pref.getBoolean("change_bellmode", false);
794                 mChangeAlphaBigMode    = pref.getBoolean("change_alphamode", false);
795                 mGetNoFlipScreen       = pref.getBoolean("no_flip_screen", false);
796                 mFlickNicoInput        = flickModeTable.get(pref.getString("nicoflick_mode", "none_flick"));
797                 //if ((true == mGetNoFlipScreen) && (NICOFLICK_NONE != mFlickNicoInput)) {
798                 if (true == mGetNoFlipScreen) {
799                         mNoFlipScreen = true;
800                 }
801                 else{
802                         mNoFlipScreen = false;
803                 }
804
805                 if (old12keyqwerty != mChange12keyQwertyMode) {
806                         restartkey = true;
807                         if (false == mChange12keyQwertyMode) {
808                                 mCurrentKeyboardType = mHookStockKeyType; // change last keyboard type.
809                         }
810                 }
811                 if (oldnicobell != mChangeBellMode) {
812                         restartkey = true;
813                 }
814                 if (false == mChangeBellMode) {
815                         mNicoBellKeyboardMode = KEYBOARD_NICO;
816                 }
817                 else{
818                         mNicoBellKeyboardMode = KEYBOARD_BELL;
819                 }
820
821                 if (inputType != mLastInputType) {
822                         changeNicoBellLayout();
823                         setDefaultKeyboard();
824                         mLastInputType = inputType;
825                 }
826                 else if (true == restartkey) {
827                         changeNicoBellLayout();
828                         setDefaultKeyboard();
829                 }
830
831                 setStatusIcon();
832                 setShiftByEditorInfo();
833         }
834
835         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#onUpdateState */
836         @Override public void onUpdateState(NicoWnn parent) {
837                 super.onUpdateState(parent);
838                 if (!mCapsLock) {
839                         setShiftByEditorInfo();
840                         if (true == mNoInput && true == mNikoFirst) {
841                                 resetNikoKeyboard();
842                         }
843                 }
844         }
845         /**
846          * Change the keyboard to default
847          */
848         public void setDefaultKeyboard() {
849                 Locale locale = Locale.getDefault();
850                 int keymode = KEYMODE_JA_FULL_NIKO;
851
852
853                 if (mPreferenceKeyMode != INVALID_KEYMODE) {
854                         keymode = mPreferenceKeyMode;
855                 } else if (mLimitedKeyMode != null) {
856                         keymode = mLimitedKeyMode[0];
857                 } else {
858                         if (!locale.getLanguage().equals(Locale.JAPANESE.getLanguage())) {
859                                 keymode = KEYMODE_JA_HALF_ALPHABET;
860                         }
861                 }
862
863                 changeKeyMode(keymode);
864         }
865
866     
867         /**
868          * Change to the next input mode
869          */
870         public void nextKeyMode() {
871                 /* Search the current mode in the toggle table */
872                 boolean found = false;
873                 int index;
874                 for (index = 0; index < JP_MODE_CYCLE_TABLE.length; index++) {
875                         if (JP_MODE_CYCLE_TABLE[index] == mCurrentKeyMode) {
876                                 found = true;
877                                 break;
878                         }
879                 }
880
881                 if (!found) {
882                         /* If the current mode not exists, set the default mode */
883                         setDefaultKeyboard();
884                 } else {
885                         /* If the current mode exists, set the next input mode */
886                         int size = JP_MODE_CYCLE_TABLE.length;
887                         int keyMode = INVALID_KEYMODE;
888                         for (int i = 0; i < size; i++) {
889                                 index = (++index) % size;
890
891                                 keyMode = filterKeyMode(JP_MODE_CYCLE_TABLE[index]);
892                                 if (keyMode != INVALID_KEYMODE) {
893                                         break;
894                                 }
895                         }
896
897                         if (keyMode != INVALID_KEYMODE) {
898                                 changeKeyMode(keyMode);
899                         }
900                 }
901         }
902
903         /**
904          * Create the keyboard for portrait mode
905          * <br>
906          * @param parent  The context
907          */
908         private void createKeyboardsPortrait(NicoWnn parent) {
909                 Keyboard[][] keyList;
910                 /* qwerty shift_off (portrait) */
911                 keyList = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_QWERTY][KEYBOARD_SHIFT_OFF];
912                 keyList[KEYMODE_JA_FULL_HIRAGANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp);
913                 keyList[KEYMODE_JA_FULL_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_alphabet);
914                 keyList[KEYMODE_JA_FULL_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_symbols);
915                 keyList[KEYMODE_JA_FULL_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_katakana);
916                 keyList[KEYMODE_JA_HALF_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_alphabet);
917                 keyList[KEYMODE_JA_HALF_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_symbols);
918                 keyList[KEYMODE_JA_HALF_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_katakana);
919                 keyList[KEYMODE_JA_HALF_PHONE][0]    = new Keyboard(parent, R.xml.keyboard_12key_phone);
920                 keyList[KEYMODE_JA_FULL_NIKO][0]     = keyList[KEYMODE_JA_FULL_HIRAGANA][0];
921
922                 /* qwerty shift_on (portrait) */
923                 keyList = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_QWERTY][KEYBOARD_SHIFT_ON];
924                 keyList[KEYMODE_JA_FULL_HIRAGANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_shift);
925                 keyList[KEYMODE_JA_FULL_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_alphabet_shift);
926                 keyList[KEYMODE_JA_FULL_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_symbols_shift);
927                 keyList[KEYMODE_JA_FULL_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_katakana_shift);
928                 keyList[KEYMODE_JA_HALF_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_alphabet_shift);
929                 keyList[KEYMODE_JA_HALF_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_symbols_shift);
930                 keyList[KEYMODE_JA_HALF_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_katakana_shift);
931                 keyList[KEYMODE_JA_HALF_PHONE][0]    = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_QWERTY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_PHONE][0];
932                 keyList[KEYMODE_JA_FULL_NIKO][0]     = keyList[KEYMODE_JA_FULL_HIRAGANA][0];
933
934                 /* 12-keys shift_off (portrait) */
935                 keyList = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF];
936                 keyList[KEYMODE_JA_FULL_HIRAGANA][0] = new Keyboard(parent, R.xml.keyboard_12keyjp);
937                 keyList[KEYMODE_JA_FULL_HIRAGANA][1] = new Keyboard(parent, R.xml.keyboard_12keyjp_input);
938                 keyList[KEYMODE_JA_FULL_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_12key_full_katakana);
939                 keyList[KEYMODE_JA_FULL_KATAKANA][1] = new Keyboard(parent, R.xml.keyboard_12key_full_katakana_input);
940                 keyList[KEYMODE_JA_HALF_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_12key_half_katakana);
941                 keyList[KEYMODE_JA_HALF_KATAKANA][1] = new Keyboard(parent, R.xml.keyboard_12key_half_katakana_input);
942                 keyList[KEYMODE_JA_HALF_PHONE][0]    = new Keyboard(parent, R.xml.keyboard_12key_phone);
943
944                 keyList[KEYMODE_JA_FULL_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_12key_full_alphabet);
945                 keyList[KEYMODE_JA_FULL_ALPHABET][1] = new Keyboard(parent, R.xml.keyboard_12key_full_alphabet_input);
946                 keyList[KEYMODE_JA_FULL_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_12key_full_num);
947                 keyList[KEYMODE_JA_HALF_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_12key_half_alphabet);
948                 keyList[KEYMODE_JA_HALF_ALPHABET][1] = new Keyboard(parent, R.xml.keyboard_12key_half_alphabet_input);
949                 keyList[KEYMODE_JA_HALF_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_12key_half_num);
950
951                 /* 12-keys shift_on (portrait) */
952                 keyList = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_ON];
953                 keyList[KEYMODE_JA_FULL_HIRAGANA] = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_HIRAGANA];
954                 keyList[KEYMODE_JA_FULL_KATAKANA] = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_KATAKANA];
955                 keyList[KEYMODE_JA_HALF_KATAKANA] = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_KATAKANA];
956                 keyList[KEYMODE_JA_HALF_PHONE]    = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_PHONE];
957
958                 keyList[KEYMODE_JA_FULL_ALPHABET] = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_ALPHABET];
959                 keyList[KEYMODE_JA_FULL_NUMBER]   = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_NUMBER];
960                 keyList[KEYMODE_JA_HALF_ALPHABET] = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_ALPHABET];;
961                 keyList[KEYMODE_JA_HALF_NUMBER]   = mKeyboard[LANG_JA][PORTRAIT][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_NUMBER];
962
963                 mNicoBellKeyboard = new Keyboard[KEYBOARD_MAX][11][2];
964                 // nikotouch slide
965                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_TOP][0]   = new Keyboard(parent, R.xml.keyboard_12key_full_niko_top);
966                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_A][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_a);
967                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_K][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_k);
968                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_S][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_s);
969                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_T][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_t);
970                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_N][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_n);
971                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_H][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_h);
972                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_M][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_m);
973                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_Y][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_y);
974                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_R][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_r);
975                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_W][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_w);
976
977                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_TOP][1]   = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_top);
978                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_A][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_a);
979                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_K][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_k);
980                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_S][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_s);
981                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_T][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_t);
982                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_N][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_n);
983                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_H][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_h);
984                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_M][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_m);
985                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_Y][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_y);
986                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_R][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_r);
987                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_W][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_w);
988
989                 // belltouch slide
990                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_TOP][0]   = new Keyboard(parent, R.xml.keyboard_12key_full_bell_top);
991                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_A][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_a);
992                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_K][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_k);
993                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_S][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_s);
994                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_T][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_t);
995                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_N][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_n);
996                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_H][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_h);
997                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_M][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_m);
998                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_Y][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_y);
999                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_R][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_r);
1000                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_W][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_w);
1001
1002                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_TOP][1]   = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_top);
1003                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_A][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_a);
1004                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_K][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_k);
1005                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_S][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_s);
1006                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_T][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_t);
1007                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_N][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_n);
1008                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_H][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_h);
1009                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_M][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_m);
1010                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_Y][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_y);
1011                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_R][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_r);
1012                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_W][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_w);
1013
1014                 changeNicoBellLayout();
1015         }
1016
1017         /**
1018          * Create the keyboard for landscape mode
1019          * <br>
1020          * @param parent  The context
1021          */
1022         private void createKeyboardsLandscape(NicoWnn parent) {
1023                 Keyboard[][] keyList;
1024                 /* qwerty shift_off (landscape) */
1025                 keyList = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_QWERTY][KEYBOARD_SHIFT_OFF];
1026                 keyList[KEYMODE_JA_FULL_HIRAGANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_land);
1027                 keyList[KEYMODE_JA_FULL_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_alphabet_land);
1028                 keyList[KEYMODE_JA_FULL_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_symbols_land);
1029                 keyList[KEYMODE_JA_FULL_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_katakana_land);
1030                 keyList[KEYMODE_JA_HALF_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_alphabet_land);
1031                 keyList[KEYMODE_JA_HALF_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_symbols_land);
1032                 keyList[KEYMODE_JA_HALF_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_katakana_land);
1033                 keyList[KEYMODE_JA_HALF_PHONE][0]    = new Keyboard(parent, R.xml.keyboard_12key_phone_land);
1034                 /*
1035                 if (false == mChangeBellMode) {
1036                         keyList[KEYMODE_JA_FULL_NIKO][0]     = new Keyboard(parent, R.xml.keyboard_qwerty_jp_niko_land);
1037                 }
1038                 else{
1039                         keyList[KEYMODE_JA_FULL_NIKO][0]     = new Keyboard(parent, R.xml.keyboard_qwerty_jp_bell_land);
1040                 }
1041                 */
1042                 keyList[KEYMODE_JA_FULL_NIKO][0]     = keyList[KEYMODE_JA_FULL_HIRAGANA][0];
1043
1044                 /* qwerty shift_on (landscape) */
1045                 keyList = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_QWERTY][KEYBOARD_SHIFT_ON];
1046                 keyList[KEYMODE_JA_FULL_HIRAGANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_shift_land);
1047                 keyList[KEYMODE_JA_FULL_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_alphabet_shift_land);
1048                 keyList[KEYMODE_JA_FULL_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_symbols_shift_land);
1049                 keyList[KEYMODE_JA_FULL_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_full_katakana_shift_land);
1050                 keyList[KEYMODE_JA_HALF_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_alphabet_shift_land);
1051                 keyList[KEYMODE_JA_HALF_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_symbols_shift_land);
1052                 keyList[KEYMODE_JA_HALF_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_qwerty_jp_half_katakana_shift_land);
1053                 keyList[KEYMODE_JA_HALF_PHONE][0]    = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_QWERTY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_PHONE][0];
1054                 /*
1055                 if (false == mChangeBellMode) {
1056                         keyList[KEYMODE_JA_FULL_NIKO][0]     = new Keyboard(parent, R.xml.keyboard_qwerty_jp_niko_shift_land);
1057                 }
1058                 else{
1059                         keyList[KEYMODE_JA_FULL_NIKO][0]     = new Keyboard(parent, R.xml.keyboard_qwerty_jp_bell_shift_land);
1060                 }
1061                 */
1062                 keyList[KEYMODE_JA_FULL_NIKO][0]     = keyList[KEYMODE_JA_FULL_HIRAGANA][0];
1063
1064                 /* 12-keys shift_off (landscape) */
1065                 keyList = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF];
1066                 keyList[KEYMODE_JA_FULL_HIRAGANA][0] = new Keyboard(parent, R.xml.keyboard_12keyjp_land);
1067                 keyList[KEYMODE_JA_FULL_HIRAGANA][1] = new Keyboard(parent, R.xml.keyboard_12keyjp_input_land);
1068                 keyList[KEYMODE_JA_FULL_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_12key_full_alphabet_land);
1069                 keyList[KEYMODE_JA_FULL_ALPHABET][1] = new Keyboard(parent, R.xml.keyboard_12key_full_alphabet_input_land);
1070                 keyList[KEYMODE_JA_FULL_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_12key_full_num_land);
1071                 keyList[KEYMODE_JA_FULL_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_12key_full_katakana_land);
1072                 keyList[KEYMODE_JA_FULL_KATAKANA][1] = new Keyboard(parent, R.xml.keyboard_12key_full_katakana_input_land);
1073                 keyList[KEYMODE_JA_HALF_ALPHABET][0] = new Keyboard(parent, R.xml.keyboard_12key_half_alphabet_land);
1074                 keyList[KEYMODE_JA_HALF_ALPHABET][1] = new Keyboard(parent, R.xml.keyboard_12key_half_alphabet_input_land);
1075                 keyList[KEYMODE_JA_HALF_NUMBER][0]   = new Keyboard(parent, R.xml.keyboard_12key_half_num_land);
1076                 keyList[KEYMODE_JA_HALF_KATAKANA][0] = new Keyboard(parent, R.xml.keyboard_12key_half_katakana_land);
1077                 keyList[KEYMODE_JA_HALF_KATAKANA][1] = new Keyboard(parent, R.xml.keyboard_12key_half_katakana_input_land);
1078                 keyList[KEYMODE_JA_HALF_PHONE][0]    = new Keyboard(parent, R.xml.keyboard_12key_phone_land);
1079
1080                 /* 12-keys shift_on (landscape) */
1081                 keyList = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_ON];
1082                 keyList[KEYMODE_JA_FULL_HIRAGANA] = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_HIRAGANA];
1083                 keyList[KEYMODE_JA_FULL_ALPHABET] = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_ALPHABET];
1084                 keyList[KEYMODE_JA_FULL_NUMBER]   = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_NUMBER];
1085                 keyList[KEYMODE_JA_FULL_KATAKANA] = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_FULL_KATAKANA];
1086                 keyList[KEYMODE_JA_HALF_ALPHABET] = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_ALPHABET];;
1087                 keyList[KEYMODE_JA_HALF_NUMBER]   = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_NUMBER];
1088                 keyList[KEYMODE_JA_HALF_KATAKANA] = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_KATAKANA];
1089                 keyList[KEYMODE_JA_HALF_PHONE]    = mKeyboard[LANG_JA][LANDSCAPE][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF][KEYMODE_JA_HALF_PHONE];
1090
1091                 mNicoBellKeyboard = new Keyboard[KEYBOARD_MAX][11][2];
1092                 // nikotouch slide
1093                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_TOP][0]   = new Keyboard(parent, R.xml.keyboard_12key_full_niko_top_land);
1094                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_A][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_a_land);
1095                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_K][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_k_land);
1096                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_S][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_s_land);
1097                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_T][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_t_land);
1098                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_N][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_n_land);
1099                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_H][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_h_land);
1100                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_M][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_m_land);
1101                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_Y][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_y_land);
1102                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_R][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_r_land);
1103                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_W][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_w_land);
1104
1105                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_TOP][1]   = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_top_land);
1106                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_A][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_a_land);
1107                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_K][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_k_land);
1108                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_S][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_s_land);
1109                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_T][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_t_land);
1110                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_N][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_n_land);
1111                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_H][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_h_land);
1112                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_M][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_m_land);
1113                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_Y][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_y_land);
1114                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_R][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_r_land);
1115                 mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_W][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_niko_input_w_land);
1116
1117                 // belltouch slide
1118                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_TOP][0]   = new Keyboard(parent, R.xml.keyboard_12key_full_bell_top_land);
1119                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_A][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_a_land);
1120                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_K][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_k_land);
1121                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_S][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_s_land);
1122                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_T][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_t_land);
1123                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_N][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_n_land);
1124                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_H][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_h_land);
1125                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_M][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_m_land);
1126                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_Y][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_y_land);
1127                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_R][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_r_land);
1128                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_W][0]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_w_land);
1129
1130                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_TOP][1]   = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_top_land);
1131                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_A][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_a_land);
1132                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_K][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_k_land);
1133                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_S][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_s_land);
1134                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_T][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_t_land);
1135                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_N][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_n_land);
1136                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_H][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_h_land);
1137                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_M][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_m_land);
1138                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_Y][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_y_land);
1139                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_R][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_r_land);
1140                 mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_W][1]     = new Keyboard(parent, R.xml.keyboard_12key_full_bell_input_w_land);
1141
1142                 changeNicoBellLayout();
1143         }
1144
1145         /**
1146          * Convert the key code to the index of table
1147          * <br>
1148          * @param index     The key code
1149          * @return          The index of the toggle table for input
1150          */
1151         private int getTableIndex(int keyCode) {
1152                 int index =
1153                         (keyCode == KEYCODE_JP12_1)     ?  0 :
1154                         (keyCode == KEYCODE_JP12_2)     ?  1 :
1155                         (keyCode == KEYCODE_JP12_3)     ?  2 :
1156                         (keyCode == KEYCODE_JP12_4)     ?  3 :
1157                         (keyCode == KEYCODE_JP12_5)     ?  4 :
1158                         (keyCode == KEYCODE_JP12_6)     ?  5 :
1159                         (keyCode == KEYCODE_JP12_7)     ?  6 :
1160                         (keyCode == KEYCODE_JP12_8)     ?  7 :
1161                         (keyCode == KEYCODE_JP12_9)     ?  8 :
1162                         (keyCode == KEYCODE_JP12_0)     ?  9 :
1163                         (keyCode == KEYCODE_JP12_SHARP) ? 10 :
1164                         (keyCode == KEYCODE_JP12_ASTER) ? 11 :
1165                         0;
1166
1167                 return index;
1168         }
1169
1170         /**
1171          * Get the toggle table for input that is appropriate in current mode.
1172          * 
1173          * @return      The toggle table for input
1174          */
1175         private String[][] getCycleTable() {
1176                 String[][] cycleTable = null;
1177                 switch (mCurrentKeyMode) {
1178                 case KEYMODE_JA_FULL_HIRAGANA:
1179                         cycleTable = JP_FULL_HIRAGANA_CYCLE_TABLE;
1180                         break;
1181
1182                 case KEYMODE_JA_FULL_KATAKANA:
1183                         cycleTable = JP_FULL_KATAKANA_CYCLE_TABLE;
1184                         break;
1185
1186                 case KEYMODE_JA_FULL_ALPHABET:
1187                         cycleTable = JP_FULL_ALPHABET_CYCLE_TABLE;
1188                         break;
1189
1190                 case KEYMODE_JA_FULL_NUMBER:
1191                 case KEYMODE_JA_HALF_NUMBER:
1192                         /* Because these modes belong to direct input group, No toggle table exists */ 
1193                         break;
1194
1195                 case KEYMODE_JA_HALF_ALPHABET:
1196                         cycleTable = JP_HALF_ALPHABET_CYCLE_TABLE;
1197                         break;
1198
1199                 case KEYMODE_JA_HALF_KATAKANA:
1200                         cycleTable = JP_HALF_KATAKANA_CYCLE_TABLE;
1201                         break;
1202
1203                 case KEYMODE_JA_FULL_NIKO:
1204                         if (false == mChangeBellMode) {
1205                                 if (false == mChangeAlphaBigMode) {
1206                                         cycleTable = JP_FULL_NIKO_CYCLE_TABLE;
1207                                 }
1208                                 else{
1209                                         cycleTable = JP_FULL_NIKO_CYCLE_TABLE_BIG;
1210                                 }
1211                         }
1212                         else{
1213                                 if (false == mChangeAlphaBigMode) {
1214                                         cycleTable = JP_FULL_BELL_CYCLE_TABLE;
1215                                 }
1216                                 else{
1217                                         cycleTable = JP_FULL_BELL_CYCLE_TABLE_BIG;
1218                                 }
1219                         }
1220                         break;
1221
1222                 default:
1223                         break;
1224                 }
1225                 return cycleTable;
1226         }
1227
1228         /**
1229          * Get the replace table that is appropriate in current mode.
1230          * 
1231          * @return      The replace table
1232          */
1233         private HashMap getReplaceTable() {
1234                 HashMap hashTable = null;
1235                 switch (mCurrentKeyMode) {
1236                 case KEYMODE_JA_FULL_HIRAGANA:
1237                         hashTable = JP_FULL_HIRAGANA_REPLACE_TABLE;
1238                         break;
1239                 case KEYMODE_JA_FULL_KATAKANA:
1240                         hashTable = JP_FULL_KATAKANA_REPLACE_TABLE;
1241                         break;
1242
1243                 case KEYMODE_JA_FULL_ALPHABET:
1244                         hashTable = JP_FULL_ALPHABET_REPLACE_TABLE;
1245                         break;
1246
1247                 case KEYMODE_JA_FULL_NUMBER:
1248                 case KEYMODE_JA_HALF_NUMBER:
1249                         /* Because these modes belong to direct input group, No replacing table exists */ 
1250                         break;
1251
1252                 case KEYMODE_JA_HALF_ALPHABET:
1253                         hashTable = JP_HALF_ALPHABET_REPLACE_TABLE;
1254                         break;
1255
1256                 case KEYMODE_JA_HALF_KATAKANA:
1257                         hashTable = JP_HALF_KATAKANA_REPLACE_TABLE;
1258                         break;
1259
1260                 case KEYMODE_JA_FULL_NIKO:
1261                         hashTable = JP_FULL_NIKO_REPLACE_TABLE;
1262                         break;
1263
1264                 default:
1265                         break;
1266                 }
1267                 return hashTable;
1268         }
1269     
1270         /**
1271          * Set the status icon that is appropriate in current mode
1272          */
1273         private void setStatusIcon() {
1274                 int icon = 0;
1275
1276                 switch (mCurrentKeyMode) {
1277                 case KEYMODE_JA_FULL_HIRAGANA:
1278                         icon = R.drawable.immodeic_hiragana;
1279                         break;
1280                 case KEYMODE_JA_FULL_KATAKANA:
1281                         icon = R.drawable.immodeic_full_kana;
1282                         break;
1283                 case KEYMODE_JA_FULL_ALPHABET:
1284                         icon = R.drawable.immodeic_full_alphabet;
1285                         break;
1286                 case KEYMODE_JA_FULL_NUMBER:
1287                         icon = R.drawable.immodeic_full_number;
1288                         break;
1289                 case KEYMODE_JA_HALF_KATAKANA:
1290                         icon = R.drawable.immodeic_half_kana;
1291                         break;
1292                 case KEYMODE_JA_HALF_ALPHABET:
1293                         icon = R.drawable.immodeic_half_alphabet;
1294                         break;
1295                 case KEYMODE_JA_HALF_NUMBER:
1296                 case KEYMODE_JA_HALF_PHONE:
1297                         icon = R.drawable.immodeic_half_number;
1298                         break;
1299                 case KEYMODE_JA_FULL_NIKO:
1300                         icon = R.drawable.immodeic_niko;
1301                         break;
1302
1303                 default:
1304                         break;
1305                 }
1306
1307                 mWnn.showStatusIcon(icon);
1308         }
1309
1310         /**
1311          * Get the shift key state from the editor.
1312          * <br>
1313          * @param editor    The editor information
1314          * @return          The state id of the shift key (0:off, 1:on)
1315          */
1316         protected int getShiftKeyState(EditorInfo editor) {
1317                 InputConnection connection = mWnn.getCurrentInputConnection();
1318                 if (connection != null) {
1319                         int caps = connection.getCursorCapsMode(editor.inputType);
1320                         return (caps == 0) ? 0 : 1;
1321                 } else {
1322                         return 0;
1323                 }
1324         }
1325
1326         /**
1327          * Set the shift key state from {@link EditorInfo}.
1328          */
1329         private void setShiftByEditorInfo() {
1330                 if (mEnableAutoCaps && (mCurrentKeyMode == KEYMODE_JA_HALF_ALPHABET)) {
1331                         int shift = getShiftKeyState(mWnn.getCurrentInputEditorInfo());
1332             
1333                         mShiftOn = shift;
1334                         changeKeyboard(getShiftChangeKeyboard(shift));
1335                 }
1336         }
1337
1338         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#setHardKeyboardHidden */
1339         @Override public void setHardKeyboardHidden(boolean hidden) {
1340                 if (mWnn != null) {
1341                         if (!hidden) {
1342                                 mWnn.onEvent(mEventChangeModeQwerty);
1343                         }
1344
1345                         if (mHardKeyboardHidden != hidden) {
1346                                 if ((mLimitedKeyMode != null)
1347                                     || ((mCurrentKeyMode != KEYMODE_JA_FULL_NIKO) && (mCurrentKeyMode != KEYMODE_JA_FULL_HIRAGANA) && (mCurrentKeyMode != KEYMODE_JA_HALF_ALPHABET))) {
1348                                         
1349                                         mLastInputType = EditorInfo.TYPE_NULL;
1350                                         if (mWnn.isInputViewShown()) {
1351                                                 setDefaultKeyboard();
1352                                         }
1353                                 }
1354                         }
1355                 }
1356                 super.setHardKeyboardHidden(hidden);
1357         }
1358
1359         /**
1360          * Change the key-mode to the allowed one which is restricted
1361          *  by the text input field or the type of the keyboard.
1362          * @param keyMode The key-mode
1363          * @return the key-mode allowed
1364          */
1365         private int filterKeyMode(int keyMode) {
1366                 int targetMode = keyMode;
1367                 int[] limits = mLimitedKeyMode;
1368
1369                 if (!mHardKeyboardHidden) { /* for hardware keyboard */
1370                         if ((targetMode != KEYMODE_JA_FULL_NIKO) && (targetMode != KEYMODE_JA_FULL_HIRAGANA) && (targetMode != KEYMODE_JA_HALF_ALPHABET)) {
1371                                 Locale locale = Locale.getDefault();
1372                                 int keymode = KEYMODE_JA_HALF_ALPHABET;
1373                                 if (locale.getLanguage().equals(Locale.JAPANESE.getLanguage())) {
1374                                         switch (targetMode) {
1375                                         case KEYMODE_JA_FULL_NIKO:
1376                                         case KEYMODE_JA_FULL_HIRAGANA:
1377                                         case KEYMODE_JA_FULL_KATAKANA:
1378                                         case KEYMODE_JA_HALF_KATAKANA:
1379                                                 // hiromitsu-s!!! 2009-09-23 12:47:08
1380                                                 //keymode = KEYMODE_JA_FULL_NIKO;
1381                                                 break;
1382                                         default:
1383                                                 /* half-alphabet */
1384                                                 break;
1385                                         }
1386                                 }
1387                                 targetMode = keymode;
1388                         }
1389                 } 
1390
1391                 /* restrict by the type of the text field */
1392                 if (limits != null) {
1393                         boolean hasAccepted = false;
1394                         boolean hasRequiredChange = true;
1395                         int size = limits.length;
1396                         int nowMode = mCurrentKeyMode;
1397
1398                         for (int i = 0; i < size; i++) {
1399                                 if (targetMode == limits[i]) {
1400                                         hasAccepted = true;
1401                                         break;
1402                                 }
1403                                 if (nowMode == limits[i]) {
1404                                         hasRequiredChange = false;
1405                                 }
1406                         }
1407
1408                         if (!hasAccepted) {
1409                                 if (hasRequiredChange) {
1410                                         targetMode = mLimitedKeyMode[0];
1411                                 } else {
1412                                         targetMode = INVALID_KEYMODE;
1413                                 }
1414                         }
1415                 }
1416
1417                 return targetMode;
1418         }
1419
1420
1421
1422         /*****************************************
1423          * onkey (normal)
1424          */
1425         /** @see com.hiroshica.android.input.nicownn2.DefaultSoftKeyboard#onKey */
1426         @Override public void onKey(int primaryCode, int[] keyCodes) {
1427
1428                 if (mDisableKeyInput) {
1429                         return;
1430                 }
1431
1432                 if (mCurrentKeyMode == KEYMODE_JA_FULL_NIKO) {
1433                         if (true == onKeyNico(primaryCode, keyCodes)) {
1434                                 /* update shift key's state */
1435                                 if (!mCapsLock && (primaryCode != DefaultSoftKeyboard.KEYCODE_QWERTY_SHIFT)) {
1436                                         setShiftByEditorInfo();
1437                                 }
1438                                 return;
1439                         }
1440                 }
1441                 if (true == mIsEnableFlick) {
1442                         onkeyFlick(primaryCode, keyCodes);
1443                         return;
1444                 }
1445
1446                 switch (primaryCode) {
1447                 case KEYCODE_JP12_TOGGLE_MODE:
1448                 case KEYCODE_QWERTY_TOGGLE_MODE:
1449                         if (!mIsInputTypeNull) {
1450                                 nextKeyMode();
1451                         }
1452                         break;
1453
1454                 case DefaultSoftKeyboard.KEYCODE_QWERTY_BACKSPACE:
1455                 case KEYCODE_JP12_BACKSPACE:
1456                         mWnn.onEvent(mEventInputKeyDel);
1457                         break;
1458
1459                 case DefaultSoftKeyboard.KEYCODE_QWERTY_SHIFT:
1460                         toggleShiftLock();
1461                         break;
1462             
1463                 case DefaultSoftKeyboard.KEYCODE_QWERTY_ALT:
1464                         processAltKey();
1465                         break;
1466
1467                 case KEYCODE_QWERTY_ENTER:
1468                 case KEYCODE_JP12_ENTER:
1469                         mWnn.onEvent(mEventInputEnter);
1470                         break;
1471
1472                 case KEYCODE_JP12_REVERSE:
1473                         if (!mNoInput) {
1474                                 mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.TOGGLE_REVERSE_CHAR, mCurrentCycleTable));
1475                         }
1476                         break;
1477
1478                 case KEYCODE_QWERTY_KBD:
1479                         changeKeyboardType(KEYBOARD_12KEY);
1480                         mHookStockKeyType = KEYBOARD_12KEY;
1481                         break;
1482             
1483                 case KEYCODE_JP12_KBD:
1484                         changeKeyboardType(KEYBOARD_QWERTY);
1485                         mHookStockKeyType = KEYBOARD_QWERTY;
1486                         break;
1487
1488                 case KEYCODE_JP12_EMOJI:
1489                 case KEYCODE_QWERTY_EMOJI:
1490                         commitText();
1491                         mWnn.onEvent(mEventChangeModeSymbol);
1492                         break;
1493
1494                 case KEYCODE_JP12_1:
1495                 case KEYCODE_JP12_2:
1496                 case KEYCODE_JP12_3:
1497                 case KEYCODE_JP12_4:
1498                 case KEYCODE_JP12_5:
1499                 case KEYCODE_JP12_6:
1500                 case KEYCODE_JP12_7:
1501                 case KEYCODE_JP12_8:
1502                 case KEYCODE_JP12_9:
1503                 case KEYCODE_JP12_0:
1504                 case KEYCODE_JP12_SHARP:
1505                         /* Processing to input by ten key */
1506                         if (mInputType == INPUT_TYPE_INSTANT) {
1507                                 /* Send a input character directly if instant input type is selected */
1508                                 commitText();
1509                                 mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.INPUT_CHAR, mCurrentInstantTable[getTableIndex(primaryCode)]));
1510                         } else {
1511                                 if ((mPrevInputKeyCode != primaryCode)) {
1512                                         mWnn.onEvent(mEventTouchOtherKey);
1513                                         if ((mCurrentKeyMode == KEYMODE_JA_HALF_ALPHABET)
1514                                             && (primaryCode == KEYCODE_JP12_SHARP)) {
1515                                                 /* Commit text by symbol character (',' '.') when alphabet input mode is selected */
1516                                                 commitText();
1517                                         }
1518                                 }
1519
1520                                 /* Convert the key code to the table index and send the toggle event with the table index */
1521                                 String[][] cycleTable = getCycleTable();
1522                                 if (cycleTable == null) {
1523                                         Log.e("NicoWnn", "not founds cycle table");
1524                                 } else {
1525                                         int index = getTableIndex(primaryCode);
1526                                         mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.TOGGLE_CHAR, cycleTable[index]));
1527                                         mCurrentCycleTable = cycleTable[index];
1528                                 }
1529                                 mPrevInputKeyCode = primaryCode;
1530                         }
1531                         break;
1532
1533                 case KEYCODE_JP12_ASTER:
1534                         if (mInputType == INPUT_TYPE_INSTANT) {
1535                                 commitText();
1536                                 mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.INPUT_CHAR, mCurrentInstantTable[getTableIndex(primaryCode)]));
1537                         } else {
1538                                 if (!mNoInput) {
1539                                         /* Processing to toggle Dakuten, Handakuten, and capital */
1540                                         HashMap replaceTable = getReplaceTable();
1541                                         if (replaceTable == null) {
1542                                                 Log.e("NicoWnn", "not founds replace table");
1543                                         } else {
1544                                                 mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.REPLACE_CHAR, replaceTable));
1545                                                 mPrevInputKeyCode = primaryCode;
1546                                         }
1547                                 }
1548                         }
1549                         break;
1550
1551                 case KEYCODE_SWITCH_FULL_HIRAGANA:
1552                         /* Change mode to Full width hiragana */
1553                         changeKeyMode(KEYMODE_JA_FULL_HIRAGANA);
1554                         break;
1555
1556                 case KEYCODE_SWITCH_FULL_KATAKANA:
1557                         /* Change mode to Full width katakana */
1558                         changeKeyMode(KEYMODE_JA_FULL_KATAKANA);
1559                         break;
1560
1561                 case KEYCODE_SWITCH_FULL_ALPHABET:
1562                         /* Change mode to Full width alphabet */
1563                         changeKeyMode(KEYMODE_JA_FULL_ALPHABET);
1564                         break;
1565
1566                 case KEYCODE_SWITCH_FULL_NUMBER:
1567                         /* Change mode to Full width numeric */
1568                         changeKeyMode(KEYMODE_JA_FULL_NUMBER);
1569                         break;
1570
1571                 case KEYCODE_SWITCH_HALF_KATAKANA:
1572                         /* Change mode to Half width katakana */
1573                         changeKeyMode(KEYMODE_JA_HALF_KATAKANA);
1574                         break;
1575
1576                 case KEYCODE_SWITCH_HALF_ALPHABET: 
1577                         /* Change mode to Half width alphabet */
1578                         changeKeyMode(KEYMODE_JA_HALF_ALPHABET);
1579                         break;
1580
1581                 case KEYCODE_SWITCH_HALF_NUMBER:
1582                         /* Change mode to Half width numeric */
1583                         changeKeyMode(KEYMODE_JA_HALF_NUMBER);
1584                         break;
1585
1586                 case KEYCODE_SWITCH_FULL_NIKO:
1587                         /* Change mode to Full width nikotouch */
1588                         changeKeyMode(KEYMODE_JA_FULL_NIKO);
1589                         break;
1590
1591                 case KEYCODE_SELECT_CASE:
1592                         int shifted = (mShiftOn == 0) ? 1 : 0;
1593                         Keyboard newKeyboard = getShiftChangeKeyboard(shifted);
1594                         if (newKeyboard != null) {
1595                                 mShiftOn = shifted;
1596                                 changeKeyboard(newKeyboard);
1597                         }
1598                         break;
1599
1600                 case KEYCODE_JP12_SPACE:
1601                         if ((mCurrentKeyMode == KEYMODE_JA_FULL_HIRAGANA) && !mNoInput) {
1602                                 mWnn.onEvent(mEventConvert);
1603                         } else {
1604                                 mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.INPUT_CHAR, ' '));
1605                         }
1606                         break;
1607
1608                 case KEYCODE_EISU_KANA:
1609                         mWnn.onEvent(mEventChangeModeEisuKana);
1610                         break;
1611
1612                 case KEYCODE_JP12_CLOSE:
1613                         mWnn.onEvent(mEventInputBack);
1614                         break;
1615             
1616                 case KEYCODE_JP12_LEFT:
1617                         mWnn.onEvent(mEventInputDpadLeft);
1618                         break;
1619             
1620                 case KEYCODE_JP12_RIGHT:
1621                         mWnn.onEvent(mEventInputDpadRight);
1622                         break;
1623                 case KEYCODE_NOP:
1624                         break;
1625
1626                 default:
1627                         if (primaryCode >= 0) {
1628                                 if (mKeyboardView.isShifted()) {
1629                                         primaryCode = Character.toUpperCase(primaryCode);
1630                                 }
1631                                 mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.INPUT_CHAR, (char)primaryCode));
1632                         }
1633                         break;
1634                 }
1635
1636                 /* update shift key's state */
1637                 if (!mCapsLock && (primaryCode != DefaultSoftKeyboard.KEYCODE_QWERTY_SHIFT)) {
1638                         setShiftByEditorInfo();
1639                 }
1640         }
1641
1642
1643         /*****************************************
1644          * onkey nikotouch
1645          */
1646         private boolean onKeyNico(int primaryCode, int[] keyCodes) {
1647                 Keyboard newKeyboard = null;
1648                 boolean retcode = false;
1649
1650                 //Log.v("key", "onkey event!!\n");
1651
1652                 switch (primaryCode) {
1653                 case DefaultSoftKeyboard.KEYCODE_QWERTY_BACKSPACE:
1654                 case KEYCODE_JP12_BACKSPACE:
1655                         if (mNikoFirst == true) {
1656                                 resetNikoKeyboard();
1657                         }
1658                         else {
1659                                 mWnn.onEvent(mEventInputKeyDel);
1660                         }
1661                         retcode = true;
1662                         break;
1663                 case KEYCODE_QWERTY_ENTER:
1664                 case KEYCODE_JP12_ENTER:
1665                         if (mNikoFirst == false) {
1666                                 mWnn.onEvent(mEventInputEnter);
1667                         }
1668                         retcode = true;
1669                         break;
1670
1671                 case KEYCODE_JP12_REVERSE:
1672                         if (mNikoFirst == true) {
1673                                 resetNikoKeyboard();
1674                         }
1675                         //mWnn.mushup();
1676                         retcode = true;
1677                         break;
1678
1679                 case KEYCODE_QWERTY_KBD:
1680                 case KEYCODE_JP12_KBD:
1681                         resetNikoKeyboard();
1682                         break;
1683
1684                 case KEYCODE_JP12_EMOJI:
1685                 case KEYCODE_QWERTY_EMOJI:
1686                         if (mNikoFirst == false) {
1687                                 commitText();
1688                                 mWnn.onEvent(mEventChangeModeSymbol);
1689                         }
1690                         retcode = true;
1691                         break;
1692
1693                 case KEYCODE_JP12_SHARP:
1694                         if (mNikoFirst == false) {
1695                                 commitText();
1696                                 mWnn.onEvent(mEventChangeModeDocomo);
1697                         }
1698                         retcode = true;
1699                         break;
1700
1701                 case KEYCODE_JP12_1:
1702                 case KEYCODE_JP12_2:
1703                 case KEYCODE_JP12_3:
1704                 case KEYCODE_JP12_4:
1705                 case KEYCODE_JP12_5:
1706                 case KEYCODE_JP12_6:
1707                 case KEYCODE_JP12_7:
1708                 case KEYCODE_JP12_8:
1709                 case KEYCODE_JP12_9:
1710                 case KEYCODE_JP12_0:
1711                         if ((NICOFLICK_1STROKE == mFlickNicoInput) && (false == mNikoFirst)) {
1712                                 retcode = true;
1713                                 break;
1714                         }
1715                         if ((NICOFLICK_NICOSTROKE == mFlickNicoInput) && (true == mNicoFlick) && (mPrevInputKeyCode == primaryCode)) {
1716                                 mNicoFlick = false;
1717                                 retcode = true;
1718                                 break;
1719                         }
1720
1721                         if (mNikoFirst == false) {
1722                                 mWnn.onEvent(mEventTouchOtherKey);
1723                                 /* change keymap */
1724                                 int index = getTableIndex(primaryCode);
1725                                 Keyboard[][] keyList = mKeyboard[LANG_JA][mDisplayMode][KEYBOARD_12KEY][KEYBOARD_SHIFT_ON];
1726
1727                                 keyList[KEYMODE_JA_FULL_NIKO] = mNicoBellKeyboard[mNicoBellKeyboardMode][index+1];
1728                                 if (false == mNoFlipScreen) {
1729                                         newKeyboard = getShiftChangeKeyboard(KEYBOARD_SHIFT_ON);
1730                                         if (newKeyboard != null) {
1731                                                 mShiftOn = KEYBOARD_SHIFT_ON;
1732                                                 changeKeyboard(newKeyboard);
1733                                         }
1734                                 }
1735                                 mPrevInputKeyCode = primaryCode;
1736                                 mNikoFirst = true;
1737                         }
1738                         else{
1739                                 int col = getTableIndex(mPrevInputKeyCode);
1740                                 int row = getTableIndex(primaryCode);
1741                                 String[][] cycleTable = getCycleTable();
1742                                 if (cycleTable == null) {
1743                                         Log.e("NicoWnn", "not founds cycle table");
1744                                 }
1745                                 else{
1746                                         mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.TOGGLE_CHAR, cycleTable[col * 10 + row]));
1747                                 }
1748                                 if (false == mNoFlipScreen) {
1749                                         newKeyboard = getShiftChangeKeyboard(KEYBOARD_SHIFT_OFF);
1750                                         if (newKeyboard != null) {
1751                                                 mShiftOn = KEYBOARD_SHIFT_OFF;
1752                                                 changeKeyboard(newKeyboard);
1753                                         }
1754                                 }
1755                                 mNikoFirst = false;
1756                                 mNicoFlick = false;
1757                         }
1758                         retcode = true;
1759                         break;
1760
1761                 case KEYCODE_JP12_ASTER:
1762                         if (mNikoFirst == true) {
1763                                 resetNikoKeyboard();
1764                         }
1765                         if (mNikoFirst == false && !mNoInput) {
1766                                 /* Processing to toggle Dakuten, Handakuten, and capital */
1767                                 HashMap replaceTable = getReplaceTable();
1768                                 if (replaceTable == null) {
1769                                         Log.e("NicoWnn", "not founds replace table");
1770                                 } else {
1771                                         mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.REPLACE_CHAR, replaceTable));
1772                                         mPrevInputKeyCode = primaryCode;
1773                                 }
1774                         }
1775                         retcode = true;
1776                         break;
1777
1778                 case KEYCODE_JP12_SPACE:
1779                         if (mNikoFirst == false) {
1780                                 if ((mCurrentKeyMode == KEYMODE_JA_FULL_HIRAGANA) && !mNoInput) {
1781                                         mWnn.onEvent(mEventConvert);
1782                                 } else {
1783                                         mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.INPUT_CHAR, ' '));
1784                                 }
1785                         }
1786                         retcode = true;
1787                         break;
1788
1789                 case KEYCODE_EISU_KANA:
1790                         if (mNikoFirst == false) {
1791                                 mWnn.onEvent(mEventChangeModeEisuKana);
1792                         }
1793                         retcode = true;
1794                         break;
1795
1796                 case KEYCODE_JP12_CLOSE:
1797                         mWnn.onEvent(mEventInputBack);
1798                         retcode = true;
1799                         break;
1800             
1801                 case KEYCODE_JP12_LEFT:
1802                         if (mNikoFirst == false) {
1803                                 mWnn.onEvent(mEventInputDpadLeft);
1804                         }
1805                         retcode = true;
1806                         break;
1807                 case KEYCODE_JP12_RIGHT:
1808                         if (mNikoFirst == false) {
1809                                 mWnn.onEvent(mEventInputDpadRight);
1810                         }
1811                         retcode = true;
1812                         break;
1813                 }
1814                 return retcode;
1815         } // onKeyNico
1816         /*
1817          * reset nikotouch keyboard
1818          */
1819         @Override public void resetNikoKeyboard() {
1820                 Keyboard newKeyboard = getShiftChangeKeyboard(KEYBOARD_SHIFT_OFF);
1821                 if (newKeyboard != null) {
1822                         mShiftOn = KEYBOARD_SHIFT_OFF;
1823                         changeKeyboard(newKeyboard);
1824                 }
1825                 mNikoFirst = false;
1826                 mNicoFlick = false;
1827         } // resetNikoKeyboard
1828         private void setLastNikoChar(int keycode) {
1829                 int col = getTableIndex(keycode);
1830                 String[][] cycleTable = getCycleTable();
1831                 if (cycleTable == null) {
1832                         Log.e("NicoWnn", "not founds cycle table");
1833                 }
1834                 else{
1835                         mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.TOGGLE_CHAR, cycleTable[col * 10]));
1836                 }
1837                 mWnn.onEvent(mEventTouchOtherKey);
1838         } // setLastNikoChar
1839
1840         private void changeNicoBellLayout() {
1841                 Keyboard[][] keyList, keyListOn;
1842                 keyList   = mKeyboard[LANG_JA][mDisplayMode][KEYBOARD_12KEY][KEYBOARD_SHIFT_OFF];
1843                 keyListOn = mKeyboard[LANG_JA][mDisplayMode][KEYBOARD_12KEY][KEYBOARD_SHIFT_ON];
1844                 if (false == mChangeBellMode) {
1845                         keyList[KEYMODE_JA_FULL_NIKO]     = mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_TOP];
1846                         keyListOn[KEYMODE_JA_FULL_NIKO]   = mNicoBellKeyboard[KEYBOARD_NICO][NIKO_SLIDE_MODE_A];
1847                 }
1848                 else{
1849                         keyList[KEYMODE_JA_FULL_NIKO]     = mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_TOP];
1850                         keyListOn[KEYMODE_JA_FULL_NIKO]   = mNicoBellKeyboard[KEYBOARD_BELL][NIKO_SLIDE_MODE_A];
1851                 }
1852         
1853         }
1854
1855         /*************************************************
1856          * flick mode
1857          */
1858         private void onkeyFlick(int primaryCode, int[] keyCodes) {
1859                 switch (primaryCode) {
1860                 case KEYCODE_JP12_TOGGLE_MODE:
1861                 case KEYCODE_QWERTY_TOGGLE_MODE:
1862                         if (!mIsInputTypeNull) {
1863                                 nextKeyMode();
1864                         }
1865                         break;
1866                 case KEYCODE_SWITCH_FULL_HIRAGANA:
1867                         /* Change mode to Full width hiragana */
1868                         changeKeyMode(KEYMODE_JA_FULL_HIRAGANA);
1869                         break;
1870                         
1871                 case KEYCODE_SWITCH_FULL_KATAKANA:
1872                         /* Change mode to Full width katakana */
1873                         changeKeyMode(KEYMODE_JA_FULL_KATAKANA);
1874                         break;
1875
1876                 case KEYCODE_SWITCH_FULL_ALPHABET:
1877                         /* Change mode to Full width alphabet */
1878                         changeKeyMode(KEYMODE_JA_FULL_ALPHABET);
1879                         break;
1880
1881                 case KEYCODE_SWITCH_FULL_NUMBER:
1882                         /* Change mode to Full width numeric */
1883                         changeKeyMode(KEYMODE_JA_FULL_NUMBER);
1884                         break;
1885
1886                 case KEYCODE_SWITCH_HALF_KATAKANA:
1887                         /* Change mode to Half width katakana */
1888                         changeKeyMode(KEYMODE_JA_HALF_KATAKANA);
1889                         break;
1890
1891                 case KEYCODE_SWITCH_HALF_ALPHABET: 
1892                         /* Change mode to Half width alphabet */
1893                         changeKeyMode(KEYMODE_JA_HALF_ALPHABET);
1894                         break;
1895
1896                 case KEYCODE_SWITCH_HALF_NUMBER:
1897                         /* Change mode to Half width numeric */
1898                         changeKeyMode(KEYMODE_JA_HALF_NUMBER);
1899                         break;
1900
1901                 case KEYCODE_SWITCH_FULL_NIKO:
1902                         /* Change mode to Full width nikotouch */
1903                         changeKeyMode(KEYMODE_JA_FULL_NIKO);
1904                         break;
1905                 case KEYCODE_SELECT_CASE:
1906                         int shifted = (mShiftOn == 0) ? 1 : 0;
1907                         Keyboard newKeyboard = getShiftChangeKeyboard(shifted);
1908                         if (newKeyboard != null) {
1909                                 mShiftOn = shifted;
1910                                 changeKeyboard(newKeyboard);
1911                         }
1912                         break;
1913                 case KEYCODE_NOP:
1914                         break;
1915                 }
1916                 /* update shift key's state */
1917                 if (!mCapsLock && (primaryCode != DefaultSoftKeyboard.KEYCODE_QWERTY_SHIFT)) {
1918                         setShiftByEditorInfo();
1919                 }
1920         }
1921         /**
1922          */
1923         @Override public void onPress(int primaryCode) {
1924                 super.onPress(primaryCode);
1925                 Keyboard newKeyboard = null;
1926
1927                 mStockFlickCode = primaryCode;
1928                 if (mCurrentKeyMode == KEYMODE_JA_FULL_NIKO) {
1929                         if (NICOFLICK_NONE == mFlickNicoInput) {
1930                                 return;
1931                         }
1932                         switch (primaryCode) {
1933                         case KEYCODE_JP12_1:
1934                         case KEYCODE_JP12_2:
1935                         case KEYCODE_JP12_3:
1936                         case KEYCODE_JP12_4:
1937                         case KEYCODE_JP12_5:
1938                         case KEYCODE_JP12_6:
1939                         case KEYCODE_JP12_7:
1940                         case KEYCODE_JP12_8:
1941                         case KEYCODE_JP12_9:
1942                         case KEYCODE_JP12_0:
1943                                 if ((false == mNikoFirst) && (false == mNicoFlick)) {
1944                                         mWnn.onEvent(mEventTouchOtherKey);
1945                                         /* change keymap */
1946                                         int index = getTableIndex(primaryCode);
1947                                         Keyboard[][] keyList = mKeyboard[LANG_JA][mDisplayMode][KEYBOARD_12KEY][KEYBOARD_SHIFT_ON];
1948                                         keyList[KEYMODE_JA_FULL_NIKO] = mNicoBellKeyboard[mNicoBellKeyboardMode][index+1];
1949                                         if (false == mNoFlipScreen) {
1950                                                 newKeyboard = getShiftChangeKeyboard(KEYBOARD_SHIFT_ON);
1951                                                 if (newKeyboard != null) {
1952                                                         mShiftOn = KEYBOARD_SHIFT_ON;
1953                                                         changeKeyboard(newKeyboard);
1954                                                 }
1955                                         }
1956                                         mPrevInputKeyCode = primaryCode;
1957                                         mNikoFirst = true;
1958                                         mNicoFlick = true;
1959                                 }
1960                                 break;
1961                         }
1962                 }
1963         }
1964         /**
1965          */
1966         @Override public void onRelease(int primaryCode) {
1967                 super.onRelease(primaryCode);
1968         } // onRelease
1969
1970 }