Search in sources :

Example 31 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_404Launcher by P-404.

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

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_404Launcher by P-404.

the class SecondaryDisplayLauncher method onIconClicked.

private void onIconClicked(View v) {
    // view has detached (it's possible for this to happen if the view is removed mid touch).
    if (v.getWindowToken() == null)
        return;
    Object tag = v.getTag();
    if (tag instanceof ItemInfo) {
        ItemInfo item = (ItemInfo) tag;
        Intent intent;
        if (item instanceof ItemInfoWithIcon && (((ItemInfoWithIcon) item).runtimeStatusFlags & ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE) != 0) {
            ItemInfoWithIcon appInfo = (ItemInfoWithIcon) item;
            intent = appInfo.getMarketIntent(this);
        } else {
            intent = item.getIntent();
        }
        if (intent == null) {
            throw new IllegalArgumentException("Input must have a valid intent");
        }
        startActivitySafely(v, intent, item);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) Intent(android.content.Intent) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon)

Example 33 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_404Launcher by P-404.

the class ItemClickHandler method onClick.

private static void onClick(View v) {
    // 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);
    } else if (tag instanceof FolderInfo) {
        if (v instanceof FolderIcon) {
            onClickFolderIcon(v);
        }
    } else if (tag instanceof AppInfo) {
        startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher);
    } else if (tag instanceof LauncherAppWidgetInfo) {
        if (v instanceof PendingAppWidgetHostView) {
            onClickPendingWidget((PendingAppWidgetHostView) v, launcher);
        }
    } else if (tag instanceof SearchActionItemInfo) {
        onClickSearchAction(launcher, (SearchActionItemInfo) tag);
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) Launcher(com.android.launcher3.Launcher) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) 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)

Example 34 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_404Launcher by P-404.

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

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_404Launcher by P-404.

the class TaskbarDragController method startSystemDrag.

private void startSystemDrag(BubbleTextView btv) {
    View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(btv) {

        @Override
        public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
            shadowSize.set(mDragIconSize, mDragIconSize);
            // The registration point was taken before the icon scaled to mDragIconSize, so
            // offset the registration to where the touch is on the new size.
            int offsetX = (mDragIconSize - mDragObject.dragView.getDragRegionWidth()) / 2;
            int offsetY = (mDragIconSize - mDragObject.dragView.getDragRegionHeight()) / 2;
            shadowTouchPoint.set(mRegistrationX + offsetX, mRegistrationY + offsetY);
        }

        @Override
        public void onDrawShadow(Canvas canvas) {
            canvas.save();
            float scale = mDragObject.dragView.getScaleX();
            canvas.scale(scale, scale);
            mDragObject.dragView.draw(canvas);
            canvas.restore();
        }
    };
    Object tag = btv.getTag();
    ClipDescription clipDescription = null;
    Intent intent = null;
    if (tag instanceof WorkspaceItemInfo) {
        WorkspaceItemInfo item = (WorkspaceItemInfo) tag;
        LauncherApps launcherApps = mActivity.getSystemService(LauncherApps.class);
        clipDescription = new ClipDescription(item.title, new String[] { item.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT ? ClipDescriptionCompat.MIMETYPE_APPLICATION_SHORTCUT : ClipDescriptionCompat.MIMETYPE_APPLICATION_ACTIVITY });
        intent = new Intent();
        if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
            intent.putExtra(Intent.EXTRA_PACKAGE_NAME, item.getIntent().getPackage());
            intent.putExtra(Intent.EXTRA_SHORTCUT_ID, item.getDeepShortcutId());
        } else {
            intent.putExtra(ClipDescriptionCompat.EXTRA_PENDING_INTENT, LauncherAppsCompat.getMainActivityLaunchIntent(launcherApps, item.getIntent().getComponent(), null, item.user));
        }
        intent.putExtra(Intent.EXTRA_USER, item.user);
    } else if (tag instanceof Task) {
        Task task = (Task) tag;
        clipDescription = new ClipDescription(task.titleDescription, new String[] { ClipDescriptionCompat.MIMETYPE_APPLICATION_TASK });
        intent = new Intent();
        intent.putExtra(ClipDescriptionCompat.EXTRA_TASK_ID, task.key.id);
        intent.putExtra(Intent.EXTRA_USER, UserHandle.of(task.key.userId));
    }
    if (clipDescription != null && intent != null) {
        // Need to share the same InstanceId between launcher3 and WM Shell (internal).
        InstanceId internalInstanceId = new InstanceIdSequence(com.android.launcher3.logging.InstanceId.INSTANCE_ID_MAX).newInstanceId();
        com.android.launcher3.logging.InstanceId launcherInstanceId = new com.android.launcher3.logging.InstanceId(internalInstanceId.getId());
        intent.putExtra(ClipDescription.EXTRA_LOGGING_INSTANCE_ID, internalInstanceId);
        ClipData clipData = new ClipData(clipDescription, new ClipData.Item(intent));
        if (btv.startDragAndDrop(clipData, shadowBuilder, null, /* localState */
        View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_OPAQUE)) {
            onSystemDragStarted();
            mActivity.getStatsLogManager().logger().withItemInfo(mDragObject.dragInfo).withInstanceId(launcherInstanceId).log(StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DRAG_STARTED);
        }
    }
}
Also used : Task(com.android.systemui.shared.recents.model.Task) InstanceId(com.android.internal.logging.InstanceId) Canvas(android.graphics.Canvas) Intent(android.content.Intent) LauncherApps(android.content.pm.LauncherApps) Point(android.graphics.Point) DraggableView(com.android.launcher3.dragndrop.DraggableView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point) InstanceIdSequence(com.android.internal.logging.InstanceIdSequence) ClipData(android.content.ClipData) ClipDescription(android.content.ClipDescription) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

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