use of com.android.launcher3.FolderInfo in project android_packages_apps_Trebuchet by LineageOS.
the class Workspace method updateShortcuts.
void updateShortcuts(ArrayList<WorkspaceItemInfo> shortcuts) {
final HashSet<WorkspaceItemInfo> updates = new HashSet<>(shortcuts);
ItemOperator op = (info, v) -> {
if (v instanceof BubbleTextView && updates.contains(info)) {
WorkspaceItemInfo si = (WorkspaceItemInfo) info;
BubbleTextView shortcut = (BubbleTextView) v;
Drawable oldIcon = shortcut.getIcon();
boolean oldPromiseState = (oldIcon instanceof PreloadIconDrawable) && ((PreloadIconDrawable) oldIcon).hasNotCompleted();
shortcut.applyFromWorkspaceItem(si, si.isPromise() != oldPromiseState);
} else if (info instanceof FolderInfo && v instanceof FolderIcon) {
((FolderIcon) v).updatePreviewItems(updates::contains);
}
// Iterate all items
return false;
};
mapOverItems(op);
Folder openFolder = Folder.getOpen(mLauncher);
if (openFolder != null) {
openFolder.iterateOverItems(op);
}
}
use of com.android.launcher3.FolderInfo in project android_packages_apps_Trebuchet by LineageOS.
the class WorkspaceAccessibilityHelper method intersectsValidDropTarget.
/**
* Find the virtual view id corresponding to the top left corner of any drop region by which
* the passed id is contained. For an icon, this is simply
*/
@Override
protected int intersectsValidDropTarget(int id) {
int mCountX = mView.getCountX();
int mCountY = mView.getCountY();
int x = id % mCountX;
int y = id / mCountX;
LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
if (dragInfo.dragType == DragType.WIDGET && !mView.acceptsWidget()) {
return INVALID_POSITION;
}
if (dragInfo.dragType == DragType.WIDGET) {
// For a widget, every cell must be vacant. In addition, we will return any valid
// drop target by which the passed id is contained.
boolean fits = false;
// These represent the amount that we can back off if we hit a problem. They
// get consumed as we move up and to the right, trying new regions.
int spanX = dragInfo.info.spanX;
int spanY = dragInfo.info.spanY;
for (int m = 0; m < spanX; m++) {
for (int n = 0; n < spanY; n++) {
fits = true;
int x0 = x - m;
int y0 = y - n;
if (x0 < 0 || y0 < 0)
continue;
for (int i = x0; i < x0 + spanX; i++) {
if (!fits)
break;
for (int j = y0; j < y0 + spanY; j++) {
if (i >= mCountX || j >= mCountY || mView.isOccupied(i, j)) {
fits = false;
break;
}
}
}
if (fits) {
return x0 + mCountX * y0;
}
}
}
return INVALID_POSITION;
} else {
// For an icon, we simply check the view directly below
View child = mView.getChildAt(x, y);
if (child == null || child == dragInfo.item) {
// Empty cell. Good for an icon or folder.
return id;
} else if (dragInfo.dragType != DragType.FOLDER) {
// For icons, we can consider cells that have another icon or a folder.
ItemInfo info = (ItemInfo) child.getTag();
if (info instanceof AppInfo || info instanceof FolderInfo || info instanceof WorkspaceItemInfo) {
return id;
}
}
return INVALID_POSITION;
}
}
use of com.android.launcher3.FolderInfo in project android_packages_apps_Trebuchet by LineageOS.
the class Launcher method removeItem.
/**
* Unbinds the view for the specified item, and removes the item and all its children.
*
* @param v the view being removed.
* @param itemInfo the {@link ItemInfo} for this view.
* @param deleteFromDb whether or not to delete this item from the db.
*/
public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
if (itemInfo instanceof WorkspaceItemInfo) {
// Remove the shortcut from the folder before removing it from launcher
View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
if (folderIcon instanceof FolderIcon) {
((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
} else {
mWorkspace.removeWorkspaceItem(v);
}
if (deleteFromDb) {
getModelWriter().deleteItemFromDatabase(itemInfo);
}
} else if (itemInfo instanceof FolderInfo) {
final FolderInfo folderInfo = (FolderInfo) itemInfo;
if (v instanceof FolderIcon) {
((FolderIcon) v).removeListeners();
}
mWorkspace.removeWorkspaceItem(v);
if (deleteFromDb) {
getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
}
} else if (itemInfo instanceof LauncherAppWidgetInfo) {
final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
mWorkspace.removeWorkspaceItem(v);
if (deleteFromDb) {
getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
}
} else {
return false;
}
return true;
}
use of com.android.launcher3.FolderInfo in project android_packages_apps_Trebuchet by LineageOS.
the class Launcher method completeAddShortcut.
/**
* Add a shortcut to the workspace or to a Folder.
*
* @param data The intent describing the shortcut.
*/
private void completeAddShortcut(Intent data, int container, int screenId, int cellX, int cellY, PendingRequestArgs args) {
if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT || args.getPendingIntent().getComponent() == null) {
return;
}
int[] cellXY = mTmpAddItemCellCoordinates;
CellLayout layout = getCellLayout(container, screenId);
WorkspaceItemInfo info = null;
if (Utilities.ATLEAST_OREO) {
info = PinRequestHelper.createWorkspaceItemFromPinItemRequest(this, PinRequestHelper.getPinItemRequest(data), 0);
}
if (info == null) {
// Legacy shortcuts are only supported for primary profile.
info = Process.myUserHandle().equals(args.user) ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
if (info == null) {
Log.e(TAG, "Unable to parse a valid custom shortcut result");
return;
} else if (!new PackageManagerHelper(this).hasPermissionForActivity(info.intent, args.getPendingIntent().getComponent().getPackageName())) {
// The app is trying to add a shortcut without sufficient permissions
Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
return;
}
}
if (container < 0) {
// Adding a shortcut to the Workspace.
final View view = createShortcut(info);
boolean foundCellSpan = false;
// First we check if we already know the exact location where we want to add this item.
if (cellX >= 0 && cellY >= 0) {
cellXY[0] = cellX;
cellXY[1] = cellY;
foundCellSpan = true;
DragObject dragObject = new DragObject(getApplicationContext());
dragObject.dragInfo = info;
// If appropriate, either create a folder or add to an existing folder
if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, true, dragObject)) {
return;
}
if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, true)) {
return;
}
} else {
foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
}
if (!foundCellSpan) {
mWorkspace.onNoCellFound(layout);
return;
}
getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
mWorkspace.addInScreen(view, info);
} else {
// Adding a shortcut to a Folder.
FolderIcon folderIcon = findFolderIcon(container);
if (folderIcon != null) {
FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
folderInfo.add(info, args.rank, false);
} else {
Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
}
}
}
use of com.android.launcher3.FolderInfo in project android_packages_apps_Trebuchet by LineageOS.
the class ItemInfoMatcher method filterItemInfos.
/**
* Filters {@param infos} to those satisfying the {@link #matches(ItemInfo, ComponentName)}.
*/
default HashSet<ItemInfo> filterItemInfos(Iterable<ItemInfo> infos) {
HashSet<ItemInfo> filtered = new HashSet<>();
for (ItemInfo i : infos) {
if (i instanceof WorkspaceItemInfo) {
WorkspaceItemInfo info = (WorkspaceItemInfo) i;
ComponentName cn = info.getTargetComponent();
if (cn != null && matches(info, cn)) {
filtered.add(info);
}
} else if (i instanceof FolderInfo) {
FolderInfo info = (FolderInfo) i;
for (WorkspaceItemInfo s : info.contents) {
ComponentName cn = s.getTargetComponent();
if (cn != null && matches(s, cn)) {
filtered.add(s);
}
}
} else if (i instanceof LauncherAppWidgetInfo) {
LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) i;
ComponentName cn = info.providerName;
if (cn != null && matches(info, cn)) {
filtered.add(info);
}
}
}
return filtered;
}
Aggregations