Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove animations when it's disabled in system settings #222

Merged
merged 5 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.NavDirections;
import androidx.navigation.NavOptions;
import androidx.navigation.fragment.NavHostFragment;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import org.lsposed.manager.App;
import org.lsposed.manager.R;
import org.lsposed.manager.util.AccessibilityUtils;

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

public boolean safeNavigate(@IdRes int resId) {
try {
getNavController().navigate(resId);
if (!AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver())) {
var clearedNavOptions = new NavOptions.Builder().build();
getNavController().navigate(resId, clearedNavOptions);
} else {
getNavController().navigate(resId);
}
return true;
} catch (IllegalArgumentException ignored) {
return false;
Expand All @@ -62,7 +69,12 @@ public boolean safeNavigate(@IdRes int resId) {

public boolean safeNavigate(NavDirections direction) {
try {
getNavController().navigate(direction);
if (!AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver())) {
var clearedNavOptions = new NavOptions.Builder().build();
getNavController().navigate(direction, clearedNavOptions);
} else {
getNavController().navigate(direction);
}
return true;
} catch (IllegalArgumentException ignored) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.lsposed.manager.databinding.SwiperefreshRecyclerviewBinding;
import org.lsposed.manager.receivers.LSPManagerServiceHolder;
import org.lsposed.manager.ui.widget.EmptyStateRecyclerView;
import org.lsposed.manager.util.AccessibilityUtils;

import java.io.BufferedReader;
import java.io.FileInputStream;
Expand Down Expand Up @@ -109,7 +110,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
binding.toolbar.setSubtitle(ConfigManager.isVerboseLogEnabled() ? R.string.enabled_verbose_log : R.string.disabled_verbose_log);
adapter = new LogPageAdapter(this);
binding.viewPager.setAdapter(adapter);
new TabLayoutMediator(binding.tabLayout, binding.viewPager, (tab, position) -> tab.setText((int) adapter.getItemId(position))).attach();

var isAnimationEnabled = AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver());
new TabLayoutMediator(
binding.tabLayout,
binding.viewPager,
// `autoRefresh = true` by default. Update the tabs automatically when the data set of the view pager's
// adapter changes.
true,
isAnimationEnabled,
(tab, position) -> tab.setText((int) adapter.getItemId(position))
).attach();

binding.tabLayout.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
ViewGroup vg = (ViewGroup) binding.tabLayout.getChildAt(0);
Expand Down Expand Up @@ -359,6 +370,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
horizontalScrollView.setFillViewport(true);
horizontalScrollView.setHorizontalScrollBarEnabled(false);
horizontalScrollView.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
if (!AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver())) {
horizontalScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
binding.swipeRefreshLayout.addView(horizontalScrollView);
horizontalScrollView.addView(binding.recyclerView);
binding.recyclerView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.lsposed.manager.ui.dialog.BlurBehindDialogBuilder;
import org.lsposed.manager.ui.widget.EmptyStateRecyclerView;
import org.lsposed.manager.ui.widget.LinkifyTextView;
import org.lsposed.manager.util.AccessibilityUtils;
import org.lsposed.manager.util.NavUtil;
import org.lsposed.manager.util.SimpleStatefulAdaptor;
import org.lsposed.manager.util.chrome.CustomTabsURLSpan;
Expand Down Expand Up @@ -122,7 +123,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
binding.toolbar.setSubtitle(modulePackageName);
binding.viewPager.setAdapter(new PagerAdapter(this));
int[] titles = new int[]{R.string.module_readme, R.string.module_releases, R.string.module_information};
new TabLayoutMediator(binding.tabLayout, binding.viewPager, (tab, position) -> tab.setText(titles[position])).attach();

var isAnimationEnabled = AccessibilityUtils.isAnimationEnabled(requireContext().getContentResolver());
new TabLayoutMediator(
binding.tabLayout,
binding.viewPager,
// `autoRefresh = true` by default. Update the tabs automatically when the data set of the view pager's
// adapter changes.
true,
isAnimationEnabled,
(tab, position) -> tab.setText(titles[position])
).attach();

binding.tabLayout.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
ViewGroup vg = (ViewGroup) binding.tabLayout.getChildAt(0);
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/lsposed/manager/util/AccessibilityUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.lsposed.manager.util;

import android.content.ContentResolver;
import android.provider.Settings;

public class AccessibilityUtils {
public static boolean isAnimationEnabled(ContentResolver cr) {
return !(Settings.Global.getFloat(cr, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f) == 0.0f
&& Settings.Global.getFloat(cr, Settings.Global.TRANSITION_ANIMATION_SCALE, 1.0f) == 0.0f
&& Settings.Global.getFloat(cr, Settings.Global.WINDOW_ANIMATION_SCALE, 1.0f) == 0.0f);
}
}