From 911cb1fa768614732d08ece70cbeab5158ecec15 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Thu, 16 May 2019 14:18:42 -0700 Subject: DO NOT MERGE - Re-add ContentCapture support from standard SDK toolkit. This reverts commit ef1c0b36ab402c9f936220dd4f64f4ac96f52e37. Test: atest CtsContentCaptureServiceTestCases Test: m update-api Bug: 130726495 Change-Id: Iecda9df96722ac8a3184710796032b6c01bd8ea3 --- core/java/android/widget/TextView.java | 39 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'core/java/android/widget/TextView.java') diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 17c56c3f216a..cf7d09de8b3c 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -162,6 +162,8 @@ import android.view.accessibility.AccessibilityNodeInfo; import android.view.animation.AnimationUtils; import android.view.autofill.AutofillManager; import android.view.autofill.AutofillValue; +import android.view.contentcapture.ContentCaptureManager; +import android.view.contentcapture.ContentCaptureSession; import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CorrectionInfo; @@ -977,6 +979,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) { setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES); } + if (getImportantForContentCapture() == IMPORTANT_FOR_CONTENT_CAPTURE_AUTO) { + setImportantForContentCapture(IMPORTANT_FOR_CONTENT_CAPTURE_YES); + } setTextInternal(""); @@ -10550,7 +10555,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Notify managers (such as {@link AutofillManager}) that are interested in text changes. + * Notify managers (such as {@link AutofillManager} and {@link ContentCaptureManager}) that are + * interested on text changes. */ private void notifyListeningManagersAfterTextChanged() { @@ -10566,6 +10572,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener afm.notifyValueChanged(TextView.this); } } + + // TODO(b/121045053): should use a flag / boolean to keep status of SHOWN / HIDDEN instead + // of using isLaidout(), so it's not called in cases where it's laid out but a + // notifyAppeared was not sent. + + // ContentCapture + if (isLaidOut() && isImportantForContentCapture() && isTextEditable()) { + final ContentCaptureManager cm = mContext.getSystemService(ContentCaptureManager.class); + if (cm != null && cm.isContentCaptureEnabled()) { + final ContentCaptureSession session = getContentCaptureSession(); + if (session != null) { + // TODO(b/111276913): pass flags when edited by user / add CTS test + session.notifyViewTextChanged(getAutofillId(), getText()); + } + } + } } private boolean isAutofillable() { @@ -11399,7 +11421,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final boolean isPassword = hasPasswordTransformationMethod() || isPasswordInputType(getInputType()); - if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) { + if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL + || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) { if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) { structure.setDataIsSensitive(!mTextSetFromXmlOrResourceId); } @@ -11415,8 +11438,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - if (!isPassword || viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) { + if (!isPassword || viewFor == VIEW_STRUCTURE_FOR_AUTOFILL + || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) { if (mLayout == null) { + if (viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) { + Log.w(LOG_TAG, "onProvideContentCaptureStructure(): calling assumeLayout()"); + } assumeLayout(); } Layout layout = mLayout; @@ -11504,7 +11531,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - if (viewFor == VIEW_STRUCTURE_FOR_ASSIST) { + if (viewFor == VIEW_STRUCTURE_FOR_ASSIST + || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) { // Extract style information that applies to the TextView as a whole. int style = 0; int typefaceStyle = getTypefaceStyle(); @@ -11532,7 +11560,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener structure.setTextStyle(getTextSize(), getCurrentTextColor(), AssistStructure.ViewNode.TEXT_COLOR_UNDEFINED /* bgColor */, style); } - if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) { + if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL + || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) { structure.setMinTextEms(getMinEms()); structure.setMaxTextEms(getMaxEms()); int maxLength = -1; -- cgit v1.2.3