Various style fixes
This commit is contained in:
@@ -158,7 +158,7 @@ class DiscoverActivity : Activity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this@DiscoverActivity.nsdManager!!.resolveService(service, resolver)
|
this@DiscoverActivity.nsdManager.resolveService(service, resolver)
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Unknown Service name: " + service.serviceName)
|
Log.d(TAG, "Unknown Service name: " + service.serviceName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,14 +72,11 @@ class ListenService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
this.listenThread?.let {
|
this.listenThread?.interrupt()
|
||||||
this.listenThread = null
|
this.listenThread = null
|
||||||
it.interrupt()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel the persistent notification.
|
// Cancel the persistent notification.
|
||||||
val NOTIFICATION = R.string.listening
|
notificationManager.cancel(R.string.listening)
|
||||||
notificationManager.cancel(NOTIFICATION)
|
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
// Tell the user we stopped.
|
// Tell the user we stopped.
|
||||||
Toast.makeText(this, R.string.stopped, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.stopped, Toast.LENGTH_SHORT).show()
|
||||||
|
|||||||
@@ -166,17 +166,18 @@ class MonitorService : Service() {
|
|||||||
// Save the service name. Android may have changed it in order to
|
// Save the service name. Android may have changed it in order to
|
||||||
// resolve a conflict, so update the name you initially requested
|
// resolve a conflict, so update the name you initially requested
|
||||||
// with the name Android actually used.
|
// with the name Android actually used.
|
||||||
val serviceName = nsdServiceInfo.serviceName
|
nsdServiceInfo.serviceName.let { serviceName ->
|
||||||
Log.i(TAG, "Service name: $serviceName")
|
Log.i(TAG, "Service name: $serviceName")
|
||||||
val ma = monitorActivity
|
monitorActivity?.let { ma ->
|
||||||
ma?.runOnUiThread {
|
ma.runOnUiThread {
|
||||||
val statusText = ma.findViewById<TextView>(R.id.textStatus)
|
val statusText = ma.findViewById<TextView>(R.id.textStatus)
|
||||||
statusText.setText(R.string.waitingForParent)
|
statusText.setText(R.string.waitingForParent)
|
||||||
val serviceText = ma.findViewById<TextView>(R.id.textService)
|
val serviceText = ma.findViewById<TextView>(R.id.textService)
|
||||||
serviceText.text = serviceName
|
serviceText.text = serviceName
|
||||||
val portText = ma.findViewById<TextView>(R.id.port)
|
val portText = ma.findViewById<TextView>(R.id.port)
|
||||||
portText.text = Integer.toString(port)
|
portText.text = port.toString()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRegistrationFailed(serviceInfo: NsdServiceInfo, errorCode: Int) {
|
override fun onRegistrationFailed(serviceInfo: NsdServiceInfo, errorCode: Int) {
|
||||||
@@ -237,13 +238,13 @@ class MonitorService : Service() {
|
|||||||
unregisterService()
|
unregisterService()
|
||||||
this.connectionToken = null
|
this.connectionToken = null
|
||||||
this.currentSocket?.let {
|
this.currentSocket?.let {
|
||||||
this.currentSocket = null
|
|
||||||
try {
|
try {
|
||||||
it.close()
|
it.close()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(TAG, "Failed to close active socket on port $currentPort")
|
Log.e(TAG, "Failed to close active socket on port $currentPort")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.currentSocket = null
|
||||||
|
|
||||||
// Cancel the persistent notification.
|
// Cancel the persistent notification.
|
||||||
this.notificationManager.cancel(R.string.listening)
|
this.notificationManager.cancel(R.string.listening)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.graphics.Color
|
|||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class VolumeView : View {
|
class VolumeView : View {
|
||||||
private val paint: Paint
|
private val paint: Paint
|
||||||
@@ -52,8 +53,7 @@ class VolumeView : View {
|
|||||||
val size = volumeHistory.size() // Size is at most width
|
val size = volumeHistory.size() // Size is at most width
|
||||||
val volumeNorm = volumeHistory.volumeNorm
|
val volumeNorm = volumeHistory.volumeNorm
|
||||||
val relativeBrightness: Double = if (size > 0) {
|
val relativeBrightness: Double = if (size > 0) {
|
||||||
val normalizedVolume = volumeHistory[size - 1]
|
volumeHistory[size - 1].coerceAtLeast(0.3)
|
||||||
Math.max(0.3, normalizedVolume)
|
|
||||||
} else {
|
} else {
|
||||||
0.3
|
0.3
|
||||||
}
|
}
|
||||||
@@ -73,11 +73,11 @@ class VolumeView : View {
|
|||||||
}
|
}
|
||||||
val margins = height * 0.1
|
val margins = height * 0.1
|
||||||
val graphHeight = height - 2.0 * margins
|
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
|
val graphScale = graphHeight * volumeNorm
|
||||||
var xPrev = 0
|
var xPrev = 0
|
||||||
var yPrev = (margins + graphHeight - volumeHistory[leftMost] * graphScale).toInt()
|
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) {
|
for (xNext in 1 until length - 1) {
|
||||||
val yNext = (margins + graphHeight - volumeHistory[leftMost + xNext] * graphScale).toInt()
|
val yNext = (margins + graphHeight - volumeHistory[leftMost + xNext] * graphScale).toInt()
|
||||||
canvas.drawLine(xPrev.toFloat(), yPrev.toFloat(), xNext.toFloat(), yNext.toFloat(), paint)
|
canvas.drawLine(xPrev.toFloat(), yPrev.toFloat(), xNext.toFloat(), yNext.toFloat(), paint)
|
||||||
|
|||||||
Reference in New Issue
Block a user