diff options
4 files changed, 26 insertions, 10 deletions
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 07b6cc1c22d2..94ca550b0e76 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -23,6 +23,8 @@ import static android.view.InsetsState.ISIDE_LEFT; import static android.view.InsetsState.ISIDE_RIGHT; import static android.view.InsetsState.ISIDE_TOP; +import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; + import android.annotation.Nullable; import android.graphics.Insets; import android.graphics.Matrix; @@ -76,6 +78,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll private boolean mShownOnFinish; private float mCurrentAlpha = 1.0f; private float mPendingAlpha = 1.0f; + @VisibleForTesting(visibility = PACKAGE) + public boolean mReadyDispatched; @VisibleForTesting public InsetsAnimationControlImpl(SparseArray<InsetsSourceControl> controls, Rect frame, @@ -214,7 +218,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll return; } mCancelled = true; - mListener.onCancelled(this); + mListener.onCancelled(mReadyDispatched ? this : null); releaseLeashes(); } diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 3e082ab94c31..8eb9b5f6ef23 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -27,8 +27,6 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_BEHAVIOR_CONT import android.animation.AnimationHandler; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; import android.animation.TypeEvaluator; import android.animation.ValueAnimator; import android.annotation.IntDef; @@ -39,11 +37,9 @@ import android.graphics.Rect; import android.os.CancellationSignal; import android.os.Handler; import android.os.RemoteException; -import android.renderscript.Sampler.Value; import android.util.ArraySet; import android.util.Log; import android.util.Pair; -import android.util.Property; import android.util.SparseArray; import android.view.InsetsSourceConsumer.ShowResult; import android.view.InsetsState.InternalInsetsType; @@ -1064,6 +1060,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation } mViewRoot.mView.dispatchWindowInsetsAnimationStart(animation, bounds); mStartingAnimation = true; + controller.mReadyDispatched = true; listener.onReady(controller, types); mStartingAnimation = false; return true; diff --git a/core/java/android/view/WindowInsetsAnimation.java b/core/java/android/view/WindowInsetsAnimation.java index e32648809f8f..cf5e7e3d3e26 100644 --- a/core/java/android/view/WindowInsetsAnimation.java +++ b/core/java/android/view/WindowInsetsAnimation.java @@ -110,14 +110,13 @@ public final class WindowInsetsAnimation { * and 1. * </p> * @see #getFraction() for raw fraction. - * @return The current interpolated progress of this animation. -1 if interpolator isn't - * specified. + * @return The current interpolated progress of this animation. */ public float getInterpolatedFraction() { if (mInterpolator != null) { return mInterpolator.getInterpolation(mFraction); } - return -1; + return mFraction; } /** diff --git a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java index d78746918e65..6c01181c48c9 100644 --- a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java +++ b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java @@ -20,14 +20,17 @@ import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; import static android.view.WindowInsets.Type.systemBars; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -43,6 +46,8 @@ import android.view.SyncRtSurfaceTransactionApplier.SurfaceParams; import android.view.animation.LinearInterpolator; import android.view.test.InsetsModeSession; +import androidx.test.runner.AndroidJUnit4; + import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -54,8 +59,6 @@ import org.mockito.MockitoAnnotations; import java.util.List; -import androidx.test.runner.AndroidJUnit4; - /** * Tests for {@link InsetsAnimationControlImpl}. * @@ -124,6 +127,7 @@ public class InsetsAnimationControlImplTest { new Rect(0, 0, 500, 500), mInsetsState, mMockListener, systemBars(), mMockController, 10 /* durationMs */, new LinearInterpolator(), 0 /* animationType */); + mController.mReadyDispatched = true; } @Test @@ -204,6 +208,18 @@ public class InsetsAnimationControlImplTest { assertTrue(mController.isCancelled()); verify(mMockListener).onCancelled(mController); mController.finish(true /* shown */); + verify(mMockListener, never()).onFinished(any()); + } + + @Test + public void testCancelled_beforeReadyDispatched() { + mController.mReadyDispatched = false; + mController.cancel(); + assertFalse(mController.isReady()); + assertFalse(mController.isFinished()); + assertTrue(mController.isCancelled()); + verify(mMockListener).onCancelled(null); + verify(mMockListener, never()).onFinished(any()); } private void assertPosition(Matrix m, Rect original, Rect transformed) { |