Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 305b72c9 authored by Felipe Leme's avatar Felipe Leme
Browse files

Added auto-fill support for DatePicker and TimePicker.

Also fixed some getAutoFillType() implementations to return null
when the view is disabled.

Bug: 33550221
Bug: 35840787
Test: CtsAutoFillServiceTestCases (with new tests) pass
Test: m update-api

Change-Id: I46acc1fb106cf2153515cc1c9567b34cfabd1c62
parent f561734e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -47095,10 +47095,12 @@ package android.view.autofill {
  public final class AutoFillType implements android.os.Parcelable {
    method public int describeContents();
    method public static android.view.autofill.AutoFillType forDate();
    method public static android.view.autofill.AutoFillType forList();
    method public static android.view.autofill.AutoFillType forText(int);
    method public static android.view.autofill.AutoFillType forToggle();
    method public int getSubType();
    method public boolean isDate();
    method public boolean isList();
    method public boolean isText();
    method public boolean isToggle();
@@ -47108,9 +47110,11 @@ package android.view.autofill {
  public final class AutoFillValue implements android.os.Parcelable {
    method public int describeContents();
    method public static android.view.autofill.AutoFillValue forDate(long);
    method public static android.view.autofill.AutoFillValue forList(int);
    method public static android.view.autofill.AutoFillValue forText(java.lang.CharSequence);
    method public static android.view.autofill.AutoFillValue forToggle(boolean);
    method public long getDateValue();
    method public int getListValue();
    method public java.lang.CharSequence getTextValue();
    method public boolean getToggleValue();
+4 −0
Original line number Diff line number Diff line
@@ -50443,10 +50443,12 @@ package android.view.autofill {
  public final class AutoFillType implements android.os.Parcelable {
    method public int describeContents();
    method public static android.view.autofill.AutoFillType forDate();
    method public static android.view.autofill.AutoFillType forList();
    method public static android.view.autofill.AutoFillType forText(int);
    method public static android.view.autofill.AutoFillType forToggle();
    method public int getSubType();
    method public boolean isDate();
    method public boolean isList();
    method public boolean isText();
    method public boolean isToggle();
@@ -50456,9 +50458,11 @@ package android.view.autofill {
  public final class AutoFillValue implements android.os.Parcelable {
    method public int describeContents();
    method public static android.view.autofill.AutoFillValue forDate(long);
    method public static android.view.autofill.AutoFillValue forList(int);
    method public static android.view.autofill.AutoFillValue forText(java.lang.CharSequence);
    method public static android.view.autofill.AutoFillValue forToggle(boolean);
    method public long getDateValue();
    method public int getListValue();
    method public java.lang.CharSequence getTextValue();
    method public boolean getToggleValue();
+4 −0
Original line number Diff line number Diff line
@@ -47459,10 +47459,12 @@ package android.view.autofill {
  public final class AutoFillType implements android.os.Parcelable {
    method public int describeContents();
    method public static android.view.autofill.AutoFillType forDate();
    method public static android.view.autofill.AutoFillType forList();
    method public static android.view.autofill.AutoFillType forText(int);
    method public static android.view.autofill.AutoFillType forToggle();
    method public int getSubType();
    method public boolean isDate();
    method public boolean isList();
    method public boolean isText();
    method public boolean isToggle();
@@ -47472,9 +47474,11 @@ package android.view.autofill {
  public final class AutoFillValue implements android.os.Parcelable {
    method public int describeContents();
    method public static android.view.autofill.AutoFillValue forDate(long);
    method public static android.view.autofill.AutoFillValue forList(int);
    method public static android.view.autofill.AutoFillValue forText(java.lang.CharSequence);
    method public static android.view.autofill.AutoFillValue forToggle(boolean);
    method public long getDateValue();
    method public int getListValue();
    method public java.lang.CharSequence getTextValue();
    method public boolean getToggleValue();
+28 −10
Original line number Diff line number Diff line
@@ -40,18 +40,13 @@ public final class AutoFillType implements Parcelable {
    private static class DefaultTypesHolder {
        static final AutoFillType TOGGLE = new AutoFillType(TYPE_TOGGLE, 0);
        static final AutoFillType LIST = new AutoFillType(TYPE_LIST, 0);
        static final AutoFillType DATE = new AutoFillType(TYPE_DATE, 0);
    }

    private static final int TYPE_TEXT = 1;
    private static final int TYPE_TOGGLE = 2;
    private static final int TYPE_LIST = 3;

    // TODO(b/33197203): add others, like date picker? That would be trick, because they're set as:
    // updateDate(int year, int month, int dayOfMonth)
    // So, we would have to either use a long representing the Date.time(), or a custom long
    // representing:
    // year * 10000 + month * 100 + day
    // Then a custom getDatePickerValue(Bundle) that returns an immutable object with these 3 fields
    private static final int TYPE_DATE = 4;

    private final int mType;
    private final int mSubType;
@@ -65,7 +60,7 @@ public final class AutoFillType implements Parcelable {
     * Checks if this is a type for a text field, which is filled by a {@link CharSequence}.
     *
     * <p>{@link AutoFillValue} instances for auto-filling a {@link View} can be obtained through
     * {@link AutoFillValue#forText(CharSequence)}, and the value of a bundle passed to auto-fill a
     * {@link AutoFillValue#forText(CharSequence)}, and the value passed to auto-fill a
     * {@link View} can be fetched through {@link AutoFillValue#getTextValue()}.
     *
     * <p>Sub-type for this type is the value defined by {@link TextView#getInputType()}.
@@ -78,7 +73,7 @@ public final class AutoFillType implements Parcelable {
     * Checks if this is a a type for a togglable field, which is filled by a {@code boolean}.
     *
     * <p>{@link AutoFillValue} instances for auto-filling a {@link View} can be obtained through
     * {@link AutoFillValue#forToggle(boolean)}, and the value of a bundle passed to auto-fill a
     * {@link AutoFillValue#forToggle(boolean)}, and the value passed to auto-fill a
     * {@link View} can be fetched through {@link AutoFillValue#getToggleValue()}.
     *
     * <p>This type has no sub-types.
@@ -92,7 +87,7 @@ public final class AutoFillType implements Parcelable {
     * representing the element index inside the list (starting at {@code 0}.
     *
     * <p>{@link AutoFillValue} instances for auto-filling a {@link View} can be obtained through
     * {@link AutoFillValue#forList(int)}, and the value of a bundle passed to auto-fill a
     * {@link AutoFillValue#forList(int)}, and the value passed to auto-fill a
     * {@link View} can be fetched through {@link AutoFillValue#getListValue()}.
     *
     * <p>This type has no sub-types.
@@ -101,6 +96,20 @@ public final class AutoFillType implements Parcelable {
        return mType == TYPE_LIST;
    }

    /**
     * Checks if this is a type for a date and time, which is represented by a long representing
     * the number of milliseconds since the standard base time known as "the epoch", namely
     * January 1, 1970, 00:00:00 GMT (see {@link java.util.Date#getTime()}.
     *
     * <p>{@link AutoFillValue} instances for auto-filling a {@link View} can be obtained through
     * {@link AutoFillValue#forDate(long)}, and the values passed to
     * auto-fill a {@link View} can be fetched through {@link AutoFillValue#getDateValue()}.
     *
     * <p>This type has no sub-types.
     */
    public boolean isDate() {
        return mType == TYPE_DATE;
    }

    /**
     * Gets the optional sub-type, representing the {@link View}'s semantic.
@@ -206,4 +215,13 @@ public final class AutoFillType implements Parcelable {
    public static AutoFillType forList() {
        return DefaultTypesHolder.LIST;
    }

    /**
     * Creates a type that represents a date.
     *
     * <p>See {@link #isDate()} for more info.
     */
    public static AutoFillType forDate() {
        return DefaultTypesHolder.DATE;
    }
}
+38 −10
Original line number Diff line number Diff line
@@ -35,11 +35,13 @@ public final class AutoFillValue implements Parcelable {
    private final String mText;
    private final int mListIndex;
    private final boolean mToggle;
    private final long mDate;

    private AutoFillValue(CharSequence text, int listIndex, boolean toggle) {
    private AutoFillValue(CharSequence text, int listIndex, boolean toggle, long date) {
        mText = (text == null) ? null : text.toString();
        mListIndex = listIndex;
        mToggle = toggle;
        mDate = date;
    }

    /**
@@ -69,6 +71,17 @@ public final class AutoFillValue implements Parcelable {
        return mListIndex;
    }

    /**
     * Gets the value representing the the number of milliseconds since the standard base time known
     * as "the epoch", namely January 1, 1970, 00:00:00 GMT (see {@link java.util.Date#getTime()}
     * of a date field.
     *
     * <p>See {@link AutoFillType#isDate()} for more info.
     */
    public long getDateValue() {
        return mDate;
    }

    /////////////////////////////////////
    //  Object "contract" methods. //
    /////////////////////////////////////
@@ -77,9 +90,10 @@ public final class AutoFillValue implements Parcelable {
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + mListIndex;
        result = prime * result + ((mText == null) ? 0 : mText.hashCode());
        result = prime * result + mListIndex;
        result = prime * result + (mToggle ? 1231 : 1237);
        result = prime * result + (int) (mDate ^ (mDate >>> 32));
        return result;
    }

@@ -89,13 +103,14 @@ public final class AutoFillValue implements Parcelable {
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        final AutoFillValue other = (AutoFillValue) obj;
        if (mListIndex != other.mListIndex) return false;
        if (mText == null) {
            if (other.mText != null) return false;
        } else {
            if (!mText.equals(other.mText)) return false;
        }
        if (mListIndex != other.mListIndex) return false;
        if (mToggle != other.mToggle) return false;
        if (mDate != other.mDate) return false;
        return true;
    }

@@ -113,7 +128,7 @@ public final class AutoFillValue implements Parcelable {
            return mText.length() + "_chars";
        }

        return "[listIndex=" + mListIndex + ", toggle=" + mToggle + "]";
        return "[l=" + mListIndex + ", t=" + mToggle + ", d=" + mDate + "]";
    }

    /////////////////////////////////////
@@ -130,12 +145,14 @@ public final class AutoFillValue implements Parcelable {
        parcel.writeString(mText);
        parcel.writeInt(mListIndex);
        parcel.writeInt(mToggle ? 1 : 0);
        parcel.writeLong(mDate);
    }

    private AutoFillValue(Parcel parcel) {
        mText = parcel.readString();
        mListIndex = parcel.readInt();
        mToggle = parcel.readInt() == 1;
        mDate = parcel.readLong();
    }

    public static final Parcelable.Creator<AutoFillValue> CREATOR =
@@ -157,31 +174,42 @@ public final class AutoFillValue implements Parcelable {

    // TODO(b/33197203): add unit tests for each supported type (new / get should return same value)
    /**
     * Creates a new {@link AutoFillValue} to auto-fill a text field.
     * Creates a new {@link AutoFillValue} to auto-fill a {@link View} representing a text field.
     *
     * <p>See {@link AutoFillType#isText()} for more info.
     */
    // TODO(b/33197203): use cache
    @Nullable
    public static AutoFillValue forText(@Nullable CharSequence value) {
        return value == null ? null : new AutoFillValue(value, 0, false);
        return value == null ? null : new AutoFillValue(value, 0, false, 0);
    }

    /**
     * Creates a new {@link AutoFillValue} to auto-fill a toggable field.
     * Creates a new {@link AutoFillValue} to auto-fill a {@link View} representing a toggable
     * field.
     *
     * <p>See {@link AutoFillType#isToggle()} for more info.
     */
    public static AutoFillValue forToggle(boolean value) {
        return new AutoFillValue(null, 0, value);
        return new AutoFillValue(null, 0, value, 0);
    }

    /**
     * Creates a new {@link AutoFillValue} to auto-fill a selection list field.
     * Creates a new {@link AutoFillValue} to auto-fill a {@link View} representing a selection
     * list.
     *
     * <p>See {@link AutoFillType#isList()} for more info.
     */
    public static AutoFillValue forList(int value) {
        return new AutoFillValue(null, value, false);
        return new AutoFillValue(null, value, false, 0);
    }

    /**
     * Creates a new {@link AutoFillValue} to auto-fill a {@link View} representing a date.
     *
     * <p>See {@link AutoFillType#isDate()} for more info.
     */
    public static AutoFillValue forDate(long date) {
        return new AutoFillValue(null, 0, false, date);
    }
}
Loading