diff options
| author | Adrian Roos <roosa@google.com> | 2020-03-12 18:30:54 +0000 |
|---|---|---|
| committer | Adrian Roos <roosa@google.com> | 2020-03-13 19:40:34 +0000 |
| commit | 5ad8cd2586cb384b364d32d42e9c543c6eca0191 (patch) | |
| tree | 78f76a0b0db7957397e25fbc33fbc83b574a06b4 /core/java/android | |
| parent | a03b6abb5be607a0dfb3b913a21011863225af6e (diff) | |
Revert "Revert "WindowInsetsController: Address API feedback""
This reverts commit 5e7097b21ea3841550044b933238f273be7cf2b6
and relands Id4cb53fddcecac17b7926068046760df5130dc39
Change-Id: I348141f27efcf7c22736778fbcdde4a110e95982
Fixes: 150472709
Test: atest InsetsControllerTest
Diffstat (limited to 'core/java/android')
4 files changed, 52 insertions, 50 deletions
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index c1763d62d829..e669d6d266eb 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -53,7 +53,6 @@ import android.view.animation.Interpolator; import android.view.animation.PathInterpolator; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.util.Preconditions; import com.android.internal.graphics.SfVsyncFrameCallbackProvider; import java.io.PrintWriter; @@ -518,14 +517,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation PendingControlRequest pendingRequest = mPendingImeControlRequest; mPendingImeControlRequest = null; mHandler.removeCallbacks(mPendingControlTimeout); - CancellationSignal cancellationSignal = controlAnimationUnchecked( - pendingRequest.types, + controlAnimationUnchecked( + pendingRequest.types, pendingRequest.cancellationSignal, pendingRequest.listener, mFrame, true /* fromIme */, pendingRequest.durationMs, pendingRequest.interpolator, false /* fade */, pendingRequest.animationType, pendingRequest.layoutInsetsDuringAnimation, pendingRequest.useInsetsAnimationThread); - pendingRequest.cancellationSignal.setOnCancelListener(cancellationSignal::cancel); return; } @@ -571,24 +569,26 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation } @Override - public CancellationSignal controlWindowInsetsAnimation(@InsetsType int types, long durationMs, + public void controlWindowInsetsAnimation(@InsetsType int types, long durationMillis, @Nullable Interpolator interpolator, + @Nullable CancellationSignal cancellationSignal, @NonNull WindowInsetsAnimationControlListener listener) { - return controlWindowInsetsAnimation(types, listener, false /* fromIme */, durationMs, - interpolator, ANIMATION_TYPE_USER); + controlWindowInsetsAnimation(types, cancellationSignal, listener, + false /* fromIme */, durationMillis, interpolator, ANIMATION_TYPE_USER); } - private CancellationSignal controlWindowInsetsAnimation(@InsetsType int types, - WindowInsetsAnimationControlListener listener, boolean fromIme, long durationMs, - @Nullable Interpolator interpolator, @AnimationType int animationType) { + private void controlWindowInsetsAnimation(@InsetsType int types, + @Nullable CancellationSignal cancellationSignal, + WindowInsetsAnimationControlListener listener, + boolean fromIme, long durationMs, @Nullable Interpolator interpolator, + @AnimationType int animationType) { if (!checkDisplayFramesForControlling()) { listener.onCancelled(); - CancellationSignal cancellationSignal = new CancellationSignal(); - cancellationSignal.cancel(); - return cancellationSignal; + return; } - return controlAnimationUnchecked(types, listener, mFrame, fromIme, durationMs, interpolator, - false /* fade */, animationType, getLayoutInsetsDuringAnimationMode(types), + controlAnimationUnchecked(types, cancellationSignal, listener, mFrame, fromIme, durationMs, + interpolator, false /* fade */, animationType, + getLayoutInsetsDuringAnimationMode(types), false /* useInsetsAnimationThread */); } @@ -599,18 +599,17 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation return mState.getDisplayFrame().equals(mFrame); } - private CancellationSignal controlAnimationUnchecked(@InsetsType int types, + private void controlAnimationUnchecked(@InsetsType int types, + @Nullable CancellationSignal cancellationSignal, WindowInsetsAnimationControlListener listener, Rect frame, boolean fromIme, long durationMs, Interpolator interpolator, boolean fade, @AnimationType int animationType, @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation, boolean useInsetsAnimationThread) { - CancellationSignal cancellationSignal = new CancellationSignal(); if (types == 0) { // nothing to animate. listener.onCancelled(); - cancellationSignal.cancel(); - return cancellationSignal; + return; } cancelExistingControllers(types); mLastStartedAnimTypes |= types; @@ -631,18 +630,19 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation useInsetsAnimationThread); mPendingImeControlRequest = request; mHandler.postDelayed(mPendingControlTimeout, PENDING_CONTROL_TIMEOUT_MS); - cancellationSignal.setOnCancelListener(() -> { - if (mPendingImeControlRequest == request) { - abortPendingImeControlRequest(); - } - }); - return cancellationSignal; + if (cancellationSignal != null) { + cancellationSignal.setOnCancelListener(() -> { + if (mPendingImeControlRequest == request) { + abortPendingImeControlRequest(); + } + }); + } + return; } if (typesReady == 0) { listener.onCancelled(); - cancellationSignal.cancel(); - return cancellationSignal; + return; } @@ -654,13 +654,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation frame, mState, listener, typesReady, this, durationMs, interpolator, fade, animationType); mRunningAnimations.add(new RunningAnimation(runner, animationType)); - cancellationSignal.setOnCancelListener(runner::cancel); + if (cancellationSignal != null) { + cancellationSignal.setOnCancelListener(runner::cancel); + } if (layoutInsetsDuringAnimation == LAYOUT_INSETS_DURING_ANIMATION_SHOWN) { showDirectly(types); } else { hideDirectly(types, false /* animationFinished */, animationType); } - return cancellationSignal; } /** @@ -922,7 +923,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation // Show/hide animations always need to be relative to the display frame, in order that shown // and hidden state insets are correct. controlAnimationUnchecked( - types, listener, mState.getDisplayFrame(), fromIme, listener.getDurationMs(), + types, null /* cancellationSignal */, listener, mState.getDisplayFrame(), fromIme, + listener.getDurationMs(), INTERPOLATOR, true /* fade */, show ? ANIMATION_TYPE_SHOW : ANIMATION_TYPE_HIDE, show ? LAYOUT_INSETS_DURING_ANIMATION_SHOWN : LAYOUT_INSETS_DURING_ANIMATION_HIDDEN, diff --git a/core/java/android/view/PendingInsetsController.java b/core/java/android/view/PendingInsetsController.java index 7f3641803770..e8d9bb50c290 100644 --- a/core/java/android/view/PendingInsetsController.java +++ b/core/java/android/view/PendingInsetsController.java @@ -16,6 +16,8 @@ package android.view; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.os.CancellationSignal; import android.view.WindowInsets.Type.InsetsType; import android.view.animation.Interpolator; @@ -60,21 +62,6 @@ public class PendingInsetsController implements WindowInsetsController { } @Override - public CancellationSignal controlWindowInsetsAnimation(int types, long durationMillis, - Interpolator interpolator, - WindowInsetsAnimationControlListener listener) { - if (mReplayedInsetsController != null) { - return mReplayedInsetsController.controlWindowInsetsAnimation(types, durationMillis, - interpolator, listener); - } else { - listener.onCancelled(); - CancellationSignal cancellationSignal = new CancellationSignal(); - cancellationSignal.cancel(); - return cancellationSignal; - } - } - - @Override public void setSystemBarsAppearance(int appearance, int mask) { if (mReplayedInsetsController != null) { mReplayedInsetsController.setSystemBarsAppearance(appearance, mask); @@ -176,6 +163,19 @@ public class PendingInsetsController implements WindowInsetsController { mReplayedInsetsController = null; } + @Override + public void controlWindowInsetsAnimation(@InsetsType int types, long durationMillis, + @Nullable Interpolator interpolator, + CancellationSignal cancellationSignal, + @NonNull WindowInsetsAnimationControlListener listener) { + if (mReplayedInsetsController != null) { + mReplayedInsetsController.controlWindowInsetsAnimation(types, durationMillis, + interpolator, cancellationSignal, listener); + } else { + listener.onCancelled(); + } + } + private interface PendingRequest { void replay(InsetsController controller); } diff --git a/core/java/android/view/WindowInsetsAnimationControlListener.java b/core/java/android/view/WindowInsetsAnimationControlListener.java index 701bd3158b1e..faaf9203af32 100644 --- a/core/java/android/view/WindowInsetsAnimationControlListener.java +++ b/core/java/android/view/WindowInsetsAnimationControlListener.java @@ -16,7 +16,6 @@ package android.view; -import android.annotation.Hide; import android.annotation.NonNull; import android.view.WindowInsets.Type.InsetsType; import android.view.inputmethod.EditorInfo; diff --git a/core/java/android/view/WindowInsetsController.java b/core/java/android/view/WindowInsetsController.java index 2ad557e6d9f6..0282ecac8920 100644 --- a/core/java/android/view/WindowInsetsController.java +++ b/core/java/android/view/WindowInsetsController.java @@ -156,16 +156,17 @@ public interface WindowInsetsController { * calculate {@link WindowInsetsAnimation#getInterpolatedFraction()}. * @param listener The {@link WindowInsetsAnimationControlListener} that gets called when the * windows are ready to be controlled, among other callbacks. - * @return A cancellation signal that the caller can use to cancel the request to obtain - * control, or once they have control, to cancel the control. + * @param cancellationSignal A cancellation signal that the caller can use to cancel the + * request to obtain control, or once they have control, to cancel the + * control. * @see WindowInsetsAnimation#getFraction() * @see WindowInsetsAnimation#getInterpolatedFraction() * @see WindowInsetsAnimation#getInterpolator() * @see WindowInsetsAnimation#getDurationMillis() */ - @NonNull - CancellationSignal controlWindowInsetsAnimation(@InsetsType int types, long durationMillis, + void controlWindowInsetsAnimation(@InsetsType int types, long durationMillis, @Nullable Interpolator interpolator, + @Nullable CancellationSignal cancellationSignal, @NonNull WindowInsetsAnimationControlListener listener); /** |
