Search in sources :

Example 11 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Trebuchet by LineageOS.

the class DragController method startDrag.

/**
 * Starts a drag.
 * When the drag is started, the UI automatically goes into spring loaded mode. On a successful
 * drop, it is the responsibility of the {@link DropTarget} to exit out of the spring loaded
 * mode. If the drop was cancelled for some reason, the UI will automatically exit out of this mode.
 *
 * @param b The bitmap to display as the drag image.  It will be re-scaled to the
 *          enlarged size.
 * @param originalView The source view (ie. icon, widget etc.) that is being dragged
 *          and which the DragView represents
 * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
 * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
 * @param source An object representing where the drag originated
 * @param dragInfo The data associated with the object that is being dragged
 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
 *          Makes dragging feel more precise, e.g. you can clip out a transparent border
 */
public DragView startDrag(Bitmap b, DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source, ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale, float dragViewScaleOnDrop, DragOptions options) {
    if (PROFILE_DRAWING_DURING_DRAG) {
        android.os.Debug.startMethodTracing("Launcher");
    }
    mLauncher.hideKeyboard();
    AbstractFloatingView.closeOpenViews(mLauncher, false, TYPE_DISCOVERY_BOUNCE);
    mOptions = options;
    if (mOptions.simulatedDndStartPoint != null) {
        mLastTouch.x = mMotionDown.x = mOptions.simulatedDndStartPoint.x;
        mLastTouch.y = mMotionDown.y = mOptions.simulatedDndStartPoint.y;
    }
    final int registrationX = mMotionDown.x - dragLayerX;
    final int registrationY = mMotionDown.y - dragLayerY;
    final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
    final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
    mLastDropTarget = null;
    mDragObject = new DropTarget.DragObject(mLauncher.getApplicationContext());
    mDragObject.originalView = originalView;
    mIsInPreDrag = mOptions.preDragCondition != null && !mOptions.preDragCondition.shouldStartDrag(0);
    final Resources res = mLauncher.getResources();
    final float scaleDps = mIsInPreDrag ? res.getDimensionPixelSize(R.dimen.pre_drag_view_scale) : 0f;
    final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX, registrationY, initialDragViewScale, dragViewScaleOnDrop, scaleDps);
    dragView.setItemInfo(dragInfo);
    mDragObject.dragComplete = false;
    mDragObject.xOffset = mMotionDown.x - (dragLayerX + dragRegionLeft);
    mDragObject.yOffset = mMotionDown.y - (dragLayerY + dragRegionTop);
    mDragDriver = DragDriver.create(this, mOptions, mFlingToDeleteHelper::recordMotionEvent);
    if (!mOptions.isAccessibleDrag) {
        mDragObject.stateAnnouncer = DragViewStateAnnouncer.createFor(dragView);
    }
    mDragObject.dragSource = source;
    mDragObject.dragInfo = dragInfo;
    mDragObject.originalDragInfo = mDragObject.dragInfo.makeShallowCopy();
    if (dragOffset != null) {
        dragView.setDragVisualizeOffset(new Point(dragOffset));
    }
    if (dragRegion != null) {
        dragView.setDragRegion(new Rect(dragRegion));
    }
    mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    dragView.show(mLastTouch.x, mLastTouch.y);
    mDistanceSinceScroll = 0;
    if (!mIsInPreDrag) {
        callOnDragStart();
    } else if (mOptions.preDragCondition != null) {
        mOptions.preDragCondition.onPreDragStart(mDragObject);
    }
    handleMoveEvent(mLastTouch.x, mLastTouch.y);
    mLauncher.getUserEventDispatcher().resetActionDurationMillis();
    if (!mLauncher.isTouchInProgress() && options.simulatedDndStartPoint == null) {
        // If it is an internal drag and the touch is already complete, cancel immediately
        MAIN_EXECUTOR.submit(this::cancelDrag);
    }
    return dragView;
}
Also used : Rect(android.graphics.Rect) DropTarget(com.android.launcher3.DropTarget) Resources(android.content.res.Resources) Point(android.graphics.Point) Point(android.graphics.Point)

Example 12 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Trebuchet by LineageOS.

the class LoggerUtils method newTouchAction.

public static Action newTouchAction(int touch) {
    Action a = newAction(Action.Type.TOUCH);
    a.touch = touch;
    return a;
}
Also used : Action(com.android.launcher3.userevent.nano.LauncherLogProto.Action)

Example 13 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project Neo-Launcher by NeoApplications.

the class OverviewWithoutFocusInputConsumer method finishTouchTracking.

