Skip to content

Commit

Permalink
Added None scaling option
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthonyy232 committed Sep 9, 2024
1 parent 78d7e09 commit 9f67243
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdk = 26
targetSdk = 35
versionCode = 31
versionName = "2.1.1"
versionName = "2.2.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -113,6 +113,7 @@ dependencies {
implementation("androidx.compose.foundation:foundation:1.7.0")
implementation("com.github.nanihadesuka:LazyColumnScrollbar:2.2.0")
implementation("com.joaomgcd:taskerpluginlibrary:0.4.10")
implementation("com.google.ar.sceneform:filament-android:1.17.1")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.anthonyla.paperize.core
enum class ScalingConstants {
FIT,
FILL,
STRETCH
STRETCH,
NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -150,6 +156,7 @@ fun WallpaperPreviewAndScale(
0 -> ScalingConstants.FILL
1 -> ScalingConstants.FIT
2 -> ScalingConstants.STRETCH
3 -> ScalingConstants.NONE
else -> ScalingConstants.FILL
}
) },
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import javax.inject.Inject


/**
* Service for changing home screen
*/
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/none.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="128dp"
android:height="128dp"
android:viewportWidth="128"
android:viewportHeight="128">
<path
android:pathData="M29.66,113.89L29.66,113.89L98.34,113.89L98.34,113.89L98.34,15.04L98.34,15.04L29.66,15.04L29.66,15.04L29.66,113.89Z"
android:fillColor="#e1e0a6"/>
<path
android:pathData="M79.94,109.3C79.94,111.06 78.5,112.5 76.74,112.5L38.39,112.5C36.63,112.5 35.19,111.06 35.19,109.3C35.19,109.3 55.8,82.13 57.56,82.13C59.32,82.13 79.93,109.3 79.93,109.3Z"
android:fillColor="#b8ca43"/>
<path
android:pathData="M76.14,113.89L37.91,113.89C35.26,113.89 33.12,111.74 33.12,109.1L33.12,108.62C33.12,108.62 33.44,108.14 33.44,108.14C54.47,80.33 56.07,80.33 57.02,80.33C57.98,80.33 59.57,80.33 80.6,108.14L80.92,108.62L80.92,109.1C80.92,111.82 78.85,113.89 76.14,113.89L76.14,113.89ZM36.18,109.53C36.34,110.17 36.98,110.65 37.78,110.65L76.13,110.65C76.93,110.65 77.41,110.17 77.73,109.53C70.38,99.94 59.99,86.68 56.96,83.8C53.92,86.68 43.54,99.94 36.19,109.53Z"
android:fillColor="#231c1c"/>
<path
android:pathData="M93.63,108.73C93.63,110.38 92.27,111.83 90.5,111.83L53.46,111.83C51.79,111.83 50.33,110.49 50.33,108.73C50.33,108.73 70.26,82.81 71.93,82.81C73.7,82.81 93.63,108.73 93.63,108.73Z"
android:fillColor="#b8ca43"/>
<path
android:pathData="M90.84,113.89L52.87,113.89C50.52,113.89 48.6,111.97 48.6,109.62L48.6,109.3C48.6,109.3 48.81,108.98 48.81,108.98C69.56,81.75 71.16,81.75 71.8,81.75C72.44,81.75 74.05,81.75 94.79,108.98L95,109.3L95,109.62C95.11,111.97 93.18,113.89 90.83,113.89ZM50.91,109.76C51.02,110.72 51.98,111.58 52.94,111.58L90.85,111.58C91.92,111.58 92.77,110.83 92.88,109.76C84.23,98.33 74.3,85.84 71.95,83.81C69.6,85.84 59.67,98.33 50.91,109.76Z"
android:fillColor="#231c1c"/>
<path
android:pathData="M53.55,45.67C58.25,45.67 61.79,40.68 59.14,35.7C58.13,33.81 56.12,32.67 53.98,32.67L53.37,32.67C50.82,32.67 48.48,34.19 47.55,36.57C45.72,41.24 49.11,45.67 53.54,45.67L53.54,45.67Z"
android:fillColor="#f29b54"/>
<path
android:pathData="M60.87,39.62C60.87,44.09 57.35,47.61 52.88,47.61C48.41,47.61 44.89,44.09 44.89,39.62C44.89,35.15 48.41,31.63 52.88,31.63C57.35,31.63 60.87,35.15 60.87,39.62ZM48.09,39.62C48.09,42.34 50.17,44.41 52.88,44.41C55.59,44.41 57.67,42.33 57.67,39.62C57.67,36.91 55.59,34.83 52.88,34.83C50.17,34.83 48.09,36.91 48.09,39.62Z"
android:fillColor="#231c1c"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@
<string name="unselected_album">Unselected album</string>
<string name="lock">Lock</string>
<string name="change_vignette">Change Vignette</string>
<string name="none">None</string>
</resources>

0 comments on commit 9f67243

Please sign in to comment.