Add Dismiss action in Talkback Local Context Menu

- Add dismiss action for cards that can be dismissed.
- Remove importantForAccessibility from sliceView so Talkback can
recognise this view in order to generate Local Context Menu.

Fixes: 146910157
Test: Enable Talkback -> Move focus to removeable contextual card -> use
up-right gesture -> see Local Context Menu

Change-Id: I75a7394e94e6939d48cc379f62eab66f7903fd98
diff --git a/res/layout/contextual_slice_full_tile.xml b/res/layout/contextual_slice_full_tile.xml
index 4b1155e..b6ab410 100644
--- a/res/layout/contextual_slice_full_tile.xml
+++ b/res/layout/contextual_slice_full_tile.xml
@@ -19,7 +19,8 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    style="@style/ContextualCardStyle">
+    style="@style/ContextualCardStyle"
+    android:importantForAccessibility="no">
 
     <include layout="@layout/dismissal_swipe_background"/>
 
@@ -28,10 +29,9 @@
         android:theme="@style/Theme.Settings.ContextualCard"
         style="@style/ContextualCardSliceViewStyle"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:importantForAccessibility="no"/>
+        android:layout_height="wrap_content"/>
 
-    <!--dismissal view-->
+    <!--dismissal view -->
     <include layout="@layout/contextual_card_dismissal_view"/>
 
 </com.google.android.material.card.MaterialCardView>
\ No newline at end of file
diff --git a/res/layout/contextual_slice_sticky_tile.xml b/res/layout/contextual_slice_sticky_tile.xml
index 5991068..2e7a2be 100644
--- a/res/layout/contextual_slice_sticky_tile.xml
+++ b/res/layout/contextual_slice_sticky_tile.xml
@@ -19,14 +19,14 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    style="@style/ContextualCardStyle">
+    style="@style/ContextualCardStyle"
+    android:importantForAccessibility="no">
 
     <androidx.slice.widget.SliceView
         android:id="@+id/slice_view"
         android:theme="@style/Theme.Settings.ContextualCard"
         style="@style/ContextualCardSliceViewStyle"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:importantForAccessibility="no"/>
+        android:layout_height="wrap_content"/>
 
 </com.google.android.material.card.MaterialCardView>
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
index 5f1e955..740c328 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
@@ -21,6 +21,7 @@
 import android.content.ContentResolver;
 import android.content.Context;
 import android.net.Uri;
+import android.os.Bundle;
 import android.util.ArrayMap;
 import android.util.ArraySet;
 import android.util.Log;
@@ -29,6 +30,9 @@
 
 import androidx.annotation.LayoutRes;
 import androidx.annotation.VisibleForTesting;
+import androidx.core.view.AccessibilityDelegateCompat;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
 import androidx.lifecycle.Lifecycle;
 import androidx.lifecycle.LifecycleObserver;
 import androidx.lifecycle.LifecycleOwner;
@@ -167,6 +171,27 @@
             resetCardView(holder);
             mSliceLiveDataMap.get(card.getSliceUri()).removeObservers(mLifecycleOwner);
         });
+
+        ViewCompat.setAccessibilityDelegate(getInitialView(holder),
+                new AccessibilityDelegateCompat() {
+                    @Override
+                    public void onInitializeAccessibilityNodeInfo(View host,
+                            AccessibilityNodeInfoCompat info) {
+                        super.onInitializeAccessibilityNodeInfo(host, info);
+                        info.addAction(AccessibilityNodeInfoCompat.ACTION_DISMISS);
+                        info.setDismissable(true);
+                    }
+
+                    @Override
+                    public boolean performAccessibilityAction(View host, int action, Bundle args) {
+                        if (action == AccessibilityNodeInfoCompat.ACTION_DISMISS) {
+                            mControllerRendererPool.getController(mContext,
+                                    card.getCardType()).onDismissed(card);
+                        }
+                        return super.performAccessibilityAction(host, action, args);
+                    }
+                });
+
     }
 
     @OnLifecycleEvent(Lifecycle.Event.ON_STOP)