Various style fixes

This commit is contained in:
Fabian Wiesel
2024-03-01 17:24:35 +01:00
parent b9964d24d2
commit f5aa9da84c
4 changed files with 21 additions and 23 deletions

View File

@@ -158,7 +158,7 @@ class DiscoverActivity : Activity() {
}
}
}
this@DiscoverActivity.nsdManager!!.resolveService(service, resolver)
this@DiscoverActivity.nsdManager.resolveService(service, resolver)
} else {
Log.d(TAG, "Unknown Service name: " + service.serviceName)
}

View File

@@ -72,14 +72,11 @@ class ListenService : Service() {
}
override fun onDestroy() {
this.listenThread?.let {
this.listenThread = null
it.interrupt()
}
this.listenThread?.interrupt()
this.listenThread = null
// Cancel the persistent notification.
val NOTIFICATION = R.string.listening
notificationManager.cancel(NOTIFICATION)
notificationManager.cancel(R.string.listening)
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
// Tell the user we stopped.
Toast.makeText(this, R.string.stopped, Toast.LENGTH_SHORT).show()

View File

@@ -166,17 +166,18 @@ class MonitorService : Service() {
// Save the service name. Android may have changed it in order to
// resolve a conflict, so update the name you initially requested
// with the name Android actually used.
val serviceName = nsdServiceInfo.serviceName
Log.i(TAG, "Service name: $serviceName")
val ma = monitorActivity
ma?.runOnUiThread {
val statusText = ma.findViewById<TextView>(R.id.textStatus)
statusText.setText(R.string.waitingForParent)
val serviceText = ma.findViewById<TextView>(R.id.textService)
serviceText.text = serviceName
val portText = ma.findViewById<TextView>(R.id.port)
portText.text = Integer.toString(port)
}
nsdServiceInfo.serviceName.let { serviceName ->
Log.i(TAG, "Service name: $serviceName")
monitorActivity?.let { ma ->
ma.runOnUiThread {
val statusText = ma.findViewById<TextView>(R.id.textStatus)
statusText.setText(R.string.waitingForParent)
val serviceText = ma.findViewById<TextView>(R.id.textService)
serviceText.text = serviceName
val portText = ma.findViewById<TextView>(R.id.port)
portText.text = port.toString()
}
}
}
override fun onRegistrationFailed(serviceInfo: NsdServiceInfo, errorCode: Int) {
@@ -237,13 +238,13 @@ class MonitorService : Service() {
unregisterService()
this.connectionToken = null
this.currentSocket?.let {
this.currentSocket = null
try {
it.close()
} catch (e: IOException) {
Log.e(TAG, "Failed to close active socket on port $currentPort")
}
}
this.currentSocket = null
// Cancel the persistent notification.
this.notificationManager.cancel(R.string.listening)

View File

@@ -22,6 +22,7 @@ import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import kotlin.math.min
class VolumeView : View {
private val paint: Paint
@@ -52,8 +53,7 @@ class VolumeView : View {
val size = volumeHistory.size() // Size is at most width
val volumeNorm = volumeHistory.volumeNorm
val relativeBrightness: Double = if (size > 0) {
val normalizedVolume = volumeHistory[size - 1]
Math.max(0.3, normalizedVolume)
volumeHistory[size - 1].coerceAtLeast(0.3)
} else {
0.3
}
@@ -73,11 +73,11 @@ class VolumeView : View {
}
val margins = height * 0.1
val graphHeight = height - 2.0 * margins
val leftMost = Math.max(0, volumeHistory.size() - width)
val leftMost = (volumeHistory.size() - width).coerceAtLeast(0)
val graphScale = graphHeight * volumeNorm
var xPrev = 0
var yPrev = (margins + graphHeight - volumeHistory[leftMost] * graphScale).toInt()
val length = Math.min(size, width)
val length = min(size, width)
for (xNext in 1 until length - 1) {
val yNext = (margins + graphHeight - volumeHistory[leftMost + xNext] * graphScale).toInt()
canvas.drawLine(xPrev.toFloat(), yPrev.toFloat(), xNext.toFloat(), yNext.toFloat(), paint)