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.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. */

View File

@@ -71,6 +71,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 PipPinchResizingAlgorithm mPinchResizingAlgorithm;
private final int mDisplayId;
@@ -117,9 +118,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;
@@ -127,6 +129,7 @@ public class PipResizeGestureHandler {
mPipBoundsState = pipBoundsState;
mMotionHelper = motionHelper;
mPipTaskOrganizer = pipTaskOrganizer;
mPipDismissTargetHandler = pipDismissTargetHandler;
mMovementBoundsSupplier = movementBoundsSupplier;
mUpdateMovementBoundsRunnable = updateMovementBoundsRunnable;
mPhonePipMenuController = menuActivityController;
@@ -510,6 +513,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 {

View File

@@ -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()) {