Respect animation setting for ViewPager2 scrolling

This commit is contained in:
kitsunyan
2020-07-06 15:22:10 +03:00
parent 6866a04932
commit 2c4f693d64
2 changed files with 11 additions and 1 deletions
@@ -206,7 +206,7 @@ class TabsFragment: ScreenFragment() {
tab.background = tab.context.getDrawableFromAttr(android.R.attr.selectableItemBackground) tab.background = tab.context.getDrawableFromAttr(android.R.attr.selectableItemBackground)
tab.setOnClickListener { _ -> tab.setOnClickListener { _ ->
setSelectedTab(it) setSelectedTab(it)
viewPager!!.currentItem = it.ordinal viewPager!!.setCurrentItem(it.ordinal, Utils.areAnimationsEnabled(tab.context))
} }
layout.tabs.addView(tab, 0, LinearLayout.LayoutParams.MATCH_PARENT) layout.tabs.addView(tab, 0, LinearLayout.LayoutParams.MATCH_PARENT)
(tab.layoutParams as LinearLayout.LayoutParams).weight = 1f (tab.layoutParams as LinearLayout.LayoutParams).weight = 1f
@@ -1,10 +1,12 @@
package nya.kitsunyan.foxydroid.utility package nya.kitsunyan.foxydroid.utility
import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import android.content.pm.Signature import android.content.pm.Signature
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.LocaleList import android.os.LocaleList
import android.provider.Settings
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import nya.kitsunyan.foxydroid.BuildConfig import nya.kitsunyan.foxydroid.BuildConfig
import nya.kitsunyan.foxydroid.R import nya.kitsunyan.foxydroid.R
@@ -88,4 +90,12 @@ object Utils {
} }
return context.createConfigurationContext(newConfiguration) return context.createConfigurationContext(newConfiguration)
} }
fun areAnimationsEnabled(context: Context): Boolean {
return if (Android.sdk(26)) {
ValueAnimator.areAnimatorsEnabled()
} else {
Settings.Global.getFloat(context.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) != 0f
}
}
} }