diff options
author | Douglas Sigelbaum <sigelbaum@google.com> | 2017-05-16 19:27:54 -0700 |
---|---|---|
committer | Douglas Sigelbaum <sigelbaum@google.com> | 2017-05-16 20:48:59 -0700 |
commit | da8a32010a16096f7efd32b117bd487d06393b2c (patch) | |
tree | 3378d119762a3f58a682c423951af7e912fb447c /input | |
parent | 3c27c881a4d14b22a55304cd096414df76ab5aef (diff) | |
download | android-da8a32010a16096f7efd32b117bd487d06393b2c.tar.gz |
Fixed autofill for VirtualLoginActivity:
- Added autofill hints and types to custom virtual view.
- Fixed view focus.
Bug: 38182790
Test: manual
Change-Id: I82e3d9ec1af77cce92d2f2a6080a9ebcdc71129f
Diffstat (limited to 'input')
-rw-r--r-- | input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/app/CustomVirtualView.java | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/app/CustomVirtualView.java b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/app/CustomVirtualView.java index 61197efe..085f827c 100644 --- a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/app/CustomVirtualView.java +++ b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/app/CustomVirtualView.java @@ -84,9 +84,9 @@ public class CustomVirtualView extends View { mLineLength = mTextHeight + mVerticalGap; mTextPaint.setTextSize(mTextHeight); mUsernameLine = addLine("usernameField", context.getString(R.string.username_label), - " ", true); + new String[] {View.AUTOFILL_HINT_USERNAME}, " ", true); mPasswordLine = addLine("passwordField", context.getString(R.string.password_label), - " ", false); + new String[] {View.AUTOFILL_HINT_PASSWORD}, " ", false); Log.d(TAG, "Text height: " + mTextHeight); } @@ -127,10 +127,12 @@ public class CustomVirtualView extends View { Log.d(TAG, "Adding new child at index " + index + ": " + item); ViewStructure child = structure.newChild(index); child.setAutofillId(structure, item.id); + child.setAutofillHints(item.hints); + child.setAutofillType(item.type); child.setDataIsSensitive(!item.sanitized); child.setText(item.text); child.setAutofillValue(AutofillValue.forText(item.text)); - child.setFocused(item.line.focused); + child.setFocused(item.focused); child.setId(item.id, getContext().getPackageName(), null, item.line.idEntry); child.setClassName(item.getClassName()); index++; @@ -148,7 +150,7 @@ public class CustomVirtualView extends View { x = mLeftMargin; Line line = mLines.get(i); Log.v(TAG, "Drawing '" + line + "' at " + x + "x" + y); - mTextPaint.setColor(line.focused ? mFocusedColor : mUnfocusedColor); + mTextPaint.setColor(line.fieldTextItem.focused ? mFocusedColor : mUnfocusedColor); String readOnlyText = line.labelItem.text + ": ["; String writeText = line.fieldTextItem.text + "]"; // Paints the label first... @@ -204,8 +206,8 @@ public class CustomVirtualView extends View { postInvalidate(); } - private Line addLine(String idEntry, String label, String text, boolean sanitized) { - Line line = new Line(idEntry, label, text, sanitized); + private Line addLine(String idEntry, String label, String[] hints, String text, boolean sanitized) { + Line line = new Line(idEntry, label, hints, text, sanitized); mLines.add(line); mItems.put(line.labelItem.id, line.labelItem); mItems.put(line.fieldTextItem.id, line.fieldTextItem); @@ -217,14 +219,19 @@ public class CustomVirtualView extends View { private final int id; private final boolean editable; private final boolean sanitized; + private final String[] hints; + private final int type; private CharSequence text; + private boolean focused = false; - Item(Line line, int id, CharSequence text, boolean editable, boolean sanitized) { + Item(Line line, int id, String[] hints, int type, CharSequence text, boolean editable, boolean sanitized) { this.line = line; this.id = id; this.text = text; this.editable = editable; this.sanitized = sanitized; + this.hints = hints; + this.type = type; } @Override @@ -245,15 +252,15 @@ public class CustomVirtualView extends View { private Item labelItem; private Item fieldTextItem; private String idEntry; - private boolean focused; - private Line(String idEntry, String label, String text, boolean sanitized) { + private Line(String idEntry, String label, String[] hints, String text, boolean sanitized) { this.idEntry = idEntry; - this.labelItem = new Item(this, ++nextId, label, false, true); - this.fieldTextItem = new Item(this, ++nextId, text, true, sanitized); + this.labelItem = new Item(this, ++nextId, null, AUTOFILL_TYPE_NONE, label, false, true); + this.fieldTextItem = new Item(this, ++nextId, hints, AUTOFILL_TYPE_TEXT, text, true, sanitized); } void changeFocus(boolean focused) { + fieldTextItem.focused = focused; if (focused) { final Rect absBounds = getAbsCoordinates(); Log.d(TAG, "focus gained on " + fieldTextItem.id + "; absBounds=" + absBounds); @@ -282,7 +289,8 @@ public class CustomVirtualView extends View { @Override public String toString() { - return "Label: " + labelItem + " Text: " + fieldTextItem + " Focused: " + focused; + return "Label: " + labelItem + " Text: " + fieldTextItem + " Focused: " + + fieldTextItem.focused; } } }
\ No newline at end of file |