Add an preference to disable the blur effect on Android 12+
This commit is contained in:
parent
18539c5f64
commit
24242c45cd
@ -469,6 +469,9 @@
|
||||
<string name="preference_category_wallpaper">Wallpaper</string>
|
||||
<string name="preference_dim_wallpaper">Dim wallpaper</string>
|
||||
<string name="preference_dim_wallpaper_summary">In dark themes, darken wallpaper</string>
|
||||
<string name="preference_blur_wallpaper">Blur wallpaper</string>
|
||||
<string name="preference_blur_wallpaper_summary">Use a blur effect for the wallpaper</string>
|
||||
<string name="preference_blur_wallpaper_unsupported">Not supported on this device</string>
|
||||
<string name="preference_wallpaper_summary">Choose a wallpaper</string>
|
||||
<string name="preference_screen_badges">Badges</string>
|
||||
<string name="preference_screen_badges_summary">Configure icon badges</string>
|
||||
|
||||
@ -22,7 +22,7 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
|
||||
}
|
||||
)
|
||||
|
||||
internal const val SchemaVersion = 7
|
||||
internal const val SchemaVersion = 8
|
||||
|
||||
internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
|
||||
return listOf(
|
||||
@ -33,5 +33,6 @@ internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
|
||||
Migration_4_5(),
|
||||
Migration_5_6(),
|
||||
Migration_6_7(),
|
||||
Migration_7_8(),
|
||||
)
|
||||
}
|
||||
@ -11,6 +11,7 @@ fun createFactorySettings(context: Context): Settings {
|
||||
.setTheme(Settings.AppearanceSettings.Theme.System)
|
||||
.setColorScheme(Settings.AppearanceSettings.ColorScheme.Default)
|
||||
.setDimWallpaper(false)
|
||||
.setBlurWallpaper(true)
|
||||
.setCustomColors(Settings.AppearanceSettings.CustomColors.newBuilder()
|
||||
.setAdvancedMode(false)
|
||||
.setBaseColors(DefaultCustomColorsBase)
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
package de.mm20.launcher2.preferences.migrations
|
||||
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
|
||||
class Migration_7_8: VersionedMigration(7, 8) {
|
||||
override suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder {
|
||||
return builder.setAppearance(
|
||||
builder.appearance.toBuilder()
|
||||
.setBlurWallpaper(true)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@ -77,6 +77,8 @@ message Settings {
|
||||
SystemDefault = 1;
|
||||
}
|
||||
Font font = 10;
|
||||
|
||||
bool blur_wallpaper = 11;
|
||||
}
|
||||
AppearanceSettings appearance = 2;
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.launcher
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import kotlinx.coroutines.flow.first
|
||||
@ -47,4 +48,6 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
|
||||
isSearchOpen.value = false
|
||||
isWidgetEditMode.value = editMode
|
||||
}
|
||||
|
||||
val wallpaperBlur = dataStore.data.map { it.appearance.blurWallpaper }.asLiveData()
|
||||
}
|
||||
@ -126,11 +126,14 @@ fun PagerScaffold(
|
||||
}
|
||||
}
|
||||
|
||||
val blurEnabled by viewModel.wallpaperBlur.observeAsState(false)
|
||||
|
||||
val blurWallpaper by remember {
|
||||
derivedStateOf {
|
||||
isSearchOpen || swipeableState.progress.to == Page.Widgets && swipeableState.progress.fraction <= 0.5f ||
|
||||
swipeableState.progress.to == Page.Search && swipeableState.progress.fraction > 0.5f ||
|
||||
!isWidgetsScrollZero
|
||||
blurEnabled && (
|
||||
isSearchOpen || swipeableState.progress.to == Page.Widgets && swipeableState.progress.fraction <= 0.5f ||
|
||||
swipeableState.progress.to == Page.Search && swipeableState.progress.fraction > 0.5f ||
|
||||
!isWidgetsScrollZero)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -131,9 +131,11 @@ fun PullDownScaffold(
|
||||
|
||||
val maxSearchBarOffset = with(density) { 128.dp.toPx() }
|
||||
|
||||
val blurEnabled by viewModel.wallpaperBlur.observeAsState(false)
|
||||
|
||||
val blurWallpaper by remember {
|
||||
derivedStateOf {
|
||||
isSearchOpen || offsetY.value > toggleSearchThreshold || widgetsScrollState.value > 0
|
||||
blurEnabled && (isSearchOpen || offsetY.value > toggleSearchThreshold || widgetsScrollState.value > 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package de.mm20.launcher2.ui.settings.appearance
|
||||
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
@ -28,9 +27,9 @@ import com.google.accompanist.pager.ExperimentalPagerApi
|
||||
import com.google.accompanist.pager.HorizontalPager
|
||||
import com.google.accompanist.pager.HorizontalPagerIndicator
|
||||
import com.google.accompanist.pager.rememberPagerState
|
||||
import de.mm20.launcher2.icons.ColorLayer
|
||||
import de.mm20.launcher2.icons.StaticIconLayer
|
||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.preferences.Settings.*
|
||||
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.ColorScheme
|
||||
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme
|
||||
@ -155,6 +154,22 @@ fun AppearanceSettingsScreen() {
|
||||
viewModel.setDimWallpaper(it)
|
||||
}
|
||||
)
|
||||
if (isAtLeastApiLevel(31)) {
|
||||
val isBlurSupported = remember { viewModel.isBlurAvailable(context) }
|
||||
val blurWallpaper by viewModel.blurWallpaper.observeAsState()
|
||||
SwitchPreference(
|
||||
title = stringResource(R.string.preference_blur_wallpaper),
|
||||
summary = stringResource(
|
||||
if (isBlurSupported) R.string.preference_blur_wallpaper_summary
|
||||
else R.string.preference_blur_wallpaper_unsupported
|
||||
),
|
||||
value = blurWallpaper == true && isBlurSupported,
|
||||
onValueChanged = {
|
||||
viewModel.setBlurWallpaper(it)
|
||||
},
|
||||
enabled = isBlurSupported
|
||||
)
|
||||
}
|
||||
}
|
||||
PreferenceCategory(stringResource(R.string.preference_category_icons)) {
|
||||
val iconShape by viewModel.iconShape.observeAsState(IconSettings.IconShape.PlatformDefault)
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
package de.mm20.launcher2.ui.settings.appearance
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.lifecycle.*
|
||||
import de.mm20.launcher2.icons.IconPack
|
||||
import de.mm20.launcher2.icons.IconRepository
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.*
|
||||
@ -85,6 +89,22 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
}
|
||||
}
|
||||
|
||||
fun isBlurAvailable(context: Context): Boolean {
|
||||
if (!isAtLeastApiLevel(31)) return false
|
||||
return context.getSystemService<WindowManager>()?.isCrossWindowBlurEnabled == true
|
||||
}
|
||||
|
||||
val blurWallpaper = dataStore.data.map { it.appearance.blurWallpaper }.asLiveData()
|
||||
fun setBlurWallpaper(blurWallpaper: Boolean) {
|
||||
viewModelScope.launch {
|
||||
dataStore.updateData {
|
||||
it.toBuilder()
|
||||
.setAppearance(it.appearance.toBuilder().setBlurWallpaper(blurWallpaper))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openWallpaperChooser(context: AppCompatActivity) {
|
||||
context.startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user