use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.
the class Workspace method beginDragShared.
public void beginDragShared(View child, DragSource source, DragOptions options) {
Object dragObject = child.getTag();
if (!(dragObject instanceof ItemInfo)) {
String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag();
throw new IllegalStateException(msg);
}
beginDragShared(child, null, source, (ItemInfo) dragObject, new DragPreviewProvider(child), options);
}
use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.
the class ItemLongClickListener method onAllAppsItemLongClick.
private static boolean onAllAppsItemLongClick(View v) {
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onAllAppsItemLongClick");
v.cancelLongPress();
Launcher launcher = Launcher.getLauncher(v.getContext());
if (!canStartDrag(launcher))
return false;
// When we have exited all apps or are in transition, disregard long clicks
if (!launcher.isInState(ALL_APPS) && !launcher.isInState(OVERVIEW))
return false;
if (launcher.getWorkspace().isSwitchingState())
return false;
StatsLogger logger = launcher.getStatsLogManager().logger();
if (v.getTag() instanceof ItemInfo) {
logger.withItemInfo((ItemInfo) v.getTag());
}
logger.log(LAUNCHER_ALLAPPS_ITEM_LONG_PRESSED);
// Start the drag
final DragController dragController = launcher.getDragController();
dragController.addDragListener(new DragController.DragListener() {
@Override
public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
v.setVisibility(INVISIBLE);
}
@Override
public void onDragEnd() {
v.setVisibility(VISIBLE);
dragController.removeDragListener(this);
}
});
DeviceProfile grid = launcher.getDeviceProfile();
DragOptions options = new DragOptions();
options.intrinsicIconScaleFactor = (float) grid.allAppsIconSizePx / grid.iconSizePx;
launcher.getWorkspace().beginDragShared(v, launcher.getAppsView(), options);
return false;
}
use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.
the class FlingToDeleteHelper method getFlingAnimation.
public Runnable getFlingAnimation(DropTarget.DragObject dragObject, DragOptions options) {
if (options == null) {
return null;
}
PointF vel = isFlingingToDelete();
options.isFlingToDelete = vel != null;
if (!options.isFlingToDelete) {
return null;
}
return new FlingAnimation(dragObject, vel, mDropTarget, mLauncher, options);
}
use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.
the class Folder method onDrop.
@Override
public void onDrop(DragObject d, DragOptions options) {
// the target location again such that the icon is placed of the final page.
if (!mContent.rankOnCurrentPage(mEmptyCellRank)) {
// Reorder again.
mTargetRank = getTargetRank(d, null);
// Rearrange items immediately.
mReorderAlarmListener.onAlarm(mReorderAlarm);
mOnScrollHintAlarm.cancelAlarm();
mScrollPauseAlarm.cancelAlarm();
}
mContent.completePendingPageChanges();
Launcher launcher = mLauncherDelegate.getLauncher();
if (launcher == null) {
return;
}
PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo ? (PendingAddShortcutInfo) d.dragInfo : null;
WorkspaceItemInfo pasiSi = pasi != null ? pasi.activityInfo.createWorkspaceItemInfo() : null;
if (pasi != null && pasiSi == null) {
// There is no WorkspaceItemInfo, so we have to go through a configuration activity.
pasi.container = mInfo.id;
pasi.rank = mEmptyCellRank;
launcher.addPendingItem(pasi, pasi.container, pasi.screenId, null, pasi.spanX, pasi.spanY);
d.deferDragViewCleanupPostAnimation = false;
mRearrangeOnClose = true;
} else {
final WorkspaceItemInfo si;
if (pasiSi != null) {
si = pasiSi;
} else if (d.dragInfo instanceof AppInfo) {
// Came from all apps -- make a copy.
si = ((AppInfo) d.dragInfo).makeWorkspaceItem();
} else {
// WorkspaceItemInfo
si = (WorkspaceItemInfo) d.dragInfo;
}
View currentDragView;
if (mIsExternalDrag) {
currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
// Actually move the item in the database if it was an external drag. Call this
// before creating the view, so that WorkspaceItemInfo is updated appropriately.
mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(si, mInfo.id, 0, si.cellX, si.cellY);
mIsExternalDrag = false;
} else {
currentDragView = mCurrentDragView;
mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
}
if (d.dragView.hasDrawn()) {
// Temporarily reset the scale such that the animation target gets calculated
// correctly.
float scaleX = getScaleX();
float scaleY = getScaleY();
setScaleX(1.0f);
setScaleY(1.0f);
launcher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, null);
setScaleX(scaleX);
setScaleY(scaleY);
} else {
d.deferDragViewCleanupPostAnimation = false;
currentDragView.setVisibility(VISIBLE);
}
mItemsInvalidated = true;
rearrangeChildren();
// Temporarily suppress the listener, as we did all the work already here.
try (SuppressInfoChanges s = new SuppressInfoChanges()) {
mInfo.add(si, mEmptyCellRank, false);
}
// #onDropCompleted.
if (d.dragSource != this) {
updateItemLocationsInDatabaseBatch(false);
}
}
// Clear the drag info, as it is no longer being dragged.
mDragInProgress = false;
if (mContent.getPageCount() > 1) {
// The animation has already been shown while opening the folder.
mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncherDelegate.getModelWriter());
}
launcher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
if (d.stateAnnouncer != null) {
d.stateAnnouncer.completeAction(R.string.item_moved);
}
mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LAUNCHER_ITEM_DROP_COMPLETED);
}
use of com.android.launcher3.dragndrop.DragOptions in project android_packages_apps_Launcher3 by crdroidandroid.
the class PendingItemDragHelper method startDrag.
/**
* Starts the drag for the pending item associated with the view.
*
* @param previewBounds The bounds where the image was displayed,
* {@link WidgetImageView#getBitmapBounds()}
* @param previewBitmapWidth The actual width of the bitmap displayed in the view.
* @param previewViewWidth The width of {@link WidgetImageView} displaying the preview
* @param screenPos Position of {@link WidgetImageView} on the screen
*/
public void startDrag(Rect previewBounds, int previewBitmapWidth, int previewViewWidth, Point screenPos, DragSource source, DragOptions options) {
final Launcher launcher = Launcher.getLauncher(mView.getContext());
LauncherAppState app = LauncherAppState.getInstance(launcher);
Drawable preview = null;
final int previewWidth;
final int previewHeight;
final float scale;
final Point dragOffset;
final Rect dragRegion;
mEstimatedCellSize = launcher.getWorkspace().estimateItemSize(mAddInfo);
DraggableView draggableView;
if (mAddInfo instanceof PendingAddWidgetInfo) {
PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) mAddInfo;
int maxWidth = Math.min((int) (previewBitmapWidth * MAX_WIDGET_SCALE), mEstimatedCellSize[0]);
int[] previewSizeBeforeScale = new int[1];
if (mRemoteViewsPreview != null) {
mAppWidgetHostViewPreview = new LauncherAppWidgetHostView(launcher);
mAppWidgetHostViewPreview.setAppWidget(/* appWidgetId= */
-1, ((PendingAddWidgetInfo) mAddInfo).info);
DeviceProfile deviceProfile = launcher.getDeviceProfile();
Rect padding = new Rect();
mAppWidgetHostViewPreview.getWidgetInset(deviceProfile, padding);
mAppWidgetHostViewPreview.setPadding(padding.left, padding.top, padding.right, padding.bottom);
mAppWidgetHostViewPreview.updateAppWidget(/* remoteViews= */
mRemoteViewsPreview);
int width = deviceProfile.cellWidthPx * mAddInfo.spanX + padding.left + padding.right;
int height = deviceProfile.cellHeightPx * mAddInfo.spanY + padding.top + padding.bottom;
mAppWidgetHostViewPreview.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
if (mAppWidgetHostViewPreview != null) {
previewSizeBeforeScale[0] = mAppWidgetHostViewPreview.getMeasuredWidth();
launcher.getDragController().addDragListener(new AppWidgetHostViewDragListener(launcher));
}
if (preview == null && mAppWidgetHostViewPreview == null) {
Drawable p = new FastBitmapDrawable(app.getWidgetCache().generateWidgetPreview(launcher, createWidgetInfo.info, maxWidth, null, previewSizeBeforeScale).first);
if (RoundedCornerEnforcement.isRoundedCornerEnabled()) {
p = new RoundDrawableWrapper(p, mEnforcedRoundedCornersForWidget);
}
preview = p;
}
if (previewSizeBeforeScale[0] < previewBitmapWidth) {
// The icon has extra padding around it.
int padding = (previewBitmapWidth - previewSizeBeforeScale[0]) / 2;
if (previewBitmapWidth > previewViewWidth) {
padding = padding * previewViewWidth / previewBitmapWidth;
}
previewBounds.left += padding;
previewBounds.right -= padding;
}
if (mAppWidgetHostViewPreview != null) {
previewWidth = mAppWidgetHostViewPreview.getMeasuredWidth();
previewHeight = mAppWidgetHostViewPreview.getMeasuredHeight();
} else {
previewWidth = preview.getIntrinsicWidth();
previewHeight = preview.getIntrinsicHeight();
}
scale = previewBounds.width() / (float) previewWidth;
launcher.getDragController().addDragListener(new WidgetHostViewLoader(launcher, mView));
dragOffset = null;
dragRegion = null;
draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_WIDGET);
} else {
PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) mAddInfo;
Drawable icon = createShortcutInfo.activityInfo.getFullResIcon(app.getIconCache());
LauncherIcons li = LauncherIcons.obtain(launcher);
preview = new FastBitmapDrawable(li.createScaledBitmapWithoutShadow(icon, 0));
previewWidth = preview.getIntrinsicWidth();
previewHeight = preview.getIntrinsicHeight();
li.recycle();
scale = ((float) launcher.getDeviceProfile().iconSizePx) / previewWidth;
dragOffset = new Point(previewPadding / 2, previewPadding / 2);
// Create a preview same as the workspace cell size and draw the icon at the
// appropriate position.
DeviceProfile dp = launcher.getDeviceProfile();
int iconSize = dp.iconSizePx;
int padding = launcher.getResources().getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
previewBounds.left += padding;
previewBounds.top += padding;
dragRegion = new Rect();
dragRegion.left = (mEstimatedCellSize[0] - iconSize) / 2;
dragRegion.right = dragRegion.left + iconSize;
dragRegion.top = (mEstimatedCellSize[1] - iconSize - dp.iconTextSizePx - dp.iconDrawablePaddingPx) / 2;
dragRegion.bottom = dragRegion.top + iconSize;
draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_ICON);
}
// Since we are not going through the workspace for starting the drag, set drag related
// information on the workspace before starting the drag.
launcher.getWorkspace().prepareDragWithProvider(this);
int dragLayerX = screenPos.x + previewBounds.left + (int) ((scale * previewWidth - previewWidth) / 2);
int dragLayerY = screenPos.y + previewBounds.top + (int) ((scale * previewHeight - previewHeight) / 2);
// Start the drag
if (mAppWidgetHostViewPreview != null) {
launcher.getDragController().startDrag(mAppWidgetHostViewPreview, draggableView, dragLayerX, dragLayerY, source, mAddInfo, dragOffset, dragRegion, scale, scale, options);
} else {
launcher.getDragController().startDrag(preview, draggableView, dragLayerX, dragLayerY, source, mAddInfo, dragOffset, dragRegion, scale, scale, options);
}
}
Aggregations