小部件列表包括两种类型:widget和shortcut。如何在小部件列表中隐藏某个widget或者shortcut?例如隐藏设置的电量控制小部件(Power Control)?
路径 packages\apps\Launcher3\src\com\android\launcher3\AppsCustomizePagedView.java
public void onPackagesUpdated(ArrayList widgetsAndShortcuts) {
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
// Get the list of widgets and shortcuts
mWidgets.clear();
if (LauncherLog.DEBUG) {
LauncherLog.d(TAG, "updatePackages: widgetsAndShortcuts size = " + widgetsAndShortcuts.size());
}
for (Object o : widgetsAndShortcuts) {
if (o instanceof AppWidgetProviderInfo) {
AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o;
if (!app.shouldShowAppOrWidgetProvider(widget.provider)) {
continue;
}
widget.label = widget.label.trim();
if (widget.minWidth > 0 && widget.minHeight > 0) {
// Ensure that all widgets we show can be added on a workspace of this size
int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget);
int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget);
int minSpanX = Math.min(spanXY[0], minSpanXY[0]);
int minSpanY = Math.min(spanXY[1], minSpanXY[1]);
if (minSpanX <= (int) grid.numColumns &&
minSpanY <= (int) grid.numRows) {
//hide widgets xxx20151230
if(!widget.provider.getPackageName().equals("com.mediatek.videofavorites")){//add xxx
mWidgets.add(widget);
}//add xxx
} else {
Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" +
widget.minWidth + ", " + widget.minHeight + "), min span is (" + minSpanX + ", " + minSpanY + ")"
+ "), span is (" + spanXY[0] + ", " + spanXY[1] + ")");
}
} else {
LauncherLog.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" +
widget.minWidth + ", " + widget.minHeight);
}
} else {
//Hide shortcut modify here
ResolveInfo info=(ResolveInfo)o;//add xxx
if(!info.activityInfo.packageName.equals("com.example.appwidget")){//xxx add
// just add shortcuts
mWidgets.add(o);
}//xxx add
}
}
updatePageCountsAndInvalidateData();
}