From adb6eb4952fdbace301db8d41077c821eb79982b Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Wed, 11 Jun 2025 17:27:45 +0300 Subject: [PATCH] Disable emoji view animation according to system setting --- .../keyboard/emoji/EmojiPalettesView.java | 4 ++-- .../keyboard/latin/settings/SettingsValues.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java index 4023be50f..d5a84eb4e 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java @@ -71,7 +71,7 @@ public final class EmojiPalettesView extends LinearLayout private final class PagerAdapter extends RecyclerView.Adapter { private boolean mInitialized; - private Map mViews = new HashMap<>(mEmojiCategory.getShownCategories().size()); + private final Map mViews = new HashMap<>(mEmojiCategory.getShownCategories().size()); private PagerAdapter(ViewPager2 pager) { setHasStableIds(true); @@ -403,7 +403,7 @@ public final class EmojiPalettesView extends LinearLayout if (mPager.getScrollState() != ViewPager2.SCROLL_STATE_DRAGGING) { // Not swiping mPager.setCurrentItem(mEmojiCategory.getTabIdFromCategoryId( - mEmojiCategory.getCurrentCategoryId()), ! initial); + mEmojiCategory.getCurrentCategoryId()), ! initial && ! Settings.getValues().mAnimationDisabled); } if (Settings.getValues().mSecondaryStripVisible) { diff --git a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java index 689a63700..ae6ee8b2e 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java @@ -49,6 +49,10 @@ public class SettingsValues { public final Locale mLocale; public final boolean mHasHardwareKeyboard; public final int mDisplayOrientation; + + // From system + public final boolean mAnimationDisabled; + // From preferences public final boolean mAutoCap; public final boolean mVibrateOn; @@ -159,6 +163,8 @@ public class SettingsValues { mDisplayOrientation = res.getConfiguration().orientation; final InputMethodSubtype selectedSubtype = SubtypeSettings.INSTANCE.getSelectedSubtype(prefs); + mAnimationDisabled = isAnimationDisabled(context); + // Store the input attributes mInputAttributes = inputAttributes; @@ -424,4 +430,14 @@ public class SettingsValues { sb.append("\n mAppWorkarounds = "); return sb.toString(); } + + private static boolean isAnimationDisabled(Context context) { + return isZeroSetting(android.provider.Settings.Global.ANIMATOR_DURATION_SCALE, context) + && isZeroSetting(android.provider.Settings.Global.TRANSITION_ANIMATION_SCALE, context) + && isZeroSetting(android.provider.Settings.Global.WINDOW_ANIMATION_SCALE, context); + } + + private static boolean isZeroSetting(String name, Context context) { + return android.provider.Settings.Global.getFloat(context.getContentResolver(), name, 1.0f) == 0.0f; + } }