Пример #1
0
 /**
  * Called by the framework when your view for creating input needs to be generated. This will be
  * called the first time your input method is displayed, and every time it needs to be re-created
  * such as due to a configuration change.
  */
 @Override
 public View onCreateInputView() {
   mInputView = (LatinKeyboardView) getLayoutInflater().inflate(R.layout.input, null);
   mInputView.setOnKeyboardActionListener(this);
   mInputView.setKeyboard(mQwertyKeyboard);
   return mInputView;
 }
Пример #2
0
  public void swipeUp() {
    if (mInputView == null) {
      return;
    }

    Keyboard currentKeyboard = mInputView.getKeyboard();
    if (mQwertyKeyboard == currentKeyboard) {
      int height = mQwertyKeyboard.getHeight();
      Log.d("Keyboard Height:", Integer.toString(height));
      if (height == 300) mQwertyKeyboard = new LatinKeyboard(this, R.xml.qwerty2);
      else if (height == 400) mQwertyKeyboard = new LatinKeyboard(this, R.xml.qwerty3);
      mInputView.setKeyboard(mQwertyKeyboard);
    } else if (currentKeyboard == mSymbolsKeyboard) {
      int height = mSymbolsKeyboard.getHeight();
      Log.d("Keyboard Height:", Integer.toString(height));
      if (height == 240) mSymbolsKeyboard = new LatinKeyboard(this, R.xml.symbols2);
      else if (height == 320) mSymbolsKeyboard = new LatinKeyboard(this, R.xml.symbols3);
      mInputView.setKeyboard(mSymbolsKeyboard);
    } else if (currentKeyboard == mSymbolsShiftedKeyboard) {
      int height = mSymbolsShiftedKeyboard.getHeight();
      Log.d("Keyboard Height:", Integer.toString(height));
      if (height == 240) mSymbolsShiftedKeyboard = new LatinKeyboard(this, R.xml.symbols_shift2);
      else if (height == 320)
        mSymbolsShiftedKeyboard = new LatinKeyboard(this, R.xml.symbols_shift3);
      mInputView.setKeyboard(mSymbolsShiftedKeyboard);
    }
  }
Пример #3
0
 public void onKey(int primaryCode, int[] keyCodes) {
   if (isWordSeparator(primaryCode)) {
     // Handle separator
     if (mComposing.length() > 0) {
       commitTyped(getCurrentInputConnection());
     }
     sendKey(primaryCode);
     updateShiftKeyState(getCurrentInputEditorInfo());
   } else if (primaryCode == Keyboard.KEYCODE_DELETE) {
     handleBackspace();
   } else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
     handleShift();
   } else if (primaryCode == Keyboard.KEYCODE_CANCEL) {
     handleClose();
     return;
   } else if (primaryCode == LatinKeyboardView.KEYCODE_OPTIONS) {
     // Show a menu or somethin'
   } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE && mInputView != null) {
     Keyboard current = mInputView.getKeyboard();
     if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) {
       current = mQwertyKeyboard;
     } else {
       current = mSymbolsKeyboard;
     }
     mInputView.setKeyboard(current);
     if (current == mSymbolsKeyboard) {
       current.setShifted(false);
     }
   } else {
     handleCharacter(primaryCode, keyCodes);
   }
 }
Пример #4
0
 @Override
 public void onStartInputView(EditorInfo attribute, boolean restarting) {
   super.onStartInputView(attribute, restarting);
   // Apply the selected keyboard to the input view.
   mInputView.setKeyboard(mCurKeyboard);
   mInputView.closing();
   final InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype();
   mInputView.setSubtypeOnSpaceKey(subtype);
 }
Пример #5
0
 /** Helper to update the shift state of our keyboard based on the initial editor state. */
 private void updateShiftKeyState(EditorInfo attr) {
   if (attr != null && mInputView != null && mQwertyKeyboard == mInputView.getKeyboard()) {
     int caps = 0;
     EditorInfo ei = getCurrentInputEditorInfo();
     if (ei != null && ei.inputType != InputType.TYPE_NULL) {
       caps = getCurrentInputConnection().getCursorCapsMode(attr.inputType);
     }
     mInputView.setShifted(mCapsLock || caps != 0);
   }
 }
