Merge "WindowInsetsAnimationController: Fix minor API issues" into rvc-dev am: b259d151ce

Change-Id: I5347ddb8f3176a4c95a689e0e5a56aeabe33c1d3
This commit is contained in:
TreeHugger Robot
2020-03-31 20:12:00 +00:00
committed by Automerger Merge Worker
4 changed files with 26 additions and 10 deletions

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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;
}
/**

View File

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