Search in sources :

Example 51 with Touch

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

the class AddItemActivity method onLongClick.

@Override
public boolean onLongClick(View view) {
    // Find the position of the preview relative to the touch location.
    WidgetImageView img = mWidgetCell.getWidgetView();
    // we abort the drag.
    if (img.getBitmap() == null) {
        return false;
    }
    Rect bounds = img.getBitmapBounds();
    bounds.offset(img.getLeft() - (int) mLastTouchPos.x, img.getTop() - (int) mLastTouchPos.y);
    // Start home and pass the draw request params
    PinItemDragListener listener = new PinItemDragListener(mRequest, bounds, img.getBitmap().getWidth(), img.getWidth());
    // Start a system drag and drop. We use a transparent bitmap as preview for system drag
    // as the preview is handled internally by launcher.
    ClipDescription description = new ClipDescription("", new String[] { listener.getMimeType() });
    ClipData data = new ClipData(description, new ClipData.Item(""));
    view.startDragAndDrop(data, new DragShadowBuilder(view) {

        @Override
        public void onDrawShadow(Canvas canvas) {
        }

        @Override
        public void onProvideShadowMetrics(Point outShadowSize, Point outShadowTouchPoint) {
            outShadowSize.set(SHADOW_SIZE, SHADOW_SIZE);
            outShadowTouchPoint.set(SHADOW_SIZE / 2, SHADOW_SIZE / 2);
        }
    }, null, View.DRAG_FLAG_GLOBAL);
    Intent homeIntent = listener.addToIntent(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME).setPackage(getPackageName()).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    listener.initWhenReady();
    startActivity(homeIntent, ActivityOptions.makeCustomAnimation(this, 0, android.R.anim.fade_out).toBundle());
    mFinishOnPause = true;
    return false;
}
Also used : WidgetImageView(com.android.launcher3.widget.WidgetImageView) Rect(android.graphics.Rect) DragShadowBuilder(android.view.View.DragShadowBuilder) Canvas(android.graphics.Canvas) Intent(android.content.Intent) Point(android.graphics.Point) ClipData(android.content.ClipData) ClipDescription(android.content.ClipDescription)

Example 52 with Touch

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

the class DragController method completeAccessibleDrag.

/**
 * As above, since accessible drag and drop won't cause the same sequence of touch events,
 * we manually ensure appropriate drag and drop events get emulated for accessible drag.
 */
public void completeAccessibleDrag(int[] location) {
    final int[] coordinates = mCoordinatesTemp;
    // We make sure that we prime the target for drop.
    DropTarget dropTarget = findDropTarget(location[0], location[1], coordinates);
    mDragObject.x = coordinates[0];
    mDragObject.y = coordinates[1];
    checkTouchMove(dropTarget);
    dropTarget.prepareAccessibilityDrop();
    // Perform the drop
    drop(dropTarget, null);
    endDrag();
}
Also used : DropTarget(com.android.launcher3.DropTarget)

Example 53 with Touch

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

the class ScrimView method updateDragHandleBounds.

