use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by crdroidandroid.
the class Workspace method widgetsRestored.
public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) {
if (!changedInfo.isEmpty()) {
DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, mLauncher.getAppWidgetHost());
LauncherAppWidgetInfo item = changedInfo.get(0);
final AppWidgetProviderInfo widgetInfo;
WidgetManagerHelper widgetHelper = new WidgetManagerHelper(getContext());
if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
widgetInfo = widgetHelper.findProvider(item.providerName, item.user);
} else {
widgetInfo = widgetHelper.getLauncherAppWidgetInfo(item.appWidgetId);
}
if (widgetInfo != null) {
// Re-inflate the widgets which have changed status
widgetRefresh.run();
} else {
// widgetRefresh will automatically run when the packages are updated.
// For now just update the progress bars
mapOverItems(new ItemOperator() {
@Override
public boolean evaluate(ItemInfo info, View view) {
if (view instanceof PendingAppWidgetHostView && changedInfo.contains(info)) {
((LauncherAppWidgetInfo) info).installProgress = 100;
((PendingAppWidgetHostView) view).applyState();
}
// process all the shortcuts
return false;
}
});
}
}
}
use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by crdroidandroid.
the class Launcher method handleActivityResult.
private void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (isWorkspaceLoading()) {
// process the result once the workspace has loaded.
mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
return;
}
mPendingActivityResult = null;
// Reset the startActivity waiting flag
final PendingRequestArgs requestArgs = mPendingRequestArgs;
setWaitingForResult(null);
if (requestArgs == null) {
return;
}
final int pendingAddWidgetId = requestArgs.getWidgetId();
Runnable exitSpringLoaded = new Runnable() {
@Override
public void run() {
mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
}
};
if (requestCode == REQUEST_BIND_APPWIDGET) {
// This is called only if the user did not previously have permissions to bind widgets
final int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
if (resultCode == RESULT_CANCELED) {
completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
} else if (resultCode == RESULT_OK) {
addAppWidgetImpl(appWidgetId, requestArgs, null, requestArgs.getWidgetHandler(), ON_ACTIVITY_RESULT_ANIMATION_DELAY);
}
return;
}
boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET);
// We have special handling for widgets
if (isWidgetDrop) {
final int appWidgetId;
int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
if (widgetId < 0) {
appWidgetId = pendingAddWidgetId;
} else {
appWidgetId = widgetId;
}
final int result;
if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " + "returned from the widget configuration activity.");
result = RESULT_CANCELED;
completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, () -> getStateManager().goToState(NORMAL));
} else {
if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
// When the screen id represents an actual screen (as opposed to a rank)
// we make sure that the drop page actually exists.
requestArgs.screenId = ensurePendingDropLayoutExists(requestArgs.screenId);
}
final CellLayout dropLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
dropLayout.setDropPending(true);
final Runnable onComplete = new Runnable() {
@Override
public void run() {
completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
dropLayout.setDropPending(false);
}
};
mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, onComplete);
}
return;
}
if (requestCode == REQUEST_RECONFIGURE_APPWIDGET || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
if (resultCode == RESULT_OK) {
// Update the widget view.
completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
}
// Leave the widget in the pending state if the user canceled the configure.
return;
}
if (requestCode == REQUEST_CREATE_SHORTCUT) {
// Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
completeAdd(requestCode, data, -1, requestArgs);
mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
} else if (resultCode == RESULT_CANCELED) {
mWorkspace.removeExtraEmptyScreenDelayed(ON_ACTIVITY_RESULT_ANIMATION_DELAY, false, exitSpringLoaded);
}
}
mDragLayer.clearAnimatedView();
}
use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by crdroidandroid.
the class LauncherAppWidgetProviderInfo method initSpans.
public void initSpans(Context context, InvariantDeviceProfile idp) {
int minSpanX = 0;
int minSpanY = 0;
int maxSpanX = idp.numColumns;
int maxSpanY = idp.numRows;
int spanX = 0;
int spanY = 0;
Rect widgetPadding = new Rect();
Rect localPadding = new Rect();
AppWidgetHostView.getDefaultPaddingForWidget(context, provider, widgetPadding);
Point cellSize = new Point();
for (DeviceProfile dp : idp.supportedProfiles) {
dp.getCellSize(cellSize);
// If grids supports insetting widgets, we do not account for widget padding.
if (dp.shouldInsetWidgets()) {
localPadding.setEmpty();
} else {
localPadding.set(widgetPadding);
}
minSpanX = Math.max(minSpanX, getSpanX(localPadding, minResizeWidth, dp.cellLayoutBorderSpacingPx, cellSize.x));
minSpanY = Math.max(minSpanY, getSpanY(localPadding, minResizeHeight, dp.cellLayoutBorderSpacingPx, cellSize.y));
if (ATLEAST_S) {
if (maxResizeWidth > 0) {
maxSpanX = Math.min(maxSpanX, getSpanX(localPadding, maxResizeWidth, dp.cellLayoutBorderSpacingPx, cellSize.x));
}
if (maxResizeHeight > 0) {
maxSpanY = Math.min(maxSpanY, getSpanY(localPadding, maxResizeHeight, dp.cellLayoutBorderSpacingPx, cellSize.y));
}
}
spanX = Math.max(spanX, getSpanX(localPadding, minWidth, dp.cellLayoutBorderSpacingPx, cellSize.x));
spanY = Math.max(spanY, getSpanY(localPadding, minHeight, dp.cellLayoutBorderSpacingPx, cellSize.y));
}
if (ATLEAST_S) {
// Ensures maxSpan >= minSpan
maxSpanX = Math.max(maxSpanX, minSpanX);
maxSpanY = Math.max(maxSpanY, minSpanY);
// Otherwise, use the span of minWidth/Height.
if (targetCellWidth >= minSpanX && targetCellWidth <= maxSpanX && targetCellHeight >= minSpanY && targetCellHeight <= maxSpanY) {
spanX = targetCellWidth;
spanY = targetCellHeight;
}
}
// If minSpanX/Y > spanX/Y, ignore the minSpanX/Y to match the behavior described in
// minResizeWidth & minResizeHeight Android documentation. See
// https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo
this.minSpanX = Math.min(spanX, minSpanX);
this.minSpanY = Math.min(spanY, minSpanY);
this.maxSpanX = maxSpanX;
this.maxSpanY = maxSpanY;
this.mIsMinSizeFulfilled = Math.min(spanX, minSpanX) <= idp.numColumns && Math.min(spanY, minSpanY) <= idp.numRows;
// Ensures the default span X and span Y will not exceed the current grid size.
this.spanX = Math.min(spanX, idp.numColumns);
this.spanY = Math.min(spanY, idp.numRows);
}
use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsModel method setWidgetsAndShortcuts.
private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts, LauncherAppState app, @Nullable PackageUserKey packageUser) {
if (DEBUG) {
Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
}
// Temporary cache for {@link PackageItemInfos} to avoid having to go through
// {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
PackageItemInfoCache packageItemInfoCache = new PackageItemInfoCache();
if (packageUser == null) {
// Clear the list if this is an update on all widgets and shortcuts.
mWidgetsList.clear();
} else {
// Otherwise, only clear the widgets and shortcuts for the changed package.
mWidgetsList.remove(packageItemInfoCache.getOrCreate(new WidgetPackageOrCategoryKey(packageUser)));
}
// add and update.
mWidgetsList.putAll(rawWidgetsShortcuts.stream().filter(new WidgetValidityCheck(app)).collect(Collectors.groupingBy(item -> packageItemInfoCache.getOrCreate(getWidgetPackageOrCategoryKey(item)))));
// Update each package entry
IconCache iconCache = app.getIconCache();
for (PackageItemInfo p : packageItemInfoCache.values()) {
iconCache.getTitleAndIconForApp(p, true);
}
}
use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsModel method getAllWidgetsWithoutShortcuts.
/**
* Returns a mapping of packages to their widgets without static shortcuts.
*/
public synchronized Map<PackageUserKey, List<WidgetItem>> getAllWidgetsWithoutShortcuts() {
Map<PackageUserKey, List<WidgetItem>> packagesToWidgets = new HashMap<>();
mWidgetsList.forEach((packageItemInfo, widgetsAndShortcuts) -> {
List<WidgetItem> widgets = widgetsAndShortcuts.stream().filter(item -> item.widgetInfo != null).collect(toList());
if (widgets.size() > 0) {
packagesToWidgets.put(new PackageUserKey(packageItemInfo.packageName, packageItemInfo.user), widgets);
}
});
return packagesToWidgets;
}
Aggregations