}
public static class CharSequenceTransformation.Builder {
- ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
- method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
+ ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
+ method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
method public android.service.autofill.CharSequenceTransformation build();
}
}
public static class ImageTransformation.Builder {
- ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, int);
- method public android.service.autofill.ImageTransformation.Builder addOption(java.lang.String, int);
+ ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, int);
+ method public android.service.autofill.ImageTransformation.Builder addOption(java.util.regex.Pattern, int);
method public android.service.autofill.ImageTransformation build();
}
}
public final class SimpleRegexValidator implements android.os.Parcelable android.service.autofill.Validator {
- ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.lang.String);
+ ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.util.regex.Pattern);
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.service.autofill.SimpleRegexValidator> CREATOR;
}
public static class CharSequenceTransformation.Builder {
- ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
- method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
+ ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
+ method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
method public android.service.autofill.CharSequenceTransformation build();
}
}
public static class ImageTransformation.Builder {
- ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, int);
- method public android.service.autofill.ImageTransformation.Builder addOption(java.lang.String, int);
+ ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, int);
+ method public android.service.autofill.ImageTransformation.Builder addOption(java.util.regex.Pattern, int);
method public android.service.autofill.ImageTransformation build();
}
}
public final class SimpleRegexValidator implements android.os.Parcelable android.service.autofill.Validator {
- ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.lang.String);
+ ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.util.regex.Pattern);
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.service.autofill.SimpleRegexValidator> CREATOR;
}
public static class CharSequenceTransformation.Builder {
- ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
- method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
+ ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
+ method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
method public android.service.autofill.CharSequenceTransformation build();
}
}
public static class ImageTransformation.Builder {
- ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, int);
- method public android.service.autofill.ImageTransformation.Builder addOption(java.lang.String, int);
+ ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, int);
+ method public android.service.autofill.ImageTransformation.Builder addOption(java.util.regex.Pattern, int);
method public android.service.autofill.ImageTransformation build();
}
}
public final class SimpleRegexValidator implements android.os.Parcelable android.service.autofill.Validator {
- ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.lang.String);
+ ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.util.regex.Pattern);
method public int describeContents();
method public boolean isValid(android.service.autofill.ValueFinder);
method public void writeToParcel(android.os.Parcel, int);
* be:
*
* <pre class="prettyprint">
- * new CharSequenceTransformation.Builder(ccNumberId, "^.*(\\d\\d\\d\\d)$", "...$1").build();
+ * new CharSequenceTransformation
+ * .Builder(ccNumberId, Pattern.compile("^.*(\\d\\d\\d\\d)$"), "...$1")
+ * .build();
* </pre>
*
* <p>But a transformation that generates a {@code Exp: MM / YYYY} credit expiration date from two
* fields (month and year) would be:
*
* <pre class="prettyprint">
- * new CharSequenceTransformation.Builder(ccExpMonthId, "^(\\d\\d)$", "Exp: $1")
- * .addField(ccExpYearId, "^(\\d\\d\\d\\d)$", " / $1");
+ * new CharSequenceTransformation.Builder(ccExpMonthId, Pattern.compile("^(\\d\\d)$"), "Exp: $1")
+ * .addField(ccExpYearId, Pattern.compile("^(\\d\\d\\d\\d)$"), " / $1");
* </pre>
*/
public final class CharSequenceTransformation extends InternalTransformation implements
*
* @param id id of the screen field.
* @param regex regular expression with groups (delimited by {@code (} and {@code (}) that
- * are used to substitute parts of the value. The pattern will be {@link Pattern#compile
- * compiled} without setting any flags.
+ * are used to substitute parts of the value.
* @param subst the string that substitutes the matched regex, using {@code $} for
* group substitution ({@code $1} for 1st group match, {@code $2} for 2nd, etc).
*/
- public Builder(@NonNull AutofillId id, @NonNull String regex, @NonNull String subst) {
+ public Builder(@NonNull AutofillId id, @NonNull Pattern regex, @NonNull String subst) {
addField(id, regex, subst);
}
*
* @param id id of the screen field.
* @param regex regular expression with groups (delimited by {@code (} and {@code (}) that
- * are used to substitute parts of the value. The pattern will be {@link Pattern#compile
- * compiled} without setting any flags.
+ * are used to substitute parts of the value.
* @param subst the string that substitutes the matched regex, using {@code $} for
* group substitution ({@code $1} for 1st group match, {@code $2} for 2nd, etc).
*
* @return this builder.
*/
- public Builder addField(@NonNull AutofillId id, @NonNull String regex,
+ public Builder addField(@NonNull AutofillId id, @NonNull Pattern regex,
@NonNull String subst) {
throwIfDestroyed();
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(regex);
Preconditions.checkNotNull(subst);
- // Check if the regex is valid
- Pattern pattern = Pattern.compile(regex);
-
- mFields.put(id, new Pair<>(pattern, subst));
+ mFields.put(id, new Pair<>(regex, subst));
return this;
}
public void writeToParcel(Parcel parcel, int flags) {
final int size = mFields.size();
final AutofillId[] ids = new AutofillId[size];
- final String[] regexs = new String[size];
+ final Pattern[] regexs = new Pattern[size];
final String[] substs = new String[size];
Pair<Pattern, String> pair;
for (int i = 0; i < size; i++) {
ids[i] = mFields.keyAt(i);
pair = mFields.valueAt(i);
- regexs[i] = pair.first.pattern();
+ regexs[i] = pair.first;
substs[i] = pair.second;
}
parcel.writeParcelableArray(ids, flags);
- parcel.writeStringArray(regexs);
+ parcel.writeSerializable(regexs);
parcel.writeStringArray(substs);
}
@Override
public CharSequenceTransformation createFromParcel(Parcel parcel) {
final AutofillId[] ids = parcel.readParcelableArray(null, AutofillId.class);
- final String[] regexs = parcel.createStringArray();
+ final Pattern[] regexs = (Pattern[]) parcel.readSerializable();
final String[] substs = parcel.createStringArray();
// Always go through the builder to ensure the data ingested by
* <p>Typically used to display credit card logos. Example:
*
* <pre class="prettyprint">
- * new ImageTransformation.Builder(ccNumberId, "^4815.*$", R.drawable.ic_credit_card_logo1)
- * .addOption("^1623.*$", R.drawable.ic_credit_card_logo2)
- * .addOption("^42.*$", R.drawable.ic_credit_card_logo3)
+ * new ImageTransformation.Builder(ccNumberId, Pattern.compile("^4815.*$"),
+ * R.drawable.ic_credit_card_logo1)
+ * .addOption(Pattern.compile("^1623.*$"), R.drawable.ic_credit_card_logo2)
+ * .addOption(Pattern.compile("^42.*$"), R.drawable.ic_credit_card_logo3)
* .build();
* </pre>
*
*
* @param id id of the screen field that will be used to evaluate whether the image should
* be used.
- * @param regex regular expression defining what should be matched to use this image. The
- * pattern will be {@link Pattern#compile compiled} without setting any flags.
+ * @param regex regular expression defining what should be matched to use this image.
* @param resId resource id of the image (in the autofill service's package). The
* {@link RemoteViews presentation} must contain a {@link ImageView} child with that id.
*/
- public Builder(@NonNull AutofillId id, @NonNull String regex, @DrawableRes int resId) {
+ public Builder(@NonNull AutofillId id, @NonNull Pattern regex, @DrawableRes int resId) {
mId = Preconditions.checkNotNull(id);
addOption(regex, resId);
/**
* Adds an option to replace the child view with a different image when the regex matches.
*
- * @param regex regular expression defining what should be matched to use this image. The
- * pattern will be {@link Pattern#compile compiled} without setting any flags.
+ * @param regex regular expression defining what should be matched to use this image.
* @param resId resource id of the image (in the autofill service's package). The
* {@link RemoteViews presentation} must contain a {@link ImageView} child with that id.
*
* @return this build
*/
- public Builder addOption(@NonNull String regex, @DrawableRes int resId) {
+ public Builder addOption(@NonNull Pattern regex, @DrawableRes int resId) {
throwIfDestroyed();
+ Preconditions.checkNotNull(regex);
Preconditions.checkArgument(resId != 0);
- // Check regex
- Pattern pattern = Pattern.compile(regex);
-
- mOptions.add(new Pair<>(pattern, resId));
+ mOptions.add(new Pair<>(regex, resId));
return this;
}
/**
* Creates a new {@link ImageTransformation} instance.
- *
- * @throws IllegalStateException if no call to {@link #addOption(String, int)} was made.
*/
public ImageTransformation build() {
throwIfDestroyed();
- Preconditions.checkState(mOptions != null && !mOptions.isEmpty(),
- "Must add at least one option");
mDestroyed = true;
return new ImageTransformation(this);
}
parcel.writeParcelable(mId, flags);
final int size = mOptions.size();
- final String[] regexs = new String[size];
+ final Pattern[] regexs = new Pattern[size];
final int[] resIds = new int[size];
for (int i = 0; i < size; i++) {
Pair<Pattern, Integer> regex = mOptions.get(i);
- regexs[i] = regex.first.pattern();
+ regexs[i] = regex.first;
resIds[i] = regex.second;
}
- parcel.writeStringArray(regexs);
+ parcel.writeSerializable(regexs);
parcel.writeIntArray(resIds);
}
public ImageTransformation createFromParcel(Parcel parcel) {
final AutofillId id = parcel.readParcelable(null);
- final String[] regexs = parcel.createStringArray();
+ final Pattern[] regexs = (Pattern[]) parcel.readSerializable();
final int[] resIds = parcel.createIntArray();
// Always go through the builder to ensure the data ingested by the system obeys the
* @param id id of the field whose regex is applied to.
* @param regex regular expression that defines the result of the validator: if the regex
* matches the contents of the field identified by {@code id}, it returns {@code true};
- * otherwise, it returns {@code false}. The pattern will be {@link Pattern#compile compiled}
- * without setting any flags.
+ * otherwise, it returns {@code false}.
*/
- public SimpleRegexValidator(@NonNull AutofillId id, @NonNull String regex) {
+ public SimpleRegexValidator(@NonNull AutofillId id, @NonNull Pattern regex) {
mId = Preconditions.checkNotNull(id);
- mRegex = Pattern.compile(regex);
+ mRegex = Preconditions.checkNotNull(regex);
}
/** @hide */
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeParcelable(mId, flags);
- parcel.writeString(mRegex.pattern());
+ parcel.writeSerializable(mRegex);
}
public static final Parcelable.Creator<SimpleRegexValidator> CREATOR =
new Parcelable.Creator<SimpleRegexValidator>() {
@Override
public SimpleRegexValidator createFromParcel(Parcel parcel) {
- return new SimpleRegexValidator(parcel.readParcelable(null), parcel.readString());
+ return new SimpleRegexValidator(parcel.readParcelable(null),
+ (Pattern) parcel.readSerializable());
}
@Override