Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a3403943 authored by Ats Jenk's avatar Ats Jenk
Browse files

Support expanded view drag to left or right

When dragging the expanded view across screen middle of the screen,
pin it to the other side.

Bug: 313661121
Flag: ACONFIG com.android.wm.shell.enable_bubble_bar DEVELOPMENT
Test: manual
Change-Id: I66b5f09c7f5b3226aebe9172e7cc1cf8bf5b4c66
parent 89f6fa68
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public class BubbleData {
         * used when {@link BubbleController#isShowingAsBubbleBar()} is true.
         */
        BubbleBarUpdate getInitialState() {
            BubbleBarUpdate bubbleBarUpdate = new BubbleBarUpdate();
            BubbleBarUpdate bubbleBarUpdate = BubbleBarUpdate.createInitialState();
            bubbleBarUpdate.shouldShowEducation = shouldShowEducation;
            for (int i = 0; i < bubbles.size(); i++) {
                bubbleBarUpdate.currentBubbleList.add(bubbles.get(i).asBubbleBarBubble());
+50 −18
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.wm.shell.bubbles.bar
import android.annotation.SuppressLint
import android.view.MotionEvent
import android.view.View
import com.android.wm.shell.bubbles.BubblePositioner
import com.android.wm.shell.common.bubbles.BubbleBarLocation
import com.android.wm.shell.common.bubbles.DismissView
import com.android.wm.shell.common.bubbles.RelativeTouchListener
import com.android.wm.shell.common.magnetictarget.MagnetizedObject
@@ -29,7 +31,8 @@ class BubbleBarExpandedViewDragController(
    private val expandedView: BubbleBarExpandedView,
    private val dismissView: DismissView,
    private val animationHelper: BubbleBarAnimationHelper,
    private val onDismissed: () -> Unit
    private val bubblePositioner: BubblePositioner,
    private val dragListener: DragListener
) {

    var isStuckToDismiss: Boolean = false
@@ -73,13 +76,34 @@ class BubbleBarExpandedViewDragController(
        }
    }

    /** Listener to receive callback about dragging events */
    interface DragListener {
        /**
         * Bubble bar [BubbleBarLocation] has changed as a result of dragging the expanded view.
         *
         * Triggered when drag gesture passes the middle of the screen and before touch up.
         * Can be triggered multiple times per gesture.
         *
         * @param location new location of the bubble bar as a result of the ongoing drag operation
         */
        fun onLocationChanged(location: BubbleBarLocation)

        /** Expanded view has been released in the dismiss target */
        fun onReleasedInDismiss()
    }

    private inner class HandleDragListener : RelativeTouchListener() {

        private var isMoving = false
        private var screenCenterX: Int = -1
        private var isOnLeft = false

        override fun onDown(v: View, ev: MotionEvent): Boolean {
            // While animating, don't allow new touch events
            return !expandedView.isAnimating
            if (expandedView.isAnimating) return false
            screenCenterX = bubblePositioner.screenRect.centerX()
            isOnLeft = bubblePositioner.isBubbleBarOnLeft
            return true
        }

        override fun onMove(
@@ -97,6 +121,14 @@ class BubbleBarExpandedViewDragController(
            expandedView.translationX = expandedViewInitialTranslationX + dx
            expandedView.translationY = expandedViewInitialTranslationY + dy
            dismissView.show()

            if (isOnLeft && ev.rawX > screenCenterX) {
                isOnLeft = false
                dragListener.onLocationChanged(BubbleBarLocation.RIGHT)
            } else if (!isOnLeft && ev.rawX < screenCenterX) {
                isOnLeft = true
                dragListener.onLocationChanged(BubbleBarLocation.LEFT)
            }
        }

        override fun onUp(
@@ -113,6 +145,7 @@ class BubbleBarExpandedViewDragController(
        }

        override fun onCancel(v: View, ev: MotionEvent, viewInitialX: Float, viewInitialY: Float) {
            isStuckToDismiss = false
            finishDrag()
        }

@@ -148,9 +181,8 @@ class BubbleBarExpandedViewDragController(
            target: MagnetizedObject.MagneticTarget,
            draggedObject: MagnetizedObject<*>
        ) {
            onDismissed()
            dragListener.onReleasedInDismiss()
            dismissView.hide()
        }
    }
}
+17 −5
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;

import com.android.wm.shell.R;
import com.android.wm.shell.bubbles.Bubble;
import com.android.wm.shell.bubbles.BubbleController;
@@ -42,6 +44,8 @@ import com.android.wm.shell.bubbles.BubblePositioner;
import com.android.wm.shell.bubbles.BubbleViewProvider;
import com.android.wm.shell.bubbles.DeviceConfig;
import com.android.wm.shell.bubbles.DismissViewUtils;
import com.android.wm.shell.bubbles.bar.BubbleBarExpandedViewDragController.DragListener;
import com.android.wm.shell.common.bubbles.BubbleBarLocation;
import com.android.wm.shell.common.bubbles.DismissView;

import kotlin.Unit;
@@ -201,15 +205,23 @@ public class BubbleBarLayerView extends FrameLayout
                }
            });

            DragListener dragListener = new DragListener() {
                @Override
                public void onLocationChanged(@NonNull BubbleBarLocation location) {
                    mBubbleController.setBubbleBarLocation(location);
                }

                @Override
                public void onReleasedInDismiss() {
                    mBubbleController.dismissBubble(mExpandedBubble.getKey(), DISMISS_USER_GESTURE);
                }
            };
            mDragController = new BubbleBarExpandedViewDragController(
                    mExpandedView,
                    mDismissView,
                    mAnimationHelper,
                    () -> {
                        mBubbleController.dismissBubble(mExpandedBubble.getKey(),
                                DISMISS_USER_GESTURE);
                        return Unit.INSTANCE;
                    });
                    mPositioner,
                    dragListener);

            addView(mExpandedView, new LayoutParams(width, height, Gravity.LEFT));
        }
+21 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class BubbleBarUpdate implements Parcelable {

    public static final String BUNDLE_KEY = "update";

    public final boolean initialState;
    public boolean expandedChanged;
    public boolean expanded;
    public boolean shouldShowEducation;
@@ -58,10 +59,17 @@ public class BubbleBarUpdate implements Parcelable {
    // This is only populated the first time a listener is connected so it gets the current state.
    public List<BubbleInfo> currentBubbleList = new ArrayList<>();


    public BubbleBarUpdate() {
        this(false);
    }

    private BubbleBarUpdate(boolean initialState) {
        this.initialState = initialState;
    }

    public BubbleBarUpdate(Parcel parcel) {
        initialState = parcel.readBoolean();
        expandedChanged = parcel.readBoolean();
        expanded = parcel.readBoolean();
        shouldShowEducation = parcel.readBoolean();
@@ -99,7 +107,9 @@ public class BubbleBarUpdate implements Parcelable {

    @Override
    public String toString() {
        return "BubbleBarUpdate{ expandedChanged=" + expandedChanged
        return "BubbleBarUpdate{"
                + " initialState=" + initialState
                + " expandedChanged=" + expandedChanged
                + " expanded=" + expanded
                + " selectedBubbleKey=" + selectedBubbleKey
                + " shouldShowEducation=" + shouldShowEducation
@@ -121,6 +131,7 @@ public class BubbleBarUpdate implements Parcelable {

    @Override
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeBoolean(initialState);
        parcel.writeBoolean(expandedChanged);
        parcel.writeBoolean(expanded);
        parcel.writeBoolean(shouldShowEducation);
@@ -135,6 +146,15 @@ public class BubbleBarUpdate implements Parcelable {
        parcel.writeParcelable(bubbleBarLocation, flags);
    }

    /**
     * Create update for initial set of values.
     * <p>
     * Used when bubble bar is newly created.
     */
    public static BubbleBarUpdate createInitialState() {
        return new BubbleBarUpdate(true);
    }

    @NonNull
    public static final Creator<BubbleBarUpdate> CREATOR =
            new Creator<BubbleBarUpdate>() {