use of com.android.launcher3.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.
the class Utilities method getBadge.
/**
* For apps icons and shortcut icons that have badges, this method creates a drawable that can
* later on be rendered on top of the layers for the badges. For app icons, work profile badges
* can only be applied. For deep shortcuts, when dragged from the pop up container, there's no
* badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge
*/
@TargetApi(Build.VERSION_CODES.O)
public static Drawable getBadge(Launcher launcher, ItemInfo info, Object obj) {
LauncherAppState appState = LauncherAppState.getInstance(launcher);
int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize;
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
boolean iconBadged = (info instanceof ItemInfoWithIcon) && (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0;
if ((info.id == ItemInfo.NO_ID && !iconBadged) || !(obj instanceof ShortcutInfo)) {
// The item is not yet added on home screen.
return new FixedSizeEmptyDrawable(iconSize);
}
ShortcutInfo si = (ShortcutInfo) obj;
Bitmap badge = LauncherAppState.getInstance(appState.getContext()).getIconCache().getShortcutInfoBadge(si).icon;
float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize);
float insetFraction = (iconSize - badgeSize) / iconSize;
return new InsetDrawable(new FastBitmapDrawable(badge), insetFraction, insetFraction, 0, 0);
} else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
return ((FolderAdaptiveIcon) obj).getBadge();
} else {
return launcher.getPackageManager().getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user);
}
}
use of com.android.launcher3.tapl.Folder 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.tapl.Folder 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.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.
the class ItemLongClickListener method beginDrag.
public static void beginDrag(View v, Launcher launcher, ItemInfo info, DragOptions dragOptions) {
if (info.container >= 0) {
Folder folder = Folder.getOpen(launcher);
if (folder != null) {
if (!folder.getIconsInReadingOrder().contains(v)) {
folder.close(true);
} else {
folder.startDrag(v, dragOptions);
return;
}
}
}
CellLayout.CellInfo longClickCellInfo = new CellLayout.CellInfo(v, info);
launcher.getWorkspace().startDrag(longClickCellInfo, dragOptions);
}
use of com.android.launcher3.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.
the class DragLayer method onInterceptHoverEvent.
@Override
public boolean onInterceptHoverEvent(MotionEvent ev) {
if (mActivity == null || mActivity.getWorkspace() == null) {
return false;
}
AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(mActivity);
if (!(topView instanceof Folder)) {
return false;
} else {
AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accessibilityManager.isTouchExplorationEnabled()) {
Folder currentFolder = (Folder) topView;
final int action = ev.getAction();
boolean isOverFolderOrSearchBar;
switch(action) {
case MotionEvent.ACTION_HOVER_ENTER:
isOverFolderOrSearchBar = isEventOverView(topView, ev) || isEventOverAccessibleDropTargetBar(ev);
if (!isOverFolderOrSearchBar) {
sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
mHoverPointClosesFolder = true;
return true;
}
mHoverPointClosesFolder = false;
break;
case MotionEvent.ACTION_HOVER_MOVE:
isOverFolderOrSearchBar = isEventOverView(topView, ev) || isEventOverAccessibleDropTargetBar(ev);
if (!isOverFolderOrSearchBar && !mHoverPointClosesFolder) {
sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
mHoverPointClosesFolder = true;
return true;
} else if (!isOverFolderOrSearchBar) {
return true;
}
mHoverPointClosesFolder = false;
}
}
}
return false;
}
Aggregations