Merge "Cleanup some unused code and update resources on config change" into rvc-dev am: f31ae3b370

Change-Id: I83449d7e3738fba712007dc098f1fc5e18fcd6c8
This commit is contained in:
Winson Chung
2020-05-22 15:58:43 +00:00
committed by Automerger Merge Worker
8 changed files with 67 additions and 73 deletions

View File

@@ -1006,6 +1006,9 @@
<!-- The corner radius for PiP window. -->
<dimen name="pip_corner_radius">8dp</dimen>
<!-- The buffer to use when calculating whether the pip is in an adjust zone. -->
<dimen name="pip_bottom_offset_buffer">1dp</dimen>
<dimen name="default_gear_space">18dp</dimen>
<dimen name="cell_overlay_padding">18dp</dimen>

View File

@@ -500,6 +500,5 @@ public class PipBoundsHandler {
pw.println(innerPrefix + "mImeHeight=" + mImeHeight);
pw.println(innerPrefix + "mIsShelfShowing=" + mIsShelfShowing);
pw.println(innerPrefix + "mShelfHeight=" + mShelfHeight);
mSnapAlgorithm.dump(pw, innerPrefix);
}
}

View File

@@ -17,14 +17,11 @@
package com.android.systemui.pip;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.Size;
import java.io.PrintWriter;
import javax.inject.Inject;
/**
@@ -39,8 +36,6 @@ public class PipSnapAlgorithm {
private final float mMinAspectRatioForMinSize;
private final float mMaxAspectRatioForMinSize;
private int mOrientation = Configuration.ORIENTATION_UNDEFINED;
@Inject
public PipSnapAlgorithm(Context context) {
Resources res = context.getResources();
@@ -50,15 +45,6 @@ public class PipSnapAlgorithm {
mMaxAspectRatioForMinSize = res.getFloat(
com.android.internal.R.dimen.config_pictureInPictureAspectRatioLimitForMinSize);
mMinAspectRatioForMinSize = 1f / mMaxAspectRatioForMinSize;
onConfigurationChanged();
}
/**
* Updates the snap algorithm when the configuration changes.
*/
public void onConfigurationChanged() {
Resources res = mContext.getResources();
mOrientation = res.getConfiguration().orientation;
}
/**
@@ -221,10 +207,4 @@ public class PipSnapAlgorithm {
boundsOut.offsetTo(boundedLeft, movementBounds.bottom);
}
}
public void dump(PrintWriter pw, String prefix) {
final String innerPrefix = prefix + " ";
pw.println(prefix + PipSnapAlgorithm.class.getSimpleName());
pw.println(innerPrefix + "mOrientation=" + mOrientation);
}
}

View File

@@ -24,6 +24,7 @@ import android.graphics.RectF;
import android.view.SurfaceControl;
import com.android.systemui.R;
import com.android.systemui.statusbar.policy.ConfigurationController;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -32,10 +33,11 @@ import javax.inject.Singleton;
* Abstracts the common operations on {@link SurfaceControl.Transaction} for PiP transition.
*/
@Singleton
public class PipSurfaceTransactionHelper {
public class PipSurfaceTransactionHelper implements ConfigurationController.ConfigurationListener {
private final Context mContext;
private final boolean mEnableCornerRadius;
private final int mCornerRadius;
private int mCornerRadius;
/** for {@link #scale(SurfaceControl.Transaction, SurfaceControl, Rect, Rect)} operation */
private final Matrix mTmpTransform = new Matrix();
@@ -44,9 +46,16 @@ public class PipSurfaceTransactionHelper {
private final RectF mTmpDestinationRectF = new RectF();
@Inject
public PipSurfaceTransactionHelper(Context context) {
public PipSurfaceTransactionHelper(Context context, ConfigurationController configController) {
final Resources res = context.getResources();
mContext = context;
mEnableCornerRadius = res.getBoolean(R.bool.config_pipEnableRoundCorner);
configController.addCallback(this);
}
@Override
public void onDensityOrFontScaleChanged() {
final Resources res = mContext.getResources();
mCornerRadius = res.getDimensionPixelSize(R.dimen.pip_corner_radius);
}

View File

@@ -28,7 +28,6 @@ import androidx.dynamicanimation.animation.SpringForce;
import com.android.systemui.pip.PipSnapAlgorithm;
import com.android.systemui.pip.PipTaskOrganizer;
import com.android.systemui.shared.system.WindowManagerWrapper;
import com.android.systemui.util.FloatingContentCoordinator;
import com.android.systemui.util.animation.FloatProperties;
import com.android.systemui.util.animation.PhysicsAnimator;
@@ -60,8 +59,6 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
private PipMenuActivityController mMenuController;
private PipSnapAlgorithm mSnapAlgorithm;
private final Rect mStableInsets = new Rect();
/** PIP's current bounds on the screen. */
private final Rect mBounds = new Rect();
@@ -148,7 +145,6 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
mMenuController = menuController;
mSnapAlgorithm = snapAlgorithm;
mFloatingContentCoordinator = floatingContentCoordinator;
onConfigurationChanged();
mPipTaskOrganizer.registerPipTransitionCallback(mPipTransitionCallback);
}
@@ -169,14 +165,6 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
animateToBounds(bounds, mConflictResolutionSpringConfig);
}
/**
* Updates whenever the configuration changes.
*/
void onConfigurationChanged() {
mSnapAlgorithm.onConfigurationChanged();
WindowManagerWrapper.getInstance().getStableInsets(mStableInsets);
}
/**
* Synchronizes the current bounds with the pinned stack, cancelling any ongoing animations.
*/
@@ -530,6 +518,5 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
final String innerPrefix = prefix + " ";
pw.println(prefix + TAG);
pw.println(innerPrefix + "mBounds=" + mBounds);
pw.println(innerPrefix + "mStableInsets=" + mStableInsets);
}
}

