use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.
the class WidgetsModel method update.
/**
* @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
* only widgets and shortcuts associated with the package/user are.
*/
public List<ComponentWithLabelAndIcon> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
Preconditions.assertWorkerThread();
Context context = app.getContext();
final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
List<ComponentWithLabelAndIcon> updatedItems = new ArrayList<>();
try {
InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
PackageManager pm = app.getContext().getPackageManager();
// Widgets
WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
updatedItems.add(launcherWidgetInfo);
}
// Shortcuts
for (ShortcutConfigActivityInfo info : queryList(context, packageUser)) {
widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
updatedItems.add(info);
}
setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
} catch (Exception e) {
if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
// the returned value may be incomplete and will not be refreshed until the next
// time Launcher starts.
// TODO: after figuring out a repro step, introduce a dirty bit to check when
// onResume is called to refresh the widget provider list.
} else {
throw e;
}
}
return updatedItems;
}
use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.
the class AddItemActivity method setupWidget.
private boolean setupWidget() {
LauncherAppWidgetProviderInfo widgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this, mRequest.getAppWidgetProviderInfo(this));
if (widgetInfo.minSpanX > mIdp.numColumns || widgetInfo.minSpanY > mIdp.numRows) {
// Cannot add widget
return false;
}
mWidgetCell.setRemoteViewsPreview(PinItemDragListener.getPreview(mRequest));
mAppWidgetManager = new WidgetManagerHelper(this);
mAppWidgetHost = new LauncherAppWidgetHost(this);
PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(widgetInfo, CONTAINER_PIN_WIDGETS);
pendingInfo.spanX = Math.min(mIdp.numColumns, widgetInfo.spanX);
pendingInfo.spanY = Math.min(mIdp.numRows, widgetInfo.spanY);
mWidgetOptions = pendingInfo.getDefaultSizeOptions(this);
mWidgetCell.getWidgetView().setTag(pendingInfo);
applyWidgetItemAsync(() -> new WidgetItem(widgetInfo, mIdp, mApp.getIconCache()));
return true;
}
use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.
the class PinItemDragListener method createDragHelper.
@Override
protected PendingItemDragHelper createDragHelper() {
final PendingAddItemInfo item;
if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
item = new PendingAddShortcutInfo(new PinShortcutRequestActivityInfo(mRequest, mLauncher));
} else {
// mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET
LauncherAppWidgetProviderInfo providerInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(mLauncher, mRequest.getAppWidgetProviderInfo(mLauncher));
final PinWidgetFlowHandler flowHandler = new PinWidgetFlowHandler(providerInfo, mRequest);
item = new PendingAddWidgetInfo(providerInfo, CONTAINER_PIN_WIDGETS) {
@Override
public WidgetAddFlowHandler getHandler() {
return flowHandler;
}
};
}
View view = new View(mLauncher);
view.setTag(item);
PendingItemDragHelper dragHelper = new PendingItemDragHelper(view);
if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_APPWIDGET) {
dragHelper.setRemoteViewsPreview(getPreview(mRequest), mPreviewScale);
}
return dragHelper;
}
use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.
the class LauncherAppWidgetProviderInfoTest method isMinSizeFulfilled_minWidthAndMinResizeWidthExceededGridColumns_shouldReturnFalse.
@Test
public void isMinSizeFulfilled_minWidthAndMinResizeWidthExceededGridColumns_shouldReturnFalse() {
LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
info.minWidth = CELL_SIZE * (NUM_OF_COLS + 2);
info.minHeight = 80;
info.minResizeWidth = CELL_SIZE * (NUM_OF_COLS + 1);
info.minResizeHeight = 50;
InvariantDeviceProfile idp = createIDP();
info.initSpans(mContext, idp);
assertThat(info.isMinSizeFulfilled()).isFalse();
}
use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.
the class LauncherAppWidgetProviderInfoTest method initSpans_minWidthSmallerThanCellWidth_shouldInitializeSpansToOne.
@Test
public void initSpans_minWidthSmallerThanCellWidth_shouldInitializeSpansToOne() {
LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
info.minWidth = 20;
info.minHeight = 20;
InvariantDeviceProfile idp = createIDP();
info.initSpans(mContext, idp);
assertThat(info.spanX).isEqualTo(1);
assertThat(info.spanY).isEqualTo(1);
}
Aggregations