Merge "PiP: update magnetic field radius for dismissmal as PiP resizes." into sc-dev

This commit is contained in:
Ben Lin
2021-03-31 16:29:22 +00:00
committed by Android (Google) Code Review
3 changed files with 28 additions and 15 deletions

View File

@@ -22,7 +22,6 @@ import android.graphics.PixelFormat;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.TransitionDrawable; import android.graphics.drawable.TransitionDrawable;
import android.os.Handler;
import android.view.Gravity; import android.view.Gravity;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; 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.common.magnetictarget.MagnetizedObject;
import com.android.wm.shell.pip.PipUiEventLogger; import com.android.wm.shell.pip.PipUiEventLogger;
import java.util.concurrent.TimeUnit;
import kotlin.Unit; import kotlin.Unit;
/** /**
@@ -89,7 +86,9 @@ public class PipDismissTargetHandler {
// Allow dragging the PIP to a location to close it // Allow dragging the PIP to a location to close it
private boolean mEnableDismissDragToEdge; private boolean mEnableDismissDragToEdge;
private int mTargetSize;
private int mDismissAreaHeight; private int mDismissAreaHeight;
private float mMagneticFieldRadiusPercent = 1f;
private final Context mContext; private final Context mContext;
private final PipMotionHelper mMotionHelper; private final PipMotionHelper mMotionHelper;
@@ -183,18 +182,27 @@ public class PipDismissTargetHandler {
} }
final Resources res = mContext.getResources(); 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); mDismissAreaHeight = res.getDimensionPixelSize(R.dimen.floating_dismiss_gradient_height);
final FrameLayout.LayoutParams newParams = final FrameLayout.LayoutParams newParams =
new FrameLayout.LayoutParams(targetSize, targetSize); new FrameLayout.LayoutParams(mTargetSize, mTargetSize);
newParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; newParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
newParams.bottomMargin = mContext.getResources().getDimensionPixelSize( newParams.bottomMargin = mContext.getResources().getDimensionPixelSize(
R.dimen.floating_dismiss_bottom_margin); R.dimen.floating_dismiss_bottom_margin);
mTargetView.setLayoutParams(newParams); mTargetView.setLayoutParams(newParams);
// Set the magnetic field radius equal to the target size from the center of the target // Set the magnetic field radius equal to the target size from the center of the target
mMagneticTarget.setMagneticFieldRadiusPx( setMagneticFieldRadiusPercent(mMagneticFieldRadiusPercent);
(int) (targetSize * MAGNETIC_FIELD_RADIUS_MULTIPLIER)); }
/**
* 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. */ /** Adds the magnetic target view to the WindowManager so it's ready to be animated in. */

View File

@@ -71,6 +71,7 @@ public class PipResizeGestureHandler {
private final PipBoundsState mPipBoundsState; private final PipBoundsState mPipBoundsState;
private final PipTaskOrganizer mPipTaskOrganizer; private final PipTaskOrganizer mPipTaskOrganizer;
private final PhonePipMenuController mPhonePipMenuController; private final PhonePipMenuController mPhonePipMenuController;
private final PipDismissTargetHandler mPipDismissTargetHandler;
private final PipUiEventLogger mPipUiEventLogger; private final PipUiEventLogger mPipUiEventLogger;
private final PipPinchResizingAlgorithm mPinchResizingAlgorithm; private final PipPinchResizingAlgorithm mPinchResizingAlgorithm;
private final int mDisplayId; private final int mDisplayId;
@@ -117,9 +118,10 @@ public class PipResizeGestureHandler {
public PipResizeGestureHandler(Context context, PipBoundsAlgorithm pipBoundsAlgorithm, public PipResizeGestureHandler(Context context, PipBoundsAlgorithm pipBoundsAlgorithm,
PipBoundsState pipBoundsState, PipMotionHelper motionHelper, PipBoundsState pipBoundsState, PipMotionHelper motionHelper,
PipTaskOrganizer pipTaskOrganizer, Function<Rect, Rect> movementBoundsSupplier, PipTaskOrganizer pipTaskOrganizer, PipDismissTargetHandler pipDismissTargetHandler,
Runnable updateMovementBoundsRunnable, PipUiEventLogger pipUiEventLogger, Function<Rect, Rect> movementBoundsSupplier, Runnable updateMovementBoundsRunnable,
PhonePipMenuController menuActivityController, ShellExecutor mainExecutor) { PipUiEventLogger pipUiEventLogger, PhonePipMenuController menuActivityController,
ShellExecutor mainExecutor) {
mContext = context; mContext = context;
mDisplayId = context.getDisplayId(); mDisplayId = context.getDisplayId();
mMainExecutor = mainExecutor; mMainExecutor = mainExecutor;
@@ -127,6 +129,7 @@ public class PipResizeGestureHandler {
mPipBoundsState = pipBoundsState; mPipBoundsState = pipBoundsState;
mMotionHelper = motionHelper; mMotionHelper = motionHelper;
mPipTaskOrganizer = pipTaskOrganizer; mPipTaskOrganizer = pipTaskOrganizer;
mPipDismissTargetHandler = pipDismissTargetHandler;
mMovementBoundsSupplier = movementBoundsSupplier; mMovementBoundsSupplier = movementBoundsSupplier;
mUpdateMovementBoundsRunnable = updateMovementBoundsRunnable; mUpdateMovementBoundsRunnable = updateMovementBoundsRunnable;
mPhonePipMenuController = menuActivityController; mPhonePipMenuController = menuActivityController;
@@ -510,6 +513,8 @@ public class PipResizeGestureHandler {
mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds, mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds,
PipAnimationController.TRANSITION_DIRECTION_USER_RESIZE, callback); PipAnimationController.TRANSITION_DIRECTION_USER_RESIZE, callback);
} }
mPipDismissTargetHandler
.setMagneticFieldRadiusPercent((float) mLastResizeBounds.width() / mMinSize.x);
mPipUiEventLogger.log( mPipUiEventLogger.log(
PipUiEventLogger.PipUiEventEnum.PICTURE_IN_PICTURE_RESIZE); PipUiEventLogger.PipUiEventEnum.PICTURE_IN_PICTURE_RESIZE);
} else { } else {

View File

@@ -176,13 +176,13 @@ public class PipTouchHandler {
mMotionHelper = new PipMotionHelper(mContext, pipBoundsState, pipTaskOrganizer, mMotionHelper = new PipMotionHelper(mContext, pipBoundsState, pipTaskOrganizer,
mMenuController, mPipBoundsAlgorithm.getSnapAlgorithm(), pipTransitionController, mMenuController, mPipBoundsAlgorithm.getSnapAlgorithm(), pipTransitionController,
floatingContentCoordinator); floatingContentCoordinator);
mPipResizeGestureHandler =
new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
mMotionHelper, pipTaskOrganizer, this::getMovementBounds,
this::updateMovementBounds, pipUiEventLogger, menuController,
mainExecutor);
mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger, mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger,
mMotionHelper, mainExecutor); mMotionHelper, mainExecutor);
mPipResizeGestureHandler =
new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
mMotionHelper, pipTaskOrganizer, mPipDismissTargetHandler,
this::getMovementBounds, this::updateMovementBounds, pipUiEventLogger,
menuController, mainExecutor);
mTouchState = new PipTouchState(ViewConfiguration.get(context), mTouchState = new PipTouchState(ViewConfiguration.get(context),
() -> { () -> {
if (mPipBoundsState.isStashed()) { if (mPipBoundsState.isStashed()) {