Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Snippets Groups Projects
Commit dd2b8b6f authored by Andy Wickham's avatar Andy Wickham Committed by Android (Google) Code Review
Browse files

Merge "Updates OptionsPopupView to allow non-resource strings/icons." into sc-dev

parents 7ec7c22b 7d821d98
Branches
Tags
No related merge requests found
......@@ -265,7 +265,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
List<OptionItem> 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)));
}
......
......@@ -67,7 +67,7 @@ public class AccessibilityActionsView extends View implements StateListener<Laun
info.addAction(new AccessibilityAction(
R.string.all_apps_button_label, l.getText(R.string.all_apps_button_label)));
for (OptionItem item : OptionsPopupView.getOptions(l)) {
info.addAction(new AccessibilityAction(item.labelRes, l.getText(item.labelRes)));
info.addAction(new AccessibilityAction(item.labelRes, item.label));
}
return info;
}
......
......@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.AttributeSet;
......@@ -37,6 +38,7 @@ import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.ContextCompat;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings;
......@@ -62,6 +64,7 @@ public class OptionsPopupView extends ArrowPopup
private final ArrayMap<View, OptionItem> 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<OptionItem> items) {
Launcher launcher, RectF targetRect, List<OptionItem> 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<OptionItem> getOptions(Launcher launcher) {
ArrayList<OptionItem> 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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment