Info.TYPE_TEXT_VARIATION_PASSWORD variation EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD // Do not display predictions / what the user is typing // when they are entering a password. mPredictionOn false if variation EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS variation EditorInfo.TYPE_TEXT_VARIATION_URI variation EditorInfo.TYPE_TEXT_VARIATION_FILTER // Our predictions are not useful for e-mail addresses // or URIs. mPredictionOn false if attribute.inputTypeampEditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE 0 // If this is an auto-complete text view then our predictions // will not be shown and instead we will allow the editor // to supply their own. We only show the editors // candidates when in fullscreen mode otherwise relying // own it displaying its own UI. mPredictionOn false mCompletionOn isFullscreenMode // We also want to look at the current state of the editor // to decide whether our alphabetic keyboard should start out // shifted. updateShiftKeyStateattribute break default: // For all unknown input types default to the alphabetic // keyboard with no special features. mCurKeyboard mQwertyKeyboard updateShiftKeyStateattribute // Update the label on the enter key depending on what the application // says it will do. mCurKeyboard.setImeOptionsgetResources attribute.imeOptions / 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.setLength0 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. setCandidatesViewShownfalse mCurKeyboard mQwertyKeyboard if mInputView null mInputView.closing Override public void onStartInputViewEditorInfo attribute boolean restarting super.onStartInputViewattribute restarting // Apply the selected keyboard to the input view. mInputView.setKeyboardmCurKeyboard mInputView.closing / Deal with the editor reporting movement of its cursor. / Override public void onUpdateSelectionint oldSelStart int oldSelEnd int newSelStart int newSelEnd int candidatesStart int candidatesEnd super.onUpdateSelectionoldSelStart oldSelEnd newSelStart newSelEnd candidatesStart candidatesEnd // If the current selection in the text view changes we should // clear whatever candidate text we have. if mComposing.length gt 0 ampamp newSelStart candidatesEnd newSelEnd candidatesEnd mComposing.setLength0 updateCandidates InputConnection ic getCurrentInputConnection if ic null ic.finishComposingText / This tells us about completions that the editor has determined based on the current text in it. We want to use this in fullscreen mode to show the completions ourself since the editor can not be seen in that situation. / Override public void onDisplayCompletionsCompletionInfo completions if mCompletionOn mCompletions completions if completions null setSuggestionsnull false false return ListltStringgt stringList new ArrayListltStringgt for int i0 iltcompletions null completions.length : 0 i CompletionInfo ci completionsi if ci null stringList.addci.getText.toString setSuggestionsstringList true true / This translates incoming hard key events in to edit operations on an InputConnection. It is only needed when using the PROCESS_HARD_KEYS option. / private boolean translateKeyDownint keyCode KeyEvent event mMetaState MetaKeyKeyListener.handleKeyDownmMetaState keyCode event int c event.getUnicodeCharMetaKeyKeyListener.getMetaStatemMetaState mMetaState MetaKeyKeyListener.adjustMetaAfterKeypressmMetaState InputConnection ic getCurrentInputConnection if c 0 ic null return false boolean dead false if c amp KeyCharacterMap.COMBINING_ACCENT 0 dead true c c amp KeyCharacterMap.COMBINING_ACCENT_MASK if mComposing.length gt 0 char accent mComposing.charAtmComposing.length -1 int composed KeyEvent.getDeadCharaccent c if composed 0 c composed mComposing.setLengthmComposing.length-1 onKeyc null return true / 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 onKeyDownint 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 ampamp 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 gt 0 onKeyKeyboard.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 ampamp event.getMetaStateampKeyEvent.META_ALT_ON 0 // A silly example: in our input method AltSpace // 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.clearMetaKeyStatesKeyEvent.META_ALT_ON keyDownUpKeyEvent.KEYCODE_A keyDownUpKeyEvent.KEYCODE_N keyDownUpKeyEvent.KEYCODE_D keyDownUpKeyEvent.KEYCODE_R keyDownUpKeyEvent.KEYCODE_O keyDownUpKeyEvent.KEYCODE_I keyDownUpKeyEvent.KEYCODE_D // And we consume this event. return true if mPredictionOn ampamp translateKeyDownkeyCode event return true return super.onKeyDownkeyCode event / .
上一篇:
大量Android开源项目源代码分享_安卓入门教程
下一篇:
7*30m公路预应力混凝土连续梁桥上部结构设计