可选择关闭预见式返回动画 #183
This commit is contained in:
@@ -12,6 +12,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.window.OnBackInvokedDispatcher
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.graphics.drawable.toDrawable
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
@@ -81,6 +82,19 @@ abstract class BaseActivity<VB : ViewBinding>(
|
|||||||
initTheme()
|
initTheme()
|
||||||
window.decorView.disableAutoFill()
|
window.decorView.disableAutoFill()
|
||||||
AppContextWrapper.applyLocaleAndFont(this)
|
AppContextWrapper.applyLocaleAndFont(this)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
val enable = !AppConfig.isPredictiveBackEnabled
|
||||||
|
if (enable) {
|
||||||
|
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||||
|
OnBackInvokedDispatcher.PRIORITY_DEFAULT
|
||||||
|
) {
|
||||||
|
onBackPressedDispatcher.onBackPressed()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//不注册才是启用
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q)
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q)
|
||||||
|
|||||||
@@ -209,4 +209,5 @@ object PreferKey {
|
|||||||
const val colorImage = "colorImage"
|
const val colorImage = "colorImage"
|
||||||
const val bookshelfRefreshingLimit = "bookshelfRefreshingLimit"
|
const val bookshelfRefreshingLimit = "bookshelfRefreshingLimit"
|
||||||
const val systemMediaControlCompatibilityChange = "systemMediaControlCompatibilityChange"
|
const val systemMediaControlCompatibilityChange = "systemMediaControlCompatibilityChange"
|
||||||
|
const val isPredictiveBackEnabled = "isPredictiveBackEnabled"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -846,5 +846,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
|||||||
set(value) {
|
set(value) {
|
||||||
appCtx.putPrefBoolean(PreferKey.systemMediaControlCompatibilityChange, value)
|
appCtx.putPrefBoolean(PreferKey.systemMediaControlCompatibilityChange, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isPredictiveBackEnabled: Boolean
|
||||||
|
get() = appCtx.getPrefBoolean(PreferKey.isPredictiveBackEnabled, true)
|
||||||
|
set(value) {
|
||||||
|
appCtx.putPrefBoolean(PreferKey.isPredictiveBackEnabled, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,6 +185,10 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
|
|||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PreferKey.isPredictiveBackEnabled -> {
|
||||||
|
toastOnUi("重启以应用")
|
||||||
|
}
|
||||||
|
|
||||||
PreferKey.cPrimary -> {
|
PreferKey.cPrimary -> {
|
||||||
val color = getPrefInt(key, ThemeStore.primaryColor(requireContext()))
|
val color = getPrefInt(key, ThemeStore.primaryColor(requireContext()))
|
||||||
ThemeStore.editTheme(requireContext())
|
ThemeStore.editTheme(requireContext())
|
||||||
|
|||||||
@@ -138,6 +138,13 @@
|
|||||||
app:entries="@array/default_home_page"
|
app:entries="@array/default_home_page"
|
||||||
app:entryValues="@array/default_home_page_value" />
|
app:entryValues="@array/default_home_page_value" />
|
||||||
|
|
||||||
|
|
||||||
|
<io.legado.app.lib.prefs.SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="isPredictiveBackEnabled"
|
||||||
|
android:summary="仅部分设备可用"
|
||||||
|
android:title="预见性返回手势" />
|
||||||
|
|
||||||
</io.legado.app.lib.prefs.PreferenceCategory>
|
</io.legado.app.lib.prefs.PreferenceCategory>
|
||||||
|
|
||||||
<io.legado.app.lib.prefs.PreferenceCategory
|
<io.legado.app.lib.prefs.PreferenceCategory
|
||||||
|
|||||||
Reference in New Issue
Block a user