mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
add ClassicScan button, timer & permissions check
This commit is contained in:
parent
a3bd9564f5
commit
dd4fbc12d5
2 changed files with 31 additions and 9 deletions
|
|
@ -12,6 +12,8 @@ import android.content.pm.PackageManager
|
|||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.RemoteException
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -811,12 +813,32 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
|
||||
private fun initClassicScan() {
|
||||
|
||||
model.bluetoothEnabled.observe(viewLifecycleOwner, Observer { enabled ->
|
||||
if (enabled)
|
||||
scanModel.startScan()
|
||||
else
|
||||
binding.changeRadioButton.setOnClickListener {
|
||||
if (myActivity.warnMissingPermissions()) {
|
||||
myActivity.requestPermission()
|
||||
} else scanLeDevice()
|
||||
}
|
||||
}
|
||||
|
||||
// per https://developer.android.com/guide/topics/connectivity/bluetooth/find-ble-devices
|
||||
private fun scanLeDevice() {
|
||||
var scanning = false
|
||||
val SCAN_PERIOD: Long = 5000 // Stops scanning after 5 seconds
|
||||
|
||||
if (!scanning) { // Stops scanning after a pre-defined scan period.
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
scanning = false
|
||||
binding.scanProgressBar.visibility = View.GONE
|
||||
scanModel.stopScan()
|
||||
})
|
||||
}, SCAN_PERIOD)
|
||||
scanning = true
|
||||
binding.scanProgressBar.visibility = View.VISIBLE
|
||||
scanModel.startScan()
|
||||
} else {
|
||||
scanning = false
|
||||
binding.scanProgressBar.visibility = View.GONE
|
||||
scanModel.stopScan()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initModernScan() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue