Refactor OHM to use (float)offset for translating windows
The core function of OHM is translate all windows down instead of resize, it's unnecessary to set WCT & app bounds that will introduce DA require to cache configuration in DAInfo as well as handle configuration changes stuffs This change ensure App Compat mode works good: - Remove wct.setBounds() & wct.setAppBounds() - Use float instead of bounds for transition/animation - Remove unused code - Reset setWindowCrop(leash, -1, -1) after rotate - Reset setCornerRadius(leash, -1) after rotate - Add dump() for OneHandedAnimationController - Add dump() for OneHandedSurfaceTransactionHelper Test: atest WMShellUnitTests Test: maunal trigger OHM, rotate, and obseve function works Bug: 184091042 Bug: 181091031 Change-Id: I401d9b8a79a2a1526b8683362a1e0330458141b1
This commit is contained in:
@@ -44,8 +44,9 @@ public interface OneHandedAnimationCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when OneHanded animator is updating offset
|
||||
* Called when OneHanded animator is updating position
|
||||
*/
|
||||
default void onTutorialAnimationUpdate(int offset) {}
|
||||
default void onAnimationUpdate(float xPos, float yPos) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,10 @@ import android.view.SurfaceControl;
|
||||
import android.view.animation.BaseInterpolator;
|
||||
import android.window.WindowContainerToken;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
@@ -37,6 +39,7 @@ import java.util.List;
|
||||
* Controller class of OneHanded animations (both from and to OneHanded mode).
|
||||
*/
|
||||
public class OneHandedAnimationController {
|
||||
private static final String TAG = "OneHandedAnimationController";
|
||||
private static final float FRACTION_START = 0f;
|
||||
private static final float FRACTION_END = 1f;
|
||||
|
||||
@@ -68,17 +71,19 @@ public class OneHandedAnimationController {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
OneHandedTransitionAnimator getAnimator(WindowContainerToken token, SurfaceControl leash,
|
||||
Rect startBounds, Rect endBounds) {
|
||||
float startPos, float endPos, Rect displayBounds) {
|
||||
final OneHandedTransitionAnimator animator = mAnimatorMap.get(token);
|
||||
if (animator == null) {
|
||||
mAnimatorMap.put(token, setupOneHandedTransitionAnimator(
|
||||
OneHandedTransitionAnimator.ofBounds(token, leash, startBounds, endBounds)));
|
||||
OneHandedTransitionAnimator.ofYOffset(token, leash, startPos, endPos,
|
||||
displayBounds)));
|
||||
} else if (animator.isRunning()) {
|
||||
animator.updateEndValue(endBounds);
|
||||
animator.updateEndValue(endPos);
|
||||
} else {
|
||||
animator.cancel();
|
||||
mAnimatorMap.put(token, setupOneHandedTransitionAnimator(
|
||||
OneHandedTransitionAnimator.ofBounds(token, leash, startBounds, endBounds)));
|
||||
OneHandedTransitionAnimator.ofYOffset(token, leash, startPos, endPos,
|
||||
displayBounds)));
|
||||
}
|
||||
return mAnimatorMap.get(token);
|
||||
}
|
||||
@@ -147,9 +152,7 @@ public class OneHandedAnimationController {
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mCurrentValue = mStartValue;
|
||||
mOneHandedAnimationCallbacks.forEach(
|
||||
(callback) -> {
|
||||
callback.onOneHandedAnimationStart(this);
|
||||
}
|
||||
(callback) -> callback.onOneHandedAnimationStart(this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,9 +162,7 @@ public class OneHandedAnimationController {
|
||||
final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
|
||||
onEndTransaction(mLeash, tx);
|
||||
mOneHandedAnimationCallbacks.forEach(
|
||||
(callback) -> {
|
||||
callback.onOneHandedAnimationEnd(tx, this);
|
||||
}
|
||||
(callback) -> callback.onOneHandedAnimationEnd(tx, this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -169,9 +170,7 @@ public class OneHandedAnimationController {
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
mCurrentValue = mEndValue;
|
||||
mOneHandedAnimationCallbacks.forEach(
|
||||
(callback) -> {
|
||||
callback.onOneHandedAnimationCancel(this);
|
||||
}
|
||||
(callback) -> callback.onOneHandedAnimationCancel(this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -181,12 +180,10 @@ public class OneHandedAnimationController {
|
||||
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(),
|
||||
animation.getAnimatedFraction());
|
||||
final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
|
||||
applySurfaceControlTransaction(mLeash, tx, animation.getAnimatedFraction());
|
||||
mOneHandedAnimationCallbacks.forEach(
|
||||
(callback) -> {
|
||||
callback.onTutorialAnimationUpdate(((Rect) mCurrentValue).top);
|
||||
}
|
||||
(callback) -> callback.onAnimationUpdate(0f, (float) mCurrentValue)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -217,12 +214,8 @@ public class OneHandedAnimationController {
|
||||
return mToken;
|
||||
}
|
||||
|
||||
Rect getDestinationBounds() {
|
||||
return (Rect) mEndValue;
|
||||
}
|
||||
|
||||
int getDestinationOffset() {
|
||||
return ((Rect) mEndValue).top - ((Rect) mStartValue).top;
|
||||
float getDestinationOffset() {
|
||||
return ((float) mEndValue - (float) mStartValue);
|
||||
}
|
||||
|
||||
@TransitionDirection
|
||||
@@ -259,40 +252,42 @@ public class OneHandedAnimationController {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static OneHandedTransitionAnimator<Rect> ofBounds(WindowContainerToken token,
|
||||
SurfaceControl leash, Rect startValue, Rect endValue) {
|
||||
static OneHandedTransitionAnimator<Float> ofYOffset(WindowContainerToken token,
|
||||
SurfaceControl leash, float startValue, float endValue, Rect displayBounds) {
|
||||
|
||||
return new OneHandedTransitionAnimator<Rect>(token, leash, new Rect(startValue),
|
||||
new Rect(endValue)) {
|
||||
return new OneHandedTransitionAnimator<Float>(token, leash, startValue, endValue) {
|
||||
|
||||
private final Rect mTmpRect = new Rect();
|
||||
private final Rect mTmpRect = new Rect(displayBounds);
|
||||
|
||||
private int getCastedFractionValue(float start, float end, float fraction) {
|
||||
return (int) (start * (1 - fraction) + end * fraction + .5f);
|
||||
private float getCastedFractionValue(float start, float end, float fraction) {
|
||||
return (start * (1 - fraction) + end * fraction + .5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
void applySurfaceControlTransaction(SurfaceControl leash,
|
||||
SurfaceControl.Transaction tx, float fraction) {
|
||||
final Rect start = getStartValue();
|
||||
final Rect end = getEndValue();
|
||||
final float start = getStartValue();
|
||||
final float end = getEndValue();
|
||||
final float currentValue = getCastedFractionValue(start, end, fraction);
|
||||
mTmpRect.set(
|
||||
getCastedFractionValue(start.left, end.left, fraction),
|
||||
getCastedFractionValue(start.top, end.top, fraction),
|
||||
getCastedFractionValue(start.right, end.right, fraction),
|
||||
getCastedFractionValue(start.bottom, end.bottom, fraction));
|
||||
setCurrentValue(mTmpRect);
|
||||
getSurfaceTransactionHelper().crop(tx, leash, mTmpRect)
|
||||
.round(tx, leash);
|
||||
mTmpRect.left,
|
||||
mTmpRect.top + Math.round(currentValue),
|
||||
mTmpRect.right,
|
||||
mTmpRect.bottom + Math.round(currentValue));
|
||||
setCurrentValue(currentValue);
|
||||
getSurfaceTransactionHelper()
|
||||
.crop(tx, leash, mTmpRect)
|
||||
.round(tx, leash)
|
||||
.translate(tx, leash, currentValue);
|
||||
tx.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {
|
||||
getSurfaceTransactionHelper()
|
||||
.alpha(tx, leash, 1f)
|
||||
.translate(tx, leash, getEndValue().top - getStartValue().top)
|
||||
.round(tx, leash);
|
||||
.crop(tx, leash, mTmpRect)
|
||||
.round(tx, leash)
|
||||
.translate(tx, leash, getStartValue());
|
||||
tx.apply();
|
||||
}
|
||||
};
|
||||
@@ -309,4 +304,15 @@ public class OneHandedAnimationController {
|
||||
* (2.0f * Math.PI) / 4.0f) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void dump(@NonNull PrintWriter pw) {
|
||||
final String innerPrefix = " ";
|
||||
pw.println(TAG + "states: ");
|
||||
pw.print(innerPrefix + "mAnimatorMap=");
|
||||
pw.println(mAnimatorMap);
|
||||
|
||||
if (mSurfaceTransactionHelper != null) {
|
||||
mSurfaceTransactionHelper.dump(pw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
|
||||
private DisplayLayout mDisplayLayout = new DisplayLayout();
|
||||
|
||||
private float mLastVisualOffset = 0;
|
||||
private final Rect mLastVisualDisplayBounds = new Rect();
|
||||
private final Rect mDefaultDisplayBounds = new Rect();
|
||||
private final OneHandedSettingsUtil mOneHandedSettingsUtil;
|
||||
@@ -96,8 +97,7 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
OneHandedAnimationController.OneHandedTransitionAnimator animator) {
|
||||
mAnimationController.removeAnimator(animator.getToken());
|
||||
if (mAnimationController.isAnimatorsConsumed()) {
|
||||
resetWindowsOffsetInternal(animator.getTransitionDirection());
|
||||
finishOffset(animator.getDestinationOffset(),
|
||||
finishOffset((int) animator.getDestinationOffset(),
|
||||
animator.getTransitionDirection());
|
||||
}
|
||||
}
|
||||
@@ -107,8 +107,7 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
OneHandedAnimationController.OneHandedTransitionAnimator animator) {
|
||||
mAnimationController.removeAnimator(animator.getToken());
|
||||
if (mAnimationController.isAnimatorsConsumed()) {
|
||||
resetWindowsOffsetInternal(animator.getTransitionDirection());
|
||||
finishOffset(animator.getDestinationOffset(),
|
||||
finishOffset((int) animator.getDestinationOffset(),
|
||||
animator.getTransitionDirection());
|
||||
}
|
||||
}
|
||||
@@ -165,16 +164,16 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
@Override
|
||||
public void unregisterOrganizer() {
|
||||
super.unregisterOrganizer();
|
||||
resetWindowsOffset(null);
|
||||
resetWindowsOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for display rotation changes by {@link DisplayLayout}
|
||||
*
|
||||
* @param context Any context
|
||||
* @param toRotation target rotation of the display (after rotating).
|
||||
* @param wct A task transaction {@link WindowContainerTransaction} from
|
||||
* {@link DisplayChangeController} to populate.
|
||||
* @param context Any context
|
||||
* @param toRotation target rotation of the display (after rotating).
|
||||
* @param wct A task transaction {@link WindowContainerTransaction} from
|
||||
* {@link DisplayChangeController} to populate.
|
||||
*/
|
||||
public void onRotateDisplay(Context context, int toRotation, WindowContainerTransaction wct) {
|
||||
if (mDisplayLayout.rotation() == toRotation) {
|
||||
@@ -186,7 +185,6 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
return;
|
||||
}
|
||||
mDisplayLayout.rotateTo(context.getResources(), toRotation);
|
||||
resetWindowsOffset(wct);
|
||||
updateDisplayBounds();
|
||||
finishOffset(0, TRANSITION_DIRECTION_EXIT);
|
||||
}
|
||||
@@ -196,38 +194,20 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
* Directly perform manipulation/offset on the leash.
|
||||
*/
|
||||
public void scheduleOffset(int xOffset, int yOffset) {
|
||||
final Rect toBounds = new Rect(mDefaultDisplayBounds.left,
|
||||
mDefaultDisplayBounds.top + yOffset,
|
||||
mDefaultDisplayBounds.right,
|
||||
mDefaultDisplayBounds.bottom + yOffset);
|
||||
final Rect fromBounds = getLastVisualDisplayBounds();
|
||||
final float fromPos = mLastVisualOffset;
|
||||
final int direction = yOffset > 0
|
||||
? TRANSITION_DIRECTION_TRIGGER
|
||||
: TRANSITION_DIRECTION_EXIT;
|
||||
|
||||
final WindowContainerTransaction wct = new WindowContainerTransaction();
|
||||
mDisplayAreaTokenMap.forEach(
|
||||
(token, leash) -> {
|
||||
animateWindows(token, leash, fromBounds, toBounds, direction,
|
||||
animateWindows(token, leash, fromPos, yOffset, direction,
|
||||
mEnterExitAnimationDurationMs);
|
||||
wct.setBounds(token, toBounds);
|
||||
wct.setAppBounds(token, toBounds);
|
||||
});
|
||||
applyTransaction(wct);
|
||||
}
|
||||
|
||||
private void resetWindowsOffsetInternal(
|
||||
@OneHandedAnimationController.TransitionDirection int td) {
|
||||
if (td == TRANSITION_DIRECTION_TRIGGER) {
|
||||
return;
|
||||
}
|
||||
final WindowContainerTransaction wct = new WindowContainerTransaction();
|
||||
resetWindowsOffset(wct);
|
||||
applyTransaction(wct);
|
||||
mLastVisualOffset = yOffset;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void resetWindowsOffset(WindowContainerTransaction wct) {
|
||||
void resetWindowsOffset() {
|
||||
final SurfaceControl.Transaction tx =
|
||||
mSurfaceControlTransactionFactory.getTransaction();
|
||||
mDisplayAreaTokenMap.forEach(
|
||||
@@ -238,21 +218,20 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
animator.cancel();
|
||||
}
|
||||
tx.setPosition(leash, 0, 0)
|
||||
.setWindowCrop(leash, -1/* reset */, -1/* reset */);
|
||||
// DisplayRotationController will applyTransaction() after finish rotating
|
||||
if (wct != null) {
|
||||
wct.setBounds(token, null/* reset */);
|
||||
wct.setAppBounds(token, null/* reset */);
|
||||
}
|
||||
.setWindowCrop(leash, -1, -1)
|
||||
.setCornerRadius(leash, -1);
|
||||
});
|
||||
tx.apply();
|
||||
mLastVisualOffset = 0;
|
||||
mLastVisualDisplayBounds.offsetTo(0, 0);
|
||||
}
|
||||
|
||||
private void animateWindows(WindowContainerToken token, SurfaceControl leash, Rect fromBounds,
|
||||
Rect toBounds, @OneHandedAnimationController.TransitionDirection int direction,
|
||||
private void animateWindows(WindowContainerToken token, SurfaceControl leash, float fromPos,
|
||||
float toPos, @OneHandedAnimationController.TransitionDirection int direction,
|
||||
int durationMs) {
|
||||
final OneHandedAnimationController.OneHandedTransitionAnimator animator =
|
||||
mAnimationController.getAnimator(token, leash, fromBounds, toBounds);
|
||||
mAnimationController.getAnimator(token, leash, fromPos, toPos,
|
||||
mLastVisualDisplayBounds);
|
||||
if (animator != null) {
|
||||
animator.setTransitionDirection(direction)
|
||||
.addOneHandedAnimationCallback(mOneHandedAnimationCallback)
|
||||
@@ -265,10 +244,13 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void finishOffset(int offset,
|
||||
@OneHandedAnimationController.TransitionDirection int direction) {
|
||||
mLastVisualDisplayBounds.offsetTo(0,
|
||||
direction == TRANSITION_DIRECTION_TRIGGER ? offset : 0);
|
||||
void finishOffset(int offset, @OneHandedAnimationController.TransitionDirection int direction) {
|
||||
if (direction == TRANSITION_DIRECTION_EXIT) {
|
||||
// We must do this to ensure reset property for leash when exit one handed mode
|
||||
resetWindowsOffset();
|
||||
}
|
||||
mLastVisualOffset = direction == TRANSITION_DIRECTION_TRIGGER ? offset : 0;
|
||||
mLastVisualDisplayBounds.offsetTo(0, Math.round(mLastVisualOffset));
|
||||
for (int i = mTransitionCallbacks.size() - 1; i >= 0; i--) {
|
||||
final OneHandedTransitionCallback cb = mTransitionCallbacks.get(i);
|
||||
cb.onStartTransition(false /* isTransitioning */);
|
||||
@@ -285,7 +267,7 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
*
|
||||
* @return Rect latest finish_offset
|
||||
*/
|
||||
public Rect getLastVisualDisplayBounds() {
|
||||
private Rect getLastVisualDisplayBounds() {
|
||||
return mLastVisualDisplayBounds;
|
||||
}
|
||||
|
||||
@@ -332,5 +314,11 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
|
||||
pw.println(mDefaultDisplayBounds);
|
||||
pw.print(innerPrefix + "mLastVisualDisplayBounds=");
|
||||
pw.println(mLastVisualDisplayBounds);
|
||||
pw.print(innerPrefix + "mLastVisualOffset=");
|
||||
pw.println(mLastVisualOffset);
|
||||
|
||||
if (mAnimationController != null) {
|
||||
mAnimationController.dump(pw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,18 +21,28 @@ import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.view.SurfaceControl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.wm.shell.R;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Abstracts the common operations on {@link SurfaceControl.Transaction} for OneHanded transition.
|
||||
*/
|
||||
public class OneHandedSurfaceTransactionHelper {
|
||||
private static final String TAG = "OneHandedSurfaceTransactionHelper";
|
||||
|
||||
private final boolean mEnableCornerRadius;
|
||||
private final float mCornerRadius;
|
||||
private final float mCornerRadiusAdjustment;
|
||||
|
||||
public OneHandedSurfaceTransactionHelper(Context context) {
|
||||
final Resources res = context.getResources();
|
||||
mCornerRadius = res.getDimension(com.android.internal.R.dimen.rounded_corner_radius);
|
||||
mCornerRadiusAdjustment = res.getDimension(
|
||||
com.android.internal.R.dimen.rounded_corner_radius_adjustment);
|
||||
mCornerRadius = res.getDimension(com.android.internal.R.dimen.rounded_corner_radius)
|
||||
- mCornerRadiusAdjustment;
|
||||
mEnableCornerRadius = res.getBoolean(R.bool.config_one_handed_enable_round_corner);
|
||||
}
|
||||
|
||||
@@ -47,17 +57,6 @@ public class OneHandedSurfaceTransactionHelper {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operates the alpha on a given transaction and leash
|
||||
*
|
||||
* @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
|
||||
*/
|
||||
OneHandedSurfaceTransactionHelper alpha(SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||
float alpha) {
|
||||
tx.setAlpha(leash, alpha);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operates the crop (setMatrix) on a given transaction and leash
|
||||
*
|
||||
@@ -65,8 +64,7 @@ public class OneHandedSurfaceTransactionHelper {
|
||||
*/
|
||||
OneHandedSurfaceTransactionHelper crop(SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||
Rect destinationBounds) {
|
||||
tx.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height())
|
||||
.setPosition(leash, destinationBounds.left, destinationBounds.top);
|
||||
tx.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -85,4 +83,15 @@ public class OneHandedSurfaceTransactionHelper {
|
||||
interface SurfaceControlTransactionFactory {
|
||||
SurfaceControl.Transaction getTransaction();
|
||||
}
|
||||
|
||||
void dump(@NonNull PrintWriter pw) {
|
||||
final String innerPrefix = " ";
|
||||
pw.println(TAG + "states: ");
|
||||
pw.print(innerPrefix + "mEnableCornerRadius=");
|
||||
pw.println(mEnableCornerRadius);
|
||||
pw.print(innerPrefix + "mCornerRadiusAdjustment=");
|
||||
pw.println(mCornerRadiusAdjustment);
|
||||
pw.print(innerPrefix + "mCornerRadius=");
|
||||
pw.println(mCornerRadius);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +78,21 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
|
||||
|
||||
private final OneHandedAnimationCallback mAnimationCallback = new OneHandedAnimationCallback() {
|
||||
@Override
|
||||
public void onTutorialAnimationUpdate(int offset) {
|
||||
onAnimationUpdate(offset);
|
||||
public void onAnimationUpdate(float xPos, float yPos) {
|
||||
if (!canShowTutorial()) {
|
||||
return;
|
||||
}
|
||||
mTargetViewContainer.setVisibility(View.VISIBLE);
|
||||
mTargetViewContainer.setTransitionGroup(true);
|
||||
mTargetViewContainer.setTranslationY(yPos - mTargetViewContainer.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOneHandedAnimationStart(
|
||||
OneHandedAnimationController.OneHandedTransitionAnimator animator) {
|
||||
final Rect startValue = (Rect) animator.getStartValue();
|
||||
final float startValue = (float) animator.getStartValue();
|
||||
if (mTriggerState == ONE_HANDED_TRIGGER_STATE.UNSET) {
|
||||
mTriggerState = (startValue.top == 0)
|
||||
mTriggerState = (startValue == 0f)
|
||||
? ONE_HANDED_TRIGGER_STATE.ENTERING : ONE_HANDED_TRIGGER_STATE.EXITING;
|
||||
if (mCanShowTutorial && mTriggerState == ONE_HANDED_TRIGGER_STATE.ENTERING) {
|
||||
attachTurtorialTarget();
|
||||
@@ -239,15 +244,6 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void onAnimationUpdate(float value) {
|
||||
if (!canShowTutorial()) {
|
||||
return;
|
||||
}
|
||||
mTargetViewContainer.setVisibility(View.VISIBLE);
|
||||
mTargetViewContainer.setTransitionGroup(true);
|
||||
mTargetViewContainer.setTranslationY(value - mTargetViewContainer.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* onConfigurationChanged events for updating tutorial text.
|
||||
* @param newConfig
|
||||
|
||||
@@ -26,8 +26,6 @@ import android.window.WindowContainerToken;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.wm.shell.common.ShellExecutor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -43,8 +41,6 @@ import org.mockito.MockitoAnnotations;
|
||||
@SmallTest
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class OneHandedAnimationControllerTest extends OneHandedTestCase {
|
||||
private static final int TEST_BOUNDS_WIDTH = 1000;
|
||||
private static final int TEST_BOUNDS_HEIGHT = 1000;
|
||||
|
||||
OneHandedAnimationController mOneHandedAnimationController;
|
||||
|
||||
@@ -52,9 +48,7 @@ public class OneHandedAnimationControllerTest extends OneHandedTestCase {
|
||||
private SurfaceControl mMockLeash;
|
||||
@Mock
|
||||
private WindowContainerToken mMockToken;
|
||||
|
||||
@Mock
|
||||
private ShellExecutor mMainExecutor;
|
||||
private Rect mDisplayBounds = new Rect();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -64,12 +58,10 @@ public class OneHandedAnimationControllerTest extends OneHandedTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetAnimator_withSameBounds_returnAnimator() {
|
||||
final Rect originalBounds = new Rect(0, 0, TEST_BOUNDS_WIDTH, TEST_BOUNDS_HEIGHT);
|
||||
final Rect destinationBounds = originalBounds;
|
||||
destinationBounds.offset(0, 300);
|
||||
final float yOffset = 300;
|
||||
final OneHandedAnimationController.OneHandedTransitionAnimator animator =
|
||||
mOneHandedAnimationController
|
||||
.getAnimator(mMockToken, mMockLeash, originalBounds, destinationBounds);
|
||||
.getAnimator(mMockToken, mMockLeash, 0, yOffset, mDisplayBounds);
|
||||
|
||||
assertNotNull(animator);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,9 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mDisplayLayout = new DisplayLayout(mContext, mDisplay);
|
||||
mDisplayAreaInfo = new DisplayAreaInfo(mToken, DEFAULT_DISPLAY, FEATURE_ONE_HANDED);
|
||||
mDisplayAreaInfo.configuration.orientation = Configuration.ORIENTATION_PORTRAIT;
|
||||
when(mMockAnimationController.getAnimator(any(), any(), any(), any())).thenReturn(null);
|
||||
when(mMockAnimationController.getAnimator(any(), any(), anyFloat(), anyFloat(),
|
||||
any())).thenReturn(
|
||||
null);
|
||||
when(mMockDisplayController.getDisplay(anyInt())).thenReturn(mDisplay);
|
||||
when(mMockSurfaceTransactionHelper.translate(any(), any(), anyFloat())).thenReturn(
|
||||
mMockSurfaceTransactionHelper);
|
||||
@@ -164,7 +166,8 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
info.getDisplayAreaInfo(),
|
||||
info.getLeash()));
|
||||
|
||||
verify(mMockAnimationController, never()).getAnimator(any(), any(), any(), any());
|
||||
verify(mMockAnimationController, never()).getAnimator(any(), any(), anyFloat(), anyFloat(),
|
||||
any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,7 +192,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_90,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -200,7 +203,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_270,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -213,7 +216,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_90,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -226,7 +229,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_270,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -239,7 +242,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_0,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -252,7 +255,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_180,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -265,7 +268,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_0,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -278,7 +281,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_180,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -289,8 +292,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_0,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset(
|
||||
mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -301,7 +303,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_180,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -314,8 +316,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_180,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset(
|
||||
mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -328,7 +329,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_0,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -341,8 +342,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_90,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset(
|
||||
mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_270,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -368,8 +368,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_270,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset(
|
||||
mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -382,8 +381,7 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
mSpiedDisplayAreaOrganizer.onRotateDisplay(mContext, Surface.ROTATION_90,
|
||||
mMockWindowContainerTransaction);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset(
|
||||
mMockWindowContainerTransaction);
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
verify(mSpiedDisplayAreaOrganizer).finishOffset(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@@ -406,4 +404,18 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
|
||||
|
||||
assertThat(mSpiedDisplayAreaOrganizer.getLastDisplayBounds()).isEqualTo(testBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExit_must_resetWindowsOffset() {
|
||||
mSpiedDisplayAreaOrganizer.finishOffset(0, TRANSITION_DIRECTION_EXIT);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer).resetWindowsOffset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrigger_not_resetWindowsOffset() {
|
||||
mSpiedDisplayAreaOrganizer.finishOffset(0, TRANSITION_DIRECTION_TRIGGER);
|
||||
|
||||
verify(mSpiedDisplayAreaOrganizer, never()).resetWindowsOffset();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user