Skip to content

Commit 8415b89

Browse files
committed
fix build warnings
1 parent d5017be commit 8415b89

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

app/src/main/kotlin/com/heisenberg/lux/DetectionService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class DetectionService : Service(), LifecycleOwner {
6161
prefs.registerOnSharedPreferenceChangeListener(prefsListener)
6262

6363
powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
64+
// Note: These flags are deprecated in API 29+ but are the simplest way to wake the screen
65+
// from a background service without showing UI. Modern alternatives require launching an Activity.
66+
@Suppress("DEPRECATION")
6467
wakeLock = powerManager.newWakeLock(
6568
PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
6669
"HeisenbergLux::WakeLock"

app/src/main/kotlin/com/heisenberg/lux/MainActivity.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ class MainActivity : AppCompatActivity() {
126126
})
127127

128128
// Setup light sensor
129-
lightSeekBar?.progress = lightSensitivity
129+
lightSeekBar.progress = lightSensitivity
130130
val lightThreshold = calculateLightThreshold(lightSensitivity)
131131
val lightThresholdPercent = ((lightThreshold / LIGHT_MAX_LEVEL) * 100f).coerceIn(0f, 100f).toInt()
132-
lightValue?.text = if (lightSensitivity == 0) getString(R.string.disabled_caps) else "$lightThresholdPercent%"
132+
lightValue.text = if (lightSensitivity == 0) getString(R.string.disabled_caps) else "$lightThresholdPercent%"
133133

134-
lightSeekBar?.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
134+
lightSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
135135
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
136136
val threshold = calculateLightThreshold(progress)
137137
val thresholdPercent = ((threshold / LIGHT_MAX_LEVEL) * 100f).coerceIn(0f, 100f).toInt()
@@ -296,14 +296,14 @@ class MainActivity : AppCompatActivity() {
296296
val lightSensitivity = prefs.getInt(KEY_LIGHT_SENSITIVITY, 50)
297297
if (lightSensitivity == 0) {
298298
// Don't update display when disabled
299-
binding.lightValue?.text = getString(R.string.disabled_caps)
299+
binding.lightValue.text = getString(R.string.disabled_caps)
300300
} else {
301301
// Convert light level to percentage (0-5 lux -> 0-100%)
302302
val levelPercent = ((currentLevel / LIGHT_MAX_LEVEL) * 100f).coerceIn(0f, 100f).toInt()
303303
val thresholdPercent = ((threshold / LIGHT_MAX_LEVEL) * 100f).coerceIn(0f, 100f).toInt()
304-
binding.lightLiveReading?.text = "$emoji Current activity level: $levelPercent%"
304+
binding.lightLiveReading.text = "$emoji Current activity level: $levelPercent%"
305305
// Also update the slider value display with threshold
306-
binding.lightValue?.text = "$thresholdPercent%"
306+
binding.lightValue.text = "$thresholdPercent%"
307307
}
308308
}
309309
}

app/src/main/kotlin/com/heisenberg/lux/MotionDetector.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,18 @@ class MotionDetector(
9696
}
9797

9898
imageAnalysis = ImageAnalysis.Builder()
99-
.setTargetResolution(Size(320, 240))
99+
.setResolutionSelector(
100+
androidx.camera.core.resolutionselector.ResolutionSelector.Builder()
101+
.setResolutionFilter { supportedSizes, _ ->
102+
// Filter to get closest to 320x240
103+
supportedSizes.sortedBy {
104+
val width = if (it.width < it.height) it.width else it.height
105+
val height = if (it.width < it.height) it.height else it.width
106+
kotlin.math.abs(width - 320) + kotlin.math.abs(height - 240)
107+
}
108+
}
109+
.build()
110+
)
100111
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
101112
.build()
102113
.also {

icon.png

-3.98 MB
Loading

0 commit comments

Comments
 (0)