/** @see jp.co.omronsoft.openwnn.InputViewManager#setPreferences */
  public void setPreferences(SharedPreferences pref, EditorInfo editor) {

    /* vibrator */
    try {
      if (pref.getBoolean("key_vibration", false)) {
        mVibrator = (Vibrator) mWnn.getSystemService(Context.VIBRATOR_SERVICE);
      } else {
        mVibrator = null;
      }
    } catch (Exception ex) {
      Log.d("OpenWnn", "NO VIBRATOR");
    }

    /* sound */
    try {
      if (pref.getBoolean("key_sound", false)) {
        mSound = MediaPlayer.create(mWnn, R.raw.type);
      } else {
        mSound = null;
      }
    } catch (Exception ex) {
      Log.d("OpenWnn", "NO SOUND");
    }

    /* pop-up preview */
    mKeyboardView.setPreviewEnabled(pref.getBoolean("popup_preview", true));
  }
  /**
   * Change the keyboard type.
   *
   * @param type Type of the keyboard
   * @see jp.co.omronsoft.openwnn.DefaultSoftKeyboard#KEYBOARD_QWERTY
   * @see jp.co.omronsoft.openwnn.DefaultSoftKeyboard#KEYBOARD_12KEY
   */
  public void changeKeyboardType(int type) {
    /* ignore invalid parameter */
    if (type != KEYBOARD_QWERTY && type != KEYBOARD_12KEY) {
      return;
    }

    /* change keyboard view */
    Keyboard kbd = getTypeChangeKeyboard(type);
    if (kbd != null) {
      mCurrentKeyboardType = type;
      changeKeyboard(kbd);
    }

    /* notice that the keyboard is changed */
    mWnn.onEvent(new OpenWnnEvent(OpenWnnEvent.CHANGE_MODE, OpenWnnEvent.Mode.DEFAULT));
  }
  /** Change the circulative key-mode. */
  protected void toggleKeyMode() {
    /* unlock shift */
    mShiftOn = KEYBOARD_SHIFT_OFF;

    /* search next defined key-mode */
    Keyboard[][] keyboardList =
        mKeyboard[mCurrentLanguage][mDisplayMode][mCurrentKeyboardType][mShiftOn];
    do {
      if (++mCurrentKeyMode >= keyboardList.length) {
        mCurrentKeyMode = 0;
      }
    } while (keyboardList[mCurrentKeyMode][0] == null);

    Keyboard kbd;
    if (!mNoInput && keyboardList[mCurrentKeyMode][1] != null) {
      kbd = keyboardList[mCurrentKeyMode][1];
    } else {
      kbd = keyboardList[mCurrentKeyMode][0];
    }
    changeKeyboard(kbd);

    mWnn.onEvent(new OpenWnnEvent(OpenWnnEvent.CHANGE_MODE, OpenWnnEvent.Mode.DEFAULT));
  }
  /** @see jp.co.omronsoft.openwnn.InputViewManager#initView */
  public View initView(OpenWnn parent, int width, int height) {
    mWnn = parent;
    mDisplayMode =
        (parent.getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE)
            ? LANDSCAPE
            : PORTRAIT;

    /*
     * create keyboards & the view.
     * To re-display the input view when the display mode is changed portrait <-> landscape,
     * create keyboards every time.
     */
    createKeyboards(parent);

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(parent);
    String skin =
        pref.getString(
            "keyboard_skin", mWnn.getResources().getString(R.string.keyboard_skin_id_default));
    int id = parent.getResources().getIdentifier(skin, "layout", "jp.co.omronsoft.openwnn");

    mKeyboardView = (KeyboardView) mWnn.getLayoutInflater().inflate(id, null);
    mKeyboardView.setOnKeyboardActionListener(this);
    mCurrentKeyboard = null;

    mMainView =
        (ViewGroup) parent.getLayoutInflater().inflate(R.layout.keyboard_default_main, null);
    mSubView = (ViewGroup) parent.getLayoutInflater().inflate(R.layout.keyboard_default_sub, null);
    if (mDisplayMode == LANDSCAPE && !mHardKeyboardHidden) {
      mMainView.addView(mSubView);
    }
    if (mKeyboardView != null) {
      mMainView.addView(mKeyboardView);
    }

    return mMainView;
  }
  /**
   * Update the SHFIT/ALT keys indicator.
   *
   * @param mode The state of SHIFT/ALT keys.
   */
  public void updateIndicator(int mode) {
    Resources res = mWnn.getResources();
    TextView text1 = (TextView) mSubView.findViewById(R.id.shift);
    TextView text2 = (TextView) mSubView.findViewById(R.id.alt);

    switch (mode) {
      case HARD_KEYMODE_SHIFT_OFF_ALT_OFF:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
        text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        break;
      case HARD_KEYMODE_SHIFT_ON_ALT_OFF:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
        text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        break;
      case HARD_KEYMODE_SHIFT_LOCK_ALT_OFF:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
        text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps));
        text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        break;
      case HARD_KEYMODE_SHIFT_OFF_ALT_ON:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on));
        text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        break;
      case HARD_KEYMODE_SHIFT_OFF_ALT_LOCK:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock));
        text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt));
        break;
      case HARD_KEYMODE_SHIFT_ON_ALT_ON:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on));
        text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        break;
      case HARD_KEYMODE_SHIFT_ON_ALT_LOCK:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_on));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock));
        text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt));
        break;
      case HARD_KEYMODE_SHIFT_LOCK_ALT_ON:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_on));
        text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps));
        text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        break;
      case HARD_KEYMODE_SHIFT_LOCK_ALT_LOCK:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_lock));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_lock));
        text1.setBackgroundColor(res.getColor(R.color.indicator_background_lock_caps));
        text2.setBackgroundColor(res.getColor(R.color.indicator_background_lock_alt));
        break;
      default:
        text1.setTextColor(res.getColor(R.color.indicator_textcolor_caps_off));
        text2.setTextColor(res.getColor(R.color.indicator_textcolor_alt_off));
        text1.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        text2.setBackgroundColor(res.getColor(R.color.indicator_textbackground_default));
        break;
    }
    return;
  }