1 package com.android.launcher3.popup;
3 import android.content.Context;
4 import android.graphics.drawable.Drawable;
5 import android.view.View;
7 import com.android.launcher3.InfoDropTarget;
8 import com.android.launcher3.ItemInfo;
9 import com.android.launcher3.Launcher;
10 import com.android.launcher3.R;
11 import com.android.launcher3.model.WidgetItem;
12 import com.android.launcher3.util.PackageUserKey;
13 import com.android.launcher3.util.Themes;
14 import com.android.launcher3.widget.WidgetsBottomSheet;
16 import java.util.List;
19 * Represents a system shortcut for a given app. The shortcut should have a static label and
20 * icon, and an onClickListener that depends on the item that the shortcut services.
22 * Example system shortcuts, defined as inner classes, include Widgets and AppInfo.
24 public abstract class SystemShortcut {
25 private final int mIconResId;
26 private final int mLabelResId;
28 public SystemShortcut(int iconResId, int labelResId) {
29 mIconResId = iconResId;
30 mLabelResId = labelResId;
33 public Drawable getIcon(Context context, int colorAttr) {
34 Drawable icon = context.getResources().getDrawable(mIconResId, context.getTheme()).mutate();
35 icon.setTint(Themes.getAttrColor(context, colorAttr));
39 public String getLabel(Context context) {
40 return context.getString(mLabelResId);
43 public abstract View.OnClickListener getOnClickListener(final Launcher launcher,
44 final ItemInfo itemInfo);
46 public static class Widgets extends SystemShortcut {
49 super(R.drawable.ic_widget, R.string.widget_button_text);
53 public View.OnClickListener getOnClickListener(final Launcher launcher,
54 final ItemInfo itemInfo) {
55 final List<WidgetItem> widgets = launcher.getWidgetsForPackageUser(new PackageUserKey(
56 itemInfo.getTargetComponent().getPackageName(), itemInfo.user));
57 if (widgets == null) {
60 return new View.OnClickListener() {
62 public void onClick(View view) {
63 PopupContainerWithArrow.getOpen(launcher).close(true);
64 WidgetsBottomSheet widgetsBottomSheet =
65 (WidgetsBottomSheet) launcher.getLayoutInflater().inflate(
66 R.layout.widgets_bottom_sheet, launcher.getDragLayer(), false);
67 widgetsBottomSheet.populateAndShow(itemInfo);
73 public static class AppInfo extends SystemShortcut {
75 super(R.drawable.ic_info_no_shadow, R.string.app_info_drop_target_label);
79 public View.OnClickListener getOnClickListener(final Launcher launcher,
80 final ItemInfo itemInfo) {
81 return new View.OnClickListener() {
83 public void onClick(View view) {
84 InfoDropTarget.startDetailsActivityForInfo(itemInfo, launcher, null);