Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11267 from t895/smooth-keyboard
Android: Use smooth keyboard animation in cheats activity
  • Loading branch information
JosJuice committed Nov 16, 2022
2 parents cecd4d1 + 8bfa08f commit 9766238
Showing 1 changed file with 47 additions and 3 deletions.
Expand Up @@ -7,9 +7,11 @@
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;
Expand All @@ -22,6 +24,8 @@

import org.dolphinemu.dolphinemu.R;

import java.util.List;

public class InsetsHelper
{
public static final int FAB_INSET = 16;
Expand Down Expand Up @@ -128,14 +132,28 @@ public static void setUpCheatsLayout(AppCompatActivity activity, AppBarLayout ap

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

Expand All @@ -144,6 +162,32 @@ public static void setUpCheatsLayout(AppCompatActivity activity, AppBarLayout ap

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)
Expand Down

0 comments on commit 9766238

Please sign in to comment.