Remove unnecessary SDK version checks
With minSdk=35 all Build.VERSION.SDK_INT checks for API levels below
35 are always true. Remove all version branching in HapticFeedback
(API 29/31 checks) and PhotoSaver (API 29 checks). Keep only the
modern API calls and drop @Suppress("DEPRECATION") annotations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
41a95885c1
commit
c7fa8f16be
2 changed files with 19 additions and 55 deletions
|
|
@ -16,6 +16,7 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Result of a photo save operation.
|
* Result of a photo save operation.
|
||||||
*/
|
*/
|
||||||
|
|
@ -52,11 +53,8 @@ class PhotoSaver(private val context: Context) {
|
||||||
put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
|
put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
|
||||||
put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis() / 1000)
|
put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis() / 1000)
|
||||||
put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
|
put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
|
||||||
|
put(MediaStore.Images.Media.RELATIVE_PATH, "${Environment.DIRECTORY_PICTURES}/TiltShift")
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
put(MediaStore.Images.Media.IS_PENDING, 1)
|
||||||
put(MediaStore.Images.Media.RELATIVE_PATH, "${Environment.DIRECTORY_PICTURES}/TiltShift")
|
|
||||||
put(MediaStore.Images.Media.IS_PENDING, 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert into MediaStore
|
// Insert into MediaStore
|
||||||
|
|
@ -74,12 +72,10 @@ class PhotoSaver(private val context: Context) {
|
||||||
// Write EXIF data
|
// Write EXIF data
|
||||||
writeExifToUri(uri, orientation, location)
|
writeExifToUri(uri, orientation, location)
|
||||||
|
|
||||||
// Mark as complete (API 29+)
|
// Mark as complete
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
contentValues.clear()
|
||||||
contentValues.clear()
|
contentValues.put(MediaStore.Images.Media.IS_PENDING, 0)
|
||||||
contentValues.put(MediaStore.Images.Media.IS_PENDING, 0)
|
contentResolver.update(uri, contentValues, null, null)
|
||||||
contentResolver.update(uri, contentValues, null, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the file path for display
|
// Get the file path for display
|
||||||
val path = getPathFromUri(uri)
|
val path = getPathFromUri(uri)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package no.naiv.tiltshift.util
|
package no.naiv.tiltshift.util
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
|
||||||
import android.os.VibrationEffect
|
import android.os.VibrationEffect
|
||||||
import android.os.Vibrator
|
|
||||||
import android.os.VibratorManager
|
import android.os.VibratorManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -11,77 +9,47 @@ import android.os.VibratorManager
|
||||||
*/
|
*/
|
||||||
class HapticFeedback(private val context: Context) {
|
class HapticFeedback(private val context: Context) {
|
||||||
|
|
||||||
private val vibrator: Vibrator by lazy {
|
private val vibrator by lazy {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
val vibratorManager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
||||||
val vibratorManager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
vibratorManager.defaultVibrator
|
||||||
vibratorManager.defaultVibrator
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Light tick for UI feedback (button press, slider change).
|
* Light tick for UI feedback (button press, slider change).
|
||||||
*/
|
*/
|
||||||
fun tick() {
|
fun tick() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))
|
||||||
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
vibrator.vibrate(10L)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Click feedback for confirmations.
|
* Click feedback for confirmations.
|
||||||
*/
|
*/
|
||||||
fun click() {
|
fun click() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK))
|
||||||
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK))
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
vibrator.vibrate(20L)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Heavy click for important actions (photo capture).
|
* Heavy click for important actions (photo capture).
|
||||||
*/
|
*/
|
||||||
fun heavyClick() {
|
fun heavyClick() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK))
|
||||||
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK))
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
vibrator.vibrate(40L)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Success feedback pattern.
|
* Success feedback pattern.
|
||||||
*/
|
*/
|
||||||
fun success() {
|
fun success() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
val timings = longArrayOf(0, 30, 50, 30)
|
||||||
val timings = longArrayOf(0, 30, 50, 30)
|
val amplitudes = intArrayOf(0, 100, 0, 200)
|
||||||
val amplitudes = intArrayOf(0, 100, 0, 200)
|
vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1))
|
||||||
vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1))
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
vibrator.vibrate(longArrayOf(0, 30, 50, 30), -1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error feedback pattern.
|
* Error feedback pattern.
|
||||||
*/
|
*/
|
||||||
fun error() {
|
fun error() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
val timings = longArrayOf(0, 50, 30, 50, 30, 50)
|
||||||
val timings = longArrayOf(0, 50, 30, 50, 30, 50)
|
val amplitudes = intArrayOf(0, 150, 0, 150, 0, 150)
|
||||||
val amplitudes = intArrayOf(0, 150, 0, 150, 0, 150)
|
vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1))
|
||||||
vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1))
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
vibrator.vibrate(longArrayOf(0, 50, 30, 50, 30, 50), -1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue