Merge "Add accessibility announcement when user clicks on 'Add automatically to home screen' button" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-07-13 05:06:10 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 4 deletions

View File

@@ -62,8 +62,7 @@
android:text="@string/add_item_request_drag_hint"
android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:alpha="0.7"
android:importantForAccessibility="no"/>
android:alpha="0.7"/>
<include layout="@layout/widget_cell"
android:id="@+id/widget_cell"

View File

@@ -63,6 +63,9 @@
<string name="add_item_request_drag_hint">Touch &amp; hold the widget to move it around the Home screen</string>
<!-- Button label to automatically add a widget to home screen [CHAR_LIMIT=50] -->
<string name="add_to_home_screen">Add to Home screen</string>
<!-- Accessibility spoken message announced when a widget gets added to the home screen using a
button in a dialog. [CHAR_LIMIT=none] -->
<string name="added_to_home_screen_accessibility_text"><xliff:g id="widget_name" example="Calendar month view">%1$s</xliff:g> widget added to home screen</string>
<!-- Label for showing the number of widgets an app has in the full widgets picker.
[CHAR_LIMIT=25] -->
<plurals name="widgets_count">

View File

@@ -27,10 +27,12 @@ import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.annotation.TargetApi;
import android.app.ActivityOptions;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Intent;
import android.content.pm.LauncherApps.PinItemRequest;
import android.content.pm.ShortcutInfo;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.Point;
@@ -39,12 +41,15 @@ import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.DragShadowBuilder;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.TextView;
import com.android.launcher3.BaseActivity;
@@ -92,6 +97,7 @@ public class AddItemActivity extends BaseActivity
private InvariantDeviceProfile mIdp;
private BaseDragLayer<AddItemActivity> mDragLayer;
private AddItemWidgetsBottomSheet mSlideInView;
private AccessibilityManager mAccessibilityManager;
private WidgetCell mWidgetCell;
@@ -127,6 +133,8 @@ public class AddItemActivity extends BaseActivity
mDragLayer = findViewById(R.id.add_item_drag_layer);
mDragLayer.recreateControllers();
mWidgetCell = findViewById(R.id.widget_cell);
mAccessibilityManager =
getApplicationContext().getSystemService(AccessibilityManager.class);
if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
setupShortcut();
@@ -291,17 +299,25 @@ public class AddItemActivity extends BaseActivity
*/
public void onPlaceAutomaticallyClick(View v) {
if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
ItemInstallQueue.INSTANCE.get(this).queueItem(mRequest.getShortcutInfo());
ShortcutInfo shortcutInfo = mRequest.getShortcutInfo();
ItemInstallQueue.INSTANCE.get(this).queueItem(shortcutInfo);
logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_PLACED_AUTOMATICALLY);
mRequest.accept();
CharSequence label = shortcutInfo.getLongLabel();
if (TextUtils.isEmpty(label)) {
label = shortcutInfo.getShortLabel();
}
sendWidgetAddedToScreenAccessibilityEvent(label.toString());
mSlideInView.close(/* animate= */ true);
return;
}
mPendingBindWidgetId = mAppWidgetHost.allocateAppWidgetId();
AppWidgetProviderInfo widgetProviderInfo = mRequest.getAppWidgetProviderInfo(this);
boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
mPendingBindWidgetId, mRequest.getAppWidgetProviderInfo(this), mWidgetOptions);
mPendingBindWidgetId, widgetProviderInfo, mWidgetOptions);
if (success) {
sendWidgetAddedToScreenAccessibilityEvent(widgetProviderInfo.label);
acceptWidget(mPendingBindWidgetId);
return;
}
@@ -375,6 +391,17 @@ public class AddItemActivity extends BaseActivity
isSheetDark ? SystemUiController.FLAG_DARK_NAV : SystemUiController.FLAG_LIGHT_NAV);
}
private void sendWidgetAddedToScreenAccessibilityEvent(String widgetName) {
if (mAccessibilityManager.isEnabled()) {
AccessibilityEvent event =
AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
event.setContentDescription(
getApplicationContext().getResources().getString(
R.string.added_to_home_screen_accessibility_text, widgetName));
mAccessibilityManager.sendAccessibilityEvent(event);
}
}
private void logCommand(StatsLogManager.EventEnum command) {
getStatsLogManager().logger()
.withItemInfo((ItemInfo) mWidgetCell.getWidgetView().getTag())