Search in sources :

Example 71 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Launcher3 by ProtonAOSP.

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 72 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherDragController method startDrag.

@Override
protected DragView startDrag(@Nullable Drawable drawable, @Nullable View view, DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source, ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale, float dragViewScaleOnDrop, DragOptions options) {
    if (TestProtocol.sDebugTracing) {
        Log.d(TestProtocol.NO_DROP_TARGET, "5");
    }
    if (PROFILE_DRAWING_DURING_DRAG) {
        android.os.Debug.startMethodTracing("Launcher");
    }
    mActivity.hideKeyboard();
    AbstractFloatingView.closeOpenViews(mActivity, 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(mActivity.getApplicationContext());
    mDragObject.originalView = originalView;
    mIsInPreDrag = mOptions.preDragCondition != null && !mOptions.preDragCondition.shouldStartDrag(0);
    final Resources res = mActivity.getResources();
    final float scaleDps = mIsInPreDrag ? res.getDimensionPixelSize(R.dimen.pre_drag_view_scale) : 0f;
    final DragView dragView = mDragObject.dragView = drawable != null ? new LauncherDragView(mActivity, drawable, registrationX, registrationY, initialDragViewScale, dragViewScaleOnDrop, scaleDps) : new LauncherDragView(mActivity, view, view.getMeasuredWidth(), view.getMeasuredHeight(), 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));
    }
    mActivity.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);
    if (!mActivity.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 73 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Launcher3 by ProtonAOSP.

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)

Example 74 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsListTableViewHolderBinder method recycleTableBeforeBinding.

/**
 * Adds and hides table rows and columns from {@code table} to ensure there is sufficient room
 * to display {@code widgetItemsTable}.
 *
 * <p>Instead of recreating all UI elements in {@code table}, this function recycles all
 * existing UI elements. Instead of deleting excessive elements, it hides them.
 */
private void recycleTableBeforeBinding(TableLayout table, List<ArrayList<WidgetItem>> widgetItemsTable) {
    // Hide extra table rows.
    for (int i = widgetItemsTable.size(); i < table.getChildCount(); i++) {
        table.getChildAt(i).setVisibility(View.GONE);
    }
    for (int i = 0; i < widgetItemsTable.size(); i++) {
        List<WidgetItem> widgetItems = widgetItemsTable.get(i);
        TableRow tableRow;
        if (i < table.getChildCount()) {
            tableRow = (TableRow) table.getChildAt(i);
        } else {
            tableRow = new TableRow(table.getContext());
            tableRow.setGravity(Gravity.TOP);
            table.addView(tableRow);
        }
        if (tableRow.getChildCount() > widgetItems.size()) {
            for (int j = widgetItems.size(); j < tableRow.getChildCount(); j++) {
                tableRow.getChildAt(j).setVisibility(View.GONE);
            }
        } else {
            for (int j = tableRow.getChildCount(); j < widgetItems.size(); j++) {
                WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(R.layout.widget_cell, tableRow, false);
                // set up touch.
                View preview = widget.findViewById(R.id.widget_preview_container);
                preview.setOnClickListener(mIconClickListener);
                preview.setOnLongClickListener(mIconLongClickListener);
                widget.setAnimatePreview(false);
                tableRow.addView(widget);
            }
        }
    }
}
Also used : TableRow(android.widget.TableRow) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetCell(com.android.launcher3.widget.WidgetCell) View(android.view.View)

Example 75 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Launcher3 by AOSPA.

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();
    NavigableAppWidgetHostView appWidgetHostView = mWidgetCell.getAppWidgetHostViewPreview();
    // we abort the drag.
    if (img.getDrawable() == null && appWidgetHostView == null) {
        return false;
    }
    final Rect bounds;
    // Start home and pass the draw request params
    final PinItemDragListener listener;
    if (appWidgetHostView != null) {
        bounds = new Rect();
        appWidgetHostView.getSourceVisualDragBounds(bounds);
        float appWidgetHostViewScale = mWidgetCell.getAppWidgetHostViewScale();
        int xOffset = appWidgetHostView.getLeft() - (int) (mLastTouchPos.x * appWidgetHostViewScale);
        int yOffset = appWidgetHostView.getTop() - (int) (mLastTouchPos.y * appWidgetHostViewScale);
        bounds.offset(xOffset, yOffset);
        listener = new PinItemDragListener(mRequest, bounds, appWidgetHostView.getMeasuredWidth(), appWidgetHostView.getMeasuredWidth(), appWidgetHostViewScale);
    } else {
        bounds = img.getBitmapBounds();
        bounds.offset(img.getLeft() - (int) mLastTouchPos.x, img.getTop() - (int) mLastTouchPos.y);
        listener = new PinItemDragListener(mRequest, bounds, img.getDrawable().getIntrinsicWidth(), 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 = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME).setPackage(getPackageName()).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Launcher.ACTIVITY_TRACKER.registerCallback(listener);
    startActivity(homeIntent, ActivityOptions.makeCustomAnimation(this, 0, android.R.anim.fade_out).toBundle());
    logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_DRAGGED);
    mFinishOnPause = true;
    return false;
}
Also used : Rect(android.graphics.Rect) DragShadowBuilder(android.view.View.DragShadowBuilder) Canvas(android.graphics.Canvas) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView) Intent(android.content.Intent) Point(android.graphics.Point) Point(android.graphics.Point) WidgetImageView(com.android.launcher3.widget.WidgetImageView) ClipData(android.content.ClipData) ClipDescription(android.content.ClipDescription)

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