Updated WallpaperManager usage
This commit is contained in:
1 parent
8f30f3558a
commit
8945002652
4 files changed
+24
-12
No files matched your search
@@ -193,11 +193,17 @@ fun fitBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
if (source.width == width && source.height == height) {
|
||||
return source
|
||||
}
|
||||
if (source.width <= 0 || source.height <= 0 || width <= 0 || height <= 0) {
|
||||
Log.w("WallpaperUtil", "Invalid dimensions for fitBitmap, returning source.")
|
||||
return source
|
||||
}
|
||||
|
||||
return try {
|
||||
val bitmap = createBitmap(width, height, source.config ?: Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
val scale = width.toFloat() / source.width
|
||||
val yOffset = (height - source.height * scale) / 2f
|
||||
val scaledSourceHeight = source.height * scale
|
||||
val yOffset = (height - scaledSourceHeight) / 2f
|
||||
val matrix = Matrix().apply {
|
||||
postScale(scale, scale)
|
||||
postTranslate(0f, yOffset)
|
||||
@@ -227,7 +233,7 @@ fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
val xOffset: Float
|
||||
val yOffset: Float
|
||||
|
||||
if (sourceAspect > targetAspect) {
|
||||
if (sourceAspect >= targetAspect) {
|
||||
scale = height.toFloat() / source.height.toFloat()
|
||||
xOffset = (width - source.width * scale) / 2f
|
||||
yOffset = 0f
|
||||
@@ -238,7 +244,7 @@ fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
}
|
||||
|
||||
val matrix = Matrix().apply {
|
||||
setScale(scale, scale)
|
||||
postScale(scale, scale)
|
||||
postTranslate(xOffset, yOffset)
|
||||
}
|
||||
canvas.drawBitmap(source, matrix, SharedPaintFilterAntiAlias)
|
||||
@@ -257,12 +263,16 @@ fun stretchBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
return source
|
||||
}
|
||||
return try {
|
||||
val bitmap = createBitmap(width, height, source.config ?: Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
val matrix = Matrix().apply {
|
||||
setScale(width.toFloat() / source.width, height.toFloat() / source.height)
|
||||
}
|
||||
createBitmap(width, height, source.config ?: Bitmap.Config.ARGB_8888).apply {
|
||||
Canvas(this).drawBitmap(source, matrix, SharedPaintFilterAntiAlias)
|
||||
setScale(
|
||||
width.toFloat() / source.width,
|
||||
height.toFloat() / source.height
|
||||
)
|
||||
}
|
||||
canvas.drawBitmap(source, matrix, SharedPaintFilterAntiAlias)
|
||||
bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error stretching bitmap: $e")
|
||||
source
|
||||
|
||||
-3
@@ -26,9 +26,6 @@ interface AlbumDao {
|
||||
@Query("SELECT * FROM album WHERE selected = 1")
|
||||
fun getSelectedAlbums(): Flow<List<AlbumWithWallpaperAndFolder>>
|
||||
|
||||
/*@Query("UPDATE album SET selected = :selected WHERE initialAlbumName = :albumName")
|
||||
suspend fun updateAlbumSelection(albumName: String, selected: Boolean)*/
|
||||
|
||||
@Query("UPDATE album SET selected = :selected WHERE initialAlbumName = :albumName")
|
||||
suspend fun updateAlbumSelection(albumName: String, selected: Boolean)
|
||||
|
||||
|
||||
+7
@@ -1,10 +1,13 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
import android.Manifest
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresPermission
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.HomeWallpaperService
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.LockWallpaperService
|
||||
@@ -37,6 +40,7 @@ class WallpaperAlarmSchedulerImpl @Inject constructor(
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on the origin and changeImmediate
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.SCHEDULE_EXACT_ALARM)
|
||||
override suspend fun scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem: WallpaperAlarmItem,
|
||||
origin: Int?,
|
||||
@@ -132,6 +136,7 @@ class WallpaperAlarmSchedulerImpl @Inject constructor(
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on type and time
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.SCHEDULE_EXACT_ALARM)
|
||||
private fun scheduleWallpaper(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, origin: Int? = null, firstLaunch: Boolean = false, homeNextTime: String? = null, lockNextTime: String? = null) {
|
||||
try {
|
||||
val nextTime = calculateNextAlarmTime(wallpaperAlarmItem, type, firstLaunch, homeNextTime ?: "", lockNextTime ?: "")
|
||||
@@ -146,6 +151,7 @@ class WallpaperAlarmSchedulerImpl @Inject constructor(
|
||||
|
||||
scheduleExactAlarm(nextTime, intent)
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperAlarmScheduler", "Error scheduling wallpaper alarm: ${e.message}")
|
||||
cancelWallpaperAlarm()
|
||||
}
|
||||
}
|
||||
@@ -226,6 +232,7 @@ class WallpaperAlarmSchedulerImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresPermission(Manifest.permission.SCHEDULE_EXACT_ALARM)
|
||||
private fun scheduleExactAlarm(nextTime: LocalDateTime, intent: Intent) {
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
|
||||
-2
@@ -582,9 +582,7 @@ class HomeWallpaperService: Service() {
|
||||
processBitmap(size.width, size.height, bitmap, darken, darkenPercent, scaling, blur, blurPercent, vignette, vignettePercent, grayscale, grayscalePercent)?.let { image ->
|
||||
if (both) setWallpaperSafely(image, WallpaperManager.FLAG_LOCK, wallpaperManager)
|
||||
setWallpaperSafely(image, WallpaperManager.FLAG_SYSTEM, wallpaperManager)
|
||||
image.recycle()
|
||||
}
|
||||
bitmap.recycle()
|
||||
context.triggerWallpaperTaskerEvent()
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user