[a11y] fix the issue where launcher announces item added to homescreen before
it does

Test:
1. long press on home screen -> widgets
2. enable talkback
3. add a custom shortcut to home screen (i.e. 1x1 widgets, e.g. drive
scan in Google Drive, Driving Mode in Google Maps ... e.t.c )
4. verify talkback announces "item addded to homescreen" after it does
get added to the homescreen
5. repeat the same test for widgets (e.g. calendar)

Bug: 141527338
Change-Id: I232e6e796c9edb81128f816c71a33310c3700e73
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 8714032..4811b48 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -83,6 +83,7 @@
 import android.widget.Toast;
 
 import androidx.annotation.Nullable;
+import androidx.annotation.StringRes;
 import androidx.annotation.VisibleForTesting;
 
 import com.android.launcher3.DropTarget.DragObject;
@@ -687,6 +688,7 @@
         switch (requestCode) {
             case REQUEST_CREATE_SHORTCUT:
                 completeAddShortcut(intent, info.container, screenId, info.cellX, info.cellY, info);
+                announceForAccessibility(R.string.item_added_to_workspace);
                 break;
             case REQUEST_CREATE_APPWIDGET:
                 completeAddAppWidget(appWidgetId, info, null, null);
@@ -711,7 +713,6 @@
                 break;
             }
         }
-
         return screenId;
     }
 
@@ -1317,6 +1318,7 @@
         hostView.setVisibility(View.VISIBLE);
         prepareAppWidget(hostView, launcherInfo);
         mWorkspace.addInScreen(hostView, launcherInfo);
+        announceForAccessibility(R.string.item_added_to_workspace);
     }
 
     private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
@@ -2406,6 +2408,10 @@
         return bounceAnim;
     }
 
+    private void announceForAccessibility(@StringRes int stringResId) {
+        getDragLayer().announceForAccessibility(getString(stringResId));
+    }
+
     /**
      * Add the icons for all apps.
      *
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 0c12c60..a7ef9ef 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -191,6 +191,7 @@
                         ArrayList<ItemInfo> itemList = new ArrayList<>();
                         itemList.add(info);
                         mLauncher.bindItems(itemList, true);
+                        announceConfirmation(R.string.item_added_to_workspace);
                     } else if (item instanceof PendingAddItemInfo) {
                         PendingAddItemInfo info = (PendingAddItemInfo) item;
                         Workspace workspace = mLauncher.getWorkspace();
@@ -198,7 +199,6 @@
                         mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP,
                                 screenId, coordinates, info.spanX, info.spanY);
                     }
-                    announceConfirmation(R.string.item_added_to_workspace);
                 }
             });
             return true;