/** @hide */
  public void dispatchKeyEvent(
      Context context, int seq, KeyEvent key, IInputMethodCallback callback) {
    synchronized (mH) {
      if (DEBUG) Log.d(TAG, "dispatchKeyEvent");

      if (mCurMethod == null) {
        try {
          callback.finishedEvent(seq, false);
        } catch (RemoteException e) {
        }
        return;
      }

      if (key.getAction() == KeyEvent.ACTION_DOWN && key.getKeyCode() == KeyEvent.KEYCODE_SYM) {
        showInputMethodPicker();
        try {
          callback.finishedEvent(seq, true);
        } catch (RemoteException e) {
        }
        return;
      }
      try {
        if (DEBUG) Log.v(TAG, "DISPATCH KEY: " + mCurMethod);
        mCurMethod.dispatchKeyEvent(seq, key, callback);
      } catch (RemoteException e) {
        Log.w(TAG, "IME died: " + mCurId + " dropping: " + key, e);
        try {
          callback.finishedEvent(seq, false);
        } catch (RemoteException ex) {
        }
      }
    }
  }
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
   // Input Method stuff
   if (Utils.isMonkeyRunning()) {
     return false;
   }
   if (preference == mStatusBarImeSwitcher) {
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.STATUS_BAR_IME_SWITCHER,
         mStatusBarImeSwitcher.isChecked() ? 1 : 0);
     return true;
   } else if (preference instanceof PreferenceScreen) {
     if (preference.getFragment() != null) {
       // Fragment will be handled correctly by the super class.
     } else if (KEY_CURRENT_INPUT_METHOD.equals(preference.getKey())) {
       final InputMethodManager imm =
           (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
       imm.showInputMethodPicker();
     }
   } else if (preference instanceof CheckBoxPreference) {
     final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
     if (!mHardKeyboardPreferenceList.isEmpty()) {
       for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
         if (chkPref == mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i])) {
           System.putInt(
               getContentResolver(), sSystemSettingNames[i], chkPref.isChecked() ? 1 : 0);
           return true;
         }
       }
     }
     if (chkPref == mGameControllerCategory.findPreference("vibrate_input_devices")) {
       System.putInt(
           getContentResolver(),
           Settings.System.VIBRATE_INPUT_DEVICES,
           chkPref.isChecked() ? 1 : 0);
       return true;
     }
   }
   return super.onPreferenceTreeClick(preferenceScreen, preference);
 }