diff options
author | Jorim Jaggi <jjaggi@google.com> | 2020-03-30 17:28:51 +0200 |
---|---|---|
committer | Jorim Jaggi <jjaggi@google.com> | 2020-03-30 19:22:37 +0200 |
commit | 8c56ac6b945e4050d56968e2adac673e052b772d (patch) | |
tree | 475a45ddd35914c313a0ef85bb389cfe221bae6a /tests/WindowInsetsTests | |
parent | 49b9f6c67c777898f4f956a433a11292174e37b9 (diff) |
Revert "Defer updating InsetsSource.mFrame while animating"
This reverts commit 2751c29414d17650b1737e19c250ffbe4f266b82.
Reason: Broken logic
Test: Open IME in Messages
Fixes: 152695319
Change-Id: I6a63f20c6342d4284a5da99e39e8f835028a5b6b
Diffstat (limited to 'tests/WindowInsetsTests')
-rw-r--r-- | tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/WindowInsetsActivity.java | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/WindowInsetsActivity.java b/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/WindowInsetsActivity.java index 498cb7c1c710..548af0c54b03 100644 --- a/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/WindowInsetsActivity.java +++ b/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/WindowInsetsActivity.java @@ -18,6 +18,7 @@ package com.google.android.test.windowinsetstests; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsetsAnimation.Callback.DISPATCH_MODE_STOP; + import static java.lang.Math.max; import static java.lang.Math.min; @@ -30,7 +31,6 @@ import android.content.Context; import android.graphics.Insets; import android.os.Bundle; import android.util.AttributeSet; -import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; @@ -44,11 +44,11 @@ import android.view.WindowInsetsController.OnControllableInsetsChangedListener; import android.view.animation.LinearInterpolator; import android.widget.LinearLayout; +import androidx.appcompat.app.AppCompatActivity; + import java.util.ArrayList; import java.util.List; -import androidx.appcompat.app.AppCompatActivity; - public class WindowInsetsActivity extends AppCompatActivity { private View mRoot; @@ -191,40 +191,6 @@ public class WindowInsetsActivity extends AppCompatActivity { mTransitions.forEach(it -> it.onFinish(animation)); } }); - - findViewById(R.id.floating_action_button).setOnClickListener( - v -> v.getWindowInsetsController().controlWindowInsetsAnimation(ime(), -1, - new LinearInterpolator(), null /* cancellationSignal */, - new WindowInsetsAnimationControlListener() { - @Override - public void onReady( - WindowInsetsAnimationController controller, - int types) { - ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); - anim.setDuration(1500); - anim.addUpdateListener(animation - -> controller.setInsetsAndAlpha( - controller.getShownStateInsets(), - (float) animation.getAnimatedValue(), - anim.getAnimatedFraction())); - anim.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - controller.finish(true); - } - }); - anim.start(); - } - - @Override - public void onCancelled(WindowInsetsAnimationController controller) { - } - - @Override - public void onFinished(WindowInsetsAnimationController controller) { - } - })); } @Override @@ -234,6 +200,57 @@ public class WindowInsetsActivity extends AppCompatActivity { getWindow().getDecorView().post(() -> getWindow().setDecorFitsSystemWindows(false)); } + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + getWindow().getInsetsController().addOnControllableInsetsChangedListener( + new OnControllableInsetsChangedListener() { + + boolean hasControl = false; + @Override + public void onControllableInsetsChanged(WindowInsetsController controller, + int types) { + if ((types & ime()) != 0 && !hasControl) { + hasControl = true; + controller.controlWindowInsetsAnimation(ime(), -1, + new LinearInterpolator(), null /* cancellationSignal */, + new WindowInsetsAnimationControlListener() { + @Override + public void onReady( + WindowInsetsAnimationController controller, + int types) { + ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); + anim.setDuration(1500); + anim.addUpdateListener(animation + -> controller.setInsetsAndAlpha( + controller.getShownStateInsets(), + (float) animation.getAnimatedValue(), + anim.getAnimatedFraction())); + anim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + controller.finish(true); + } + }); + anim.start(); + } + + @Override + public void onFinished( + WindowInsetsAnimationController controller) { + } + + @Override + public void onCancelled( + WindowInsetsAnimationController controller) { + } + }); + } + } + }); + } + static class Transition { private int mEndBottom; private int mStartBottom; |