summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-03-04 06:57:21 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-03-04 06:57:25 +0000
commit3056c61155ef2ba18c6f90e98e3bad08859d49f9 (patch)
tree3ff2193302fc726b662b65abc9c34fa6b84046f4
parent3c64ca7d95c8a5ffb70e254cd767e27118644d2f (diff)
parent4461181f4b987a40d65853df594df088ff501259 (diff)
Merge "Don't run autoFill on detached view or mode=manual"
-rw-r--r--api/current.txt8
-rw-r--r--api/system-current.txt8
-rw-r--r--api/test-current.txt8
-rw-r--r--core/java/android/view/View.java72
-rw-r--r--core/java/android/view/ViewParent.java13
-rw-r--r--core/java/android/view/autofill/AutoFillManager.java69
-rw-r--r--core/res/res/values/attrs.xml6
7 files changed, 146 insertions, 38 deletions
diff --git a/api/current.txt b/api/current.txt
index 3d2b92419869..6685c1ed9eb9 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -44918,6 +44918,7 @@ package android.view {
method public float getPivotX();
method public float getPivotY();
method public android.view.PointerIcon getPointerIcon();
+ method public int getResolvedAutoFillMode();
method public android.content.res.Resources getResources();
method public final boolean getRevealOnFocusHint();
method public final int getRight();
@@ -45865,6 +45866,7 @@ package android.view {
method public abstract int getLayoutDirection();
method public abstract android.view.ViewParent getParent();
method public abstract android.view.ViewParent getParentForAccessibility();
+ method public default int getResolvedAutoFillMode();
method public abstract int getTextAlignment();
method public abstract int getTextDirection();
method public abstract deprecated void invalidateChild(android.view.View, android.graphics.Rect);
@@ -47215,10 +47217,12 @@ package android.view.autofill {
}
public final class AutoFillManager {
- method public void focusChanged(android.view.View, boolean);
method public void reset();
+ method public void startAutoFillRequest(android.view.View);
+ method public void startAutoFillRequestOnVirtualView(android.view.View, int, android.graphics.Rect);
+ method public void stopAutoFillRequest(android.view.View);
+ method public void stopAutoFillRequestOnVirtualView(android.view.View, int);
method public void valueChanged(android.view.View);
- method public void virtualFocusChanged(android.view.View, int, android.graphics.Rect, boolean);
method public void virtualValueChanged(android.view.View, int, android.view.autofill.AutoFillValue);
field public static final java.lang.String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
field public static final java.lang.String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
diff --git a/api/system-current.txt b/api/system-current.txt
index 9ce77a0b8a03..7c63e774e079 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -48306,6 +48306,7 @@ package android.view {
method public float getPivotX();
method public float getPivotY();
method public android.view.PointerIcon getPointerIcon();
+ method public int getResolvedAutoFillMode();
method public android.content.res.Resources getResources();
method public final boolean getRevealOnFocusHint();
method public final int getRight();
@@ -49253,6 +49254,7 @@ package android.view {
method public abstract int getLayoutDirection();
method public abstract android.view.ViewParent getParent();
method public abstract android.view.ViewParent getParentForAccessibility();
+ method public default int getResolvedAutoFillMode();
method public abstract int getTextAlignment();
method public abstract int getTextDirection();
method public abstract deprecated void invalidateChild(android.view.View, android.graphics.Rect);
@@ -50606,10 +50608,12 @@ package android.view.autofill {
}
public final class AutoFillManager {
- method public void focusChanged(android.view.View, boolean);
method public void reset();
+ method public void startAutoFillRequest(android.view.View);
+ method public void startAutoFillRequestOnVirtualView(android.view.View, int, android.graphics.Rect);
+ method public void stopAutoFillRequest(android.view.View);
+ method public void stopAutoFillRequestOnVirtualView(android.view.View, int);
method public void valueChanged(android.view.View);
- method public void virtualFocusChanged(android.view.View, int, android.graphics.Rect, boolean);
method public void virtualValueChanged(android.view.View, int, android.view.autofill.AutoFillValue);
field public static final java.lang.String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
field public static final java.lang.String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
diff --git a/api/test-current.txt b/api/test-current.txt
index f1e912521e90..dd4d5358fcab 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -45274,6 +45274,7 @@ package android.view {
method public float getPivotX();
method public float getPivotY();
method public android.view.PointerIcon getPointerIcon();
+ method public int getResolvedAutoFillMode();
method public android.content.res.Resources getResources();
method public final boolean getRevealOnFocusHint();
method public final int getRight();
@@ -46228,6 +46229,7 @@ package android.view {
method public abstract int getLayoutDirection();
method public abstract android.view.ViewParent getParent();
method public abstract android.view.ViewParent getParentForAccessibility();
+ method public default int getResolvedAutoFillMode();
method public abstract int getTextAlignment();
method public abstract int getTextDirection();
method public abstract deprecated void invalidateChild(android.view.View, android.graphics.Rect);
@@ -47580,10 +47582,12 @@ package android.view.autofill {
}
public final class AutoFillManager {
- method public void focusChanged(android.view.View, boolean);
method public void reset();
+ method public void startAutoFillRequest(android.view.View);
+ method public void startAutoFillRequestOnVirtualView(android.view.View, int, android.graphics.Rect);
+ method public void stopAutoFillRequest(android.view.View);
+ method public void stopAutoFillRequestOnVirtualView(android.view.View, int);
method public void valueChanged(android.view.View);
- method public void virtualFocusChanged(android.view.View, int, android.graphics.Rect, boolean);
method public void virtualValueChanged(android.view.View, int, android.view.autofill.AutoFillValue);
field public static final java.lang.String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
field public static final java.lang.String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 99051a784cb3..040a59b134f9 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}.
*/
@@ -6670,13 +6674,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
imm.focusIn(this);
}
- if (isAutoFillable()) {
- AutoFillManager afm = getAutoFillManager();
- if (afm != null) {
- afm.focusChanged(this, gainFocus);
- }
- }
-
invalidate(true);
ListenerInfo li = mListenerInfo;
if (li != null && li.mOnFocusChangeListener != null) {
@@ -6686,6 +6683,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
if (mAttachInfo != null) {
mAttachInfo.mKeyDispatchState.reset(this);
}
+
+ if (isAutoFillable() && isAttachedToWindow()
+ && getResolvedAutoFillMode() == AUTO_FILL_MODE_AUTO) {
+ AutoFillManager afm = getAutoFillManager();
+ if (afm != null) {
+ if (gainFocus) {
+ afm.startAutoFillRequest(this);
+ } else {
+ afm.stopAutoFillRequest(this);
+ }
+ }
+ }
}
/**
@@ -7248,8 +7257,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* <ol>
* <li>Also implement {@link #autoFillVirtual(int, AutoFillValue)} to auto-fill the virtual
* children.
- * <li>Call {@link android.view.autofill.AutoFillManager#virtualFocusChanged(View, int, Rect,
- * boolean)} when the focus inside the view changed.
+ * <li>Call
+ * {@link android.view.autofill.AutoFillManager#startAutoFillRequestOnVirtualView} and
+ * {@link android.view.autofill.AutoFillManager#stopAutoFillRequestOnVirtualView(View, int)}
+ * when the focus inside the view changed.
* <li>Call {@link android.view.autofill.AutoFillManager#virtualValueChanged(View, int,
* AutoFillValue)} when the value of a child changed.
* <li>Call {@link android.view.autofill.AutoFillManager#reset()} when the auto-fill context
@@ -9484,6 +9495,31 @@ 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}. If the auto-
+ * fill mode can not be resolved e.g. {@link #getAutoFillMode()} is
+ * {@link #AUTO_FILL_MODE_INHERIT} and the {@link View} is detached
+ * {@link #AUTO_FILL_MODE_AUTO} is returned.
+ */
+ public @AutoFillMode int getResolvedAutoFillMode() {
+ @AutoFillMode int autoFillMode = getAutoFillMode();
+
+ if (autoFillMode == AUTO_FILL_MODE_INHERIT) {
+ if (mParent == null) {
+ return AUTO_FILL_MODE_AUTO;
+ } 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.
*
@@ -16619,6 +16655,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
refreshDrawableState();
}
needGlobalAttributesUpdate(false);
+
+ if (isAutoFillable() && isFocused() && getResolvedAutoFillMode() == AUTO_FILL_MODE_AUTO) {
+ AutoFillManager afm = getAutoFillManager();
+ if (afm != null) {
+ afm.startAutoFillRequest(this);
+ }
+ }
}
void dispatchDetachedFromWindow() {
@@ -16665,6 +16708,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
if (mOverlay != null) {
mOverlay.getOverlayView().dispatchDetachedFromWindow();
}
+
+ if (isAutoFillable() && isFocused() && getResolvedAutoFillMode() == AUTO_FILL_MODE_AUTO) {
+ AutoFillManager afm = getAutoFillManager();
+ if (afm != null) {
+ afm.stopAutoFillRequest(this);
+ }
+ }
}
/**
diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java
index cc11cb8205d5..1467b69faf08 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 One of {@link View#AUTO_FILL_MODE_AUTO}, {@link View#AUTO_FILL_MODE_MANUAL} if the
+ * auto-fill mode can be resolved. If the auto-fill mode cannot be resolved
+ * {@link View#AUTO_FILL_MODE_AUTO}.
+ *
+ * @see View#getResolvedAutoFillMode()
+ */
+ default @View.AutoFillMode int getResolvedAutoFillMode() {
+ return View.AUTO_FILL_MODE_AUTO;
+ }
}
diff --git a/core/java/android/view/autofill/AutoFillManager.java b/core/java/android/view/autofill/AutoFillManager.java
index b44bbbebc083..e8325e89f39a 100644
--- a/core/java/android/view/autofill/AutoFillManager.java
+++ b/core/java/android/view/autofill/AutoFillManager.java
@@ -19,6 +19,7 @@ package android.view.autofill;
import static android.view.autofill.Helper.DEBUG;
import static android.view.autofill.Helper.VERBOSE;
+import android.annotation.NonNull;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
@@ -113,12 +114,11 @@ public final class AutoFillManager {
}
/**
- * Called to indicate the focus on an auto-fillable {@link View} changed.
+ * Called when an auto-fill operation on a {@link View} should start.
*
- * @param view view whose focus changed.
- * @param gainFocus whether focus was gained or lost.
+ * @param view {@link View} that triggered the auto-fill request.
*/
- public void focusChanged(View view, boolean gainFocus) {
+ public void startAutoFillRequest(@NonNull View view) {
ensureServiceClientAddedIfNeeded();
if (!mEnabled) {
@@ -131,25 +131,40 @@ public final class AutoFillManager {
final AutoFillValue value = view.getAutoFillValue();
if (!mHasSession) {
- if (gainFocus) {
- // Starts new session.
- startSession(id, view.getWindowToken(), bounds, value);
- }
+ // Starts new session.
+ startSession(id, view.getWindowToken(), bounds, value);
} else {
// Update focus on existing session.
- updateSession(id, bounds, value, gainFocus ? FLAG_FOCUS_GAINED : FLAG_FOCUS_LOST);
+ updateSession(id, bounds, value, FLAG_FOCUS_GAINED);
+ }
+ }
+
+ /**
+ * Called when an auto-fill operation on a {@link View} should stop.
+ *
+ * @param view {@link View} that triggered the auto-fill request in
+ * {@link #startAutoFillRequest(View)}.
+ */
+ public void stopAutoFillRequest(@NonNull View view) {
+ ensureServiceClientAddedIfNeeded();
+
+ if (mEnabled && mHasSession) {
+ final AutoFillId id = getAutoFillId(view);
+
+ // Update focus on existing session.
+ updateSession(id, null, null, FLAG_FOCUS_LOST);
}
}
/**
- * Called to indicate the focus on an auto-fillable virtual {@link View} changed.
+ * Called when an auto-fill operation on a virtual {@link View} should start.
*
- * @param parent parent view whose focus changed.
+ * @param parent parent of the {@link View} that triggered the auto-fill request.
* @param childId id identifying the virtual child inside the parent view.
* @param bounds child boundaries, relative to the top window.
- * @param gainFocus whether focus was gained or lost.
*/
- public void virtualFocusChanged(View parent, int childId, Rect bounds, boolean gainFocus) {
+ public void startAutoFillRequestOnVirtualView(@NonNull View parent, int childId,
+ @NonNull Rect bounds) {
ensureServiceClientAddedIfNeeded();
if (!mEnabled) {
@@ -159,20 +174,36 @@ public final class AutoFillManager {
final AutoFillId id = getAutoFillId(parent, childId);
if (!mHasSession) {
- if (gainFocus) {
- // Starts new session.
- startSession(id, parent.getWindowToken(), bounds, null);
- }
+ // Starts new session.
+ startSession(id, parent.getWindowToken(), bounds, null);
} else {
// Update focus on existing session.
- updateSession(id, bounds, null, gainFocus ? FLAG_FOCUS_GAINED : FLAG_FOCUS_LOST);
+ updateSession(id, bounds, null, FLAG_FOCUS_GAINED);
+ }
+ }
+
+ /**
+ * Called when an auto-fill operation on a virtual {@link View} should stop.
+ *
+ * @param parent parent of the {@link View} that triggered the auto-fill request in
+ * {@link #startAutoFillRequestOnVirtualView(View, int, Rect)}.
+ * @param childId id identifying the virtual child inside the parent view.
+ */
+ public void stopAutoFillRequestOnVirtualView(@NonNull View parent, int childId) {
+ ensureServiceClientAddedIfNeeded();
+
+ if (mEnabled && mHasSession) {
+ final AutoFillId id = getAutoFillId(parent, childId);
+
+ // Update focus on existing session.
+ updateSession(id, null, null, FLAG_FOCUS_LOST);
}
}
/**
* Called to indicate the value of an auto-fillable {@link View} changed.
*
- * @param view view whose focus changed.
+ * @param view view whose value changed.
*/
public void valueChanged(View view) {
if (!mEnabled || !mHasSession) {
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 55b88847da8e..2e09e7d1b0c5 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2295,12 +2295,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>