summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-02-23 05:57:17 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-02-23 05:57:21 +0000
commit30172869a7cb74abd1544b808b7e8cdb89e3f0ed (patch)
treeb4ebe0b84b078846204e1b7c1f19d5f560009e17
parent4f911e1c5a733310d3e84eabfb81c20880c680cf (diff)
parent576a847e03f213693f4e7f2f0361f52217f9e1cf (diff)
Merge "Don't trigger auto-fill request if mode is manual"
-rw-r--r--core/java/android/view/View.java39
-rw-r--r--core/java/android/view/ViewParent.java13
-rw-r--r--core/res/res/values/attrs.xml6
3 files changed, 53 insertions, 5 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index aa85a985155b..e7838a7521e0 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -953,7 +953,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
public @interface AutoFillMode {}
/**
- * This view inherits the autofill state from it's parent. If there is no parent it is
+ * This view inherits the auto-fill state from it's parent. If there is no parent it is
* {@link #AUTO_FILL_MODE_AUTO}.
* Use with {@link #setAutoFillMode(int)} and <a href="#attr_android:autoFillMode">
* {@code android:autoFillMode}.
@@ -968,7 +968,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
public static final int AUTO_FILL_MODE_AUTO = 1;
/**
- * Require the user to manually force an auto-fill request.
+ * Do not trigger an auto-fill request if this view is focused. The user can still force
+ * an auto-fill request.
+ * <p>This does not prevent this field from being auto-filled if an auto-fill operation is
+ * triggered from a different view.</p>
+ *
* Use with {@link #setAutoFillMode(int)} and <a href="#attr_android:autoFillMode">{@code
* android:autoFillMode}.
*/
@@ -6523,7 +6527,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
if (isAutoFillable()) {
AutoFillManager afm = getAutoFillManager();
if (afm != null) {
- afm.focusChanged(this, gainFocus);
+ boolean adjGainFocus = gainFocus;
+ if (adjGainFocus && getResolvedAutoFillMode() == AUTO_FILL_MODE_MANUAL) {
+ adjGainFocus = false;
+ }
+
+ afm.focusChanged(this, adjGainFocus);
}
}
@@ -9303,6 +9312,30 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
+ * Returns the resolved auto-fill mode for this view.
+ *
+ * This is the same as {@link #getAutoFillMode()} but if the mode is
+ * {@link #AUTO_FILL_MODE_INHERIT} the parents auto-fill mode will be returned.
+ *
+ * @return One of {@link #AUTO_FILL_MODE_AUTO}, or {@link #AUTO_FILL_MODE_MANUAL}.
+ *
+ * @hide
+ */
+ public @AutoFillMode int getResolvedAutoFillMode() {
+ @AutoFillMode int autoFillMode = getAutoFillMode();
+
+ if (autoFillMode == AUTO_FILL_MODE_INHERIT) {
+ if (mParent == null) {
+ throw new IllegalStateException("View is detached, cannot resolve autoFillMode");
+ } else {
+ return mParent.getResolvedAutoFillMode();
+ }
+ } else {
+ return autoFillMode;
+ }
+ }
+
+ /**
* Find the nearest view in the specified direction that can take focus.
* This does not actually give focus to that view.
*
diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java
index cc11cb8205d5..cdfd61bee083 100644
--- a/core/java/android/view/ViewParent.java
+++ b/core/java/android/view/ViewParent.java
@@ -659,4 +659,17 @@ public interface ViewParent {
* @return true if the action was consumed by this ViewParent
*/
public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle arguments);
+
+ /**
+ * Return the resolved auto-fill mode.
+ *
+ * @return The resolved auto-fill mode
+ *
+ * @see View#getResolvedAutoFillMode()
+ *
+ * @hide
+ */
+ default @View.AutoFillMode int getResolvedAutoFillMode() {
+ return View.AUTO_FILL_MODE_AUTO;
+ }
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 8031f1934088..d2d6620cd56c 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2289,12 +2289,14 @@
<!-- Controls the auto-fill behavior for this view -->
<attr name="autoFillMode">
- <!-- Inherit the behavior from the parent. If there is no parent it is auto. -->
+ <!-- Inherit the behavior from the parent. If there is no parent it is auto. This is the
+ default value for this attribute.-->
<enum name="inherit" value="0" />
<!-- Allows this view to automatically trigger an auto-fill request when it get focus.
-->
<enum name="auto" value="1" />
- <!-- The user has to manually force an auto-fill request for this view. -->
+ <!-- Do not trigger an auto-fill request when this view is focused. The user can still
+ manually force an auto-fill request for this view. -->
<enum name="manual" value="2" />
</attr>