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

[WIP] Added autofill functionality #16227

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -286,7 +286,8 @@ public static Configuration fromJson(@NonNull JSONObject json) throws JSONExcept
TextCapitalization.fromValue(json.getString("textCapitalization")),
InputType.fromJson(json.getJSONObject("inputType")),
inputAction,
json.isNull("actionLabel") ? null : json.getString("actionLabel")
json.isNull("actionLabel") ? null : json.getString("actionLabel"),
json.isNull("textContentType") ? null : TextContentType.fromValue(json.getString("textContentType"))
);
}

Expand Down Expand Up @@ -328,6 +329,8 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio
public final Integer inputAction;
@Nullable
public final String actionLabel;
@Nullable
public final TextContentType textContentType;

public Configuration(
boolean obscureText,
Expand All @@ -336,7 +339,8 @@ public Configuration(
@NonNull TextCapitalization textCapitalization,
@NonNull InputType inputType,
@Nullable Integer inputAction,
@Nullable String actionLabel
@Nullable String actionLabel,
@Nullable TextContentType textContentType
) {
this.obscureText = obscureText;
this.autocorrect = autocorrect;
Expand All @@ -345,6 +349,7 @@ public Configuration(
this.inputType = inputType;
this.inputAction = inputAction;
this.actionLabel = actionLabel;
this.textContentType = textContentType;
}
}

Expand Down Expand Up @@ -406,6 +411,95 @@ static TextInputType fromValue(@NonNull String encodedName) throws NoSuchFieldEx
}
}

/**
* Types of text content for auto-full functionality
ganttastic marked this conversation as resolved.
Show resolved Hide resolved
*/
public enum TextContentType {
NAME("TextContentType.name"),
NAME_PREFIX("TextContentType.namePrefix"),
GIVEN_NAME("TextContentType.givenName"),
MIDDLE_NAME("TextContentType.middleName"),
FAMILY_NAME("TextContentType.familyName"),
NAME_SUFFIX("TextContentType.nameSuffix"),
FULL_STREET_ADDRESS("TextContentType.fullStreetAddress"),
ADDRESS_LINE_1("TextContentType.addressLine1"),
ADDRESS_LINE_2("TextContentType.addressLine2"),
ADDRESS_CITY("TextContentType.addressCity"),
ADDRESS_STATE("TextContentType.addressState"),
COUNTRY_NAME("TextContentType.countryName"),
POSTAL_CODE("TextContentType.postalCode"),
TELEPHONE_NUMBER("TextContentType.telephoneNumber"),
EMAIL_ADDRESS("TextContentType.emailAddress"),
CREDIT_CARD_NUMBER("TextContentType.creditCardNumber"),
USERNAME("TextContentType.username"),
PASSWORD("TextContentType.password"),
NEW_PASSWORD("TextContentType.newPassword"),
ONE_TIME_CODE("TextContentType.oneTimeCode");

static TextContentType fromValue(@NonNull String encodedName) throws NoSuchFieldException {
for (TextContentType textContentType : TextContentType.values()) {
if (textContentType.encodedName.equals(encodedName)) {
return textContentType;
}
}
throw new NoSuchFieldException("No such TextContentType: " + encodedName);
}

@NonNull
private final String encodedName;

TextContentType(@NonNull String encodedName) {
this.encodedName = encodedName;
}

public String hintConstantValue() {
switch (this) {
case NAME:
return "personName";
case NAME_PREFIX:
return "personNamePrefix";
case GIVEN_NAME:
return "personGivenName";
case MIDDLE_NAME:
return "personMiddleName";
case FAMILY_NAME:
return "personFamilyName";
case NAME_SUFFIX:
return "personNameSuffix";
case FULL_STREET_ADDRESS:
return "postalAddress";
case ADDRESS_LINE_1:
return "streetAddress";
case ADDRESS_LINE_2:
return "extendedAddress";
case ADDRESS_CITY:
return "addressLocality";
case ADDRESS_STATE:
return "addressRegion";
case COUNTRY_NAME:
return "addressCountry";
case POSTAL_CODE:
return "postalCode";
case TELEPHONE_NUMBER:
return "phoneNumber";
case EMAIL_ADDRESS:
return "emailAddress";
case CREDIT_CARD_NUMBER:
return "creditCardNumber";
case USERNAME:
return "username";
case PASSWORD:
return "password";
case NEW_PASSWORD:
return "newPassword";
case ONE_TIME_CODE:
return "smsOTPCode";
}

return null;
}
}

/**
* Text capitalization schemes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ public InputConnection createInputConnection(View view, EditorInfo outAttrs) {
outAttrs.actionId = enterAction;
}
outAttrs.imeOptions |= enterAction;

String autofillHintValue = configuration.textContentType.hintConstantValue();
if (autofillHintValue != null) {
String[] autofillHints = {autofillHintValue};
view.setAutofillHints(autofillHints);
Copy link
Author

Choose a reason for hiding this comment

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

Unsure if this is the correct view to set the auto fill hints on.

}

InputConnectionAdaptor connection = new InputConnectionAdaptor(
view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,14 @@ static UITextContentType ToUITextContentType(NSDictionary* type) API_AVAILABLE(i
return UITextContentTypeName;
if ([contentType isEqualToString:@"TextContentType.namePrefix"])
return UITextContentTypeNamePrefix;
if ([contentType isEqualToString:@"TextContentType.givenName"])
return UITextContentTypeGivenName;
if ([contentType isEqualToString:@"TextContentType.middleName"])
return UITextContentTypeMiddleName;
if ([contentType isEqualToString:@"TextContentType.familyName"])
return UITextContentTypeFamilyName;
if ([contentType isEqualToString:@"TextContentType.nameSuffix"])
return UITextContentTypeNameSuffix;
if ([contentType isEqualToString:@"TextContentType.nickname"])
return UITextContentTypeNickname;
if ([contentType isEqualToString:@"TextContentType.jobTitle"])
return UITextContentTypeJobTitle;
if ([contentType isEqualToString:@"TextContentType.organizationName"])
return UITextContentTypeOrganizationName;
if ([contentType isEqualToString:@"TextContentType.location"])
return UITextContentTypeLocation;
if ([contentType isEqualToString:@"TextContentType.fullStreetAddress"])
return UITextContentTypeFullStreetAddress;
if ([contentType isEqualToString:@"TextContentType.addressLine1"])
Expand All @@ -76,10 +70,6 @@ static UITextContentType ToUITextContentType(NSDictionary* type) API_AVAILABLE(i
return UITextContentTypeAddressCity;
if ([contentType isEqualToString:@"TextContentType.addressState"])
return UITextContentTypeAddressState;
if ([contentType isEqualToString:@"TextContentType.addressCityAndState"])
return UITextContentTypeAddressCityAndState;
if ([contentType isEqualToString:@"TextContentType.sublocality"])
return UITextContentTypeSublocality;
if ([contentType isEqualToString:@"TextContentType.countryName"])
return UITextContentTypeCountryName;
if ([contentType isEqualToString:@"TextContentType.postalCode"])
Expand Down