protected void updateDragHandleBounds() {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    final int left;
    final int width = getMeasuredWidth();
    final int top = getMeasuredHeight() - mDragHandleSize.y - grid.getInsets().bottom;
    final int topMargin;
    if (grid.isVerticalBarLayout()) {
        topMargin = grid.workspacePadding.bottom + mDragHandlePaddingInVerticalBarLayout;
        if (grid.isSeascape()) {
            left = width - grid.getInsets().right - mDragHandleSize.x - mDragHandlePaddingInVerticalBarLayout;
        } else {
            left = grid.getInsets().left + mDragHandlePaddingInVerticalBarLayout;
        }
    } else {
        left = Math.round((width - mDragHandleSize.x) / 2f);
        topMargin = grid.hotseatBarSizePx;
    }
    mDragHandleBounds.offsetTo(left, top - topMargin);
    mHitRect.set(mDragHandleBounds);
    // Inset outwards to increase touch size.
    mHitRect.inset((mDragHandleSize.x - mDragHandleTouchSize) / 2f, (mDragHandleSize.y - mDragHandleTouchSize) / 2f);
    if (mDragHandle != null) {
        mDragHandle.setBounds(mDragHandleBounds);
    }
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Point(android.graphics.Point)

Example 54 with Touch

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

the class ItemClickHandler method onClick.

private static void onClick(View v, String sourceContainer) {
    // view has detached (it's possible for this to happen if the view is removed mid touch).
    if (v.getWindowToken() == null)
        return;
    Launcher launcher = Launcher.getLauncher(v.getContext());
    if (!launcher.getWorkspace().isFinishedSwitchingState())
        return;
    Object tag = v.getTag();
    if (tag instanceof WorkspaceItemInfo) {
        onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher, sourceContainer);
    } else if (tag instanceof FolderInfo) {
        if (v instanceof FolderIcon) {
            onClickFolderIcon(v);
        }
    } else if (tag instanceof AppInfo) {
        startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher, sourceContainer == null ? CONTAINER_ALL_APPS : sourceContainer);
    } else if (tag instanceof LauncherAppWidgetInfo) {
        if (v instanceof PendingAppWidgetHostView) {
            onClickPendingWidget((PendingAppWidgetHostView) v, launcher);
        }
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) Launcher(com.android.launcher3.Launcher) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AppInfo(com.android.launcher3.model.data.AppInfo) PromiseAppInfo(com.android.launcher3.model.data.PromiseAppInfo)

Example 55 with Touch

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

the class WorkspaceTouchListener method onTouch.

@Override
public boolean onTouch(View view, MotionEvent ev) {
    mGestureDetector.onTouchEvent(ev);
    int action = ev.getActionMasked();
    if (action == ACTION_DOWN) {
        // Check if we can handle long press.
        boolean handleLongPress = canHandleLongPress();
        if (handleLongPress) {
            // Check if the event is not near the edges
            DeviceProfile dp = mLauncher.getDeviceProfile();
            DragLayer dl = mLauncher.getDragLayer();
            Rect insets = dp.getInsets();
            mTempRect.set(insets.left, insets.top, dl.getWidth() - insets.right, dl.getHeight() - insets.bottom);
            mTempRect.inset(dp.edgeMarginPx, dp.edgeMarginPx);
            handleLongPress = mTempRect.contains((int) ev.getX(), (int) ev.getY());
        }
        if (handleLongPress) {
            mLongPressState = STATE_REQUESTED;
            mTouchDownPoint.set(ev.getX(), ev.getY());
        }
        mWorkspace.onTouchEvent(ev);
        // Return true to keep receiving touch events
        return true;
    }
    if (mLongPressState == STATE_PENDING_PARENT_INFORM) {
        // Inform the workspace to cancel touch handling
        ev.setAction(ACTION_CANCEL);
        mWorkspace.onTouchEvent(ev);
        ev.setAction(action);
        mLongPressState = STATE_COMPLETED;
    }
    final boolean result;
    if (mLongPressState == STATE_COMPLETED) {
        // We have handled the touch, so workspace does not need to know anything anymore.
        result = true;
    } else if (mLongPressState == STATE_REQUESTED) {
        mWorkspace.onTouchEvent(ev);
        if (mWorkspace.isHandlingTouch()) {
            cancelLongPress();
        } else if (action == ACTION_MOVE && PointF.length(mTouchDownPoint.x - ev.getX(), mTouchDownPoint.y - ev.getY()) > mTouchSlop) {
            cancelLongPress();
        }
        result = true;
    } else {
        // We don't want to handle touch, let workspace handle it as usual.
        result = false;
    }
    if (action == ACTION_UP || action == ACTION_POINTER_UP) {
        if (!mWorkspace.isHandlingTouch()) {
            final CellLayout currentPage = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
            if (currentPage != null) {
                mWorkspace.onWallpaperTap(ev);
            }
        }
    }
    if (action == ACTION_UP || action == ACTION_CANCEL) {
        cancelLongPress();
    }
    return result;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect) CellLayout(com.android.launcher3.CellLayout)

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