use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.
the class ItemInfo method buildProto.
/**
* Creates {@link LauncherAtom.ItemInfo} with important fields and parent container info.
*/
public LauncherAtom.ItemInfo buildProto(FolderInfo fInfo) {
LauncherAtom.ItemInfo.Builder itemBuilder = getDefaultItemInfoBuilder();
Optional<ComponentName> nullableComponent = Optional.ofNullable(getTargetComponent());
switch(itemType) {
case ITEM_TYPE_APPLICATION:
itemBuilder.setApplication(nullableComponent.map(component -> LauncherAtom.Application.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Application.newBuilder()));
break;
case ITEM_TYPE_DEEP_SHORTCUT:
itemBuilder.setShortcut(nullableComponent.map(component -> {
Shortcut.Builder lsb = Shortcut.newBuilder().setShortcutName(component.flattenToShortString());
Optional.ofNullable(getIntent()).map(i -> i.getStringExtra(EXTRA_SHORTCUT_ID)).ifPresent(lsb::setShortcutId);
return lsb;
}).orElse(LauncherAtom.Shortcut.newBuilder()));
break;
case ITEM_TYPE_SHORTCUT:
itemBuilder.setShortcut(nullableComponent.map(component -> LauncherAtom.Shortcut.newBuilder().setShortcutName(component.flattenToShortString())).orElse(LauncherAtom.Shortcut.newBuilder()));
break;
case ITEM_TYPE_APPWIDGET:
itemBuilder.setWidget(nullableComponent.map(component -> LauncherAtom.Widget.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Widget.newBuilder()).setSpanX(spanX).setSpanY(spanY));
break;
case ITEM_TYPE_TASK:
itemBuilder.setTask(LauncherAtom.Task.newBuilder().setComponentName(getTargetComponent().flattenToShortString()).setIndex(screenId));
break;
default:
break;
}
if (fInfo != null) {
LauncherAtom.FolderContainer.Builder folderBuilder = LauncherAtom.FolderContainer.newBuilder();
folderBuilder.setGridX(cellX).setGridY(cellY).setPageIndex(screenId);
switch(fInfo.container) {
case CONTAINER_HOTSEAT:
case CONTAINER_HOTSEAT_PREDICTION:
folderBuilder.setHotseat(LauncherAtom.HotseatContainer.newBuilder().setIndex(fInfo.screenId));
break;
case CONTAINER_DESKTOP:
folderBuilder.setWorkspace(LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(fInfo.screenId).setGridX(fInfo.cellX).setGridY(fInfo.cellY));
break;
}
itemBuilder.setContainerInfo(ContainerInfo.newBuilder().setFolder(folderBuilder));
} else {
ContainerInfo containerInfo = getContainerInfo();
if (!containerInfo.getContainerCase().equals(CONTAINER_NOT_SET)) {
itemBuilder.setContainerInfo(containerInfo);
}
}
return itemBuilder.build();
}
use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.
the class LoaderCursorTest method getAppShortcutInfo_allowMissing_invalidComponent.
@Test
public void getAppShortcutInfo_allowMissing_invalidComponent() throws Exception {
initCursor(ITEM_TYPE_APPLICATION, "");
assertTrue(mLoaderCursor.moveToNext());
ComponentName cn = new ComponentName(mContext.getPackageName(), "placeholder-do");
WorkspaceItemInfo info = Executors.MODEL_EXECUTOR.submit(() -> mLoaderCursor.getAppShortcutInfo(new Intent().setComponent(cn), true, /* allowMissingTarget */
true)).get();
assertNotNull(info);
assertTrue(PackageManagerHelper.isLauncherAppTarget(info.getIntent()));
}
use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.
the class QuickstepLauncher method logAppLaunch.
@Override
protected void logAppLaunch(ItemInfo info, InstanceId instanceId) {
// LiveSearchManager to recreate the AllApps session on the server side.
if (mAllAppsSessionLogId != null && ALL_APPS.equals(getStateManager().getCurrentStableState())) {
instanceId = mAllAppsSessionLogId;
}
StatsLogger logger = getStatsLogManager().logger().withItemInfo(info).withInstanceId(instanceId);
if (mAllAppsPredictions != null && (info.itemType == ITEM_TYPE_APPLICATION || info.itemType == ITEM_TYPE_SHORTCUT || info.itemType == ITEM_TYPE_DEEP_SHORTCUT)) {
int count = mAllAppsPredictions.items.size();
for (int i = 0; i < count; i++) {
ItemInfo targetInfo = mAllAppsPredictions.items.get(i);
if (targetInfo.itemType == info.itemType && targetInfo.user.equals(info.user) && Objects.equals(targetInfo.getIntent(), info.getIntent())) {
logger.withRank(i);
break;
}
}
}
logger.log(LAUNCHER_APP_LAUNCH_TAP);
mHotseatPredictionController.logLaunchedAppRankingInfo(info, instanceId);
}
use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.
the class LoaderCursorTest method getAppShortcutInfo_dontAllowMissing_validComponent.
@Test
public void getAppShortcutInfo_dontAllowMissing_validComponent() throws Exception {
ComponentName cn = new ComponentName(TEST_PACKAGE, TEST_PACKAGE);
shadowOf(mContext.getPackageManager()).addActivityIfNotPresent(cn);
initCursor(ITEM_TYPE_APPLICATION, "");
assertTrue(mLoaderCursor.moveToNext());
WorkspaceItemInfo info = Executors.MODEL_EXECUTOR.submit(() -> mLoaderCursor.getAppShortcutInfo(new Intent().setComponent(cn), false, /* allowMissingTarget */
true)).get();
assertNotNull(info);
assertTrue(PackageManagerHelper.isLauncherAppTarget(info.getIntent()));
}
use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.
the class Workspace method onDropExternal.
/**
* Drop an item that didn't originate on one of the workspace screens.
* It may have come from Launcher (e.g. from all apps or customize), or it may have
* come from another app altogether.
*
* NOTE: This can also be called when we are outside of a drag event, when we want
* to add an item to one of the workspace screens.
*/
private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
if (d.dragInfo instanceof PendingAddShortcutInfo) {
WorkspaceItemInfo si = ((PendingAddShortcutInfo) d.dragInfo).activityInfo.createWorkspaceItemInfo();
if (si != null) {
d.dragInfo = si;
}
}
ItemInfo info = d.dragInfo;
int spanX = info.spanX;
int spanY = info.spanY;
if (mDragInfo != null) {
spanX = mDragInfo.spanX;
spanY = mDragInfo.spanY;
}
final int container = mLauncher.isHotseatLayout(cellLayout) ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP;
final int screenId = getIdForScreen(cellLayout);
if (!mLauncher.isHotseatLayout(cellLayout) && screenId != getScreenIdForPageIndex(mCurrentPage) && !mLauncher.isInState(SPRING_LOADED)) {
snapToPage(getPageIndexForScreenId(screenId));
}
if (info instanceof PendingAddItemInfo) {
final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) info;
boolean findNearestVacantCell = true;
if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true) || willAddToExistingUserFolder(d.dragInfo, cellLayout, mTargetCell, distance)) {
findNearestVacantCell = false;
}
}
final ItemInfo item = d.dragInfo;
boolean updateWidgetSize = false;
if (findNearestVacantCell) {
int minSpanX = item.spanX;
int minSpanY = item.spanY;
if (item.minSpanX > 0 && item.minSpanY > 0) {
minSpanX = item.minSpanX;
minSpanY = item.minSpanY;
}
int[] resultSpan = new int[2];
mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY, null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL);
if (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY) {
updateWidgetSize = true;
}
item.spanX = resultSpan[0];
item.spanY = resultSpan[1];
}
Runnable onAnimationCompleteRunnable = new Runnable() {
@Override
public void run() {
// Normally removeExtraEmptyScreen is called in Workspace#onDrop, but when
// adding an item that may not be dropped right away (due to a config activity)
// we defer the removal until the activity returns.
deferRemoveExtraEmptyScreen();
// When dragging and dropping from customization tray, we deal with creating
// widgets/shortcuts/folders in a slightly different way
mLauncher.addPendingItem(pendingInfo, container, screenId, mTargetCell, item.spanX, item.spanY);
mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
}
};
boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
AppWidgetHostView finalView = isWidget ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
if (finalView != null && updateWidgetSize) {
WidgetSizes.updateWidgetSizeRanges(finalView, mLauncher, item.spanX, item.spanY);
}
int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR;
if (isWidget && ((PendingAddWidgetInfo) pendingInfo).info != null && ((PendingAddWidgetInfo) pendingInfo).getHandler().needsConfigure()) {
animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN;
}
animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable, animationStyle, finalView, true);
} else {
// This is for other drag/drop cases, like dragging from All Apps
mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
View view;
switch(info.itemType) {
case ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
if (info instanceof AppInfo) {
// Came from all apps -- make a copy
info = ((AppInfo) info).makeWorkspaceItem();
d.dragInfo = info;
}
view = mLauncher.createShortcut(cellLayout, (WorkspaceItemInfo) info);
break;
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
view = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, mLauncher, cellLayout, (FolderInfo) info);
break;
default:
throw new IllegalStateException("Unknown item type: " + info.itemType);
}
// dropped, without any consideration to whether there is an item there.
if (touchXY != null) {
mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, true, d)) {
return;
}
if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, true)) {
return;
}
}
if (touchXY != null) {
// when dragging and dropping, just find the closest free spot
mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], 1, 1, 1, 1, null, mTargetCell, null, CellLayout.MODE_ON_DROP_EXTERNAL);
} else {
cellLayout.findCellForSpan(mTargetCell, 1, 1);
}
// Add the item to DB before adding to screen ensures that the container and other
// values of the info is properly updated.
mLauncher.getModelWriter().addOrMoveItemInDatabase(info, container, screenId, mTargetCell[0], mTargetCell[1]);
addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, info.spanY);
cellLayout.onDropChild(view);
cellLayout.getShortcutsAndWidgets().measureChild(view);
if (d.dragView != null) {
// We wrap the animation call in the temporary set and reset of the current
// cellLayout to its final transform -- this means we animate the drag view to
// the correct final location.
setFinalTransitionTransform();
mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, this);
resetTransitionTransform();
}
mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
}
}
Aggregations