2020-01-20 15:53:22 -08:00
|
|
|
package com.geeksville.meshutil
|
|
|
|
|
|
2020-01-21 09:37:39 -08:00
|
|
|
import android.bluetooth.*
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
2020-01-20 15:53:22 -08:00
|
|
|
import android.os.Bundle
|
2020-01-21 09:37:39 -08:00
|
|
|
import android.os.Handler
|
|
|
|
|
import android.util.Log
|
2020-01-20 15:53:22 -08:00
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
|
import android.view.Menu
|
|
|
|
|
import android.view.MenuItem
|
|
|
|
|
|
|
|
|
|
import kotlinx.android.synthetic.main.activity_main.*
|
2020-01-21 09:37:39 -08:00
|
|
|
import java.util.*
|
|
|
|
|
|
2020-01-20 15:53:22 -08:00
|
|
|
|
|
|
|
|
class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
2020-01-21 09:37:39 -08:00
|
|
|
companion object {
|
|
|
|
|
const val REQUEST_ENABLE_BT = 10
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val bluetoothAdapter: BluetoothAdapter by lazy(LazyThreadSafetyMode.NONE) {
|
|
|
|
|
val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
|
|
|
|
bluetoothManager.adapter!!
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 15:53:22 -08:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
setContentView(R.layout.activity_main)
|
|
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
|
|
|
|
|
|
fab.setOnClickListener { view ->
|
|
|
|
|
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
2020-01-21 09:37:39 -08:00
|
|
|
.setAction("Action", null).show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensures Bluetooth is available on the device and it is enabled. If not,
|
|
|
|
|
// displays a dialog requesting user permission to enable Bluetooth.
|
2020-01-21 10:39:01 -08:00
|
|
|
bluetoothAdapter.takeIf { !it.isEnabled }?.apply {
|
2020-01-21 09:37:39 -08:00
|
|
|
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
|
|
|
|
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
|
2020-01-20 15:53:22 -08:00
|
|
|
}
|
2020-01-21 12:07:03 -08:00
|
|
|
|
|
|
|
|
SoftwareUpdateService.enqueueWork(this, SoftwareUpdateService.scanDevicesIntent)
|
2020-01-20 15:53:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
|
menuInflater.inflate(R.menu.menu_main, menu)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
2020-01-20 16:13:40 -08:00
|
|
|
return when (item.itemId) {
|
2020-01-20 15:53:22 -08:00
|
|
|
R.id.action_settings -> true
|
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-21 09:37:39 -08:00
|
|
|
|