OSDN Git Service

Merge "Update icon badges to match spec" into ub-launcher3-dorval
[android-x86/packages-apps-Launcher3.git] / src / com / android / launcher3 / popup / SystemShortcut.java
1 package com.android.launcher3.popup;
2
3 import android.content.Context;
4 import android.graphics.drawable.Drawable;
5 import android.view.View;
6
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;
15
16 import java.util.List;
17
18 /**
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.
21  *
22  * Example system shortcuts, defined as inner classes, include Widgets and AppInfo.
23  */
24 public abstract class SystemShortcut {
25     private final int mIconResId;
26     private final int mLabelResId;
27
28     public SystemShortcut(int iconResId, int labelResId) {
29         mIconResId = iconResId;
30         mLabelResId = labelResId;
31     }
32
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));
36         return icon;
37     }
38
39     public String getLabel(Context context) {
40         return context.getString(mLabelResId);
41     }
42
43     public abstract View.OnClickListener getOnClickListener(final Launcher launcher,
44             final ItemInfo itemInfo);
45
46     public static class Widgets extends SystemShortcut {
47
48         public Widgets() {
49             super(R.drawable.ic_widget, R.string.widget_button_text);
50         }
51
52         @Override
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) {
58                 return null;
59             }
60             return new View.OnClickListener() {
61                 @Override
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);
68                 }
69             };
70         }
71     }
72
73     public static class AppInfo extends SystemShortcut {
74         public AppInfo() {
75             super(R.drawable.ic_info_no_shadow, R.string.app_info_drop_target_label);
76         }
77
78         @Override
79         public View.OnClickListener getOnClickListener(final Launcher launcher,
80                 final ItemInfo itemInfo) {
81             return new View.OnClickListener() {
82                 @Override
83                 public void onClick(View view) {
84                     InfoDropTarget.startDetailsActivityForInfo(itemInfo, launcher, null);
85                 }
86             };
87         }
88     }
89 }