diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index db7fd3feca8aa75255aae9e01b7fa992ee282168..a5852ba8280579a25324ab3637095dce49abf472 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -265,7 +265,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme List actions = getSupportedResizeActions(host, info); Rect pos = new Rect(); mLauncher.getDragLayer().getDescendantRectRelativeToSelf(host, pos); - ArrowPopup popup = OptionsPopupView.show(mLauncher, new RectF(pos), actions); + ArrowPopup popup = OptionsPopupView.show(mLauncher, new RectF(pos), actions, false); popup.requestFocus(); popup.setOnCloseCallback(host::requestFocus); return true; @@ -294,15 +294,17 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0) { if (layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY) || layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY)) { - actions.add(new OptionItem( - R.string.action_increase_width, R.drawable.ic_widget_width_increase, + actions.add(new OptionItem(mLauncher, + R.string.action_increase_width, + R.drawable.ic_widget_width_increase, IGNORE, v -> performResizeAction(R.string.action_increase_width, host, info))); } if (info.spanX > info.minSpanX && info.spanX > 1) { - actions.add(new OptionItem( - R.string.action_decrease_width, R.drawable.ic_widget_width_decrease, + actions.add(new OptionItem(mLauncher, + R.string.action_decrease_width, + R.drawable.ic_widget_width_decrease, IGNORE, v -> performResizeAction(R.string.action_decrease_width, host, info))); } @@ -311,15 +313,17 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) { if (layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1) || layout.isRegionVacant(info.cellX, info.cellY - 1, info.spanX, 1)) { - actions.add(new OptionItem( - R.string.action_increase_height, R.drawable.ic_widget_height_increase, + actions.add(new OptionItem(mLauncher, + R.string.action_increase_height, + R.drawable.ic_widget_height_increase, IGNORE, v -> performResizeAction(R.string.action_increase_height, host, info))); } if (info.spanY > info.minSpanY && info.spanY > 1) { - actions.add(new OptionItem( - R.string.action_decrease_height, R.drawable.ic_widget_height_decrease, + actions.add(new OptionItem(mLauncher, + R.string.action_decrease_height, + R.drawable.ic_widget_height_decrease, IGNORE, v -> performResizeAction(R.string.action_decrease_height, host, info))); } diff --git a/src/com/android/launcher3/views/AccessibilityActionsView.java b/src/com/android/launcher3/views/AccessibilityActionsView.java index 0eacaa30095192b7092a4f19424db8bee248e176..1d136c3a9fdb4e24e1cf0e06d0cf8ce6563af76a 100644 --- a/src/com/android/launcher3/views/AccessibilityActionsView.java +++ b/src/com/android/launcher3/views/AccessibilityActionsView.java @@ -67,7 +67,7 @@ public class AccessibilityActionsView extends View implements StateListener mItemMap = new ArrayMap<>(); private RectF mTargetRect; + private boolean mShouldAddArrow; public OptionsPopupView(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -113,9 +116,13 @@ public class OptionsPopupView extends ArrowPopup return (type & TYPE_OPTIONS_POPUP) != 0; } + public void setShouldAddArrow(boolean shouldAddArrow) { + mShouldAddArrow = shouldAddArrow; + } + @Override protected boolean shouldAddArrow() { - return false; + return mShouldAddArrow; } @Override @@ -124,16 +131,17 @@ public class OptionsPopupView extends ArrowPopup } public static OptionsPopupView show( - Launcher launcher, RectF targetRect, List items) { + Launcher launcher, RectF targetRect, List items, boolean shouldAddArrow) { OptionsPopupView popup = (OptionsPopupView) launcher.getLayoutInflater() .inflate(R.layout.longpress_options_menu, launcher.getDragLayer(), false); popup.mTargetRect = targetRect; + popup.setShouldAddArrow(shouldAddArrow); for (OptionItem item : items) { DeepShortcutView view = (DeepShortcutView) popup.inflateAndAdd(R.layout.system_shortcut, popup); - view.getIconView().setBackgroundResource(item.iconRes); - view.getBubbleText().setText(item.labelRes); + view.getIconView().setBackgroundDrawable(item.icon); + view.getBubbleText().setText(item.label); view.setOnClickListener(popup); view.setOnLongClickListener(popup); popup.mItemMap.put(view, item); @@ -154,7 +162,7 @@ public class OptionsPopupView extends ArrowPopup y = launcher.getDragLayer().getHeight() / 2; } RectF target = new RectF(x - halfSize, y - halfSize, x + halfSize, y + halfSize); - show(launcher, target, getOptions(launcher)); + show(launcher, target, getOptions(launcher), false); } /** @@ -162,11 +170,15 @@ public class OptionsPopupView extends ArrowPopup */ public static ArrayList getOptions(Launcher launcher) { ArrayList options = new ArrayList<>(); - options.add(new OptionItem(R.string.settings_button_text, R.drawable.ic_setting, + options.add(new OptionItem(launcher, + R.string.settings_button_text, + R.drawable.ic_setting, LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS, OptionsPopupView::startSettings)); if (!WidgetsModel.GO_DISABLE_WIDGETS) { - options.add(new OptionItem(R.string.widget_button_text, R.drawable.ic_widget, + options.add(new OptionItem(launcher, + R.string.widget_button_text, + R.drawable.ic_widget, LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS, OptionsPopupView::onWidgetsClicked)); } @@ -174,7 +186,9 @@ public class OptionsPopupView extends ArrowPopup R.string.styles_wallpaper_button_text : R.string.wallpaper_button_text; int resDrawable = Utilities.existsStyleWallpapers(launcher) ? R.drawable.ic_palette : R.drawable.ic_wallpaper; - options.add(new OptionItem(resString, resDrawable, + options.add(new OptionItem(launcher, + resString, + resDrawable, IGNORE, OptionsPopupView::startWallpaperPicker)); return options; @@ -241,15 +255,28 @@ public class OptionsPopupView extends ArrowPopup public static class OptionItem { + // Used to create AccessibilityNodeInfo in AccessibilityActionsView.java. public final int labelRes; - public final int iconRes; + + public final CharSequence label; + public final Drawable icon; public final EventEnum eventId; public final OnLongClickListener clickListener; - public OptionItem(int labelRes, int iconRes, EventEnum eventId, - OnLongClickListener clickListener) { + public OptionItem(Context context, int labelRes, int iconRes, EventEnum eventId, + OnLongClickListener clickListener) { this.labelRes = labelRes; - this.iconRes = iconRes; + this.label = context.getText(labelRes); + this.icon = ContextCompat.getDrawable(context, iconRes); + this.eventId = eventId; + this.clickListener = clickListener; + } + + public OptionItem(CharSequence label, Drawable icon, EventEnum eventId, + OnLongClickListener clickListener) { + this.labelRes = 0; + this.label = label; + this.icon = icon; this.eventId = eventId; this.clickListener = clickListener; }