diff --git a/app/src/main/java/com/anthonyla/paperize/core/SettingsConstants.kt b/app/src/main/java/com/anthonyla/paperize/core/SettingsConstants.kt index 8d6c937..34b3e56 100644 --- a/app/src/main/java/com/anthonyla/paperize/core/SettingsConstants.kt +++ b/app/src/main/java/com/anthonyla/paperize/core/SettingsConstants.kt @@ -39,4 +39,7 @@ object SettingsConstants { const val LOCK_NEXT_SET_TIME = "next_set_time_2" const val NEXT_HOME_WALLPAPER = "next_home_wallpaper" const val NEXT_LOCK_WALLPAPER = "next_lock_wallpaper" + const val GRAYSCALE = "grayscale" + const val HOME_GRAYSCALE_PERCENTAGE = "home_grayscale_percentage" + const val LOCK_GRAYSCALE_PERCENTAGE = "lock_grayscale_percentage" } \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/core/WallpaperUtil.kt b/app/src/main/java/com/anthonyla/paperize/core/WallpaperUtil.kt index 9da4760..8550e6b 100644 --- a/app/src/main/java/com/anthonyla/paperize/core/WallpaperUtil.kt +++ b/app/src/main/java/com/anthonyla/paperize/core/WallpaperUtil.kt @@ -306,6 +306,42 @@ fun vignetteBitmap(source: Bitmap, percent: Int): Bitmap { } } +/** + * Apply a grey filter to the bitmap based on a percentage + */ +fun grayBitmap(bitmap: Bitmap, percent: Int): Bitmap { + val factor = percent / 100f + val colorMatrix = ColorMatrix().apply { + setSaturation(1 - factor) + } + val paint = Paint().apply { + colorFilter = ColorMatrixColorFilter(colorMatrix) + } + val grayBitmap = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888) + val canvas = Canvas(grayBitmap) + canvas.drawBitmap(bitmap, 0f, 0f, paint) + + return grayBitmap +} + +/** + * Calculate the brightness of a bitmap (0-100) + * https://gist.github.com/httnn/b1d772caf76cdc0c11e2 + */ +fun calculateBrightness(bitmap: Bitmap, pixelSpacing: Int = 1): Int { + var brightness = 0.0 + val pixels = IntArray(bitmap.width * bitmap.height) + bitmap.getPixels(pixels, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height) + for (i in pixels.indices step pixelSpacing.coerceAtLeast(1)) { + val color = pixels[i] + val R = Color.red(color) + val G = Color.green(color) + val B = Color.blue(color) + brightness += 0.299*R + 0.587*G + 0.114*B + } + return (brightness / (pixels.size / pixelSpacing)).toInt() +} + /** * Retrieve wallpaper URIs from a folder directory URI */ @@ -313,7 +349,7 @@ fun getWallpaperFromFolder(folderUri: String, context: Context): List { return try { val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri()) listFilesRecursive(folderDocumentFile, context) - } catch (e: Exception) { + } catch (_: Exception) { val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri()) listFilesRecursive(folderDocumentFile, context) } @@ -364,7 +400,7 @@ fun findFirstValidUri(context: Context, wallpapers: List, folders: Li if (file?.exists() == true) { return wallpaper.wallpaperUri } - } catch (e: Exception) { + } catch (_: Exception) { val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri()) if (file?.exists() == true) { return wallpaper.wallpaperUri @@ -378,7 +414,7 @@ fun findFirstValidUri(context: Context, wallpapers: List, folders: Li if (file?.exists() == true) { return wallpaper } - } catch (e: Exception) { + } catch (_: Exception) { val file = DocumentFile.fromSingleUri(context, wallpaper.toUri()) if (file?.exists() == true) { return wallpaper @@ -395,7 +431,7 @@ fun findFirstValidUri(context: Context, wallpapers: List, folders: Li fun getFolderNameFromUri(folderUri: String, context: Context): String? { return try { DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name - } catch (e: Exception) { + } catch (_: Exception) { DocumentFile.fromTreeUri(context, folderUri.toUri())?.name } } @@ -411,25 +447,7 @@ fun isValidUri(context: Context, uriString: String?): Boolean { inputStream?.close() } true - } catch (e: Exception) { false } -} - -/** - * Calculate the brightness of a bitmap (0-100) - * https://gist.github.com/httnn/b1d772caf76cdc0c11e2 - */ -fun calculateBrightness(bitmap: Bitmap, pixelSpacing: Int = 1): Int { - var brightness = 0.0 - val pixels = IntArray(bitmap.width * bitmap.height) - bitmap.getPixels(pixels, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height) - for (i in pixels.indices step pixelSpacing.coerceAtLeast(1)) { - val color = pixels[i] - val R = Color.red(color) - val G = Color.green(color) - val B = Color.blue(color) - brightness += 0.299*R + 0.587*G + 0.114*B - } - return (brightness / (pixels.size / pixelSpacing)).toInt() + } catch (_: Exception) { false } } /** @@ -446,7 +464,9 @@ fun processBitmap( blur: Boolean, blurPercent: Int, vignette: Boolean, - vignettePercent: Int + vignettePercent: Int, + grayscale: Boolean, + grayscalePercent: Int ): Bitmap? { try { var processedBitmap = source @@ -474,6 +494,11 @@ fun processBitmap( processedBitmap = vignetteBitmap(processedBitmap, vignettePercent) } + // Apply gray effect + if (grayscale && grayscalePercent > 0) { + processedBitmap = grayBitmap(processedBitmap, grayscalePercent) + } + return processedBitmap } catch (e: Exception) { Log.e("PaperizeWallpaperChanger", "Error darkening bitmap", e) diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt index e8e0f1d..4d4c382 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt @@ -227,6 +227,9 @@ fun PaperizeApp( vignette = settingsState.value.vignette, homeVignettePercentage = settingsState.value.homeVignettePercentage, lockVignettePercentage = settingsState.value.lockVignettePercentage, + grayscale = settingsState.value.grayscale, + homeGrayscalePercentage = settingsState.value.homeGrayscalePercentage, + lockGrayscalePercentage = settingsState.value.lockGrayscalePercentage, onSettingsClick = { navController.navigate(Settings) }, navigateToAddWallpaperScreen = { navController.navigate(AddEdit(it)) @@ -708,6 +711,26 @@ fun PaperizeApp( } } }, + onGrayscaleChange = { + settingsViewModel.onEvent(SettingsEvent.SetGrayscale(it)) + if (settingsState.value.enableChanger) { + job?.cancel() + job = scope.launch { + delay(1000) + scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + } + } + }, + onGrayscalePercentageChange = { home, lock -> + settingsViewModel.onEvent(SettingsEvent.SetGrayscalePercentage(home, lock)) + if (settingsState.value.enableChanger && settingsState.value.grayscale) { + job?.cancel() + job = scope.launch { + delay(3000) + scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + } + } + }, ) } // Navigate to the add album screen to create a new album and add wallpapers to it diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt index fea87a6..e5a3847 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt @@ -74,7 +74,12 @@ fun HomeScreen( lockVignettePercentage: Int, onVignettePercentageChange: (Int, Int) -> Unit, onVignetteChange: (Boolean) -> Unit, - vignette: Boolean + vignette: Boolean, + homeGrayscalePercentage: Int, + lockGrayscalePercentage: Int, + onGrayscalePercentageChange: (Int, Int) -> Unit, + onGrayscaleChange: (Boolean) -> Unit, + grayscale: Boolean ) { val tabItems = getTabItems() val pagerState = rememberPagerState(0) { tabItems.size } @@ -178,7 +183,12 @@ fun HomeScreen( lockVignettePercentage = lockVignettePercentage, onVignettePercentageChange = onVignettePercentageChange, onVignetteChange = onVignetteChange, - vignette = vignette + vignette = vignette, + homeGrayscalePercentage = homeGrayscalePercentage, + lockGrayscalePercentage = lockGrayscalePercentage, + onGrayscalePercentageChange = onGrayscalePercentageChange, + onGrayscaleChange = onGrayscaleChange, + grayscale = grayscale ) else -> LibraryScreen( albums = albums, diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsEvent.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsEvent.kt index 256709e..0d77c30 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsEvent.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsEvent.kt @@ -15,6 +15,7 @@ sealed class SettingsEvent { data class SetDarken(val darken: Boolean): SettingsEvent() data class SetBlur(val blur: Boolean): SettingsEvent() data class SetVignette(val vignette: Boolean): SettingsEvent() + data class SetGrayscale(val grayscale: Boolean): SettingsEvent() data class SetLock(val lock: Boolean): SettingsEvent() data class SetHome(val home: Boolean): SettingsEvent() data class SetCurrentHomeWallpaper(val currentHomeWallpaper: String?): SettingsEvent() @@ -29,6 +30,7 @@ sealed class SettingsEvent { data class SetDarkenPercentage(val homeDarkenPercentage: Int?, val lockDarkenPercentage: Int?): SettingsEvent() data class SetBlurPercentage(val homeBlurPercentage: Int?, val lockBlurPercentage: Int?): SettingsEvent() data class SetVignettePercentage(val homeVignettePercentage: Int?, val lockVignettePercentage: Int?): SettingsEvent() + data class SetGrayscalePercentage(val homeGrayscalePercentage: Int?, val lockGrayscalePercentage: Int?): SettingsEvent() data class SetChangerToggle(val toggle: Boolean): SettingsEvent() data class SetWallpaperScaling(val scaling: ScalingConstants): SettingsEvent() data class SetNextHomeWallpaper(val nextHomeWallpaper: String?): SettingsEvent() diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt index cd51c01..e1190cf 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt @@ -31,6 +31,9 @@ data class SettingsState( val vignette: Boolean = false, val homeVignettePercentage: Int = 0, val lockVignettePercentage: Int = 0, + val grayscale: Boolean = false, + val homeGrayscalePercentage: Int = 0, + val lockGrayscalePercentage: Int = 0, val wallpaperScaling: ScalingConstants = ScalingConstants.FILL, val nextHomeWallpaper: String? = null, val nextLockWallpaper: String? = null diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt index 4c58b8e..2907789 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt @@ -61,6 +61,9 @@ class SettingsViewModel @Inject constructor ( val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false } val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 } val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 } + val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false } + val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 } + val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 } val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) } val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) } @@ -94,7 +97,10 @@ class SettingsViewModel @Inject constructor ( nextLockWallpaper = nextLockWallpaper.await(), vignette = vignette.await(), homeVignettePercentage = homeVignettePercentage.await(), - lockVignettePercentage = lockVignettePercentage.await() + lockVignettePercentage = lockVignettePercentage.await(), + grayscale = grayscale.await(), + homeGrayscalePercentage = homeGrayscalePercentage.await(), + lockGrayscalePercentage = lockGrayscalePercentage.await() ) } setKeepOnScreenCondition = false @@ -156,6 +162,9 @@ class SettingsViewModel @Inject constructor ( val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false } val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 } val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 } + val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false } + val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 } + val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 } _state.update { it.copy( @@ -186,7 +195,10 @@ class SettingsViewModel @Inject constructor ( nextLockWallpaper = nextLockWallpaper.await(), vignette = vignette.await(), homeVignettePercentage = homeVignettePercentage.await(), - lockVignettePercentage = lockVignettePercentage.await() + lockVignettePercentage = lockVignettePercentage.await(), + grayscale = grayscale.await(), + homeGrayscalePercentage = homeGrayscalePercentage.await(), + lockGrayscalePercentage = lockGrayscalePercentage.await() ) } } @@ -467,6 +479,34 @@ class SettingsViewModel @Inject constructor ( } } + is SettingsEvent.SetGrayscale -> { + viewModelScope.launch(Dispatchers.IO) { + settingsDataStoreImpl.putBoolean(SettingsConstants.GRAYSCALE, event.grayscale) + _state.update { + it.copy( + grayscale = event.grayscale + ) + } + } + } + + is SettingsEvent.SetGrayscalePercentage -> { + viewModelScope.launch(Dispatchers.IO) { + if (event.lockGrayscalePercentage != null) { + settingsDataStoreImpl.putInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE, event.lockGrayscalePercentage) + } + if (event.homeGrayscalePercentage != null) { + settingsDataStoreImpl.putInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE, event.homeGrayscalePercentage) + } + _state.update { + it.copy( + homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.homeGrayscalePercentage, + lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.lockGrayscalePercentage + ) + } + } + } + is SettingsEvent.SetCurrentHomeWallpaper -> { viewModelScope.launch(Dispatchers.IO) { if (event.currentHomeWallpaper != null) { @@ -703,6 +743,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.deleteBoolean(SettingsConstants.VIGNETTE) settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) + settingsDataStoreImpl.deleteBoolean(SettingsConstants.GRAYSCALE) + settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) + settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) _state.update { it.copy( @@ -734,7 +777,10 @@ class SettingsViewModel @Inject constructor ( nextLockWallpaper = null, vignette = false, homeVignettePercentage = 0, - lockVignettePercentage = 0 + lockVignettePercentage = 0, + grayscale = false, + homeGrayscalePercentage = 0, + lockGrayscalePercentage = 0 ) } } diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt index 52a53af..9cce2db 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt @@ -38,6 +38,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.co import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.DarkenSwitchAndSlider +import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.GrayscaleSwitchAndSlider import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.IndividualSchedulingAndToggleRow import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.TimeSliders import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.VignetteSwitchAndSlider @@ -85,7 +86,12 @@ fun WallpaperScreen( lockVignettePercentage: Int, onVignettePercentageChange: (Int, Int) -> Unit, onVignetteChange: (Boolean) -> Unit, - vignette: Boolean + vignette: Boolean, + homeGrayscalePercentage: Int, + lockGrayscalePercentage: Int, + onGrayscalePercentageChange: (Int, Int) -> Unit, + onGrayscaleChange: (Boolean) -> Unit, + grayscale: Boolean, ) { val shouldShowScreen = homeEnabled || lockEnabled val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null @@ -208,7 +214,10 @@ fun WallpaperScreen( lockBlurPercentage = lockBlurPercentage, vignette = vignette, homeVignettePercentage = homeVignettePercentage, - lockVignettePercentage = lockVignettePercentage + lockVignettePercentage = lockVignettePercentage, + grayscale = grayscale, + homeGrayscalePercentage = homeGrayscalePercentage, + lockGrayscalePercentage = lockGrayscalePercentage ) CurrentAndNextChange(lastSetTime, nextSetTime) TimeSliders( @@ -256,6 +265,15 @@ fun WallpaperScreen( animate = animate, bothEnabled = homeEnabled && lockEnabled ) + GrayscaleSwitchAndSlider( + onGrayscalePercentageChange = onGrayscalePercentageChange, + onGrayscaleChange = onGrayscaleChange, + grayscale = grayscale, + homeGrayscalePercentage = homeGrayscalePercentage, + lockGrayscalePercentage = lockGrayscalePercentage, + animate = animate, + bothEnabled = homeEnabled && lockEnabled + ) } } } diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/GrayscaleBitmapTransformation.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/GrayscaleBitmapTransformation.kt new file mode 100644 index 0000000..bd69dbf --- /dev/null +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/GrayscaleBitmapTransformation.kt @@ -0,0 +1,39 @@ +package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components + +import android.graphics.Bitmap +import com.anthonyla.paperize.core.grayBitmap +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation +import com.bumptech.glide.util.Util +import java.security.MessageDigest + +/** + * A BitmapTransformation that applies a grayscale effect to a bitmap to be used with Glide + */ +class GrayscaleBitmapTransformation(private val percent: Int): BitmapTransformation() { + + override fun transform( + pool: BitmapPool, + toTransform: Bitmap, + outWidth: Int, + outHeight: Int + ): Bitmap { + return grayBitmap(toTransform, percent) + } + + override fun equals(other: Any?): Boolean { + return other is GrayscaleBitmapTransformation && other.percent == percent + } + + override fun hashCode(): Int { + return Util.hashCode(percent) + } + + override fun updateDiskCacheKey(messageDigest: MessageDigest) { + messageDigest.update((ID + percent).toByteArray(CHARSET)) + } + + companion object { + private const val ID = "com.bumptech.glide.transformations.GrayscaleBitmapTransformation" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/GrayscaleSwitchAndSlider.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/GrayscaleSwitchAndSlider.kt new file mode 100644 index 0000000..47e3cbd --- /dev/null +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/GrayscaleSwitchAndSlider.kt @@ -0,0 +1,229 @@ +package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components + +import android.view.HapticFeedbackConstants +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.animateContentSize +import androidx.compose.animation.core.LinearOutSlowInEasing +import androidx.compose.animation.core.Spring +import androidx.compose.animation.core.spring +import androidx.compose.animation.core.tween +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeOut +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Slider +import androidx.compose.material3.Surface +import androidx.compose.material3.Switch +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import com.anthonyla.paperize.R +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlin.math.roundToInt + +/** + * Composable that displays a switch and slider for the grayscale effect + */ +@Composable +fun GrayscaleSwitchAndSlider( + onGrayscalePercentageChange: (Int, Int) -> Unit, + onGrayscaleChange: (Boolean) -> Unit, + grayscale: Boolean, + bothEnabled: Boolean, + homeGrayscalePercentage: Int, + lockGrayscalePercentage: Int, + animate: Boolean +) { + val view = LocalView.current + val scope = rememberCoroutineScope() + var job by remember { mutableStateOf(null) } + var homePercentage by rememberSaveable { mutableFloatStateOf(homeGrayscalePercentage.toFloat()) } + var lockPercentage by rememberSaveable { mutableFloatStateOf(lockGrayscalePercentage.toFloat()) } + + Surface( + tonalElevation = 10.dp, + shape = RoundedCornerShape(16.dp), + modifier = Modifier + .fillMaxWidth() + .padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp)) + ) { + val columnModifier = if (animate) { + Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing)) + } else { Modifier } + Column ( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + modifier = columnModifier + ) { + Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) { + Text( + text = stringResource(R.string.gray_filter), + modifier = Modifier.padding(16.dp), + fontWeight = FontWeight.W500 + ) + Switch( + checked = grayscale, + onCheckedChange = onGrayscaleChange + ) + } + if (animate) { + AnimatedVisibility( + visible = grayscale, + enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)), + exit = fadeOut( + animationSpec = tween( + durationMillis = 300, + easing = LinearOutSlowInEasing + ) + ) + ) { + Column { + Spacer(modifier = Modifier.height(8.dp)) + if (bothEnabled) { + Text( + text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()), + modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)), + fontWeight = FontWeight.W400 + ) + } + else { + Text( + text = stringResource(R.string.percentage, homePercentage.roundToInt()), + modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)), + fontWeight = FontWeight.W400 + ) + } + Slider( + value = homePercentage, + onValueChange = { + view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK) + homePercentage = it + job?.cancel() + job = scope.launch { + delay(500) + if (bothEnabled) { + onGrayscalePercentageChange(it.roundToInt(), lockPercentage.roundToInt()) + } else { + onGrayscalePercentageChange(it.roundToInt(), it.roundToInt()) + } + } + }, + valueRange = 0f..100f, + steps = 100, + modifier = Modifier.padding(PaddingValues(horizontal = 30.dp)) + ) + if (bothEnabled) { + Text( + text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()), + modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)), + fontWeight = FontWeight.W400 + ) + Spacer(modifier = Modifier.height(16.dp)) + Slider( + value = lockPercentage, + onValueChange = { + view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK) + lockPercentage = it + job?.cancel() + job = scope.launch { + delay(500) + onGrayscalePercentageChange(homePercentage.roundToInt(), it.roundToInt()) + } + }, + valueRange = 0f..100f, + steps = 100, + modifier = Modifier.padding(PaddingValues(horizontal = 30.dp)) + ) + } + Spacer(modifier = Modifier.height(16.dp)) + } + } + } else { + if (grayscale) { + Column { + Spacer(modifier = Modifier.height(8.dp)) + if (bothEnabled) { + Text( + text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()), + modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)), + fontWeight = FontWeight.W400 + ) + } + else { + Text( + text = stringResource(R.string.percentage, homePercentage.roundToInt()), + modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)), + fontWeight = FontWeight.W400 + ) + } + Slider( + value = homePercentage, + onValueChange = { + view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK) + homePercentage = it + job?.cancel() + job = scope.launch { + delay(500) + if (bothEnabled) { + onGrayscalePercentageChange(it.roundToInt(), lockPercentage.roundToInt()) + } else { + onGrayscalePercentageChange(it.roundToInt(), it.roundToInt()) + } + } + }, + valueRange = 0f..100f, + steps = 100, + modifier = Modifier.padding(PaddingValues(horizontal = 30.dp)) + ) + if (bothEnabled) { + Text( + text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()), + modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)), + fontWeight = FontWeight.W400 + ) + Spacer(modifier = Modifier.height(16.dp)) + Slider( + value = lockPercentage, + onValueChange = { + view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK) + lockPercentage = it + job?.cancel() + job = scope.launch { + delay(500) + onGrayscalePercentageChange(homePercentage.roundToInt(), it.roundToInt()) + } + }, + valueRange = 0f..100f, + steps = 100, + modifier = Modifier.padding(PaddingValues(horizontal = 30.dp)) + ) + } + Spacer(modifier = Modifier.height(16.dp)) + } + } + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/PreviewItem.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/PreviewItem.kt index 0a56865..717afa3 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/PreviewItem.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/PreviewItem.kt @@ -39,7 +39,9 @@ fun PreviewItem( blurPercentage: Int, scaling: ScalingConstants, vignette: Boolean, - vignettePercentage: Int + vignettePercentage: Int, + grayscale: Boolean, + grayscalePercentage: Int ) { val context = LocalContext.current val showUri by remember { mutableStateOf(isValidUri(context, wallpaperUri)) } @@ -64,13 +66,23 @@ fun PreviewItem( BlendMode.Darken ) } else { null }, - tag = vignette.toString() + vignettePercentage.toString(), + tag = vignette.toString() + vignettePercentage.toString() + grayscale.toString() + grayscalePercentage.toString(), ), requestOptions = { - if (vignette && vignettePercentage > 0) { - RequestOptions.bitmapTransform(VignetteBitmapTransformation(vignettePercentage)) - } else { - RequestOptions() + when { + grayscale && grayscalePercentage > 0 && vignette && vignettePercentage > 0 -> { + RequestOptions().transform( + VignetteBitmapTransformation(vignettePercentage), + GrayscaleBitmapTransformation(grayscalePercentage) + ) + } + grayscale && grayscalePercentage > 0 -> { + RequestOptions().transform(GrayscaleBitmapTransformation(grayscalePercentage)) + } + vignette && vignettePercentage > 0 -> { + RequestOptions().transform(VignetteBitmapTransformation(vignettePercentage)) + } + else -> RequestOptions() } }, modifier = Modifier diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/WallpaperPreviewAndScale.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/WallpaperPreviewAndScale.kt index 451f234..37f0a40 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/WallpaperPreviewAndScale.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/components/WallpaperPreviewAndScale.kt @@ -53,7 +53,10 @@ fun WallpaperPreviewAndScale( lockBlurPercentage: Int, vignette: Boolean, homeVignettePercentage: Int, - lockVignettePercentage: Int + lockVignettePercentage: Int, + grayscale: Boolean, + homeGrayscalePercentage: Int, + lockGrayscalePercentage: Int ) { var selectedIndex by rememberSaveable { mutableIntStateOf( @@ -113,7 +116,9 @@ fun WallpaperPreviewAndScale( blur = blur, blurPercentage = if (!homeEnabled) homeBlurPercentage else lockBlurPercentage, vignette = vignette, - vignettePercentage = if (!homeEnabled) homeVignettePercentage else lockVignettePercentage + vignettePercentage = if (!homeEnabled) homeVignettePercentage else lockVignettePercentage, + grayscale = grayscale, + grayscalePercentage = if (!homeEnabled) homeGrayscalePercentage else lockGrayscalePercentage ) Spacer(modifier = Modifier.height(8.dp)) } @@ -134,7 +139,9 @@ fun WallpaperPreviewAndScale( blur = blur, blurPercentage = homeBlurPercentage, vignette = vignette, - vignettePercentage = homeVignettePercentage + vignettePercentage = homeVignettePercentage, + grayscale = grayscale, + grayscalePercentage = homeGrayscalePercentage ) Spacer(modifier = Modifier.height(8.dp)) } diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/HomeWallpaperService.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/HomeWallpaperService.kt index e88505b..9e72940 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/HomeWallpaperService.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/HomeWallpaperService.kt @@ -197,6 +197,8 @@ class HomeWallpaperService: Service() { val homeBlurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0 val vignette = settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false val homeVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 + val grayscale = settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false + val homeGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 val homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) ?: "" val lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) ?: "" var homeAlbum = selectedAlbum.find { it.album.initialAlbumName == homeAlbumName } @@ -226,7 +228,9 @@ class HomeWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (newWallpapers.size > 1) newWallpapers[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") if (success) { @@ -260,7 +264,9 @@ class HomeWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") if ((homeInterval % lockInterval == 0) || (lockInterval % homeInterval == 0) && (homeAlbumName == lockAlbumName)) { @@ -312,7 +318,9 @@ class HomeWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") if (success) { @@ -348,7 +356,9 @@ class HomeWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") if (success) { @@ -406,7 +416,9 @@ class HomeWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") @@ -443,7 +455,9 @@ class HomeWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") @@ -539,15 +553,8 @@ class HomeWallpaperService: Service() { val currentHomeWallpaper = settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER) ?: "" val vignette = settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false val homeVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 - - //log every parameter - Log.d("PaperizeWallpaperChanger", "scaling: $scaling") - Log.d("PaperizeWallpaperChanger", "darken: $darken") - Log.d("PaperizeWallpaperChanger", "homeDarkenPercentage: $homeDarkenPercentage") - Log.d("PaperizeWallpaperChanger", "blur: $blur") - Log.d("PaperizeWallpaperChanger", "homeBlurPercentage: $homeBlurPercentage") - Log.d("PaperizeWallpaperChanger", "vignette: $vignette") - Log.d("PaperizeWallpaperChanger", "homeVignettePercentage: $homeVignettePercentage") + val grayscale = settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false + val homeGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 setWallpaper( context = context, @@ -558,7 +565,9 @@ class HomeWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) } } catch (e: Exception) { @@ -578,7 +587,9 @@ class HomeWallpaperService: Service() { blur: Boolean, blurPercent: Int, vignette: Boolean, - vignettePercent: Int + vignettePercent: Int, + grayscale: Boolean, + grayscalePercent: Int ): Boolean { val wallpaperManager = WallpaperManager.getInstance(context) try { @@ -586,7 +597,7 @@ class HomeWallpaperService: Service() { val bitmap = retrieveBitmap(context, wallpaper, size.width, size.height) if (bitmap == null) return false else if (wallpaperManager.isSetWallpaperAllowed) { - processBitmap(size.width, size.height, bitmap, darken, darkenPercent, scaling, blur, blurPercent, vignette, vignettePercent)?.let { image -> + processBitmap(size.width, size.height, bitmap, darken, darkenPercent, scaling, blur, blurPercent, vignette, vignettePercent, grayscale, grayscalePercent)?.let { image -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM) wallpaperManager.forgetLoadedWallpaper() image.recycle() diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/LockWallpaperService.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/LockWallpaperService.kt index 5d9b7b3..e00a3b3 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/LockWallpaperService.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/LockWallpaperService.kt @@ -198,6 +198,9 @@ class LockWallpaperService: Service() { val vignette = settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false val homeVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 val lockVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 + val grayscale = settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false + val homeGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 + val lockGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 val lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) ?: "" val lockAlbum = selectedAlbum.find { it.album.initialAlbumName == lockAlbumName } if (lockAlbum == null) { @@ -226,7 +229,9 @@ class LockWallpaperService: Service() { blur = blur, blurPercent = lockBlurPercentage, vignette = vignette, - vignettePercent = lockVignettePercentage + vignettePercent = lockVignettePercentage, + grayscale = grayscale, + grayscalePercent = lockGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, if (newWallpapers.size > 1) newWallpapers[1] else lockAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") if (success) { @@ -260,7 +265,9 @@ class LockWallpaperService: Service() { blur = blur, blurPercent = lockBlurPercentage, vignette = vignette, - vignettePercent = lockVignettePercentage + vignettePercent = lockVignettePercentage, + grayscale = grayscale, + grayscalePercent = lockGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, if (lockAlbum.album.lockWallpapersInQueue.size > 1) lockAlbum.album.lockWallpapersInQueue[1] else lockAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") if (success) { @@ -308,7 +315,9 @@ class LockWallpaperService: Service() { blur = blur, blurPercent = lockBlurPercentage, vignette = vignette, - vignettePercent = lockVignettePercentage + vignettePercent = lockVignettePercentage, + grayscale = grayscale, + grayscalePercent = lockGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, if (homeAlbum.album.homeWallpapersInQueue.size > 1) homeAlbum.album.homeWallpapersInQueue[1] else homeAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") if (success) { @@ -337,7 +346,9 @@ class LockWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, if (newWallpapers.size > 1) newWallpapers[1] else lockAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (newWallpapers.size > 1) newWallpapers[1] else lockAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") @@ -373,7 +384,9 @@ class LockWallpaperService: Service() { blur = blur, blurPercent = homeBlurPercentage, vignette = vignette, - vignettePercent = homeVignettePercentage + vignettePercent = homeVignettePercentage, + grayscale = grayscale, + grayscalePercent = homeGrayscalePercentage ) settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, if (lockAlbum.album.lockWallpapersInQueue.size > 1) lockAlbum.album.lockWallpapersInQueue[1] else lockAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, if (lockAlbum.album.lockWallpapersInQueue.size > 1) lockAlbum.album.lockWallpapersInQueue[1] else lockAlbum.wallpapers.firstOrNull()?.wallpaperUri ?: "") @@ -460,6 +473,9 @@ class LockWallpaperService: Service() { val vignette = settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false val homeVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 val lockVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 + val grayscale = settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false + val homeGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 + val lockGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 val currentLockWallpaper = settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER) ?: "" setWallpaper( @@ -471,7 +487,9 @@ class LockWallpaperService: Service() { blur = blur, blurPercent = if (!setHome) homeBlurPercentage else lockBlurPercentage, vignette = vignette, - vignettePercent = if (!setHome) homeVignettePercentage else lockVignettePercentage + vignettePercent = if (!setHome) homeVignettePercentage else lockVignettePercentage, + grayscale = grayscale, + grayscalePercent = if (!setHome) homeGrayscalePercentage else lockGrayscalePercentage ) } } catch (e: Exception) { @@ -491,7 +509,9 @@ class LockWallpaperService: Service() { blur: Boolean, blurPercent: Int, vignette: Boolean, - vignettePercent: Int + vignettePercent: Int, + grayscale: Boolean, + grayscalePercent: Int ): Boolean { val wallpaperManager = WallpaperManager.getInstance(context) try { @@ -499,7 +519,7 @@ class LockWallpaperService: Service() { val bitmap = retrieveBitmap(context, wallpaper, size.width, size.height) if (bitmap == null) return false else if (wallpaperManager.isSetWallpaperAllowed) { - processBitmap(size.width, size.height, bitmap, darken, darkenPercent, scaling, blur, blurPercent, vignette, vignettePercent)?.let { image -> + processBitmap(size.width, size.height, bitmap, darken, darkenPercent, scaling, blur, blurPercent, vignette, vignettePercent, grayscale, grayscalePercent)?.let { image -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK) wallpaperManager.forgetLoadedWallpaper() image.recycle() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 779cd19..10c0fc6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -140,13 +140,13 @@ Fit Stretch Wallpaper Scaling - Change Brightness + Brightness Home Screen Lock Screen Individual Scheduling Show interval sliders Time Interval - Change Blur + Blur Effect Paperize is running Next wallpaper change: %1$s Delay Notice @@ -162,6 +162,7 @@ Enable Wallpaper Changer Unselected album Lock - Change Vignette + Vignette Effect None + Gray Filter \ No newline at end of file