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>
This commit is contained in:
parent
b384321cb2
commit
90d3712c6e
|
|
@ -29,6 +29,7 @@ import androidx.core.view.MenuProvider;
|
|||
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;
|
||||
|
|
@ -36,6 +37,7 @@ 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;
|
||||
|
|
@ -53,7 +55,12 @@ public abstract class BaseFragment extends Fragment {
|
|||
|
||||
public boolean safeNavigate(@IdRes int resId) {
|
||||
try {
|
||||
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;
|
||||
|
|
@ -62,7 +69,12 @@ public abstract class BaseFragment extends Fragment {
|
|||
|
||||
public boolean safeNavigate(NavDirections direction) {
|
||||
try {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ import org.lsposed.manager.databinding.ItemLogTextviewBinding;
|
|||
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;
|
||||
|
|
@ -109,7 +110,17 @@ public class LogsFragment extends BaseFragment implements MenuProvider {
|
|||
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);
|
||||
|
|
@ -359,6 +370,9 @@ public class LogsFragment extends BaseFragment implements MenuProvider {
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ import org.lsposed.manager.repo.model.ReleaseAsset;
|
|||
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;
|
||||
|
|
@ -122,7 +123,17 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue