Merge "Resize PiP on display density dpi change" into tm-d1-dev am: 1061cb16e0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18411684

Change-Id: I51db44f71b1d5e324abf1bbdec8c9c8b51a489d5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Hongwei Wang
2022-05-16 23:39:46 +00:00
committed by Automerger Merge Worker

View File

@@ -542,24 +542,44 @@ public class PipController implements PipTransitionController.PipTransitionCallb
mMenuController.attachPipMenuView(); mMenuController.attachPipMenuView();
// Calculate the snap fraction of the current stack along the old movement bounds // Calculate the snap fraction of the current stack along the old movement bounds
final PipSnapAlgorithm pipSnapAlgorithm = mPipBoundsAlgorithm.getSnapAlgorithm(); final PipSnapAlgorithm pipSnapAlgorithm = mPipBoundsAlgorithm.getSnapAlgorithm();
final Rect postChangeStackBounds = new Rect(mPipBoundsState.getBounds()); final Rect postChangeBounds = new Rect(mPipBoundsState.getBounds());
final float snapFraction = pipSnapAlgorithm.getSnapFraction(postChangeStackBounds, final float snapFraction = pipSnapAlgorithm.getSnapFraction(postChangeBounds,
mPipBoundsAlgorithm.getMovementBounds(postChangeStackBounds), mPipBoundsAlgorithm.getMovementBounds(postChangeBounds),
mPipBoundsState.getStashedState()); mPipBoundsState.getStashedState());
// Scale PiP on density dpi change, so it appears to be the same size physically.
final boolean densityDpiChanged = mPipBoundsState.getDisplayLayout().densityDpi() != 0
&& (mPipBoundsState.getDisplayLayout().densityDpi() != layout.densityDpi());
if (densityDpiChanged) {
final float scale = (float) layout.densityDpi()
/ mPipBoundsState.getDisplayLayout().densityDpi();
postChangeBounds.set(0, 0,
(int) (postChangeBounds.width() * scale),
(int) (postChangeBounds.height() * scale));
}
updateDisplayLayout.run(); updateDisplayLayout.run();
// Calculate the stack bounds in the new orientation based on same fraction along the // Calculate the PiP bounds in the new orientation based on same fraction along the
// rotated movement bounds. // rotated movement bounds.
final Rect postChangeMovementBounds = mPipBoundsAlgorithm.getMovementBounds( final Rect postChangeMovementBounds = mPipBoundsAlgorithm.getMovementBounds(
postChangeStackBounds, false /* adjustForIme */); postChangeBounds, false /* adjustForIme */);
pipSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds, pipSnapAlgorithm.applySnapFraction(postChangeBounds, postChangeMovementBounds,
snapFraction, mPipBoundsState.getStashedState(), snapFraction, mPipBoundsState.getStashedState(),
mPipBoundsState.getStashOffset(), mPipBoundsState.getStashOffset(),
mPipBoundsState.getDisplayBounds(), mPipBoundsState.getDisplayBounds(),
mPipBoundsState.getDisplayLayout().stableInsets()); mPipBoundsState.getDisplayLayout().stableInsets());
mTouchHandler.getMotionHelper().movePip(postChangeStackBounds); if (densityDpiChanged) {
// Using PipMotionHelper#movePip directly here may cause race condition since
// the app content in PiP mode may or may not be updated for the new density dpi.
final int duration = mContext.getResources().getInteger(
R.integer.config_pipEnterAnimationDuration);
mPipTaskOrganizer.scheduleAnimateResizePip(
postChangeBounds, duration, null /* updateBoundsCallback */);
} else {
mTouchHandler.getMotionHelper().movePip(postChangeBounds);
}
} else { } else {
updateDisplayLayout.run(); updateDisplayLayout.run();
} }