|
|
@@ -13,6 +13,7 @@ import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
import android.provider.Settings
|
|
|
import android.provider.Settings.SettingNotFoundException
|
|
|
+import android.view.WindowManager
|
|
|
import android.widget.Button
|
|
|
import android.widget.TextView
|
|
|
import android.widget.Toast
|
|
|
@@ -38,6 +39,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
+ setStatusBarColor()
|
|
|
// 首次加载
|
|
|
FirstRun()
|
|
|
|
|
|
@@ -48,6 +50,13 @@ class MainActivity : AppCompatActivity() {
|
|
|
linkHeartBand()
|
|
|
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ fun setStatusBarColor() {
|
|
|
+ val window = window
|
|
|
+ window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
|
|
+ window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
|
|
+ window.statusBarColor = resources.getColor(R.color.blue)
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -93,10 +102,19 @@ class MainActivity : AppCompatActivity() {
|
|
|
}
|
|
|
|
|
|
private fun login() {
|
|
|
- val login = 1
|
|
|
- if (login == 1) {
|
|
|
- val LoginActivityIntent = Intent(this, LoginActivity::class.java)
|
|
|
- startActivity(LoginActivityIntent)
|
|
|
+// 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
|
|
|
+ if (loginState) {
|
|
|
+ sharedPreferences.edit().putBoolean("token", false).commit()
|
|
|
+ startActivity(Intent(this, LoginActivity::class.java))
|
|
|
+ } else {
|
|
|
+ setContentView(R.layout.activity_main)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -168,9 +186,9 @@ class MainActivity : AppCompatActivity() {
|
|
|
AndPermission.with(this)
|
|
|
.runtime()
|
|
|
.permission(
|
|
|
- Permission.ACCESS_FINE_LOCATION,
|
|
|
- Permission.ACCESS_COARSE_LOCATION,
|
|
|
- Permission.ACCESS_BACKGROUND_LOCATION
|
|
|
+ Permission.ACCESS_FINE_LOCATION,
|
|
|
+ Permission.ACCESS_COARSE_LOCATION,
|
|
|
+ Permission.ACCESS_BACKGROUND_LOCATION
|
|
|
)
|
|
|
.onGranted { permissions ->
|
|
|
runOnUiThread {
|
|
|
@@ -181,11 +199,11 @@ class MainActivity : AppCompatActivity() {
|
|
|
.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()
|
|
|
@@ -203,8 +221,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
|