Merge "Accessibility fixes for clipboard overlay" into tm-dev am: 6e3282ca56 am: a455311d89 am: 855eb9651c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18713012

Change-Id: I6308c820ac688bdbe0e68f180a46a9bbaea193eb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 5dd1b09..490a3f5 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -788,6 +788,7 @@
                   android:theme="@style/EditTextActivity"
                   android:exported="false"
                   android:excludeFromRecents="true"
+                  android:label="@string/clipboard_editor"
                   />
 
         <activity android:name=".controls.management.ControlsProviderSelectorActivity"
diff --git a/packages/SystemUI/res/layout/clipboard_overlay.xml b/packages/SystemUI/res/layout/clipboard_overlay.xml
index 6b9d963..99a5a2e 100644
--- a/packages/SystemUI/res/layout/clipboard_overlay.xml
+++ b/packages/SystemUI/res/layout/clipboard_overlay.xml
@@ -22,7 +22,8 @@
     android:theme="@style/FloatingOverlay"
     android:alpha="0"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:contentDescription="@string/clipboard_overlay_window_name">
     <ImageView
         android:id="@+id/actions_container_background"
         android:visibility="gone"
@@ -121,6 +122,7 @@
             android:id="@+id/image_preview"
             android:scaleType="fitCenter"
             android:adjustViewBounds="true"
+            android:contentDescription="@string/clipboard_image_preview"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"/>
         <TextView
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 6cd47d2..d88428f 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -2535,6 +2535,14 @@
     <string name="clipboard_image_copied">Image copied</string>
     <!-- Accessibility announcement informing user that something has been copied [CHAR LIMIT=NONE] -->
     <string name="clipboard_content_copied">Content copied</string>
+    <!-- Name of the screen that lets the user edit the context of the clipboard (copy/paste) [CHAR LIMIT=NONE] -->
+    <string name="clipboard_editor">Clipboard Editor</string>
+    <!-- Name for the window showing the clipboard (copy/paste) preview and controls [CHAR LIMIT=NONE] -->
+    <string name="clipboard_overlay_window_name">Clipboard</string>
+    <!-- Accessibility label for an image preview [CHAR LIMIT=NONE] -->
+    <string name="clipboard_image_preview">Image preview</string>
+    <!-- Accessibility string describing what will happen when the user selects the clipboard preview. Completing the sentence "Double tap to ..." [CHAR LIMIT=NONE] -->
+    <string name="clipboard_edit">edit</string>
 
     <!-- Generic "add" string [CHAR LIMIT=NONE] -->
     <string name="add">Add</string>
diff --git a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java
index eab3745..aa67ecd 100644
--- a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java
+++ b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java
@@ -97,6 +97,9 @@
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import androidx.core.view.ViewCompat;
+import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
+
 import com.android.internal.logging.UiEventLogger;
 import com.android.internal.policy.PhoneWindow;
 import com.android.systemui.R;
@@ -218,6 +221,7 @@
         mRemoteCopyChip.setAlpha(1);
         mDismissButton = requireNonNull(mView.findViewById(R.id.dismiss_button));
 
+        mShareChip.setContentDescription(mContext.getString(com.android.internal.R.string.share));
         mView.setCallbacks(new DraggableConstraintLayout.SwipeDismissCallbacks() {
             @Override
             public void onInteraction() {
@@ -367,6 +371,8 @@
         PackageManager packageManager = mContext.getPackageManager();
         if (packageManager.resolveActivity(
                 remoteCopyIntent, PackageManager.ResolveInfoFlags.of(0)) != null) {
+            mRemoteCopyChip.setContentDescription(
+                    mContext.getString(R.string.clipboard_send_nearby_description));
             mRemoteCopyChip.setVisibility(View.VISIBLE);
             mRemoteCopyChip.setOnClickListener((v) -> {
                 mUiEventLogger.log(CLIPBOARD_OVERLAY_REMOTE_COPY_TAPPED);
@@ -581,6 +587,7 @@
         TextView textView = hidden ? mHiddenPreview : mTextPreview;
         showTextPreview(text, textView);
         View.OnClickListener listener = v -> editText();
+        setAccessibilityActionToEdit(textView);
         if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
                 CLIPBOARD_OVERLAY_SHOW_EDIT_BUTTON, false)) {
             mEditChip.setVisibility(View.VISIBLE);
@@ -602,6 +609,7 @@
             showSinglePreview(mHiddenPreview);
             if (isEditableImage) {
                 mHiddenPreview.setOnClickListener(listener);
+                setAccessibilityActionToEdit(mHiddenPreview);
             }
         } else if (isEditableImage) { // if the MIMEtype is image, try to load
             try {
@@ -612,6 +620,7 @@
                 showSinglePreview(mImagePreview);
                 mImagePreview.setImageBitmap(thumbnail);
                 mImagePreview.setOnClickListener(listener);
+                setAccessibilityActionToEdit(mImagePreview);
             } catch (IOException e) {
                 Log.e(TAG, "Thumbnail loading failed", e);
                 showTextPreview(
@@ -635,6 +644,12 @@
         return isEditableImage;
     }
 
+    private void setAccessibilityActionToEdit(View view) {
+        ViewCompat.replaceAccessibilityAction(view,
+                AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK,
+                mContext.getString(R.string.clipboard_edit), null);
+    }
+
     private Intent getRemoteCopyIntent(ClipData clipData) {
         Intent nearbyIntent = new Intent(REMOTE_COPY_ACTION);
 
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/DraggableConstraintLayout.java b/packages/SystemUI/src/com/android/systemui/screenshot/DraggableConstraintLayout.java
index f3c87d0..950806d 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/DraggableConstraintLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/DraggableConstraintLayout.java
@@ -117,6 +117,14 @@
         mCallbacks = callbacks;
     }
 
+    @Override
+    public boolean onInterceptHoverEvent(MotionEvent event) {
+        if (mCallbacks != null) {
+            mCallbacks.onInteraction();
+        }
+        return super.onInterceptHoverEvent(event);
+    }
+
     @Override // View
     protected void onFinishInflate() {
         mActionsContainer = findViewById(R.id.actions_container);