Search in sources :

Example 26 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class BaseSwipeUpHandlerV2 method onLauncherStart.

private void onLauncherStart() {
    final T activity = mActivityInterface.getCreatedActivity();
    if (mActivity != activity) {
        return;
    }
    if (mStateCallback.hasStates(STATE_HANDLER_INVALIDATED)) {
        return;
    }
    mTaskViewSimulator.setRecentsRotation(mActivity.getDisplay().getRotation());
    // as that will set the state as BACKGROUND_APP, overriding the animation to NORMAL.
    if (mGestureState.getEndTarget() != HOME) {
        Runnable initAnimFactory = () -> {
            mAnimationFactory = mActivityInterface.prepareRecentsUI(mDeviceState, mWasLauncherAlreadyVisible, this::onAnimatorPlaybackControllerCreated);
            maybeUpdateRecentsAttachedState(false);
        };
        if (mWasLauncherAlreadyVisible) {
            // Launcher is visible, but might be about to stop. Thus, if we prepare recents
            // now, it might get overridden by moveToRestState() in onStop(). To avoid this,
            // wait until the next gesture (and possibly launcher) starts.
            mStateCallback.runOnceAtState(STATE_GESTURE_STARTED, initAnimFactory);
        } else {
            initAnimFactory.run();
        }
    }
    AbstractFloatingView.closeAllOpenViewsExcept(activity, mWasLauncherAlreadyVisible, AbstractFloatingView.TYPE_LISTENER);
    if (mWasLauncherAlreadyVisible) {
        mStateCallback.setState(STATE_LAUNCHER_DRAWN);
    } else {
        Object traceToken = TraceHelper.INSTANCE.beginSection("WTS-init");
        View dragLayer = activity.getDragLayer();
        dragLayer.getViewTreeObserver().addOnDrawListener(new OnDrawListener() {

            boolean mHandled = false;

            @Override
            public void onDraw() {
                if (mHandled) {
                    return;
                }
                mHandled = true;
                TraceHelper.INSTANCE.endSection(traceToken);
                dragLayer.post(() -> dragLayer.getViewTreeObserver().removeOnDrawListener(this));
                if (activity != mActivity) {
                    return;
                }
                mStateCallback.setState(STATE_LAUNCHER_DRAWN);
            }
        });
    }
    activity.getRootView().setOnApplyWindowInsetsListener(this);
    mStateCallback.setState(STATE_LAUNCHER_STARTED);
}
Also used : LAUNCHER_QUICKSWITCH_RIGHT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_QUICKSWITCH_RIGHT) LAUNCHER_QUICKSWITCH_LEFT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_QUICKSWITCH_LEFT) STATE_END_TARGET_SET(com.android.quickstep.GestureState.STATE_END_TARGET_SET) OnDrawListener(android.view.ViewTreeObserver.OnDrawListener) View(android.view.View) TaskView(com.android.quickstep.views.TaskView) RecentsView(com.android.quickstep.views.RecentsView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 27 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class Snackbar method show.

public static void show(BaseDraggingActivity activity, int labelStringResId, int actionStringResId, Runnable onDismissed, Runnable onActionClicked) {
    closeOpenViews(activity, true, TYPE_SNACKBAR);
    Snackbar snackbar = new Snackbar(activity, null);
    // Set some properties here since inflated xml only contains the children.
    snackbar.setOrientation(HORIZONTAL);
    snackbar.setGravity(Gravity.CENTER_VERTICAL);
    Resources res = activity.getResources();
    snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
    int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
    snackbar.setPadding(padding, padding, padding, padding);
    snackbar.setBackgroundResource(R.drawable.round_rect_primary);
    snackbar.mIsOpen = true;
    BaseDragLayer dragLayer = activity.getDragLayer();
    dragLayer.addView(snackbar);
    DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
    params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
    int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
    int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
    int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
    Rect insets = activity.getDeviceProfile().getInsets();
    int maxWidth = dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right;
    int minWidth = dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right;
    params.width = minWidth;
    params.setMargins(0, 0, 0, marginBottom + insets.bottom);
    TextView labelView = snackbar.findViewById(R.id.label);
    TextView actionView = snackbar.findViewById(R.id.action);
    String labelText = res.getString(labelStringResId);
    String actionText = res.getString(actionStringResId);
    int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionView.getPaint().measureText(actionText)) + labelView.getPaddingRight() + labelView.getPaddingLeft() + actionView.getPaddingRight() + actionView.getPaddingLeft() + padding * 2;
    if (totalContentWidth > params.width) {
        // The text doesn't fit in our standard width so update width to accommodate.
        if (totalContentWidth <= maxWidth) {
            params.width = totalContentWidth;
        } else {
            // One line will be cut off, fallback to 2 lines and smaller font. (This should only
            // happen in some languages if system display and font size are set to largest.)
            int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
            float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
            labelView.setLines(2);
            labelView.getLayoutParams().height = textHeight * 2;
            actionView.getLayoutParams().height = textHeight * 2;
            labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
            actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
            params.height += textHeight;
            params.width = maxWidth;
        }
    }
    labelView.setText(labelText);
    actionView.setText(actionText);
    actionView.setOnClickListener(v -> {
        if (onActionClicked != null) {
            onActionClicked.run();
        }
        snackbar.mOnDismissed = null;
        snackbar.close(true);
    });
    snackbar.mOnDismissed = onDismissed;
    snackbar.setAlpha(0);
    snackbar.setScaleX(0.8f);
    snackbar.setScaleY(0.8f);
    snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
    int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
    snackbar.postDelayed(() -> snackbar.close(true), timeout);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Example 28 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherAppWidgetHostView method onLongClick.

@Override
public boolean onLongClick(View view) {
    if (!Utilities.isWorkspaceEditAllowed(mLauncher.getApplicationContext()))
        return true;
    if (mIsScrollable) {
        DragLayer dragLayer = Launcher.getLauncher(getContext()).getDragLayer();
        dragLayer.requestDisallowInterceptTouchEvent(false);
    }
    view.performLongClick();
    return true;
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer)

Example 29 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherAppWidgetHostView method onInterceptTouchEvent.

public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        DragLayer dragLayer = Launcher.getLauncher(getContext()).getDragLayer();
        if (mIsScrollable) {
            dragLayer.requestDisallowInterceptTouchEvent(true);
        }
        dragLayer.setTouchCompleteListener(this);
    }
    mLongPressHelper.onTouchEvent(ev);
    return mLongPressHelper.hasPerformedLongPress();
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer)

Example 30 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer 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)

Aggregations

DragLayer (com.android.launcher3.dragndrop.DragLayer)100 Rect (android.graphics.Rect)67 BaseDragLayer (com.android.launcher3.views.BaseDragLayer)33 ViewGroup (android.view.ViewGroup)23 Resources (android.content.res.Resources)22 AnimatorSet (android.animation.AnimatorSet)20 View (android.view.View)18 SuppressLint (android.annotation.SuppressLint)16 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)15 DeviceProfile (com.android.launcher3.DeviceProfile)15 Workspace (com.android.launcher3.Workspace)15 Animator (android.animation.Animator)14 ObjectAnimator (android.animation.ObjectAnimator)14 Point (android.graphics.Point)12 ItemInfo (com.android.launcher3.model.data.ItemInfo)12 CellLayout (com.android.launcher3.CellLayout)11 DragView (com.android.launcher3.dragndrop.DragView)11 ArrayList (java.util.ArrayList)11 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)10 Drawable (android.graphics.drawable.Drawable)10