[go: nahoru, domu]

Skip to content

Commit

Permalink
Android: add support for TextInputType.none (#26585)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Jun 29, 2021
1 parent 9e69740 commit 9928f4f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,8 @@ public enum TextInputType {
MULTILINE("TextInputType.multiline"),
EMAIL_ADDRESS("TextInputType.emailAddress"),
URL("TextInputType.url"),
VISIBLE_PASSWORD("TextInputType.visiblePassword");
VISIBLE_PASSWORD("TextInputType.visiblePassword"),
NONE("TextInputType.none");

static TextInputType fromValue(@NonNull String encodedName) throws NoSuchFieldException {
for (TextInputType textInputType : TextInputType.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ private static int inputTypeFromTextInputType(
return textType;
} else if (type.type == TextInputChannel.TextInputType.PHONE) {
return InputType.TYPE_CLASS_PHONE;
} else if (type.type == TextInputChannel.TextInputType.NONE) {
return InputType.TYPE_NULL;
}

int textType = InputType.TYPE_CLASS_TEXT;
Expand Down Expand Up @@ -365,9 +367,21 @@ public void sendTextInputAppPrivateCommand(String action, Bundle data) {
mImm.sendAppPrivateCommand(mView, action, data);
}

private void showTextInput(View view) {
view.requestFocus();
mImm.showSoftInput(view, 0);
private boolean canShowTextInput() {
if (configuration == null || configuration.inputType == null) {
return true;
}
return configuration.inputType.type != TextInputChannel.TextInputType.NONE;
}

@VisibleForTesting
void showTextInput(View view) {
if (canShowTextInput()) {
view.requestFocus();
mImm.showSoftInput(view, 0);
} else {
hideTextInput(view);
}
}

private void hideTextInput(View view) {
Expand All @@ -385,15 +399,19 @@ private void hideTextInput(View view) {
void setTextInputClient(int client, TextInputChannel.Configuration configuration) {
// Call notifyViewExited on the previous field.
notifyViewExited();
inputTarget = new InputTarget(InputTarget.Type.FRAMEWORK_CLIENT, client);
this.configuration = configuration;
if (canShowTextInput()) {
inputTarget = new InputTarget(InputTarget.Type.FRAMEWORK_CLIENT, client);
} else {
inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, client);
}

if (mEditable != null) {
mEditable.removeEditingStateListener(this);
}
mEditable =
new ListenableEditingState(
configuration.autofill != null ? configuration.autofill.editState : null, mView);
this.configuration = configuration;
updateAutofillConfigurationIfNeeded(configuration);

// setTextInputClient will be followed by a call to setTextInputEditingState.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,59 @@ public void inputConnection_finishComposingTextUpdatesIMM() throws JSONException
assertEquals(0, testImm.getLastCursorAnchorInfo().getComposingText().length());
}

@Test
public void inputConnection_textInputTypeNone() {
View testView = new View(RuntimeEnvironment.application);
DartExecutor dartExecutor = mock(DartExecutor.class);
TextInputChannel textInputChannel = new TextInputChannel(dartExecutor);
TextInputPlugin textInputPlugin =
new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
textInputPlugin.setTextInputClient(
0,
new TextInputChannel.Configuration(
false,
false,
true,
TextInputChannel.TextCapitalization.NONE,
new TextInputChannel.InputType(TextInputChannel.TextInputType.NONE, false, false),
null,
null,
null,
null));

InputConnection connection =
textInputPlugin.createInputConnection(
testView, mock(KeyboardManager.class), new EditorInfo());
assertEquals(connection, null);
}

@Test
public void showTextInput_textInputTypeNone() {
TestImm testImm =
Shadow.extract(
RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE));
View testView = new View(RuntimeEnvironment.application);
DartExecutor dartExecutor = mock(DartExecutor.class);
TextInputChannel textInputChannel = new TextInputChannel(dartExecutor);
TextInputPlugin textInputPlugin =
new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
textInputPlugin.setTextInputClient(
0,
new TextInputChannel.Configuration(
false,
false,
true,
TextInputChannel.TextCapitalization.NONE,
new TextInputChannel.InputType(TextInputChannel.TextInputType.NONE, false, false),
null,
null,
null,
null));

textInputPlugin.showTextInput(testView);
assertEquals(testImm.isSoftInputVisible(), false);
}

// -------- Start: Autofill Tests -------
@Test
public void autofill_onProvideVirtualViewStructure() {
Expand Down

0 comments on commit 9928f4f

Please sign in to comment.