[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: add support for TextInputType.none #26585

Merged
merged 8 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
jpnurmi marked this conversation as resolved.
Show resolved Hide resolved
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