1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package com.android.launcher3.popup;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import com.android.launcher3.InfoDropTarget;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Themes;
import com.android.launcher3.widget.WidgetsBottomSheet;
import java.util.List;
/**
* Represents a system shortcut for a given app. The shortcut should have a static label and
* icon, and an onClickListener that depends on the item that the shortcut services.
*
* Example system shortcuts, defined as inner classes, include Widgets and AppInfo.
*/
public abstract class SystemShortcut {
private final int mIconResId;
private final int mLabelResId;
public SystemShortcut(int iconResId, int labelResId) {
mIconResId = iconResId;
mLabelResId = labelResId;
}
public Drawable getIcon(Context context) {
return context.getResources().getDrawable(mIconResId, context.getTheme());
}
public String getLabel(Context context) {
return context.getString(mLabelResId);
}
public abstract View.OnClickListener getOnClickListener(final Launcher launcher,
final ItemInfo itemInfo);
public static class Widgets extends SystemShortcut {
public Widgets() {
super(R.drawable.ic_widget, R.string.widget_button_text);
}
@Override
public View.OnClickListener getOnClickListener(final Launcher launcher,
final ItemInfo itemInfo) {
final List<WidgetItem> widgets = launcher.getWidgetsForPackageUser(new PackageUserKey(
itemInfo.getTargetComponent().getPackageName(), itemInfo.user));
if (widgets == null) {
return null;
}
return new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupContainerWithArrow.getOpen(launcher).close(true);
WidgetsBottomSheet widgetsBottomSheet =
(WidgetsBottomSheet) launcher.getLayoutInflater().inflate(
R.layout.widgets_bottom_sheet, launcher.getDragLayer(), false);
widgetsBottomSheet.populateAndShow(itemInfo);
}
};
}
}
public static class AppInfo extends SystemShortcut {
public AppInfo() {
super(R.drawable.ic_info_no_shadow, R.string.app_info_drop_target_label);
}
@Override
public View.OnClickListener getOnClickListener(final Launcher launcher,
final ItemInfo itemInfo) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
InfoDropTarget.startDetailsActivityForInfo(itemInfo, launcher, null);
}
};
}
}
}
|