下面列出了android.view.inputmethod.EditorInfo#IME_FLAG_NO_EXTRACT_UI 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean onEvaluateFullscreenMode() {
final SettingsValues settingsValues = mSettings.getCurrent();
if (isImeSuppressedByHardwareKeyboard()) {
// If there is a hardware keyboard, disable full screen mode.
return false;
}
// Reread resource value here, because this method is called by the framework as needed.
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources());
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
// hack for now. Let's get rid of this once the framework gets fixed.
final EditorInfo ei = getCurrentInputEditorInfo();
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
}
return false;
}
@Override
public boolean onEvaluateFullscreenMode() {
final SettingsValues settingsValues = mSettings.getCurrent();
if (isImeSuppressedByHardwareKeyboard()) {
// If there is a hardware keyboard, disable full screen mode.
return false;
}
if (KeyboardSwitcher.getInstance().isFloatingKeyboard()) {
return false;
}
// Reread resource value here, because this method is called by the framework as needed.
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources());
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
// hack for now. Let's get rid of this once the framework gets fixed.
final EditorInfo ei = getCurrentInputEditorInfo();
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
}
return false;
}
@Override
public boolean onEvaluateFullscreenMode() {
if (isImeSuppressedByHardwareKeyboard()) {
// If there is a hardware keyboard, disable full screen mode.
return false;
}
// Reread resource value here, because this method is called by the framework as needed.
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources());
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
// hack for now. Let's get rid of this once the framework gets fixed.
final EditorInfo ei = getCurrentInputEditorInfo();
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
}
return false;
}
@Override
public boolean onEvaluateFullscreenMode() {
if (isImeSuppressedByHardwareKeyboard()) {
// If there is a hardware keyboard, disable full screen mode.
return false;
}
// Reread resource value here, because this method is called by the framework as needed.
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources());
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
// hack for now. Let's get rid of this once the framework gets fixed.
final EditorInfo ei = getCurrentInputEditorInfo();
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
}
return false;
}
@Override
public boolean onEvaluateFullscreenMode() {
final SettingsValues settingsValues = mSettings.getCurrent();
if (isImeSuppressedByHardwareKeyboard()) {
// If there is a hardware keyboard, disable full screen mode.
return false;
}
// Reread resource value here, because this method is called by the framework as needed.
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources());
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
// hack for now. Let's get rid of this once the framework gets fixed.
final EditorInfo ei = getCurrentInputEditorInfo();
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
}
return false;
}
@Override
public boolean onEvaluateFullscreenMode() {
final SettingsValues settingsValues = mSettings.getCurrent();
if (isImeSuppressedByHardwareKeyboard()) {
// If there is a hardware keyboard, disable full screen mode.
return false;
}
// Reread resource value here, because this method is called by the framework as needed.
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources());
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
// hack for now. Let's get rid of this once the framework gets fixed.
final EditorInfo ei = getCurrentInputEditorInfo();
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
}
return false;
}
/**
* Called when the fullscreen-mode extracting editor info has changed,
* to determine whether the extracting (extract text and candidates) portion
* of the UI should be shown. The standard implementation hides or shows
* the extract area depending on whether it makes sense for the
* current editor. In particular, a {@link InputType#TYPE_NULL}
* input type or {@link EditorInfo#IME_FLAG_NO_EXTRACT_UI} flag will
* turn off the extract area since there is no text to be shown.
*/
public void onUpdateExtractingVisibility(EditorInfo ei) {
if (ei.inputType == InputType.TYPE_NULL ||
(ei.imeOptions&EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0) {
// No reason to show extract UI!
setExtractViewShown(false);
return;
}
setExtractViewShown(true);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_MULTI_LINE;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_ENTER_ACTION
| EditorInfo.IME_ACTION_DONE
| EditorInfo.IME_FLAG_NO_EXTRACT_UI;
if (_inputConnection == null) {
_inputConnection = this.new TextFieldInputConnection(this);
} else {
_inputConnection.resetComposingState();
}
return _inputConnection;
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_MULTI_LINE;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_ENTER_ACTION
| EditorInfo.IME_ACTION_DONE
| EditorInfo.IME_FLAG_NO_EXTRACT_UI;
if (_inputConnection == null) {
_inputConnection = this.new TextFieldInputConnection(this);
} else {
_inputConnection.resetComposingState();
}
return _inputConnection;
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
| EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;
return ic;
}
static boolean shouldOverrideRegularCondition(@NonNull final Context context, final EditText editText) {
if ((editText.getImeOptions() & EditorInfo.IME_FLAG_NO_EXTRACT_UI) == 0) {
return getOrientation(context) == Configuration.ORIENTATION_LANDSCAPE;
}
return false;
}
/**
* @see View#onCreateInputConnection(EditorInfo)
* @param allowKeyboardLearning Whether to allow keyboard (IME) app to do personalized learning.
*/
public ChromiumBaseInputConnection onCreateInputConnection(
EditorInfo outAttrs, boolean allowKeyboardLearning) {
// InputMethodService evaluates fullscreen mode even when the new input connection is
// null. This makes sure IME doesn't enter fullscreen mode or open custom UI.
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
// TODO(changwan): Replace with EditorInfoCompat#IME_FLAG_NO_PERSONALIZED_LEARNING or
// EditorInfo#IME_FLAG_NO_PERSONALIZED_LEARNING as soon as either is
// available in all build config types.
if (!allowKeyboardLearning) outAttrs.imeOptions |= IME_FLAG_NO_PERSONALIZED_LEARNING;
// Without this line, some third-party IMEs will try to compose text even when
// not on an editable node. Even when we return null here, key events can still go
// through ImeAdapter#dispatchKeyEvent().
if (mTextInputType == TextInputType.NONE) {
setInputConnection(null);
if (DEBUG_LOGS) Log.i(TAG, "onCreateInputConnection returns null.");
return null;
}
if (mInputConnectionFactory == null) return null;
setInputConnection(mInputConnectionFactory.initializeAndGet(mContainerView, this,
mTextInputType, mTextInputFlags, mTextInputMode, mLastSelectionStart,
mLastSelectionEnd, outAttrs));
if (DEBUG_LOGS) Log.i(TAG, "onCreateInputConnection: " + mInputConnection);
if (mCursorAnchorInfoController != null) {
mCursorAnchorInfoController.onRequestCursorUpdates(false /* not an immediate request */,
false /* disable monitoring */, mContainerView);
}
if (isValid()) {
nativeRequestCursorUpdate(mNativeImeAdapterAndroid,
false /* not an immediate request */, false /* disable monitoring */);
}
return mInputConnection;
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
| EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;
return ic;
}
@Override
public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) {
InputConnection superConn = super.onCreateInputConnection(outAttrs);
if (superConn != null) {
TokenInputConnection conn = new TokenInputConnection(superConn, true);
outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;
return conn;
} else {
return null;
}
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection conn = super.onCreateInputConnection(outAttrs);
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
return conn;
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
return super.onCreateInputConnection(outAttrs);
}
@VisibleForTesting
AdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) {
super(view, true);
mInternalView = view;
mImeAdapter = imeAdapter;
mImeAdapter.setInputConnection(this);
mSingleLine = true;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
| EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeText) {
// Normal text field
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTextArea ||
imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeContentEditable) {
// TextArea or contenteditable.
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
| EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
| EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
mSingleLine = false;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypePassword) {
// Password
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeSearch) {
// Search
outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeUrl) {
// Url
// TYPE_TEXT_VARIATION_URI prevents Tab key from showing, so
// exclude it for now.
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeEmail) {
// Email
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTel) {
// Telephone
// Number and telephone do not have both a Tab key and an
// action in default OSK, so set the action to NEXT
outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeNumber) {
// Number
outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
| InputType.TYPE_NUMBER_VARIATION_NORMAL;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
}
outAttrs.initialSelStart = imeAdapter.getInitialSelectionStart();
outAttrs.initialSelEnd = imeAdapter.getInitialSelectionEnd();
mLastUpdateSelectionStart = imeAdapter.getInitialSelectionStart();
mLastUpdateSelectionEnd = imeAdapter.getInitialSelectionEnd();
}
@VisibleForTesting
AdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) {
super(view, true);
mInternalView = view;
mImeAdapter = imeAdapter;
mImeAdapter.setInputConnection(this);
mSingleLine = true;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
| EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeText) {
// Normal text field
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTextArea ||
imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeContentEditable) {
// TextArea or contenteditable.
outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
| EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
| EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
mSingleLine = false;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypePassword) {
// Password
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeSearch) {
// Search
outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeUrl) {
// Url
// TYPE_TEXT_VARIATION_URI prevents Tab key from showing, so
// exclude it for now.
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeEmail) {
// Email
outAttrs.inputType = InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTel) {
// Telephone
// Number and telephone do not have both a Tab key and an
// action in default OSK, so set the action to NEXT
outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
} else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeNumber) {
// Number
outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
| InputType.TYPE_NUMBER_VARIATION_NORMAL;
outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
}
outAttrs.initialSelStart = imeAdapter.getInitialSelectionStart();
outAttrs.initialSelEnd = imeAdapter.getInitialSelectionEnd();
mLastUpdateSelectionStart = imeAdapter.getInitialSelectionStart();
mLastUpdateSelectionEnd = imeAdapter.getInitialSelectionEnd();
}