mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-19 15:34:26 +01:00
Add connecting view to profiles
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package no.nordicsemi.android.service
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.*
|
||||
</T> */
|
||||
abstract class BatteryManager(context: Context) : BleManager(context) {
|
||||
|
||||
private val TAG = "BLE-MANAGER"
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
|
||||
private val batteryLevelDataCallback: DataReceivedCallback =
|
||||
@@ -67,6 +69,11 @@ abstract class BatteryManager(context: Context) : BleManager(context) {
|
||||
}
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
super.log(priority, message)
|
||||
Log.println(priority, TAG, message)
|
||||
}
|
||||
|
||||
protected abstract inner class BatteryManagerGattCallback : BleManagerGattCallback() {
|
||||
override fun initialize() {
|
||||
readBatteryLevelCharacteristic()
|
||||
|
||||
@@ -26,9 +26,7 @@ import android.bluetooth.BluetoothDevice
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.LifecycleService
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
@@ -90,6 +88,13 @@ abstract class BleProfileService : Service() {
|
||||
_status.value = BleManagerStatus.OK
|
||||
}
|
||||
|
||||
override fun onDeviceFailedToConnect(device: BluetoothDevice, reason: Int) {
|
||||
super.onDeviceFailedToConnect(device, reason)
|
||||
_status.value = BleManagerStatus.DISCONNECTED
|
||||
stopSelf()
|
||||
scope.close()
|
||||
}
|
||||
|
||||
override fun onDeviceDisconnected(device: BluetoothDevice, reason: Int) {
|
||||
super.onDeviceDisconnected(device, reason)
|
||||
_status.value = BleManagerStatus.DISCONNECTED
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package no.nordicsemi.android.service
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
import java.io.Closeable
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@@ -9,6 +9,6 @@ class CloseableCoroutineScope(context: CoroutineContext) : Closeable, CoroutineS
|
||||
override val coroutineContext: CoroutineContext = context
|
||||
|
||||
override fun close() {
|
||||
coroutineContext.cancel()
|
||||
coroutineContext.cancelChildren()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
package no.nordicsemi.android.service
|
||||
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.util.Log
|
||||
import no.nordicsemi.android.ble.observer.ConnectionObserver
|
||||
|
||||
abstract class ConnectionObserverAdapter : ConnectionObserver {
|
||||
|
||||
override fun onDeviceConnecting(device: BluetoothDevice) { }
|
||||
private val TAG = "BLE-CONNECTION"
|
||||
|
||||
override fun onDeviceConnected(device: BluetoothDevice) { }
|
||||
override fun onDeviceConnecting(device: BluetoothDevice) {
|
||||
Log.d(TAG, "onDeviceConnecting()")
|
||||
}
|
||||
|
||||
override fun onDeviceFailedToConnect(device: BluetoothDevice, reason: Int) { }
|
||||
override fun onDeviceConnected(device: BluetoothDevice) {
|
||||
Log.d(TAG, "onDeviceConnected()")
|
||||
}
|
||||
|
||||
override fun onDeviceReady(device: BluetoothDevice) { }
|
||||
override fun onDeviceFailedToConnect(device: BluetoothDevice, reason: Int) {
|
||||
Log.d(TAG, "onDeviceFailedToConnect()")
|
||||
}
|
||||
|
||||
override fun onDeviceDisconnecting(device: BluetoothDevice) { }
|
||||
override fun onDeviceReady(device: BluetoothDevice) {
|
||||
Log.d(TAG, "onDeviceReady()")
|
||||
}
|
||||
|
||||
override fun onDeviceDisconnected(device: BluetoothDevice, reason: Int) { }
|
||||
override fun onDeviceDisconnecting(device: BluetoothDevice) {
|
||||
Log.d(TAG, "onDeviceDisconnecting()")
|
||||
}
|
||||
|
||||
override fun onDeviceDisconnected(device: BluetoothDevice, reason: Int) {
|
||||
Log.d(TAG, "onDeviceDisconnected()")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package no.nordicsemi.android.service
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user