Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Android Autofill #17465

Merged
merged 19 commits into from
Apr 16, 2020
Merged

Android Autofill #17465

merged 19 commits into from
Apr 16, 2020

Conversation

LongCatIsLooong
Copy link
Contributor

Framework PR: flutter/flutter#52126

@auto-assign auto-assign bot requested a review from iskakaushik April 2, 2020 01:04
@LongCatIsLooong
Copy link
Contributor Author

Hi @blasten could you take a look at this? I'm trying to add androidx.autofill to embedding_bundle, but not sure if I missed anything.

private static String translateAutofillHint(@NonNull String hint) {
switch (hint) {
case "addressCity":
return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are very sensitive to adding dependencies to the embedding. This can cause conflict in the future if a plugin adds this dependency.
Since you are returning a String, is there any chance you can remove the dependency and return the raw string?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Take a look at my comment about fields, otherwise just nitpicks. 👍

@@ -119,6 +134,16 @@ public void requestExistingInputState() {
channel.invokeMethod("TextInputClient.requestExistingInputState", null);
}

private HashMap<Object, Object> createEditingStateJSON(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this method be static?

Configuration[] fields = null;
if (!json.isNull("fields")) {
final JSONArray fields = json.getJSONArray("fields");
fields = new Configuration[fields.length()];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two declarations of fields above, maybe some code got mixed up or missed being deleted.

final double height = arguments.getDouble("height");
final JSONArray jsonMatrix = arguments.getJSONArray("transform");
final double[] matrix = new double[16];
for (int i = 0; i < 16; i++) matrix[i] = jsonMatrix.getDouble(i);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (int i = 0; i < 16; i++) matrix[i] = jsonMatrix.getDouble(i);
for (int i = 0; i < 16; i++) {
matrix[i] = jsonMatrix.getDouble(i);
}


@NonNull
private static String translateAutofillHint(@NonNull String hint) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be a bit more readable if you do:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
  return hint;
}
// then switch 

Comment on lines 62 to 64
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
afm = view.getContext().getSystemService(AutofillManager.class);
else afm = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
afm = view.getContext().getSystemService(AutofillManager.class);
else afm = null;
afm = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? view.getContext().getSystemService(AutofillManager.class) : null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDK version check doesn't seem to work with ternary expressions, the linter started complaining when I applied the suggested change.

@@ -277,16 +301,48 @@ private void hideTextInput(View view) {
mImm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}

private void notifyViewEntered() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

}

private void notifyViewExited() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

}

private void notifyValueChanged(String newValue) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

Comment on lines 420 to 424
if (tx < minMax[0]) minMax[0] = tx;
else if (tx > minMax[1]) minMax[1] = tx;

if (ty < minMax[2]) minMax[2] = ty;
else if (ty > minMax[3]) minMax[3] = ty;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized the code is missing braces in a few places. The Google style guide for Java suggests that braces are used even if there's only a single statement: https://google.github.io/styleguide/javaguide.html#s4.1.1-braces-always-used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All missing braces should be added now. Does the updated code look good to you?

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants