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

Commit d73697e4 authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Show dismiss target when dragging expanded view" into main

parents 7f598d4d 9db5f377
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -1280,7 +1280,14 @@ public class BubbleController implements ConfigurationChangeListener,
     * Dismiss bubble if it exists and remove it from the stack
     */
    public void dismissBubble(Bubble bubble, @Bubbles.DismissReason int reason) {
        mBubbleData.dismissBubbleWithKey(bubble.getKey(), reason);
        dismissBubble(bubble.getKey(), reason);
    }

    /**
     * Dismiss bubble with given key if it exists and remove it from the stack
     */
    public void dismissBubble(String key, @Bubbles.DismissReason int reason) {
        mBubbleData.dismissBubbleWithKey(key, reason);
    }

    /**
+0 −3
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ public class BubbleBarExpandedView extends FrameLayout implements BubbleTaskView
    private boolean mIsOverflow;
    private BubbleTaskViewHelper mBubbleTaskViewHelper;
    private BubbleBarMenuViewController mMenuViewController;
    private BubbleBarExpandedViewDragController mDragController;
    private @Nullable Supplier<Rect> mLayerBoundsSupplier;
    private @Nullable Listener mListener;

@@ -181,8 +180,6 @@ public class BubbleBarExpandedView extends FrameLayout implements BubbleTaskView
        mHandleView.setOnClickListener(view -> {
            mMenuViewController.showMenu(true /* animated */);
        });

        mDragController = new BubbleBarExpandedViewDragController(this);
    }

    public BubbleBarHandleView getHandleView() {
+30 −10
Original line number Diff line number Diff line
@@ -19,20 +19,37 @@ package com.android.wm.shell.bubbles.bar
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.graphics.PointF
import android.graphics.Rect
import android.view.MotionEvent
import android.view.View
import com.android.wm.shell.animation.Interpolators
import com.android.wm.shell.common.bubbles.DismissView
import com.android.wm.shell.common.bubbles.RelativeTouchListener

/** Controller for handling drag interactions with [BubbleBarExpandedView] */
class BubbleBarExpandedViewDragController(private val expandedView: BubbleBarExpandedView) {
class BubbleBarExpandedViewDragController(
    private val expandedView: BubbleBarExpandedView,
    private val dismissView: DismissView,
    private val onDismissed: () -> Unit
) {

    init {
        expandedView.handleView.setOnTouchListener(HandleDragListener())
    }

    private fun finishDrag(x: Float, y: Float, viewInitialX: Float, viewInitialY: Float) {
        val dismissCircleBounds = Rect().apply { dismissView.circle.getBoundsOnScreen(this) }
        if (dismissCircleBounds.contains(x.toInt(), y.toInt())) {
            onDismissed()
        } else {
            resetExpandedViewPosition(viewInitialX, viewInitialY)
        }
        dismissView.hide()
    }

    private fun resetExpandedViewPosition(initialX: Float, initialY: Float) {
        val listener = object : AnimatorListenerAdapter() {
        val listener =
            object : AnimatorListenerAdapter() {
                override fun onAnimationStart(animation: Animator) {
                    expandedView.isAnimating = true
                }
@@ -41,7 +58,8 @@ class BubbleBarExpandedViewDragController(private val expandedView: BubbleBarExp
                    expandedView.isAnimating = false
                }
            }
        expandedView.animate()
        expandedView
            .animate()
            .translationX(initialX)
            .translationY(initialY)
            .setDuration(RESET_POSITION_ANIM_DURATION)
@@ -74,6 +92,7 @@ class BubbleBarExpandedViewDragController(private val expandedView: BubbleBarExp
        ) {
            expandedView.translationX = expandedViewRestPosition.x + dx
            expandedView.translationY = expandedViewRestPosition.y + dy
            dismissView.show()
        }

        override fun onUp(
@@ -86,11 +105,12 @@ class BubbleBarExpandedViewDragController(private val expandedView: BubbleBarExp
            velX: Float,
            velY: Float
        ) {
            resetExpandedViewPosition(expandedViewRestPosition.x, expandedViewRestPosition.y)
            finishDrag(ev.rawX, ev.rawY, expandedViewRestPosition.x, expandedViewRestPosition.y)
        }

        override fun onCancel(v: View, ev: MotionEvent, viewInitialX: Float, viewInitialY: Float) {
            resetExpandedViewPosition(expandedViewRestPosition.x, expandedViewRestPosition.y)
            dismissView.hide()
        }
    }

+32 −2
Original line number Diff line number Diff line
@@ -31,17 +31,21 @@ import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.android.wm.shell.R;
import com.android.wm.shell.bubbles.BubbleController;
import com.android.wm.shell.bubbles.BubbleOverflow;
import com.android.wm.shell.bubbles.BubblePositioner;
import com.android.wm.shell.bubbles.BubbleViewProvider;
import com.android.wm.shell.bubbles.Bubbles;
import com.android.wm.shell.bubbles.DeviceConfig;
import com.android.wm.shell.bubbles.DismissViewUtils;
import com.android.wm.shell.common.bubbles.DismissView;

import kotlin.Unit;

import java.util.Objects;
import java.util.function.Consumer;

import kotlin.Unit;

/**
 * Similar to {@link com.android.wm.shell.bubbles.BubbleStackView}, this view is added to window
 * manager to display bubbles. However, it is only used when bubbles are being displayed in
@@ -63,7 +67,11 @@ public class BubbleBarLayerView extends FrameLayout

    @Nullable
    private BubbleViewProvider mExpandedBubble;
    @Nullable
    private BubbleBarExpandedView mExpandedView;
    @Nullable
    private BubbleBarExpandedViewDragController mDragController;
    private DismissView mDismissView;
    private @Nullable Consumer<String> mUnBubbleConversationCallback;

    // TODO(b/273310265) - currently the view is always on the right, need to update for RTL.
@@ -101,6 +109,8 @@ public class BubbleBarLayerView extends FrameLayout
        mScrimView.setBackgroundDrawable(new ColorDrawable(
                getResources().getColor(android.R.color.system_neutral1_1000)));

        setUpDismissView();

        setOnClickListener(view -> hideMenuOrCollapse());
    }

@@ -196,6 +206,13 @@ public class BubbleBarLayerView extends FrameLayout
                }
            });

            mDragController = new BubbleBarExpandedViewDragController(mExpandedView, mDismissView,
                    () -> {
                        mBubbleController.dismissBubble(mExpandedBubble.getKey(),
                                Bubbles.DISMISS_USER_GESTURE);
                        return Unit.INSTANCE;
                    });

            addView(mExpandedView, new FrameLayout.LayoutParams(width, height));
        }

@@ -227,6 +244,7 @@ public class BubbleBarLayerView extends FrameLayout
        mAnimationHelper.animateCollapse(() -> removeView(viewToRemove));
        mBubbleController.getSysuiProxy().onStackExpandChanged(false);
        mExpandedView = null;
        mDragController = null;
        setTouchDelegate(null);
        showScrim(false);
    }
@@ -252,6 +270,18 @@ public class BubbleBarLayerView extends FrameLayout
        mUnBubbleConversationCallback = unBubbleConversationCallback;
    }

    private void setUpDismissView() {
        if (mDismissView != null) {
            removeView(mDismissView);
        }
        mDismissView = new DismissView(getContext());
        DismissViewUtils.setup(mDismissView);
        int elevation = getResources().getDimensionPixelSize(R.dimen.bubble_elevation);

        addView(mDismissView);
        mDismissView.setElevation(elevation);
    }

    /** Hides the current modal education/menu view, expanded view or collapses the bubble stack */
    private void hideMenuOrCollapse() {
        if (mEducationViewController.isEducationVisible()) {