Skip to content

Commit 90d3712

Browse files
Follow system settings of animation scales (#222)
1. Remove animations brought by `smoothScroll` of [TabLayoutMediator](https://developer.android.com/reference/com/google/android/material/tabs/TabLayoutMediator#TabLayoutMediator(com.google.android.material.tabs.TabLayout,%20androidx.viewpager2.widget.ViewPager2,%20boolean,%20boolean,%20com.google.android.material.tabs.TabLayoutMediator.TabConfigurationStrategy)). 2. Use default NavOptions constructor to clear previously defined animations. To navigate without animations, the value for arguments of type @AnimatorRes should be -1. Co-authored-by: JingMatrix <jingmatrix@gmail.com>
1 parent b384321 commit 90d3712

4 files changed

Lines changed: 53 additions & 4 deletions

File tree

app/src/main/java/org/lsposed/manager/ui/fragment/BaseFragment.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
import androidx.fragment.app.Fragment;
3030
import androidx.navigation.NavController;
3131
import androidx.navigation.NavDirections;
32+
import androidx.navigation.NavOptions;
3233
import androidx.navigation.fragment.NavHostFragment;
3334

3435
import com.google.android.material.floatingactionbutton.FloatingActionButton;
3536
import com.google.android.material.snackbar.Snackbar;
3637

3738
import org.lsposed.manager.App;
3839
import org.lsposed.manager.R;
40+
import org.lsposed.manager.util.AccessibilityUtils;
3941

4042
import java.util.concurrent.Callable;
4143
import java.util.concurrent.Future;
@@ -53,7 +55,12 @@ public NavController getNavController() {
5355

5456
public boolean safeNavigate(@IdRes int resId) {
5557
try {
56-
getNavController().navigate(resId);
58+
if (!AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver())) {
59+
var clearedNavOptions = new NavOptions.Builder().build();
60+
getNavController().navigate(resId, clearedNavOptions);
61+
} else {
62+
getNavController().navigate(resId);
63+
}
5764
return true;
5865
} catch (IllegalArgumentException ignored) {
5966
return false;
@@ -62,7 +69,12 @@ public boolean safeNavigate(@IdRes int resId) {
6269

6370
public boolean safeNavigate(NavDirections direction) {
6471
try {
65-
getNavController().navigate(direction);
72+
if (!AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver())) {
73+
var clearedNavOptions = new NavOptions.Builder().build();
74+
getNavController().navigate(direction, clearedNavOptions);
75+
} else {
76+
getNavController().navigate(direction);
77+
}
6678
return true;
6779
} catch (IllegalArgumentException ignored) {
6880
return false;

app/src/main/java/org/lsposed/manager/ui/fragment/LogsFragment.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.lsposed.manager.databinding.SwiperefreshRecyclerviewBinding;
5454
import org.lsposed.manager.receivers.LSPManagerServiceHolder;
5555
import org.lsposed.manager.ui.widget.EmptyStateRecyclerView;
56+
import org.lsposed.manager.util.AccessibilityUtils;
5657

5758
import java.io.BufferedReader;
5859
import java.io.FileInputStream;
@@ -109,7 +110,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
109110
binding.toolbar.setSubtitle(ConfigManager.isVerboseLogEnabled() ? R.string.enabled_verbose_log : R.string.disabled_verbose_log);
110111
adapter = new LogPageAdapter(this);
111112
binding.viewPager.setAdapter(adapter);
112-
new TabLayoutMediator(binding.tabLayout, binding.viewPager, (tab, position) -> tab.setText((int) adapter.getItemId(position))).attach();
113+
114+
var isAnimationEnabled = AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver());
115+
new TabLayoutMediator(
116+
binding.tabLayout,
117+
binding.viewPager,
118+
// `autoRefresh = true` by default. Update the tabs automatically when the data set of the view pager's
119+
// adapter changes.
120+
true,
121+
isAnimationEnabled,
122+
(tab, position) -> tab.setText((int) adapter.getItemId(position))
123+
).attach();
113124

114125
binding.tabLayout.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
115126
ViewGroup vg = (ViewGroup) binding.tabLayout.getChildAt(0);
@@ -359,6 +370,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
359370
horizontalScrollView.setFillViewport(true);
360371
horizontalScrollView.setHorizontalScrollBarEnabled(false);
361372
horizontalScrollView.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
373+
if (!AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver())) {
374+
horizontalScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
375+
}
362376
binding.swipeRefreshLayout.addView(horizontalScrollView);
363377
horizontalScrollView.addView(binding.recyclerView);
364378
binding.recyclerView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;

app/src/main/java/org/lsposed/manager/ui/fragment/RepoItemFragment.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import org.lsposed.manager.ui.dialog.BlurBehindDialogBuilder;
8080
import org.lsposed.manager.ui.widget.EmptyStateRecyclerView;
8181
import org.lsposed.manager.ui.widget.LinkifyTextView;
82+
import org.lsposed.manager.util.AccessibilityUtils;
8283
import org.lsposed.manager.util.NavUtil;
8384
import org.lsposed.manager.util.SimpleStatefulAdaptor;
8485
import org.lsposed.manager.util.chrome.CustomTabsURLSpan;
@@ -122,7 +123,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
122123
binding.toolbar.setSubtitle(modulePackageName);
123124
binding.viewPager.setAdapter(new PagerAdapter(this));
124125
int[] titles = new int[]{R.string.module_readme, R.string.module_releases, R.string.module_information};
125-
new TabLayoutMediator(binding.tabLayout, binding.viewPager, (tab, position) -> tab.setText(titles[position])).attach();
126+
127+
var isAnimationEnabled = AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver());
128+
new TabLayoutMediator(
129+
binding.tabLayout,
130+
binding.viewPager,
131+
// `autoRefresh = true` by default. Update the tabs automatically when the data set of the view pager's
132+
// adapter changes.
133+
true,
134+
isAnimationEnabled,
135+
(tab, position) -> tab.setText(titles[position])
136+
).attach();
126137

127138
binding.tabLayout.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
128139
ViewGroup vg = (ViewGroup) binding.tabLayout.getChildAt(0);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.lsposed.manager.util;
2+
3+
import android.content.ContentResolver;
4+
import android.provider.Settings;
5+
6+
public class AccessibilityUtils {
7+
public static boolean isAnimationEnabled(ContentResolver cr) {
8+
return !(Settings.Global.getFloat(cr, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f) == 0.0f
9+
&& Settings.Global.getFloat(cr, Settings.Global.TRANSITION_ANIMATION_SCALE, 1.0f) == 0.0f
10+
&& Settings.Global.getFloat(cr, Settings.Global.WINDOW_ANIMATION_SCALE, 1.0f) == 0.0f);
11+
}
12+
}

0 commit comments

Comments
 (0)