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 */ 284 public DefaultSoftKeyboard() { } 285 286 /** 287 * Create keyboard views 288 * 289 * @param parent OpenWnn using the keyboards. 290 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 } else if (mKeyboardView != null) { 544 mMainView.addView(mKeyboardView); 545 } 546 547 return mMainView; 548 } 549 550 /** 551 * Update the SHFIT/ALT keys indicator. 552 * 553 * @param mode The state of SHIFT/ALT keys. 554 */ 555 public void updateIndicator(int mode) { 556 Resources res = mWnn.getResources(); 557 TextView text1 = (TextView)mSubView.findViewById(R.id.shift); 558 TextView text2 = (TextView)mSubView.findViewById(R.id.alt); 559 560 switch (mode) { 561 case HARD_KEYMODE_SHIFT_OFF_ALT_OFF: 562 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off)); 563 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off)); 564 text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 565 text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 566 break; 567 case HARD_KEYMODE_SHIFT_ON_ALT_OFF: 568 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on)); 569 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off)); 570 text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 571 text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 572 break; 573 case HARD_KEYMODE_SHIFT_LOCK_ALT_OFF: 574 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock)); 575 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off)); 576 text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps)); 577 text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 578 break; 579 case HARD_KEYMODE_SHIFT_OFF_ALT_ON: 580 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off)); 581 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on)); 582 text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 583 text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 584 break; 585 case HARD_KEYMODE_SHIFT_OFF_ALT_LOCK: 586 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off)); 587 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock)); 588 text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 589 text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt)); 590 break; 591 case HARD_KEYMODE_SHIFT_ON_ALT_ON: 592 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on)); 593 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on)); 594 text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 595 text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 596 break; 597 case HARD_KEYMODE_SHIFT_ON_ALT_LOCK: 598 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on)); 599 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock)); 600 text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 601 text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt)); 602 break; 603 case HARD_KEYMODE_SHIFT_LOCK_ALT_ON: 604 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock)); 605 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on)); 606 text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps)); 607 text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 608 break; 609 case HARD_KEYMODE_SHIFT_LOCK_ALT_LOCK: 610 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock)); 611 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock)); 612 text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps)); 613 text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt)); 614 break; 615 default: 616 text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off)); 617 text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off)); 618 text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 619 text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default)); 620 break; 621 } 622 return; 623 } 624 625 /** @see jp.co.omronsoft.openwnn.InputViewManager#getCurrentView */ 626 public View getCurrentView() { 627 if (mCurrentKeyboard == null) { 628 return null; 629 } 630 return mMainView; 631 } 632 633 /** @see jp.co.omronsoft.openwnn.InputViewManager#onUpdateState */ 634 public void onUpdateState(OpenWnn parent) { 635 try { 636 if (parent.mComposingText.size(1) == 0) { 637 if (!mNoInput) { 638 /* when the mode changed to "no input" */ 639 mNoInput = true; 640 Keyboard newKeyboard = getKeyboardInputed(false); 641 if (mCurrentKeyboard != newKeyboard) { 642 changeKeyboard(newKeyboard); 643 } 644 } 645 } else { 646 if (mNoInput) { 647 /* when the mode changed to "input some characters" */ 648 mNoInput = false; 649 Keyboard newKeyboard = getKeyboardInputed(true); 650 if (mCurrentKeyboard != newKeyboard) { 651 changeKeyboard(newKeyboard); 652 } 653 } 654 } 655 } catch (Exception ex) { 656 } 657 } 658 659 /** @see jp.co.omronsoft.openwnn.InputViewManager#setPreferences */ 660 public void setPreferences(SharedPreferences pref, EditorInfo editor) { 661 662 /* vibrator */ 663 try { 664 if (pref.getBoolean("key_vibration", false)) { 665 mVibrator = (Vibrator)mWnn.getSystemService(Context.VIBRATOR_SERVICE); 666 } else { 667 mVibrator = null; 668 } 669 } catch (Exception ex) { 670 Log.d("OpenWnn", "NO VIBRATOR"); 671 } 672 673 /* sound */ 674 try { 675 if (pref.getBoolean("key_sound", false)) { 676 mSound = MediaPlayer.create(mWnn, R.raw.type); 677 } else { 678 mSound = null; 679 } 680 } catch (Exception ex) { 681 Log.d("OpenWnn", "NO SOUND"); 682 } 683 684 /* pop-up preview */ 685 mKeyboardView.setPreviewEnabled(pref.getBoolean("popup_preview", true)); 686 687 } 688 689 /** @see jp.co.omronsoft.openwnn.InputViewManager#closing */ 690 public void closing() { 691 if (mKeyboardView != null) { 692 mKeyboardView.closing(); 693 } 694 mDisableKeyInput = true; 695 } 696 697 /*********************************************************************** 698 * onKeyboardActionListener 699 ***********************************************************************/ 700 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onKey */ 701 public void onKey(int primaryCode, int[] keyCodes) { } 702 703 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeRight */ 704 public void swipeRight() { } 705 706 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeLeft */ 707 public void swipeLeft() { } 708 709 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeDown */ 710 public void swipeDown() { } 711 712 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeUp */ 713 public void swipeUp() { } 714 715 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onRelease */ 716 public void onRelease(int x) { } 717 718 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onPress */ 719 public void onPress(int x) { 720 /* key click sound & vibration */ 721 if (mVibrator != null) { 722 try { mVibrator.vibrate(30); } catch (Exception ex) { } 723 } 724 if (mSound != null) { 725 try { mSound.seekTo(0); mSound.start(); } catch (Exception ex) { } 726 } 727 } 728 729 /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onText */ 730 public void onText(CharSequence text) {} 731 732 /** 733 * Get current key mode. 734 * 735 * @return Current key mode 736 */ 737 public int getKeyMode() { 738 return mCurrentKeyMode; 739 } 740 741 /** 742 * Get current keyboard type. 743 * 744 * @return Current keyboard type 745 */ 746 public int getKeyboardType() { 747 return mCurrentKeyboardType; 748 } 749 750 /** 751 * Set the H/W keyboard's state. 752 * 753 * @param hidden {@code true} if hidden. 754 */ 755 public void setHardKeyboardHidden(boolean hidden) { 756 mHardKeyboardHidden = hidden; 757 } 758 759 /** 760 * Get current keyboard view. 761 */ 762 public View getKeyboardView() { 763 return mKeyboardView; 764 } 765 766 /** 767 * Reset the current keyboard 768 */ 769 public void resetCurrentKeyboard() { 770 closing(); 771 Keyboard keyboard = mCurrentKeyboard; 772 mCurrentKeyboard = null; 773 changeKeyboard(keyboard); 774 } 775 } 776