PiP: update magnetic field radius for dismissmal as PiP resizes.
As PiP gets bigger, it should be that user doesn't have to put their fingers as close as before to the dismiss bubble before it magnetizes and pulls in PiP. Bug: 164947242 Test: Manual. Resize PiP to larger and try to drag to dismiss bubble. Change-Id: I2ec0fbfd87bc010d9ca551df0eeb77a22c02c6dc
This commit is contained in:
@@ -22,7 +22,6 @@ import android.graphics.PixelFormat;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.TransitionDrawable;
|
||||
import android.os.Handler;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -41,8 +40,6 @@ import com.android.wm.shell.common.ShellExecutor;
|
||||
import com.android.wm.shell.common.magnetictarget.MagnetizedObject;
|
||||
import com.android.wm.shell.pip.PipUiEventLogger;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
/**
|
||||
@@ -89,7 +86,9 @@ public class PipDismissTargetHandler {
|
||||
// Allow dragging the PIP to a location to close it
|
||||
private boolean mEnableDismissDragToEdge;
|
||||
|
||||
private int mTargetSize;
|
||||
private int mDismissAreaHeight;
|
||||
private float mMagneticFieldRadiusPercent = 1f;
|
||||
|
||||
private final Context mContext;
|
||||
private final PipMotionHelper mMotionHelper;
|
||||
@@ -183,18 +182,27 @@ public class PipDismissTargetHandler {
|
||||
}
|
||||
|
||||
final Resources res = mContext.getResources();
|
||||
final int targetSize = res.getDimensionPixelSize(R.dimen.dismiss_circle_size);
|
||||
mTargetSize = res.getDimensionPixelSize(R.dimen.dismiss_circle_size);
|
||||
mDismissAreaHeight = res.getDimensionPixelSize(R.dimen.floating_dismiss_gradient_height);
|
||||
final FrameLayout.LayoutParams newParams =
|
||||
new FrameLayout.LayoutParams(targetSize, targetSize);
|
||||
new FrameLayout.LayoutParams(mTargetSize, mTargetSize);
|
||||
newParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
|
||||
newParams.bottomMargin = mContext.getResources().getDimensionPixelSize(
|
||||
R.dimen.floating_dismiss_bottom_margin);
|
||||
mTargetView.setLayoutParams(newParams);
|
||||
|
||||
// Set the magnetic field radius equal to the target size from the center of the target
|
||||
mMagneticTarget.setMagneticFieldRadiusPx(
|
||||
(int) (targetSize * MAGNETIC_FIELD_RADIUS_MULTIPLIER));
|
||||
setMagneticFieldRadiusPercent(mMagneticFieldRadiusPercent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase or decrease the field radius of the magnet object, e.g. with larger percent,
|
||||
* PiP will magnetize to the field sooner.
|
||||
*/
|
||||
public void setMagneticFieldRadiusPercent(float percent) {
|
||||
mMagneticFieldRadiusPercent = percent;
|
||||
mMagneticTarget.setMagneticFieldRadiusPx((int) (mMagneticFieldRadiusPercent * mTargetSize
|
||||
* MAGNETIC_FIELD_RADIUS_MULTIPLIER));
|
||||
}
|
||||
|
||||
/** Adds the magnetic target view to the WindowManager so it's ready to be animated in. */
|
||||
|
||||
@@ -74,6 +74,7 @@ public class PipResizeGestureHandler {
|
||||
private final PipBoundsState mPipBoundsState;
|
||||
private final PipTaskOrganizer mPipTaskOrganizer;
|
||||
private final PhonePipMenuController mPhonePipMenuController;
|
||||
private final PipDismissTargetHandler mPipDismissTargetHandler;
|
||||
private final PipUiEventLogger mPipUiEventLogger;
|
||||
private final int mDisplayId;
|
||||
private final ShellExecutor mMainExecutor;
|
||||
@@ -120,9 +121,10 @@ public class PipResizeGestureHandler {
|
||||
|
||||
public PipResizeGestureHandler(Context context, PipBoundsAlgorithm pipBoundsAlgorithm,
|
||||
PipBoundsState pipBoundsState, PipMotionHelper motionHelper,
|
||||
PipTaskOrganizer pipTaskOrganizer, Function<Rect, Rect> movementBoundsSupplier,
|
||||
Runnable updateMovementBoundsRunnable, PipUiEventLogger pipUiEventLogger,
|
||||
PhonePipMenuController menuActivityController, ShellExecutor mainExecutor) {
|
||||
PipTaskOrganizer pipTaskOrganizer, PipDismissTargetHandler pipDismissTargetHandler,
|
||||
Function<Rect, Rect> movementBoundsSupplier, Runnable updateMovementBoundsRunnable,
|
||||
PipUiEventLogger pipUiEventLogger, PhonePipMenuController menuActivityController,
|
||||
ShellExecutor mainExecutor) {
|
||||
mContext = context;
|
||||
mDisplayId = context.getDisplayId();
|
||||
mMainExecutor = mainExecutor;
|
||||
@@ -130,6 +132,7 @@ public class PipResizeGestureHandler {
|
||||
mPipBoundsState = pipBoundsState;
|
||||
mMotionHelper = motionHelper;
|
||||
mPipTaskOrganizer = pipTaskOrganizer;
|
||||
mPipDismissTargetHandler = pipDismissTargetHandler;
|
||||
mMovementBoundsSupplier = movementBoundsSupplier;
|
||||
mUpdateMovementBoundsRunnable = updateMovementBoundsRunnable;
|
||||
mPhonePipMenuController = menuActivityController;
|
||||
@@ -602,6 +605,8 @@ public class PipResizeGestureHandler {
|
||||
mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds,
|
||||
PipAnimationController.TRANSITION_DIRECTION_USER_RESIZE, callback);
|
||||
}
|
||||
mPipDismissTargetHandler
|
||||
.setMagneticFieldRadiusPercent((float) mLastResizeBounds.width() / mMinSize.x);
|
||||
mPipUiEventLogger.log(
|
||||
PipUiEventLogger.PipUiEventEnum.PICTURE_IN_PICTURE_RESIZE);
|
||||
} else {
|
||||
|
||||
@@ -176,13 +176,13 @@ public class PipTouchHandler {
|
||||
mMotionHelper = new PipMotionHelper(mContext, pipBoundsState, pipTaskOrganizer,
|
||||
mMenuController, mPipBoundsAlgorithm.getSnapAlgorithm(), pipTransitionController,
|
||||
floatingContentCoordinator);
|
||||
mPipResizeGestureHandler =
|
||||
new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
|
||||
mMotionHelper, pipTaskOrganizer, this::getMovementBounds,
|
||||
this::updateMovementBounds, pipUiEventLogger, menuController,
|
||||
mainExecutor);
|
||||
mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger,
|
||||
mMotionHelper, mainExecutor);
|
||||
mPipResizeGestureHandler =
|
||||
new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
|
||||
mMotionHelper, pipTaskOrganizer, mPipDismissTargetHandler,
|
||||
this::getMovementBounds, this::updateMovementBounds, pipUiEventLogger,
|
||||
menuController, mainExecutor);
|
||||
mTouchState = new PipTouchState(ViewConfiguration.get(context),
|
||||
() -> {
|
||||
if (mPipBoundsState.isStashed()) {
|
||||
|
||||
Reference in New Issue
Block a user