View File

@@ -32,7 +32,6 @@ import android.hardware.input.InputManager;
import android.os.Handler;
import android.os.Looper;
import android.provider.DeviceConfig;
import android.util.DisplayMetrics;
import android.view.InputChannel;
import android.view.InputEvent;
import android.view.InputEventReceiver;
@@ -56,7 +55,7 @@ public class PipResizeGestureHandler {
private static final String TAG = "PipResizeGestureHandler";
private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
private final Context mContext;
private final PipBoundsHandler mPipBoundsHandler;
private final PipMotionHelper mMotionHelper;
private final int mDisplayId;
@@ -74,10 +73,10 @@ public class PipResizeGestureHandler {
private final Rect mTmpBottomLeftCorner = new Rect();
private final Rect mTmpBottomRightCorner = new Rect();
private final Rect mDisplayBounds = new Rect();
private final int mDelta;
private final Supplier<Rect> mMovementBoundsSupplier;
private final Runnable mUpdateMovementBoundsRunnable;
private int mDelta;
private boolean mAllowGesture;
private boolean mIsAttached;
private boolean mIsEnabled;
@@ -93,8 +92,7 @@ public class PipResizeGestureHandler {
PipMotionHelper motionHelper, DeviceConfigProxy deviceConfig,
PipTaskOrganizer pipTaskOrganizer, Supplier<Rect> movementBoundsSupplier,
Runnable updateMovementBoundsRunnable) {
final Resources res = context.getResources();
context.getDisplay().getMetrics(mDisplayMetrics);
mContext = context;
mDisplayId = context.getDisplayId();
mMainExecutor = context.getMainExecutor();
mPipBoundsHandler = pipBoundsHandler;
@@ -102,9 +100,8 @@ public class PipResizeGestureHandler {
mPipTaskOrganizer = pipTaskOrganizer;
mMovementBoundsSupplier = movementBoundsSupplier;
mUpdateMovementBoundsRunnable = updateMovementBoundsRunnable;
context.getDisplay().getRealSize(mMaxSize);
mDelta = res.getDimensionPixelSize(R.dimen.pip_resize_edge_size);
reloadResources();
mEnableUserResize = DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_SYSTEMUI,
@@ -122,6 +119,15 @@ public class PipResizeGestureHandler {
});
}
public void onConfigurationChanged() {
reloadResources();
}
private void reloadResources() {
final Resources res = mContext.getResources();
mDelta = res.getDimensionPixelSize(R.dimen.pip_resize_edge_size);
}
private void resetDragCorners() {
mDragCornerSize.set(0, 0, mDelta, mDelta);
mTmpTopLeftCorner.set(mDragCornerSize);

View File

@@ -61,7 +61,6 @@ import com.android.systemui.pip.PipBoundsHandler;
import com.android.systemui.pip.PipSnapAlgorithm;
import com.android.systemui.pip.PipTaskOrganizer;
import com.android.systemui.shared.system.InputConsumerController;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.DismissCircleView;
import com.android.systemui.util.FloatingContentCoordinator;
@@ -77,9 +76,6 @@ import java.io.PrintWriter;
public class PipTouchHandler {
private static final String TAG = "PipTouchHandler";
private static final int SHOW_DISMISS_AFFORDANCE_DELAY = 225;
private static final int BOTTOM_OFFSET_BUFFER_DP = 1;
// Allow dragging the PIP to a location to close it
private final boolean mEnableDismissDragToEdge;
// Allow PIP to resize to a slightly bigger state upon touch
@@ -161,6 +157,7 @@ public class PipTouchHandler {
private boolean mIsShelfShowing;
private int mShelfHeight;
private int mMovementBoundsExtraOffsets;
private int mBottomOffsetBufferPx;
private float mSavedSnapFraction = -1f;
private boolean mSendingHoverAccessibilityEvents;
private boolean mMovementWithinDismiss;
@@ -168,7 +165,6 @@ public class PipTouchHandler {
// Touch state
private final PipTouchState mTouchState;
private final FlingAnimationUtils mFlingAnimationUtils;
private final FloatingContentCoordinator mFloatingContentCoordinator;
private PipMotionHelper mMotionHelper;
private PipTouchGesture mGesture;
@@ -225,8 +221,6 @@ public class PipTouchHandler {
mMenuController = menuController;
mMenuController.addListener(new PipMenuListener());
mSnapAlgorithm = pipSnapAlgorithm;
mFlingAnimationUtils = new FlingAnimationUtils(context.getResources().getDisplayMetrics(),
2.5f);
mGesture = new DefaultPipTouchGesture();
mMotionHelper = new PipMotionHelper(mContext, pipTaskOrganizer, mMenuController,
mSnapAlgorithm, floatingContentCoordinator);
@@ -239,13 +233,9 @@ public class PipTouchHandler {
true /* allowMenuTimeout */, willResizeMenu(), shouldShowResizeHandle()));
Resources res = context.getResources();
mExpandedShortestEdgeSize = res.getDimensionPixelSize(
R.dimen.pip_expanded_shortest_edge_size);
mImeOffset = res.getDimensionPixelSize(R.dimen.pip_ime_offset);
mDismissAreaHeight = res.getDimensionPixelSize(R.dimen.floating_dismiss_gradient_height);
mEnableDismissDragToEdge = res.getBoolean(R.bool.config_pipEnableDismissDragToEdge);
mEnableResize = res.getBoolean(R.bool.config_pipEnableResizeForMenu);
reloadResources();
// Register the listener for input consumer touch events
inputConsumerController.setInputListener(this::handleTouchEvent);
@@ -256,22 +246,14 @@ public class PipTouchHandler {
mConnection = new PipAccessibilityInteractionConnection(mMotionHelper,
this::onAccessibilityShowMenu, mHandler);
final int targetSize = res.getDimensionPixelSize(R.dimen.dismiss_circle_size);
mTargetView = new DismissCircleView(context);
final FrameLayout.LayoutParams newParams =
new FrameLayout.LayoutParams(targetSize, targetSize);
newParams.gravity = Gravity.CENTER;
mTargetView.setLayoutParams(newParams);
mTargetViewContainer = new FrameLayout(context);
mTargetViewContainer.setClipChildren(false);
mTargetViewContainer.addView(mTargetView);
mMagnetizedPip = mMotionHelper.getMagnetizedPip();
mMagneticTarget = mMagnetizedPip.addTarget(mTargetView, 0);
// Set the magnetic field radius equal to twice the size of the target.
mMagneticTarget.setMagneticFieldRadiusPx(targetSize * 2);
updateMagneticTargetSize();
mMagnetizedPip.setPhysicsAnimatorUpdateListener(mMotionHelper.mResizePipUpdateListener);
mMagnetizedPip.setMagnetListener(new MagnetizedObject.MagnetListener() {
@@ -311,8 +293,34 @@ public class PipTouchHandler {
mMagneticTargetAnimator = PhysicsAnimator.getInstance(mTargetView);
}
private void reloadResources() {
final Resources res = mContext.getResources();
mBottomOffsetBufferPx = res.getDimensionPixelSize(R.dimen.pip_bottom_offset_buffer);
mExpandedShortestEdgeSize = res.getDimensionPixelSize(
R.dimen.pip_expanded_shortest_edge_size);
mImeOffset = res.getDimensionPixelSize(R.dimen.pip_ime_offset);
mDismissAreaHeight = res.getDimensionPixelSize(R.dimen.floating_dismiss_gradient_height);
updateMagneticTargetSize();
}
private void updateMagneticTargetSize() {
if (mTargetView == null) {
return;
}
final Resources res = mContext.getResources();
final int targetSize = res.getDimensionPixelSize(R.dimen.dismiss_circle_size);
final FrameLayout.LayoutParams newParams =
new FrameLayout.LayoutParams(targetSize, targetSize);
newParams.gravity = Gravity.CENTER;
mTargetView.setLayoutParams(newParams);
// Set the magnetic field radius equal to twice the size of the target.
mMagneticTarget.setMagneticFieldRadiusPx(targetSize * 2);
}
private boolean shouldShowResizeHandle() {
return !mPipBoundsHandler.hasSaveReentryBounds();
return !mPipBoundsHandler.hasSaveReentryBounds();
}
public void setTouchGesture(PipTouchGesture gesture) {
@@ -371,8 +379,9 @@ public class PipTouchHandler {
}
public void onConfigurationChanged() {
mMotionHelper.onConfigurationChanged();
mPipResizeGestureHandler.onConfigurationChanged();
mMotionHelper.synchronizePinnedStackBounds();
reloadResources();
// Recreate the dismiss target for the new orientation.
createOrUpdateDismissTarget();
@@ -436,8 +445,6 @@ public class PipTouchHandler {
// Defer the update of the current movement bounds until after the user finishes
// touching the screen
} else {
final float offsetBufferPx = BOTTOM_OFFSET_BUFFER_DP
* mContext.getResources().getDisplayMetrics().density;
final boolean isExpanded = mMenuState == MENU_STATE_FULL && willResizeMenu();
final Rect toMovementBounds = isExpanded
? new Rect(expandedMovementBounds)
@@ -453,8 +460,9 @@ public class PipTouchHandler {
mSavedSnapFraction);
}
if ((Math.min(prevBottom, toBottom) - offsetBufferPx) <= curBounds.top
&& curBounds.top <= (Math.max(prevBottom, toBottom) + offsetBufferPx)) {
if ((Math.min(prevBottom, toBottom) - mBottomOffsetBufferPx) <= curBounds.top
&& curBounds.top <= (Math.max(prevBottom, toBottom)
+ mBottomOffsetBufferPx)) {
mMotionHelper.animateToOffset(curBounds, toBottom - curBounds.top);
}
}
@@ -997,7 +1005,6 @@ public class PipTouchHandler {
pw.println(innerPrefix + "mShelfHeight=" + mShelfHeight);
pw.println(innerPrefix + "mSavedSnapFraction=" + mSavedSnapFraction);
pw.println(innerPrefix + "mEnableDragToEdgeDismiss=" + mEnableDismissDragToEdge);
mSnapAlgorithm.dump(pw, innerPrefix);
mTouchState.dump(pw, innerPrefix);
mMotionHelper.dump(pw, innerPrefix);
}

View File

@@ -22,6 +22,7 @@ import static com.android.systemui.pip.PipAnimationController.TRANSITION_DIRECTI
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import android.graphics.Matrix;
@@ -33,6 +34,7 @@ import android.view.SurfaceControl;
import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.policy.ConfigurationController;
import org.junit.Before;
import org.junit.Test;
@@ -59,7 +61,8 @@ public class PipAnimationControllerTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
mPipAnimationController = new PipAnimationController(
mContext, new PipSurfaceTransactionHelper(mContext));
mContext, new PipSurfaceTransactionHelper(mContext,
mock(ConfigurationController.class)));
mLeash = new SurfaceControl.Builder()
.setContainerLayer()
.setName("FakeLeash")