private void finishTouchTracking(MotionEvent ev) {
    mVelocityTracker.computeCurrentVelocity(100);
    float velocityX = mVelocityTracker.getXVelocity();
    float velocityY = mVelocityTracker.getYVelocity();
    float velocity = mNavBarPosition.isRightEdge() ? -velocityX : (mNavBarPosition.isLeftEdge() ? velocityX : -velocityY);
    final boolean triggerQuickstep;
    int touch = Touch.FLING;
    if (Math.abs(velocity) >= ViewConfiguration.get(mContext).getScaledMinimumFlingVelocity()) {
        triggerQuickstep = velocity > 0;
    } else {
        float displacementX = mDisableHorizontalSwipe ? 0 : (ev.getX() - mDownPos.x);
        float displacementY = ev.getY() - mDownPos.y;
        triggerQuickstep = squaredHypot(displacementX, displacementY) >= mSquaredTouchSlop;
        touch = Touch.SWIPE;
    }
    if (triggerQuickstep) {
        mContext.startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        TOUCH_INTERACTION_LOG.addLog("startQuickstep");
        BaseActivity activity = BaseDraggingActivity.fromContext(mContext);
        // This number doesn't reflect workspace page index.
        int pageIndex = -1;
        // It only indicates that launcher client screen was shown.
        int containerType = StatsLogUtils.getContainerTypeFromState(activity.getCurrentState());
        activity.getUserEventDispatcher().logActionOnContainer(touch, Direction.UP, containerType, pageIndex);
        activity.getUserEventDispatcher().setPreviousHomeGesture(true);
    } else {
    // ignore
    }
}
Also used : BaseActivity(com.android.launcher3.BaseActivity) Intent(android.content.Intent)

Example 14 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project Neo-Launcher by NeoApplications.

the class Workspace method beginDragShared.

public DragView beginDragShared(View child, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    if (TestProtocol.sDebugTracing) {
        Log.d(TestProtocol.NO_CONTEXT_MENU, "beginDragShared");
    }
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    child.clearFocus();
    child.setPressed(false);
    mOutlineProvider = previewProvider;
    // The drag bitmap follows the touch point around on the screen
    final Bitmap b = previewProvider.createDragBitmap();
    int halfPadding = previewProvider.previewPadding / 2;
    float scale = previewProvider.getScaleAndPosition(b, mTempXY);
    int dragLayerX = mTempXY[0];
    int dragLayerY = mTempXY[1];
    DeviceProfile grid = mLauncher.getDeviceProfile();
    Point dragVisualizeOffset = null;
    Rect dragRect = null;
    if (child instanceof BubbleTextView) {
        dragRect = new Rect();
        BubbleTextView.getIconBounds(child, dragRect, grid.iconSizePx);
        dragLayerY += dragRect.top;
        // Note: The dragRect is used to calculate drag layer offsets, but the
        // dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    } else if (child instanceof FolderIcon) {
        int previewSize = grid.folderIconSizePx;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding - child.getPaddingTop());
        dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize);
    } else if (previewProvider instanceof ShortcutDragPreviewProvider) {
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    // Clear the pressed state if necessary
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }
    if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
        PopupContainerWithArrow popupContainer = PopupContainerWithArrow.showForIcon((BubbleTextView) child);
        if (popupContainer != null) {
            dragOptions.preDragCondition = popupContainer.createPreDragCondition();
            mLauncher.getUserEventDispatcher().resetElapsedContainerMillis("dragging started");
        }
    }
    DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    dv.setIntrinsicIconScaleFactor(dragOptions.intrinsicIconScaleFactor);
    return dv;
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Bitmap(android.graphics.Bitmap) FolderIcon(com.android.launcher3.folder.FolderIcon) ShortcutDragPreviewProvider(com.android.launcher3.shortcuts.ShortcutDragPreviewProvider) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow)

Example 15 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project Neo-Launcher by NeoApplications.

the class LoggerUtils method newTouchAction.

public static Action newTouchAction(int touch) {
    Action a = newAction(Action.Type.TOUCH);
    a.touch = touch;
    return a;
}
Also used : Action(com.android.launcher3.userevent.nano.LauncherLogProto.Action)

Aggregations

Point (android.graphics.Point)32 Rect (android.graphics.Rect)28 Intent (android.content.Intent)20 View (android.view.View)17 DragLayer (com.android.launcher3.dragndrop.DragLayer)14 DropTarget (com.android.launcher3.DropTarget)13 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)13 ClipData (android.content.ClipData)12 ClipDescription (android.content.ClipDescription)12 Canvas (android.graphics.Canvas)12 DragView (com.android.launcher3.dragndrop.DragView)12 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)12 DraggableView (com.android.launcher3.dragndrop.DraggableView)10 DeviceProfile (com.android.launcher3.DeviceProfile)8 FolderIcon (com.android.launcher3.folder.FolderIcon)8 AnimatorSet (android.animation.AnimatorSet)7 ObjectAnimator (android.animation.ObjectAnimator)7 SuppressLint (android.annotation.SuppressLint)7 Drawable (android.graphics.drawable.Drawable)7 DragShadowBuilder (android.view.View.DragShadowBuilder)7