Skip to content

Commit 4be29dd

Browse files
committed
* Fix for camera rotation
* Added feature to dynamically update clock screensaver position * Updates for Swedish translations
1 parent 5c8a2e0 commit 4be29dd

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/modules/CameraReader.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,6 @@ constructor(private val context: Context) {
287287
return
288288
}
289289
cameraOrientation = info.orientation
290-
if(configuration.cameraRotate != 0f) {
291-
cameraOrientation = configuration.cameraRotate.toInt()
292-
}
293290
val multiDetectorBuilder = MultiDetector.Builder()
294291
var detectorAdded = false
295292

@@ -307,7 +304,7 @@ constructor(private val context: Context) {
307304
}
308305
})
309306
bitmapComplete = false
310-
byteArrayCreateTask!!.execute(stream.byteArray, stream.width, stream.height, cameraOrientation)
307+
byteArrayCreateTask!!.execute(stream.byteArray, stream.width, stream.height, cameraOrientation, configuration.cameraRotate)
311308
}
312309
}
313310
}
@@ -426,24 +423,27 @@ constructor(private val context: Context) {
426423
val width = params[1] as Int
427424
val height = params[2] as Int
428425
val orientation = params[3] as Int
426+
val rotation = params[4] as Float
429427

430428
val windowService = contextRef.get()!!.getSystemService(Context.WINDOW_SERVICE) as WindowManager
431429
val currentRotation = windowService.defaultDisplay.rotation
432430
val nv21Bitmap = Nv21Image.nv21ToBitmap(renderScript, byteArray, width, height)
433-
434431
var rotate = orientation
432+
435433
when (currentRotation) {
436434
Surface.ROTATION_90 -> {
437-
rotate += 90
435+
rotate -= 90
438436
}
439437
Surface.ROTATION_180 -> {
440-
rotate += 180
438+
rotate -= 180
441439
}
442440
Surface.ROTATION_270 -> {
443-
rotate += 270
441+
rotate -= 270
444442
}
445443
}
444+
446445
rotate %= 360
446+
rotate += rotation.toInt()
447447

448448
val matrix = Matrix()
449449
matrix.postRotate(rotate.toFloat())

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/fragments/CameraSettingsFragment.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ class CameraSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnS
9090
rotatePreference!!.value = configuration.cameraRotate.toString()
9191
if(configuration.cameraRotate == 0f) {
9292
rotatePreference!!.setValueIndex(0)
93-
} else if (configuration.cameraRotate == -360f) {
93+
} else if (configuration.cameraRotate == -90f) {
9494
rotatePreference!!.setValueIndex(1)
95-
} else if (configuration.cameraRotate == 180f) {
95+
} else if (configuration.cameraRotate == 90f) {
9696
rotatePreference!!.setValueIndex(2)
97-
} else if (configuration.cameraRotate == -270f) {
97+
} else if (configuration.cameraRotate == -180f) {
9898
rotatePreference!!.setValueIndex(3)
9999
}
100100
cameraListPreference = findPreference(getString(R.string.key_setting_camera_cameraid)) as ListPreference

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/views/ScreenSaverView.kt

+23-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import retrofit2.Response
4949
import timber.log.Timber
5050
import java.text.DateFormat
5151
import java.util.*
52+
import java.util.concurrent.TimeUnit
5253

5354
class ScreenSaverView : RelativeLayout {
5455

@@ -65,6 +66,9 @@ class ScreenSaverView : RelativeLayout {
6566
private var dataSource: DarkSkyDao? = null
6667
private var useImageSaver: Boolean = false
6768
private var hasWeather: Boolean = false
69+
private var parentWidth: Int = 0
70+
private var parentHeight: Int = 0
71+
private val calendar: Calendar = Calendar.getInstance()
6872

6973
private val delayRotationRunnable = object : Runnable {
7074
override fun run() {
@@ -75,12 +79,27 @@ class ScreenSaverView : RelativeLayout {
7579

7680
private val timeRunnable = object : Runnable {
7781
override fun run() {
78-
val currentTimeString = DateUtils.formatDateTime(context, Date().time, DateUtils.FORMAT_SHOW_TIME)
79-
screenSaverClockSmall.text = currentTimeString
82+
val date = Date()
83+
calendar.time = date
84+
val currentTimeString = DateUtils.formatDateTime(context, date.time, DateUtils.FORMAT_SHOW_TIME)
8085
screenSaverClock.text = currentTimeString
81-
if (timeHandler != null) {
82-
timeHandler!!.postDelayed(this, 1000)
86+
87+
// use this only with the clock feature
88+
if (!useImageSaver) {
89+
val width = screenSaverClockLayout.width
90+
val height = screenSaverClockLayout.height
91+
parentWidth = screenSaverView.width
92+
parentHeight = screenSaverView.height
93+
if (width > 0 && height > 0) {
94+
val newX = Random().nextInt(parentWidth - width)
95+
val newY = Random().nextInt(parentHeight - height)
96+
screenSaverClockLayout.x = newX.toFloat()
97+
screenSaverClockLayout.y = newY.toFloat()
98+
}
8399
}
100+
101+
val offset = 60L - calendar.get(Calendar.SECOND)
102+
timeHandler?.postDelayed(this, TimeUnit.SECONDS.toMillis(offset))
84103
}
85104
}
86105

app/src/main/res/values/donottranslate.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@
108108

109109
<string-array name="flip_values">
110110
<item>0F</item>
111-
<item>-360f</item>
112-
<item>180f</item>
113-
<item>-270f</item>
111+
<item>-90f</item>
112+
<item>90f</item>
113+
<item>-180f</item>
114114
</string-array>
115115

116116
<string-array name="zoom_level_names">

0 commit comments

Comments
 (0)