Пример #6
0
  private void handleShift() {
    if (mInputView == null) {
      return;
    }

    Keyboard currentKeyboard = mInputView.getKeyboard();
    if (mQwertyKeyboard == currentKeyboard) {
      // Alphabet keyboard
      checkToggleCapsLock();
      mInputView.setShifted(mCapsLock || !mInputView.isShifted());
    } else if (currentKeyboard == mSymbolsKeyboard) {
      mSymbolsKeyboard.setShifted(true);
      mInputView.setKeyboard(mSymbolsShiftedKeyboard);
      mSymbolsShiftedKeyboard.setShifted(true);
    } else if (currentKeyboard == mSymbolsShiftedKeyboard) {
      mSymbolsShiftedKeyboard.setShifted(false);
      mInputView.setKeyboard(mSymbolsKeyboard);
      mSymbolsKeyboard.setShifted(false);
    }
  }
Пример #7
0
 private void handleCharacter(int primaryCode, int[] keyCodes) {
   if (isInputViewShown()) {
     if (mInputView.isShifted()) {
       primaryCode = Character.toUpperCase(primaryCode);
     }
   }
   if (isAlphabet(primaryCode) && mPredictionOn) {
     mComposing.append((char) primaryCode);
     getCurrentInputConnection().setComposingText(mComposing, 1);
     updateShiftKeyState(getCurrentInputEditorInfo());
     updateCandidates();
   } else {
     getCurrentInputConnection().commitText(String.valueOf((char) primaryCode), 1);
   }
 }
Пример #8
0
  /** This is called when the user is done editing a field. We can use this to reset our state. */
  @Override
  public void onFinishInput() {
    super.onFinishInput();

    // Clear current composing text and candidates.
    mComposing.setLength(0);
    updateCandidates();

    // We only hide the candidates window when finishing input on
    // a particular editor, to avoid popping the underlying application
    // up and down if the user is entering text into the bottom of
    // its window.
    setCandidatesViewShown(false);

    mCurKeyboard = mQwertyKeyboard;
    if (mInputView != null) {
      mInputView.closing();
    }
  }
Пример #9
0
 private void handleClose() {
   commitTyped(getCurrentInputConnection());
   requestHideSelf(0);
   mInputView.closing();
 }
Пример #10
0
  /**
   * Use this to monitor key events being delivered to the application. We get first crack at them,
   * and can either resume them or let them continue to the app.
   */
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
      case KeyEvent.KEYCODE_BACK:
        // The InputMethodService already takes care of the back
        // key for us, to dismiss the input method if it is shown.
        // However, our keyboard could be showing a pop-up window
        // that back should dismiss, so we first allow it to do that.
        if (event.getRepeatCount() == 0 && mInputView != null) {
          if (mInputView.handleBack()) {
            return true;
          }
        }
        break;

      case KeyEvent.KEYCODE_DEL:
        // Special handling of the delete key: if we currently are
        // composing text for the user, we want to modify that instead
        // of let the application to the delete itself.
        if (mComposing.length() > 0) {
          onKey(Keyboard.KEYCODE_DELETE, null);
          return true;
        }
        break;

      case KeyEvent.KEYCODE_ENTER:
        // Let the underlying text editor always handle these.
        return false;

      default:
        // For all other keys, if we want to do transformations on
        // text being entered with a hard keyboard, we need to process
        // it and do the appropriate action.
        if (PROCESS_HARD_KEYS) {
          if (keyCode == KeyEvent.KEYCODE_SPACE
              && (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) {
            // A silly example: in our input method, Alt+Space
            // is a shortcut for 'android' in lower case.
            InputConnection ic = getCurrentInputConnection();
            if (ic != null) {
              // First, tell the editor that it is no longer in the
              // shift state, since we are consuming this.
              ic.clearMetaKeyStates(KeyEvent.META_ALT_ON);
              keyDownUp(KeyEvent.KEYCODE_A);
              keyDownUp(KeyEvent.KEYCODE_N);
              keyDownUp(KeyEvent.KEYCODE_D);
              keyDownUp(KeyEvent.KEYCODE_R);
              keyDownUp(KeyEvent.KEYCODE_O);
              keyDownUp(KeyEvent.KEYCODE_I);
              keyDownUp(KeyEvent.KEYCODE_D);
              // And we consume this event.
              return true;
            }
          }
          if (mPredictionOn && translateKeyDown(keyCode, event)) {
            return true;
          }
        }
    }

    return super.onKeyDown(keyCode, event);
  }
Пример #11
0
 @Override
 public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
   mInputView.setSubtypeOnSpaceKey(subtype);
 }