diff options
| author | Charles Lombardo <clombardo169@gmail.com> | 2022-11-08 15:37:16 -0500 |
|---|---|---|
| committer | Charles Lombardo <clombardo169@gmail.com> | 2022-11-11 00:53:59 -0500 |
| commit | 8bfa08fa0e6126060ad1d1c51f8e767cf9a7a074 (patch) | |
| tree | de7212feabf61f25de9936e4fdb5e45c9f9eb0f2 /Source/Android/app/src/main/java | |
| parent | dca51f3ab0e5e11024556e495dfa4d959093c1d2 (diff) | |
Android: Use smooth keyboard animation in cheats activity
Diffstat (limited to 'Source/Android/app/src/main/java')
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java index 575756b99c..7b98528667 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java @@ -7,9 +7,11 @@ import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsAnimationCompat; import androidx.core.view.WindowInsetsCompat; import androidx.core.widget.NestedScrollView; import androidx.recyclerview.widget.RecyclerView; @@ -22,6 +24,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import org.dolphinemu.dolphinemu.R; +import java.util.List; + public class InsetsHelper { public static final int FAB_INSET = 16; @@ -128,14 +132,28 @@ public class InsetsHelper slidingPaneLayout.setPadding(barInsets.left, barInsets.top, barInsets.right, 0); - if (keyboardInsets.bottom > 0) + // Set keyboard insets if the system supports smooth keyboard animations + ViewGroup.MarginLayoutParams mlpDetails = + (ViewGroup.MarginLayoutParams) cheatDetails.getLayoutParams(); + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.R) { - cheatDetails.setPadding(0, 0, 0, keyboardInsets.bottom); + if (keyboardInsets.bottom > 0) + { + mlpDetails.bottomMargin = keyboardInsets.bottom; + } + else + { + mlpDetails.bottomMargin = barInsets.bottom; + } } else { - cheatDetails.setPadding(0, 0, 0, barInsets.bottom); + if (mlpDetails.bottomMargin == 0) + { + mlpDetails.bottomMargin = barInsets.bottom; + } } + cheatDetails.setLayoutParams(mlpDetails); applyWorkaround(barInsets.bottom, workaroundView); @@ -144,6 +162,32 @@ public class InsetsHelper return windowInsets; }); + + // Update the layout for every frame that the keyboard animates in + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) + { + ViewCompat.setWindowInsetsAnimationCallback(cheatDetails, + new WindowInsetsAnimationCompat.Callback( + WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP) + { + int keyboardInsets = 0; + int barInsets = 0; + + @NonNull + @Override + public WindowInsetsCompat onProgress(@NonNull WindowInsetsCompat insets, + @NonNull List<WindowInsetsAnimationCompat> runningAnimations) + { + ViewGroup.MarginLayoutParams mlpDetails = + (ViewGroup.MarginLayoutParams) cheatDetails.getLayoutParams(); + keyboardInsets = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom; + barInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom; + mlpDetails.bottomMargin = Math.max(keyboardInsets, barInsets); + cheatDetails.setLayoutParams(mlpDetails); + return insets; + } + }); + } } private static void insetAppBar(Insets insets, AppBarLayout appBarLayout) |
