mirror of
https://github.com/gezimos/inkOS.git
synced 2026-06-10 22:34:17 -04:00
Wallpaper Crop Implemented 7
This commit is contained in:
@@ -55,30 +55,24 @@ class WallpaperUtility(private val context: Context) {
|
||||
suspend fun setWallpaperFromBitmap(bitmap: Bitmap, flags: Int = WallpaperManager.FLAG_SYSTEM): Boolean = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
android.util.Log.d("WallpaperUtility", "Setting wallpaper with flags: $flags, SDK: ${Build.VERSION.SDK_INT}")
|
||||
android.util.Log.d("WallpaperUtility", "Bitmap size: ${bitmap.width}x${bitmap.height}, Screen: ${screenWidth}x${screenHeight}")
|
||||
|
||||
// Force the bitmap to be exactly screen size to prevent parallax scrolling
|
||||
val screenSizedBitmap = createFittedBitmap(bitmap, screenWidth, screenHeight)
|
||||
|
||||
// If both flags are set, set them individually for better compatibility
|
||||
if (flags == (WallpaperManager.FLAG_SYSTEM or WallpaperManager.FLAG_LOCK)) {
|
||||
android.util.Log.d("WallpaperUtility", "Setting both wallpapers individually")
|
||||
try {
|
||||
wallpaperManager.setBitmap(screenSizedBitmap, null, false, WallpaperManager.FLAG_SYSTEM)
|
||||
android.util.Log.d("WallpaperUtility", "Home screen wallpaper set")
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("WallpaperUtility", "Failed to set home screen wallpaper", e)
|
||||
}
|
||||
try {
|
||||
wallpaperManager.setBitmap(screenSizedBitmap, null, false, WallpaperManager.FLAG_LOCK)
|
||||
android.util.Log.d("WallpaperUtility", "Lock screen wallpaper set")
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("WallpaperUtility", "Failed to set lock screen wallpaper", e)
|
||||
}
|
||||
} else {
|
||||
wallpaperManager.setBitmap(screenSizedBitmap, null, false, flags)
|
||||
android.util.Log.d("WallpaperUtility", "Wallpaper set successfully with flags: $flags")
|
||||
}
|
||||
|
||||
screenSizedBitmap.recycle()
|
||||
@@ -153,7 +147,6 @@ class WallpaperUtility(private val context: Context) {
|
||||
bitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true)
|
||||
|
||||
// Apply transformations in order: Flip → Brightness → Contrast → Invert → Threshold → Dithering → Halftone → Overlay
|
||||
android.util.Log.d("WallpaperUtility", "setWallpaperFromResource: flipH=$flipHorizontal, flipV=$flipVertical, brightness=$brightness, contrast=$contrast, invert=$isInverted, threshold=$thresholdLevel, dither=$ditherEnabled, halftone=$halftoneIntensity dotSize=$halftoneDotSize, overlay=$overlayEnabled side=$overlaySide spread=$overlaySpread")
|
||||
var transformedBitmap = bitmap
|
||||
|
||||
if (flipHorizontal) {
|
||||
|
||||
@@ -131,7 +131,7 @@ fun WallpaperEditor(
|
||||
var thresholdLevel by remember { mutableIntStateOf(50) } // 0-100: threshold for black/white conversion
|
||||
var ditherEnabled by remember { mutableStateOf(false) }
|
||||
var ditherAlgorithm by remember { mutableStateOf(WallpaperDither.DitherAlgorithm.FLOYD_STEINBERG) }
|
||||
var effectMode by remember { mutableStateOf("crop") }
|
||||
var effectMode by remember { mutableStateOf("brightness-contrast") }
|
||||
|
||||
// Bitmap states
|
||||
// sourceBitmap: original loaded image, never modified
|
||||
@@ -735,13 +735,6 @@ fun WallpaperEditor(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
EffectButton(effectMode == "crop", {
|
||||
effectMode = "crop"
|
||||
if (!showCropOverlay) {
|
||||
showCropOverlay = true
|
||||
cropEnabled = true
|
||||
}
|
||||
}, Icons.Default.CropFree, "Crop", buttonShape, Modifier.weight(1f))
|
||||
EffectButton(effectMode == "brightness-contrast", { effectMode = "brightness-contrast" },
|
||||
Icons.Default.Brightness6, "Brightness/Contrast", buttonShape, Modifier.weight(1f))
|
||||
EffectButton(effectMode == "flip", {
|
||||
@@ -757,6 +750,13 @@ fun WallpaperEditor(
|
||||
}, Icons.Default.BlurOn, "Dither", buttonShape, Modifier.weight(1f))
|
||||
EffectButton(effectMode == "halftone", { effectMode = "halftone" },
|
||||
Icons.Default.Grain, "Halftone", buttonShape, Modifier.weight(1f))
|
||||
EffectButton(effectMode == "crop", {
|
||||
effectMode = "crop"
|
||||
if (!showCropOverlay) {
|
||||
showCropOverlay = true
|
||||
cropEnabled = true
|
||||
}
|
||||
}, Icons.Default.CropFree, "Crop", buttonShape, Modifier.weight(1f))
|
||||
}
|
||||
|
||||
// Flip/Rotate controls
|
||||
@@ -810,43 +810,7 @@ fun WallpaperEditor(
|
||||
|
||||
// Slider section
|
||||
if (effectMode != "flip" && effectMode != "dither") {
|
||||
if (effectMode == "crop") {
|
||||
// Save Crop and Reset Crop buttons
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
TextButton(
|
||||
text = "Save Crop",
|
||||
isSelected = false,
|
||||
onClick = {
|
||||
// Save the current crop settings
|
||||
cropEnabled = true
|
||||
// Optionally switch to another mode or stay
|
||||
effectMode = "brightness-contrast" // or keep as "crop"
|
||||
},
|
||||
fontSize = buttonFontSize,
|
||||
shape = buttonShape,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
TextButton(
|
||||
text = "Reset Crop",
|
||||
isSelected = false,
|
||||
onClick = {
|
||||
// Reset crop to default (no crop)
|
||||
cropX = 0f
|
||||
cropY = 0f
|
||||
cropScale = 1f
|
||||
cropEnabled = false
|
||||
showCropOverlay = false
|
||||
},
|
||||
fontSize = buttonFontSize,
|
||||
shape = buttonShape,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
} else if (effectMode == "brightness-contrast") {
|
||||
if (effectMode == "brightness-contrast") {
|
||||
// Brightness and Contrast sliders
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
|
||||
Reference in New Issue
Block a user