Added None scaling option
This commit is contained in:
1 parent
78d7e0972b
commit
9f67243f0d
9 files changed
+51
-9
No files matched your search
@@ -3,5 +3,6 @@ package com.anthonyla.paperize.core
|
||||
enum class ScalingConstants {
|
||||
FIT,
|
||||
FILL,
|
||||
STRETCH
|
||||
STRETCH,
|
||||
NONE
|
||||
}
|
||||
@@ -84,7 +84,6 @@ object ScreenMetricsCompat {
|
||||
private val api: Api =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) ApiLevel30() else Api()
|
||||
fun getScreenSize(context: Context): Size = api.getScreenSize(context)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private open class Api {
|
||||
open fun getScreenSize(context: Context): Size {
|
||||
@@ -457,6 +456,7 @@ fun processBitmap(
|
||||
ScalingConstants.FILL -> fillBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.FIT -> fitBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.STRETCH -> stretchBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.NONE -> processedBitmap
|
||||
}
|
||||
|
||||
// Apply brightness effect
|
||||
|
||||
+2
-1
@@ -54,9 +54,10 @@ fun PreviewItem(
|
||||
ScalingConstants.FILL -> ContentScale.FillHeight
|
||||
ScalingConstants.FIT -> ContentScale.FillWidth
|
||||
ScalingConstants.STRETCH -> ContentScale.FillBounds
|
||||
ScalingConstants.NONE -> ContentScale.Crop
|
||||
},
|
||||
requestSize = IntSize(300, 300),
|
||||
alignment = Alignment.Center,
|
||||
alignment = if (scaling == ScalingConstants.NONE) Alignment.CenterStart else Alignment.Center,
|
||||
colorFilter = if (darken && darkenPercentage < 100) {
|
||||
ColorFilter.tint(
|
||||
Color.Black.copy(alpha = (100 - darkenPercentage).toFloat().div(100f)),
|
||||
|
||||
+11
-3
@@ -61,13 +61,15 @@ fun WallpaperPreviewAndScale(
|
||||
ScalingConstants.FILL -> 0
|
||||
ScalingConstants.FIT -> 1
|
||||
ScalingConstants.STRETCH -> 2
|
||||
ScalingConstants.NONE -> 3
|
||||
}
|
||||
)
|
||||
}
|
||||
val options = listOf(
|
||||
stringResource(R.string.fill),
|
||||
stringResource(R.string.fit),
|
||||
stringResource(R.string.stretch)
|
||||
stringResource(R.string.stretch),
|
||||
stringResource(R.string.none)
|
||||
)
|
||||
|
||||
Surface(
|
||||
@@ -87,9 +89,13 @@ fun WallpaperPreviewAndScale(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val modifier = if (lockEnabled && homeEnabled) {
|
||||
Modifier.weight(1f).padding(8.dp)
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(8.dp)
|
||||
} else {
|
||||
Modifier.fillMaxSize(0.5f).padding(8.dp)
|
||||
Modifier
|
||||
.fillMaxSize(0.5f)
|
||||
.padding(8.dp)
|
||||
}
|
||||
|
||||
if (lockEnabled) {
|
||||
@@ -150,6 +156,7 @@ fun WallpaperPreviewAndScale(
|
||||
0 -> ScalingConstants.FILL
|
||||
1 -> ScalingConstants.FIT
|
||||
2 -> ScalingConstants.STRETCH
|
||||
3 -> ScalingConstants.NONE
|
||||
else -> ScalingConstants.FILL
|
||||
}
|
||||
) },
|
||||
@@ -164,6 +171,7 @@ fun WallpaperPreviewAndScale(
|
||||
0 -> painterResource(id = R.drawable.fill)
|
||||
1 -> painterResource(id = R.drawable.fit)
|
||||
2 -> painterResource(id = R.drawable.stretch)
|
||||
3 -> painterResource(id = R.drawable.none)
|
||||
else -> painterResource(id = R.drawable.fill)
|
||||
},
|
||||
contentDescription = null,
|
||||
|
||||
+3
-1
@@ -42,6 +42,7 @@ import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
/**
|
||||
* Service for changing home screen
|
||||
*/
|
||||
@@ -571,7 +572,7 @@ class HomeWallpaperService: Service() {
|
||||
val size = getDeviceScreenSize(context)
|
||||
val bitmap = retrieveBitmap(context, wallpaper, size.width, size.height)
|
||||
if (bitmap == null) return false
|
||||
else {
|
||||
else if (wallpaperManager.isSetWallpaperAllowed) {
|
||||
processBitmap(size.width, size.height, bitmap, darken, darkenPercent, scaling, blur, blurPercent, vignette, vignettePercent)?.let { image ->
|
||||
wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM)
|
||||
wallpaperManager.forgetLoadedWallpaper()
|
||||
@@ -580,6 +581,7 @@ class HomeWallpaperService: Service() {
|
||||
bitmap.recycle()
|
||||
return true
|
||||
}
|
||||
else return false
|
||||
} catch (e: IOException) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error setting wallpaper", e)
|
||||
return false
|
||||
|
||||
+2
-1
@@ -494,7 +494,7 @@ class LockWallpaperService: Service() {
|
||||
val size = getDeviceScreenSize(context)
|
||||
val bitmap = retrieveBitmap(context, wallpaper, size.width, size.height)
|
||||
if (bitmap == null) return false
|
||||
else {
|
||||
else if (wallpaperManager.isSetWallpaperAllowed) {
|
||||
processBitmap(size.width, size.height, bitmap, darken, darkenPercent, scaling, blur, blurPercent, vignette, vignettePercent)?.let { image ->
|
||||
wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK)
|
||||
wallpaperManager.forgetLoadedWallpaper()
|
||||
@@ -503,6 +503,7 @@ class LockWallpaperService: Service() {
|
||||
bitmap.recycle()
|
||||
return true
|
||||
}
|
||||
else return false
|
||||
} catch (e: IOException) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error setting wallpaper", e)
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user