• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package jp.co.omronsoft.openwnn;
18 
19 import android.view.View;
20 import android.view.ViewGroup;
21 import android.view.inputmethod.EditorInfo;
22 import android.widget.TextView;
23 import android.inputmethodservice.Keyboard;
24 import android.inputmethodservice.KeyboardView;
25 import android.content.SharedPreferences;
26 import android.preference.PreferenceManager;
27 import android.content.res.*;
28 import android.os.Vibrator;
29 import android.media.MediaPlayer;
30 import android.content.Context;
31 
32 import android.util.Log;
33 
34 /**
35  * The default software keyboard class.
36  *
37  * @author Copyright (C) 2009 OMRON SOFTWARE CO., LTD.  All Rights Reserved.
38  */
39 public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKeyboardActionListener {
40     /*
41      *----------------------------------------------------------------------
42      * key codes for a software keyboard
43      *----------------------------------------------------------------------
44      */
45     /** Change the keyboard language */
46     public static final int KEYCODE_CHANGE_LANG = -500;
47 
48     /* for Japanese 12-key keyboard */
49     /** Japanese 12-key keyboard [1] */
50     public static final int KEYCODE_JP12_1 = -201;
51     /** Japanese 12-key keyboard [2] */
52     public static final int KEYCODE_JP12_2 = -202;
53     /** Japanese 12-key keyboard [3] */
54     public static final int KEYCODE_JP12_3 = -203;
55     /** Japanese 12-key keyboard [4] */
56     public static final int KEYCODE_JP12_4 = -204;
57     /** Japanese 12-key keyboard [5] */
58     public static final int KEYCODE_JP12_5 = -205;
59     /** Japanese 12-key keyboard [6] */
60     public static final int KEYCODE_JP12_6 = -206;
61     /** Japanese 12-key keyboard [7] */
62     public static final int KEYCODE_JP12_7 = -207;
63     /** Japanese 12-key keyboard [8] */
64     public static final int KEYCODE_JP12_8 = -208;
65     /** Japanese 12-key keyboard [9] */
66     public static final int KEYCODE_JP12_9 = -209;
67     /** Japanese 12-key keyboard [0] */
68     public static final int KEYCODE_JP12_0 = -210;
69     /** Japanese 12-key keyboard [#] */
70     public static final int KEYCODE_JP12_SHARP = -211;
71     /** Japanese 12-key keyboard [*] */
72     public static final int KEYCODE_JP12_ASTER = -213;
73     /** Japanese 12-key keyboard [DEL] */
74     public static final int KEYCODE_JP12_BACKSPACE = -214;
75     /** Japanese 12-key keyboard [SPACE] */
76     public static final int KEYCODE_JP12_SPACE = -215;
77     /** Japanese 12-key keyboard [ENTER] */
78     public static final int KEYCODE_JP12_ENTER = -216;
79     /** Japanese 12-key keyboard [RIGHT ARROW] */
80     public static final int KEYCODE_JP12_RIGHT = -217;
81     /** Japanese 12-key keyboard [LEFT ARROW] */
82     public static final int KEYCODE_JP12_LEFT = -218;
83     /** Japanese 12-key keyboard [REVERSE TOGGLE] */
84     public static final int KEYCODE_JP12_REVERSE = -219;
85     /** Japanese 12-key keyboard [CLOSE] */
86     public static final int KEYCODE_JP12_CLOSE   = -220;
87     /** Japanese 12-key keyboard [KEYBOARD TYPE CHANGE] */
88     public static final int KEYCODE_JP12_KBD   = -221;
89     /** Japanese 12-key keyboard [EMOJI] */
90     public static final int KEYCODE_JP12_EMOJI      = -222;
91     /** Japanese 12-key keyboard [FULL-WIDTH HIRAGANA MODE] */
92     public static final int KEYCODE_JP12_ZEN_HIRA   = -223;
93     /** Japanese 12-key keyboard [FULL-WIDTH NUMBER MODE] */
94     public static final int KEYCODE_JP12_ZEN_NUM    = -224;
95     /** Japanese 12-key keyboard [FULL-WIDTH ALPHABET MODE] */
96     public static final int KEYCODE_JP12_ZEN_ALPHA  = -225;
97     /** Japanese 12-key keyboard [FULL-WIDTH KATAKANA MODE] */
98     public static final int KEYCODE_JP12_ZEN_KATA   = -226;
99     /** Japanese 12-key keyboard [HALF-WIDTH KATAKANA MODE] */
100     public static final int KEYCODE_JP12_HAN_KATA   = -227;
101     /** Japanese 12-key keyboard [HALF-WIDTH NUMBER MODE] */
102     public static final int KEYCODE_JP12_HAN_NUM    = -228;
103     /** Japanese 12-key keyboard [HALF-WIDTH ALPHABET MODE] */
104     public static final int KEYCODE_JP12_HAN_ALPHA  = -229;
105     /** Japanese 12-key keyboard [MODE TOOGLE CHANGE] */
106     public static final int KEYCODE_JP12_TOGGLE_MODE = -230;
107 
108     /* for Qwerty keyboard */
109     /** Qwerty keyboard [DEL] */
110     public static final int KEYCODE_QWERTY_BACKSPACE = -100;
111     /** Qwerty keyboard [ENTER] */
112     public static final int KEYCODE_QWERTY_ENTER = -101;
113     /** Qwerty keyboard [SHIFT] */
114     public static final int KEYCODE_QWERTY_SHIFT = Keyboard.KEYCODE_SHIFT;
115     /** Qwerty keyboard [ALT] */
116     public static final int KEYCODE_QWERTY_ALT   = -103;
117     /** Qwerty keyboard [KEYBOARD TYPE CHANGE] */
118     public static final int KEYCODE_QWERTY_KBD   = -104;
119     /** Qwerty keyboard [CLOSE] */
120     public static final int KEYCODE_QWERTY_CLOSE = -105;
121     /** Japanese Qwerty keyboard [EMOJI] */
122     public static final int KEYCODE_QWERTY_EMOJI = -106;
123     /** Japanese Qwerty keyboard [FULL-WIDTH HIRAGANA MODE] */
124     public static final int KEYCODE_QWERTY_ZEN_HIRA   = -107;
125     /** Japanese Qwerty keyboard [FULL-WIDTH NUMBER MODE] */
126     public static final int KEYCODE_QWERTY_ZEN_NUM    = -108;
127     /** Japanese Qwerty keyboard [FULL-WIDTH ALPHABET MODE] */
128     public static final int KEYCODE_QWERTY_ZEN_ALPHA  = -109;
129     /** Japanese Qwerty keyboard [FULL-WIDTH KATAKANA MODE] */
130     public static final int KEYCODE_QWERTY_ZEN_KATA   = -110;
131     /** Japanese Qwerty keyboard [HALF-WIDTH KATAKANA MODE] */
132     public static final int KEYCODE_QWERTY_HAN_KATA   = -111;
133     /** Qwerty keyboard [NUMBER MODE] */
134     public static final int KEYCODE_QWERTY_HAN_NUM    = -112;
135     /** Qwerty keyboard [ALPHABET MODE] */
136     public static final int KEYCODE_QWERTY_HAN_ALPHA  = -113;
137     /** Qwerty keyboard [MODE TOOGLE CHANGE] */
138     public static final int KEYCODE_QWERTY_TOGGLE_MODE = -114;
139     /** Qwerty keyboard [PINYIN MODE] */
140     public static final int KEYCODE_QWERTY_PINYIN  = -115;
141 
142     /** OpenWnn instance which hold this software keyboard*/
143     protected OpenWnn      mWnn;
144 
145     /** Current keyboard view */
146     protected KeyboardView mKeyboardView;
147 
148     /** View objects (main side) */
149     protected ViewGroup mMainView;
150     /** View objects (sub side) */
151     protected ViewGroup mSubView;
152 
153     /** Current keyboard definition */
154     protected Keyboard mCurrentKeyboard;
155 
156     /** Caps lock state */
157     protected boolean mCapsLock;
158 
159     /** Input restraint */
160     protected boolean mDisableKeyInput = true;
161     /**
162      * Keyboard surfaces
163      * <br>
164      * Keyboard[language][portrait/landscape][keyboard type][shift off/on][key-mode]
165      */
166     protected Keyboard[][][][][][] mKeyboard;
167 
168     /* languages */
169     /** Current language */
170     protected int mCurrentLanguage;
171     /** Language (English) */
172     public static final int LANG_EN  = 0;
173     /** Language (Japanese) */
174     public static final int LANG_JA  = 1;
175     /** Language (Chinese) */
176     public static final int LANG_CN  = 2;
177 
178     /* portrait/landscape */
179     /** State of the display */
180     protected int mDisplayMode = 0;
181     /** Display mode (Portrait) */
182     public static final int PORTRAIT  = 0;
183     /** Display mode (Landscape) */
184     public static final int LANDSCAPE = 1;
185 
186     /* keyboard type */
187     /** Current keyboard type */
188     protected int mCurrentKeyboardType;
189     /** Keyboard (QWERTY keyboard) */
190     public static final int KEYBOARD_QWERTY  = 0;
191     /** Keyboard (12-keys keyboard) */
192     public static final int KEYBOARD_12KEY   = 1;
193     /** State of the shift key */
194     protected int mShiftOn = 0;
195     /** Shift key off */
196     public static final int KEYBOARD_SHIFT_OFF = 0;
197     /** Shift key on */
198     public static final int KEYBOARD_SHIFT_ON  = 1;
199 
200     /* key-modes */
201     /** Current key-mode */
202     protected int mCurrentKeyMode;
203 
204     /* key-modes for English */
205     /** English key-mode (alphabet) */
206     public static final int KEYMODE_EN_ALPHABET = 0;
207     /** English key-mode (number) */
208     public static final int KEYMODE_EN_NUMBER   = 1;
209     /** English key-mode (phone number) */
210     public static final int KEYMODE_EN_PHONE    = 2;
211 
212     /* key-modes for Japanese */
213     /** Japanese key-mode (Full-width Hiragana) */
214     public static final int KEYMODE_JA_FULL_HIRAGANA = 0;
215     /** Japanese key-mode (Full-width alphabet) */
216     public static final int KEYMODE_JA_FULL_ALPHABET = 1;
217     /** Japanese key-mode (Full-width number) */
218     public static final int KEYMODE_JA_FULL_NUMBER   = 2;
219     /** Japanese key-mode (Full-width Katakana) */
220     public static final int KEYMODE_JA_FULL_KATAKANA = 3;
221     /** Japanese key-mode (Half-width alphabet) */
222     public static final int KEYMODE_JA_HALF_ALPHABET = 4;
223     /** Japanese key-mode (Half-width number) */
224     public static final int KEYMODE_JA_HALF_NUMBER   = 5;
225     /** Japanese key-mode (Half-width Katakana) */
226     public static final int KEYMODE_JA_HALF_KATAKANA = 6;
227     /** Japanese key-mode (Half-width phone number) */
228     public static final int KEYMODE_JA_HALF_PHONE    = 7;
229 
230     /* key-modes for Chinese */
231     /** Chinese key-mode (pinyin) */
232     public static final int KEYMODE_CN_PINYIN   = 0;
233     /** Chinese key-mode (Full-width number) */
234     public static final int KEYMODE_CN_FULL_NUMBER   = 1;
235     /** Chinese key-mode (alphabet) */
236     public static final int KEYMODE_CN_ALPHABET = 2;
237     /** Chinese key-mode (phone) */
238     public static final int KEYMODE_CN_PHONE    = 3;
239     /** Chinese key-mode (Half-width number) */
240     public static final int KEYMODE_CN_HALF_NUMBER   = 4;
241 
242     /* key-modes for HARD */
243     /** HARD key-mode (SHIFT_OFF_ALT_OFF) */
244     public static final int HARD_KEYMODE_SHIFT_OFF_ALT_OFF     = 2;
245     /** HARD key-mode (SHIFT_ON_ALT_OFF) */
246     public static final int HARD_KEYMODE_SHIFT_ON_ALT_OFF      = 3;
247     /** HARD key-mode (SHIFT_OFF_ALT_ON) */
248     public static final int HARD_KEYMODE_SHIFT_OFF_ALT_ON      = 4;
249     /** HARD key-mode (SHIFT_ON_ALT_ON) */
250     public static final int HARD_KEYMODE_SHIFT_ON_ALT_ON       = 5;
251     /** HARD key-mode (SHIFT_LOCK_ALT_OFF) */
252     public static final int HARD_KEYMODE_SHIFT_LOCK_ALT_OFF    = 6;
253     /** HARD key-mode (SHIFT_LOCK_ALT_ON) */
254     public static final int HARD_KEYMODE_SHIFT_LOCK_ALT_ON     = 7;
255     /** HARD key-mode (SHIFT_LOCK_ALT_LOCK) */
256     public static final int HARD_KEYMODE_SHIFT_LOCK_ALT_LOCK   = 8;
257     /** HARD key-mode (SHIFT_OFF_ALT_LOCK) */
258     public static final int HARD_KEYMODE_SHIFT_OFF_ALT_LOCK    = 9;
259     /** HARD key-mode (SHIFT_ON_ALT_LOCK) */
260     public static final int HARD_KEYMODE_SHIFT_ON_ALT_LOCK     = 10;
261 
262     /** Whether the H/W keyboard is hidden. */
263     protected boolean mHardKeyboardHidden = true;
264 
265     /**
266      * Status of the composing text
267      * <br>
268      * {@code true} if there is no composing text.
269      */
270     protected boolean mNoInput = true;
271 
272     /** Vibratior for key click vibration */
273     protected Vibrator mVibrator = null;
274 
275     /** MediaPlayer for key click sound */
276     protected MediaPlayer mSound = null;
277 
278     /** Key toggle cycle table currently using */
279     protected String[] mCurrentCycleTable;
280 
281     /**
282      * Constructor
283      */
DefaultSoftKeyboard()284     public DefaultSoftKeyboard() { }
285 
286     /**
287      * Create keyboard views
288      *
289      * @param parent   OpenWnn using the keyboards.
290      */
createKeyboards(OpenWnn parent)291     protected void createKeyboards(OpenWnn parent) {
292         /*
293          *  Keyboard[# of Languages][portrait/landscape][# of keyboard type]
294          *          [shift off/on][max # of key-modes][non-input/input]
295          */
296         mKeyboard = new Keyboard[3][2][4][2][7][2];
297     }
298 
299     /**
300      * Get the keyboard changed the specified shift state.
301      *
302      * @param shift     Shift state
303      * @return          Keyboard view
304      */
getShiftChangeKeyboard(int shift)305     protected Keyboard getShiftChangeKeyboard(int shift) {
306         try {
307             Keyboard[] kbd = mKeyboard[mCurrentLanguage][mDisplayMode][mCurrentKeyboardType][shift][mCurrentKeyMode];
308 
309             if (!mNoInput && kbd[1] != null) {
310                 return kbd[1];
311             }
312             return kbd[0];
313         } catch (Exception ex) {
314             return null;
315         }
316     }
317 
318     /**
319      * Get the keyboard changed the specified input mode.
320      *
321      * @param mode      Input mode
322      * @return          Keyboard view
323      */
getModeChangeKeyboard(int mode)324     protected Keyboard getModeChangeKeyboard(int mode) {
325         try {
326             Keyboard[] kbd = mKeyboard[mCurrentLanguage][mDisplayMode][mCurrentKeyboardType][mShiftOn][mode];
327 
328             if (!mNoInput && kbd[1] != null) {
329                 return kbd[1];
330             }
331             return kbd[0];
332         } catch (Exception ex) {
333             return null;
334         }
335     }
336 
337     /**
338      * Get the keyboard changed the specified keyboard type
339      *
340      * @param type      Keyboard type
341      * @return          Keyboard view
342      */
getTypeChangeKeyboard(int type)343     protected Keyboard getTypeChangeKeyboard(int type) {
344         try {
345             Keyboard[] kbd = mKeyboard[mCurrentLanguage][mDisplayMode][type][mShiftOn][mCurrentKeyMode];
346 
347             if (!mNoInput && kbd[1] != null) {
348                 return kbd[1];
349             }
350             return kbd[0];
351         } catch (Exception ex) {
352             return null;
353         }
354     }
355 
356     /**
357      * Get the keyboard when some characters are input or no character is input.
358      *
359      * @param inputed   {@code true} if some characters are inputed; {@code false} if no character is inputed.
360      * @return          Keyboard view
361      */
getKeyboardInputed(boolean inputed)362     protected Keyboard getKeyboardInputed(boolean inputed) {
363         try {
364             Keyboard[] kbd = mKeyboard[mCurrentLanguage][mDisplayMode][mCurrentKeyboardType][mShiftOn][mCurrentKeyMode];
365 
366             if (inputed && kbd[1] != null) {
367                 return kbd[1];
368             }
369             return kbd[0];
370         } catch (Exception ex) {
371             return null;
372         }
373     }
374 
375     /**
376      * Change the circulative key-mode.
377      */
toggleKeyMode()378     protected void toggleKeyMode() {
379         /* unlock shift */
380         mShiftOn = KEYBOARD_SHIFT_OFF;
381 
382         /* search next defined key-mode */
383         Keyboard[][] keyboardList = mKeyboard[mCurrentLanguage][mDisplayMode][mCurrentKeyboardType][mShiftOn];
384         do {
385             if (++mCurrentKeyMode >= keyboardList.length) {
386                 mCurrentKeyMode = 0;
387             }
388         } while (keyboardList[mCurrentKeyMode][0] == null);
389 
390         Keyboard kbd;
391         if (!mNoInput && keyboardList[mCurrentKeyMode][1] != null) {
392             kbd = keyboardList[mCurrentKeyMode][1];
393         } else {
394             kbd = keyboardList[mCurrentKeyMode][0];
395         }
396         changeKeyboard(kbd);
397 
398         mWnn.onEvent(new OpenWnnEvent(OpenWnnEvent.CHANGE_MODE,
399                                       OpenWnnEvent.Mode.DEFAULT));
400     }
401 
402     /**
403      * Toggle change the shift lock state.
404      */
toggleShiftLock()405     protected void toggleShiftLock() {
406         if (mShiftOn == 0) {
407             /* turn shift on */
408             Keyboard newKeyboard = getShiftChangeKeyboard(KEYBOARD_SHIFT_ON);
409             if (newKeyboard != null) {
410                 mShiftOn = 1;
411                 changeKeyboard(newKeyboard);
412             }
413             mCapsLock = true;
414         } else {
415             /* turn shift off */
416             Keyboard newKeyboard = getShiftChangeKeyboard(KEYBOARD_SHIFT_OFF);
417             if (newKeyboard != null) {
418                 mShiftOn = 0;
419                 changeKeyboard(newKeyboard);
420             }
421             mCapsLock = false;
422         }
423     }
424 
425     /**
426      * Handling Alt key event.
427      */
processAltKey()428     protected void processAltKey() {
429         /* invalid if it is not qwerty mode */
430         if (mCurrentKeyboardType != KEYBOARD_QWERTY) {
431             return;
432         }
433 
434         int mode = -1;
435         int keymode = mCurrentKeyMode;
436         switch (mCurrentLanguage) {
437         case LANG_EN:
438             if (keymode == KEYMODE_EN_ALPHABET) {
439                 mode = KEYMODE_EN_NUMBER;
440             } else if (keymode == KEYMODE_EN_NUMBER) {
441                 mode = KEYMODE_EN_ALPHABET;
442             }
443             break;
444 
445         case LANG_JA:
446             if (keymode == KEYMODE_JA_HALF_ALPHABET) {
447                 mode = KEYMODE_JA_HALF_NUMBER;
448             } else if (keymode == KEYMODE_JA_HALF_NUMBER) {
449                 mode = KEYMODE_JA_HALF_ALPHABET;
450             } else if (keymode == KEYMODE_JA_FULL_ALPHABET) {
451                 mode = KEYMODE_JA_FULL_NUMBER;
452             } else if (keymode == KEYMODE_JA_FULL_NUMBER) {
453                 mode = KEYMODE_JA_FULL_ALPHABET;
454             }
455             break;
456 
457         default:
458             /* invalid */
459         }
460 
461         if (mode >= 0) {
462             Keyboard kbd = getModeChangeKeyboard(mode);
463             if (kbd != null) {
464                 mCurrentKeyMode = mode;
465                 changeKeyboard(kbd);
466             }
467         }
468     }
469 
470     /**
471      * Change the keyboard type.
472      *
473      * @param type  Type of the keyboard
474      * @see jp.co.omronsoft.openwnn.DefaultSoftKeyboard#KEYBOARD_QWERTY
475      * @see jp.co.omronsoft.openwnn.DefaultSoftKeyboard#KEYBOARD_12KEY
476      */
changeKeyboardType(int type)477     public void changeKeyboardType(int type) {
478         /* ignore invalid parameter */
479         if (type != KEYBOARD_QWERTY && type != KEYBOARD_12KEY) {
480             return;
481         }
482 
483         /* change keyboard view */
484         Keyboard kbd = getTypeChangeKeyboard(type);
485         if (kbd != null) {
486             mCurrentKeyboardType = type;
487             changeKeyboard(kbd);
488         }
489 
490         /* notice that the keyboard is changed */
491         mWnn.onEvent(new OpenWnnEvent(OpenWnnEvent.CHANGE_MODE,
492                                       OpenWnnEvent.Mode.DEFAULT));
493     }
494 
495     /**
496      * Change the keyboard.
497      *
498      * @param keyboard  The new keyboard
499      * @return          {@code true} if the keyboard is changed; {@code false} if not changed.
500      */
changeKeyboard(Keyboard keyboard)501     protected boolean changeKeyboard(Keyboard keyboard) {
502 
503         if (keyboard == null) {
504             return false;
505         }
506         if (mCurrentKeyboard != keyboard) {
507             mKeyboardView.setKeyboard(keyboard);
508             mKeyboardView.setShifted((mShiftOn == 0) ? false : true);
509             mCurrentKeyboard = keyboard;
510             return true;
511         } else {
512             mKeyboardView.setShifted((mShiftOn == 0) ? false : true);
513             return false;
514         }
515     }
516     /** @see jp.co.omronsoft.openwnn.InputViewManager#initView */
initView(OpenWnn parent, int width, int height)517     public View initView(OpenWnn parent, int width, int height) {
518         mWnn = parent;
519         mDisplayMode =
520             (parent.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
521             ? LANDSCAPE : PORTRAIT;
522 
523         /*
524          * create keyboards & the view.
525          * To re-display the input view when the display mode is changed portrait <-> landscape,
526          * create keyboards every time.
527          */
528         createKeyboards(parent);
529 
530         SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(parent);
531         String skin = pref.getString("keyboard_skin",
532                                      mWnn.getResources().getString(R.string.keyboard_skin_id_default));
533         int id = parent.getResources().getIdentifier(skin, "layout", "jp.co.omronsoft.openwnn");
534 
535         mKeyboardView = (KeyboardView) mWnn.getLayoutInflater().inflate(id, null);
536         mKeyboardView.setOnKeyboardActionListener(this);
537         mCurrentKeyboard = null;
538 
539         mMainView = (ViewGroup) parent.getLayoutInflater().inflate(R.layout.keyboard_default_main, null);
540         mSubView = (ViewGroup) parent.getLayoutInflater().inflate(R.layout.keyboard_default_sub, null);
541         if (mDisplayMode == LANDSCAPE && !mHardKeyboardHidden) {
542             mMainView.addView(mSubView);
543         }
544         if (mKeyboardView != null) {
545             mMainView.addView(mKeyboardView);
546         }
547 
548         return mMainView;
549     }
550 
551     /**
552      * Update the SHFIT/ALT keys indicator.
553      *
554      * @param mode  The state of SHIFT/ALT keys.
555      */
updateIndicator(int mode)556     public void updateIndicator(int mode) {
557         Resources res = mWnn.getResources();
558         TextView text1 = (TextView)mSubView.findViewById(R.id.shift);
559         TextView text2 = (TextView)mSubView.findViewById(R.id.alt);
560 
561         switch (mode) {
562         case HARD_KEYMODE_SHIFT_OFF_ALT_OFF:
563             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
564             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
565             text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
566             text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
567             break;
568         case HARD_KEYMODE_SHIFT_ON_ALT_OFF:
569             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on));
570             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
571             text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
572             text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
573             break;
574         case HARD_KEYMODE_SHIFT_LOCK_ALT_OFF:
575             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock));
576             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
577             text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps));
578             text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
579             break;
580         case HARD_KEYMODE_SHIFT_OFF_ALT_ON:
581             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
582             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on));
583             text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
584             text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
585             break;
586         case HARD_KEYMODE_SHIFT_OFF_ALT_LOCK:
587             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
588             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock));
589             text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
590             text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt));
591             break;
592         case HARD_KEYMODE_SHIFT_ON_ALT_ON:
593             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on));
594             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on));
595             text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
596             text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
597             break;
598         case HARD_KEYMODE_SHIFT_ON_ALT_LOCK:
599             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on));
600             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock));
601             text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
602             text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt));
603             break;
604         case HARD_KEYMODE_SHIFT_LOCK_ALT_ON:
605             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock));
606             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on));
607             text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps));
608             text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
609             break;
610         case HARD_KEYMODE_SHIFT_LOCK_ALT_LOCK:
611             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock));
612             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock));
613             text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps));
614             text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt));
615             break;
616         default:
617             text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
618             text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
619             text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
620             text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
621             break;
622         }
623         return;
624     }
625 
626     /** @see jp.co.omronsoft.openwnn.InputViewManager#getCurrentView */
getCurrentView()627     public View getCurrentView() {
628         if (mCurrentKeyboard == null) {
629             return null;
630         }
631         return mMainView;
632     }
633 
634     /** @see jp.co.omronsoft.openwnn.InputViewManager#onUpdateState */
onUpdateState(OpenWnn parent)635     public void onUpdateState(OpenWnn parent) {
636         try {
637             if (parent.mComposingText.size(1) == 0) {
638                 if (!mNoInput) {
639                     /* when the mode changed to "no input" */
640                     mNoInput = true;
641                     Keyboard newKeyboard = getKeyboardInputed(false);
642                     if (mCurrentKeyboard != newKeyboard) {
643                         changeKeyboard(newKeyboard);
644                     }
645                 }
646             } else {
647                 if (mNoInput) {
648                     /* when the mode changed to "input some characters" */
649                     mNoInput = false;
650                     Keyboard newKeyboard = getKeyboardInputed(true);
651                     if (mCurrentKeyboard != newKeyboard) {
652                         changeKeyboard(newKeyboard);
653                     }
654                 }
655             }
656         } catch (Exception ex) {
657         }
658     }
659 
660     /** @see jp.co.omronsoft.openwnn.InputViewManager#setPreferences */
setPreferences(SharedPreferences pref, EditorInfo editor)661     public void setPreferences(SharedPreferences pref, EditorInfo editor) {
662 
663         /* vibrator */
664         try {
665             if (pref.getBoolean("key_vibration", false)) {
666                 mVibrator = (Vibrator)mWnn.getSystemService(Context.VIBRATOR_SERVICE);
667             } else {
668                 mVibrator = null;
669             }
670         } catch (Exception ex) {
671             Log.d("OpenWnn", "NO VIBRATOR");
672         }
673 
674         /* sound */
675         try {
676             if (pref.getBoolean("key_sound", false)) {
677                 mSound = MediaPlayer.create(mWnn, R.raw.type);
678             } else {
679                 mSound = null;
680             }
681         } catch (Exception ex) {
682             Log.d("OpenWnn", "NO SOUND");
683         }
684 
685         /* pop-up preview */
686         mKeyboardView.setPreviewEnabled(pref.getBoolean("popup_preview", true));
687 
688     }
689 
690     /** @see jp.co.omronsoft.openwnn.InputViewManager#closing */
closing()691     public void closing() {
692         if (mKeyboardView != null) {
693             mKeyboardView.closing();
694         }
695         mDisableKeyInput = true;
696     }
697 
698     /***********************************************************************
699      * onKeyboardActionListener
700      ***********************************************************************/
701     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onKey */
onKey(int primaryCode, int[] keyCodes)702     public void onKey(int primaryCode, int[] keyCodes) { }
703 
704     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeRight */
swipeRight()705     public void swipeRight() { }
706 
707     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeLeft */
swipeLeft()708     public void swipeLeft() { }
709 
710     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeDown */
swipeDown()711     public void swipeDown() { }
712 
713     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeUp */
swipeUp()714     public void swipeUp() { }
715 
716     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onRelease */
onRelease(int x)717     public void onRelease(int x) { }
718 
719     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onPress */
onPress(int x)720     public void onPress(int x) {
721         /* key click sound & vibration */
722         if (mVibrator != null) {
723             try { mVibrator.vibrate(30); } catch (Exception ex) { }
724         }
725         if (mSound != null) {
726             try { mSound.seekTo(0); mSound.start(); } catch (Exception ex) { }
727         }
728     }
729 
730     /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onText */
onText(CharSequence text)731     public void onText(CharSequence text) {}
732 
733     /**
734      * Get current key mode.
735      *
736      * @return Current key mode
737      */
getKeyMode()738     public int getKeyMode() {
739         return mCurrentKeyMode;
740     }
741 
742     /**
743      * Get current keyboard type.
744      *
745      * @return Current keyboard type
746      */
getKeyboardType()747     public int getKeyboardType() {
748         return mCurrentKeyboardType;
749     }
750 
751     /**
752      * Set the H/W keyboard's state.
753      *
754      * @param hidden {@code true} if hidden.
755      */
setHardKeyboardHidden(boolean hidden)756     public void setHardKeyboardHidden(boolean hidden) {
757         mHardKeyboardHidden = hidden;
758     }
759 
760     /**
761      * Get current keyboard view.
762      */
getKeyboardView()763     public View getKeyboardView() {
764         return mKeyboardView;
765     }
766 
767     /**
768      * Reset the current keyboard
769      */
resetCurrentKeyboard()770     public void resetCurrentKeyboard() {
771         closing();
772         Keyboard keyboard = mCurrentKeyboard;
773         mCurrentKeyboard = null;
774         changeKeyboard(keyboard);
775     }
776 }
777