|
|
@@ -13,6 +13,7 @@ import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
import android.provider.Settings
|
|
|
import android.provider.Settings.SettingNotFoundException
|
|
|
+import android.view.View
|
|
|
import android.view.WindowManager
|
|
|
import android.widget.Button
|
|
|
import android.widget.TextView
|
|
|
@@ -26,10 +27,10 @@ import com.example.watch.R
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
|
|
import com.yanzhenjie.permission.AndPermission
|
|
|
import com.yanzhenjie.permission.runtime.Permission
|
|
|
+import kotlinx.android.synthetic.main.activity_main.*
|
|
|
import timber.log.Timber
|
|
|
|
|
|
-
|
|
|
-class MainActivity : AppCompatActivity() {
|
|
|
+class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListener {
|
|
|
private val mDeviceConnected = false
|
|
|
private val mTvAppVersion: TextView? = null
|
|
|
private val mTvDeviceName: TextView? = null
|
|
|
@@ -62,7 +63,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
turnTabPage()
|
|
|
}
|
|
|
|
|
|
- fun setStatusBarColor() {
|
|
|
+ fun setStatusBarColor() {
|
|
|
val window = window
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
|
|
@@ -73,20 +74,6 @@ class MainActivity : AppCompatActivity() {
|
|
|
private fun linkHeartBand() {
|
|
|
val chainBtn = findViewById<Button>(R.id.chainBtn)
|
|
|
chainBtn.setOnClickListener {
|
|
|
-// val mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
|
|
|
-// if (mBluetoothAdapter == null) {
|
|
|
-// Toast.makeText(this, "当前设备不支持蓝牙!", Toast.LENGTH_SHORT).show()
|
|
|
-// }
|
|
|
-// if (!mBluetoothAdapter.isEnabled) {
|
|
|
-// val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
|
|
-// val REQUEST_ENABLE_BT = 1;
|
|
|
-// startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
|
|
|
-// } else {
|
|
|
-// Toast.makeText(this, "开始扫描蓝牙设备啦!", Toast.LENGTH_SHORT).show()
|
|
|
-//// showDeviceScanningDialog()
|
|
|
-// showBLEDialog()
|
|
|
-// }
|
|
|
-
|
|
|
if (isBLEEnabled()) {
|
|
|
if (!mDeviceConnected) {
|
|
|
showDeviceScanningDialog()
|
|
|
@@ -100,27 +87,24 @@ class MainActivity : AppCompatActivity() {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private fun turnTabPage(){
|
|
|
+ private fun turnTabPage() {
|
|
|
+ val home_btn = findViewById<View>(R.id.navigation_home)
|
|
|
+ home_btn.setOnClickListener {
|
|
|
+ startActivity(Intent(this, MainActivity::class.java))
|
|
|
+ }
|
|
|
+ val setting_btn = findViewById<View>(R.id.navigation_setting)
|
|
|
+ setting_btn.setOnClickListener {
|
|
|
+ val SettingActivityIntent = Intent(this, SettingActivity::class.java)
|
|
|
+ startActivity(SettingActivityIntent)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private fun initView() {
|
|
|
|
|
|
-// val navBatton = findViewById<Button>(R.id.navigation_second)
|
|
|
-// navBatton.setOnClickListener {
|
|
|
-// // 跳到其他页面
|
|
|
-// val historyIntent = Intent(this, SearchActivity::class.java)
|
|
|
-// this.startActivity(historyIntent)
|
|
|
-// }
|
|
|
|
|
|
}
|
|
|
|
|
|
private fun login() {
|
|
|
-// val login = 1
|
|
|
-// if (login == 1) {
|
|
|
-// val LoginActivityIntent = Intent(this, LoginActivity::class.java)
|
|
|
-// startActivity(LoginActivityIntent)
|
|
|
-// }
|
|
|
val sharedPreferences = getSharedPreferences("login", 0)
|
|
|
val loginState = sharedPreferences.getBoolean("token", true)
|
|
|
// val loginState = true
|
|
|
@@ -155,8 +139,8 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
private fun showLoading(message: String?) {
|
|
|
mLoading = LoadingDialog.Builder(this)
|
|
|
- .setMessage(message)
|
|
|
- .build()
|
|
|
+ .setMessage(message)
|
|
|
+ .build()
|
|
|
mLoading!!.show()
|
|
|
}
|
|
|
|
|
|
@@ -198,36 +182,36 @@ class MainActivity : AppCompatActivity() {
|
|
|
private fun showDeviceScanningDialog() {
|
|
|
if (isLocationEnabled(this)) {
|
|
|
AndPermission.with(this)
|
|
|
- .runtime()
|
|
|
- .permission(
|
|
|
- Permission.ACCESS_FINE_LOCATION,
|
|
|
- Permission.ACCESS_COARSE_LOCATION,
|
|
|
- Permission.ACCESS_BACKGROUND_LOCATION
|
|
|
- )
|
|
|
- .onGranted { permissions ->
|
|
|
- runOnUiThread {
|
|
|
- val dialog: ScannerFragment = ScannerFragment.getInstance()
|
|
|
- dialog.show(supportFragmentManager, "scan_fragment")
|
|
|
- }
|
|
|
+ .runtime()
|
|
|
+ .permission(
|
|
|
+ Permission.ACCESS_FINE_LOCATION,
|
|
|
+ Permission.ACCESS_COARSE_LOCATION,
|
|
|
+ Permission.ACCESS_BACKGROUND_LOCATION
|
|
|
+ )
|
|
|
+ .onGranted { permissions ->
|
|
|
+ runOnUiThread {
|
|
|
+ val dialog: ScannerFragment = ScannerFragment.getInstance()
|
|
|
+ dialog.show(supportFragmentManager, "scan_fragment")
|
|
|
}
|
|
|
+ }
|
|
|
.onDenied({ permissions ->
|
|
|
if (AndPermission.hasAlwaysDeniedPermission(this@MainActivity, permissions)) {
|
|
|
AlertDialog.Builder(this)
|
|
|
- .setTitle(getString(R.string.permission_required))
|
|
|
- .setMessage(getString(R.string.permission_location_info))
|
|
|
- .setPositiveButton("OK") { dialog: DialogInterface?, which: Int -> onPermissionSettings() }
|
|
|
- .setNegativeButton("Cancel", null)
|
|
|
- .show()
|
|
|
+ .setTitle(getString(R.string.permission_required))
|
|
|
+ .setMessage(getString(R.string.permission_location_info))
|
|
|
+ .setPositiveButton("OK") { dialog: DialogInterface?, which: Int -> onPermissionSettings() }
|
|
|
+ .setNegativeButton("Cancel", null)
|
|
|
+ .show()
|
|
|
}
|
|
|
})
|
|
|
- .start()
|
|
|
+ .start()
|
|
|
} else {
|
|
|
AlertDialog.Builder(this)
|
|
|
- .setTitle(getString(R.string.location_permission_title))
|
|
|
- .setMessage(getString(R.string.location_permission_info))
|
|
|
- .setPositiveButton("OK") { dialog: DialogInterface?, which: Int -> onEnableLocation() }
|
|
|
- .setNegativeButton("Cancel", null)
|
|
|
- .show()
|
|
|
+ .setTitle(getString(R.string.location_permission_title))
|
|
|
+ .setMessage(getString(R.string.location_permission_info))
|
|
|
+ .setPositiveButton("OK") { dialog: DialogInterface?, which: Int -> onEnableLocation() }
|
|
|
+ .setNegativeButton("Cancel", null)
|
|
|
+ .show()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -235,8 +219,8 @@ class MainActivity : AppCompatActivity() {
|
|
|
var locationMode = Settings.Secure.LOCATION_MODE_OFF
|
|
|
try {
|
|
|
locationMode = Settings.Secure.getInt(
|
|
|
- context.contentResolver,
|
|
|
- Settings.Secure.LOCATION_MODE
|
|
|
+ context.contentResolver,
|
|
|
+ Settings.Secure.LOCATION_MODE
|
|
|
)
|
|
|
} catch (e: SettingNotFoundException) {
|
|
|
// do nothing
|
|
|
@@ -277,9 +261,9 @@ class MainActivity : AppCompatActivity() {
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
- fun onDeviceSelected(device: BluetoothDevice?, name: String?) {
|
|
|
+ override fun onDeviceSelected(device: BluetoothDevice?, name: String?) {
|
|
|
mManager!!.connect(device, false)
|
|
|
- mTvDeviceName?.setText(getString(R.string.device_name, name))
|
|
|
+// mTvDeviceName?.setText(getString(R.string.device_name, name))
|
|
|
}
|
|
|
|
|
|
fun onError(device: BluetoothDevice, message: String, errorCode: Int) {
|
|
|
@@ -303,3 +287,4 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
|
|
+
|