Add an preference to disable the blur effect on Android 12+

This commit is contained in:
MM20 2022-07-11 18:11:25 +02:00
parent 18539c5f64
commit 24242c45cd
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
10 changed files with 70 additions and 7 deletions

View File

@ -469,6 +469,9 @@
<string name="preference_category_wallpaper">Wallpaper</string> <string name="preference_category_wallpaper">Wallpaper</string>
<string name="preference_dim_wallpaper">Dim 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_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_wallpaper_summary">Choose a wallpaper</string>
<string name="preference_screen_badges">Badges</string> <string name="preference_screen_badges">Badges</string>
<string name="preference_screen_badges_summary">Configure icon badges</string> <string name="preference_screen_badges_summary">Configure icon badges</string>

View File

@ -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>> { internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
return listOf( return listOf(
@ -33,5 +33,6 @@ internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
Migration_4_5(), Migration_4_5(),
Migration_5_6(), Migration_5_6(),
Migration_6_7(), Migration_6_7(),
Migration_7_8(),
) )
} }

View File

@ -11,6 +11,7 @@ fun createFactorySettings(context: Context): Settings {
.setTheme(Settings.AppearanceSettings.Theme.System) .setTheme(Settings.AppearanceSettings.Theme.System)
.setColorScheme(Settings.AppearanceSettings.ColorScheme.Default) .setColorScheme(Settings.AppearanceSettings.ColorScheme.Default)
.setDimWallpaper(false) .setDimWallpaper(false)
.setBlurWallpaper(true)
.setCustomColors(Settings.AppearanceSettings.CustomColors.newBuilder() .setCustomColors(Settings.AppearanceSettings.CustomColors.newBuilder()
.setAdvancedMode(false) .setAdvancedMode(false)
.setBaseColors(DefaultCustomColorsBase) .setBaseColors(DefaultCustomColorsBase)

View File

@ -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)
)
}
}

View File

@ -77,6 +77,8 @@ message Settings {
SystemDefault = 1; SystemDefault = 1;
} }
Font font = 10; Font font = 10;
bool blur_wallpaper = 11;
} }
AppearanceSettings appearance = 2; AppearanceSettings appearance = 2;

View File

@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.launcher
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import de.mm20.launcher2.preferences.LauncherDataStore import de.mm20.launcher2.preferences.LauncherDataStore
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
@ -47,4 +48,6 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
isSearchOpen.value = false isSearchOpen.value = false
isWidgetEditMode.value = editMode isWidgetEditMode.value = editMode
} }
val wallpaperBlur = dataStore.data.map { it.appearance.blurWallpaper }.asLiveData()
} }

View File

@ -126,11 +126,14 @@ fun PagerScaffold(
} }
} }
val blurEnabled by viewModel.wallpaperBlur.observeAsState(false)
val blurWallpaper by remember { val blurWallpaper by remember {
derivedStateOf { derivedStateOf {
blurEnabled && (
isSearchOpen || swipeableState.progress.to == Page.Widgets && swipeableState.progress.fraction <= 0.5f || isSearchOpen || swipeableState.progress.to == Page.Widgets && swipeableState.progress.fraction <= 0.5f ||
swipeableState.progress.to == Page.Search && swipeableState.progress.fraction > 0.5f || swipeableState.progress.to == Page.Search && swipeableState.progress.fraction > 0.5f ||
!isWidgetsScrollZero !isWidgetsScrollZero)
} }
} }

View File

@ -131,9 +131,11 @@ fun PullDownScaffold(
val maxSearchBarOffset = with(density) { 128.dp.toPx() } val maxSearchBarOffset = with(density) { 128.dp.toPx() }
val blurEnabled by viewModel.wallpaperBlur.observeAsState(false)
val blurWallpaper by remember { val blurWallpaper by remember {
derivedStateOf { derivedStateOf {
isSearchOpen || offsetY.value > toggleSearchThreshold || widgetsScrollState.value > 0 blurEnabled && (isSearchOpen || offsetY.value > toggleSearchThreshold || widgetsScrollState.value > 0)
} }
} }

View File

@ -2,7 +2,6 @@ package de.mm20.launcher2.ui.settings.appearance
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells 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.HorizontalPager
import com.google.accompanist.pager.HorizontalPagerIndicator import com.google.accompanist.pager.HorizontalPagerIndicator
import com.google.accompanist.pager.rememberPagerState import com.google.accompanist.pager.rememberPagerState
import de.mm20.launcher2.icons.ColorLayer
import de.mm20.launcher2.icons.StaticIconLayer import de.mm20.launcher2.icons.StaticIconLayer
import de.mm20.launcher2.icons.StaticLauncherIcon import de.mm20.launcher2.icons.StaticLauncherIcon
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.preferences.Settings.* import de.mm20.launcher2.preferences.Settings.*
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.ColorScheme import de.mm20.launcher2.preferences.Settings.AppearanceSettings.ColorScheme
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme
@ -155,6 +154,22 @@ fun AppearanceSettingsScreen() {
viewModel.setDimWallpaper(it) 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)) { PreferenceCategory(stringResource(R.string.preference_category_icons)) {
val iconShape by viewModel.iconShape.observeAsState(IconSettings.IconShape.PlatformDefault) val iconShape by viewModel.iconShape.observeAsState(IconSettings.IconShape.PlatformDefault)

View File

@ -1,10 +1,14 @@
package de.mm20.launcher2.ui.settings.appearance package de.mm20.launcher2.ui.settings.appearance
import android.content.Context
import android.content.Intent import android.content.Intent
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import androidx.lifecycle.* import androidx.lifecycle.*
import de.mm20.launcher2.icons.IconPack import de.mm20.launcher2.icons.IconPack
import de.mm20.launcher2.icons.IconRepository import de.mm20.launcher2.icons.IconRepository
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.preferences.LauncherDataStore import de.mm20.launcher2.preferences.LauncherDataStore
import de.mm20.launcher2.preferences.Settings import de.mm20.launcher2.preferences.Settings
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.* 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) { fun openWallpaperChooser(context: AppCompatActivity) {
context.startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null)) context.startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null))
} }