@@ -109,10 +109,8 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
109109
110110 @ Nullable
111111 private RectF inputAreaRect ;
112- @ Nullable
113- private WindowInsetsAnimationCompat imeAnimation ;
114- private int fullImeHeight ;
115- private int targetImeHeight ;
112+ private int imeHeight ;
113+ private boolean hasOngoingImeAnimation ;
116114
117115 MinecraftProfile minecraftProfile ;
118116
@@ -204,53 +202,35 @@ public void onCreate(Bundle savedInstanceState) {
204202 MCOptionUtils .addMCOptionListener (optionListener );
205203 mControlLayout .setModifiable (false );
206204
207- // Listen to IME offsets
205+ // Listen to IME insets animation
208206 ViewCompat .setWindowInsetsAnimationCallback (contentFrame , new WindowInsetsAnimationCompat .Callback (WindowInsetsAnimationCompat .Callback .DISPATCH_MODE_STOP ) {
209207 @ Override
210208 public void onPrepare (@ NonNull WindowInsetsAnimationCompat animation ) {
211209 if ((animation .getTypeMask () & WindowInsetsCompat .Type .ime ()) != 0 ) {
212- imeAnimation = animation ;
210+ hasOngoingImeAnimation = true ;
213211 }
214212 }
215213
216- @ NonNull
217- @ Override
218- public WindowInsetsAnimationCompat .BoundsCompat onStart (@ NonNull WindowInsetsAnimationCompat animation , @ NonNull WindowInsetsAnimationCompat .BoundsCompat bounds ) {
219- if ((animation .getTypeMask () & WindowInsetsCompat .Type .ime ()) != 0 ) {
220- refreshImeTranslation ();
221- }
222- return bounds ;
223- }
224-
225214 @ NonNull
226215 @ Override
227216 public WindowInsetsCompat onProgress (@ NonNull WindowInsetsCompat insets , @ NonNull List <WindowInsetsAnimationCompat > runningAnimations ) {
228- // Find an IME animation
229- for (WindowInsetsAnimationCompat animation : runningAnimations ) {
230- if ((animation .getTypeMask () & WindowInsetsCompat .Type .ime ()) != 0 ) {
231- imeAnimation = animation ;
232- break ;
233- }
234- }
217+ imeHeight = insets .getInsets (WindowInsetsCompat .Type .ime ()).bottom ;
235218 refreshImeTranslation ();
236219 return insets ;
237220 }
238221
239222 @ Override
240223 public void onEnd (@ NonNull WindowInsetsAnimationCompat animation ) {
241- imeAnimation = null ;
242- refreshImeTranslation ();
224+ if ((animation .getTypeMask () & WindowInsetsCompat .Type .ime ()) != 0 ) {
225+ hasOngoingImeAnimation = false ;
226+ }
243227 }
244228 });
245229 ViewCompat .setOnApplyWindowInsetsListener (contentFrame , (v , insets ) -> {
246- boolean imeVisible = insets .isVisible (WindowInsetsCompat .Type .ime ());
247- if (imeVisible ) {
248- int height = insets .getInsets (WindowInsetsCompat .Type .ime ()).bottom ;
249- fullImeHeight = height ;
250- targetImeHeight = height ;
251- } else {
252- // Retain last value of fullImeHeight
253- targetImeHeight = 0 ;
230+ // Only refresh translation if IME change insets itself, not the animation
231+ if (!hasOngoingImeAnimation ) {
232+ imeHeight = insets .getInsets (WindowInsetsCompat .Type .ime ()).bottom ;
233+ refreshImeTranslation ();
254234 }
255235 return insets ;
256236 });
@@ -792,7 +772,7 @@ public void updateInputAreaRect(@Nullable RectF rect) {
792772 }
793773
794774 private void refreshImeTranslation () {
795- if (fullImeHeight == 0 ) {
775+ if (imeHeight == 0 ) {
796776 // Early exit
797777 contentFrame .setTranslationY (0 );
798778 return ;
@@ -808,20 +788,8 @@ private void refreshImeTranslation() {
808788 return ;
809789 }
810790
811- int animationImeHeight ;
812- if (imeAnimation != null ) {
813- if (targetImeHeight == 0 ) {
814- // Collapsing
815- animationImeHeight = (int ) (fullImeHeight * (1 - imeAnimation .getInterpolatedFraction ()));
816- } else {
817- // Expanding
818- animationImeHeight = (int ) (targetImeHeight * imeAnimation .getInterpolatedFraction ());
819- }
820- } else {
821- animationImeHeight = targetImeHeight ;
822- }
823791 int bottomDistance = contentFrame .getHeight () - inputAreaBottom ;
824- int bottomPadding = Math .max (animationImeHeight - bottomDistance , 0 );
792+ int bottomPadding = Math .max (imeHeight - bottomDistance , 0 );
825793
826794 contentFrame .setTranslationY (-bottomPadding );
827795 }
0 commit comments