diff --git a/app/build.gradle b/app/build.gradle
index e85e6c5..30ac887 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -12,10 +12,10 @@ android {
defaultConfig {
applicationId "com.yinuo.safetywatcher"
- ndk {
- //设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so)
- abiFilters "armeabi-v7a", "x86"//, "arm64-v8a", ,"arm64-v8a","x86_64"
- }
+// ndk {
+// //设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so)
+// abiFilters "armeabi-v7a", "x86"//, "arm64-v8a", ,"arm64-v8a","x86_64"
+// }
}
viewBinding {
diff --git a/app/libs/sdkapi.jar b/app/libs/sdkapi.jar
new file mode 100644
index 0000000..c269276
Binary files /dev/null and b/app/libs/sdkapi.jar differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bb4ce33..ebd5a88 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
android:required="true" />
+
@@ -18,6 +19,7 @@
android:required="true" />
}
}
}
+
+ override fun onDestroy() {
+ super.onDestroy()
+ BatteryHelper.release(this@HomeActivity)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/BatteryHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/BatteryHelper.kt
new file mode 100644
index 0000000..6675f65
--- /dev/null
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/BatteryHelper.kt
@@ -0,0 +1,55 @@
+package com.yinuo.safetywatcher.watcher.utils
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
+import android.os.BatteryManager
+import android.util.Log
+
+object BatteryHelper {
+ private var callbacks = mutableListOf()
+ private var mLevel = -1;
+
+ private val receiver = object : BroadcastReceiver() {
+ override fun onReceive(context: Context?, intent: Intent?) {
+ val level = intent?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
+ mLevel = level!!
+ Log.i(this@BatteryHelper.javaClass.name, "onReceive level = $level")
+ callbacks.forEach {
+ if (level != null) {
+ it.onLevel(level)
+ }
+ }
+ }
+ }
+
+ fun init(context: Context) {
+ watchBattery(context)
+ }
+
+ private fun watchBattery(context: Context) {
+ val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
+ context.registerReceiver(receiver, filter)
+ }
+
+ fun addCallBack(callBack: OnBatteryLevelCallback) {
+ callbacks.add(callBack)
+ if (mLevel != -1) {
+ callBack.onLevel(mLevel)
+ }
+ }
+
+ fun removeCallback(callBack: OnBatteryLevelCallback) {
+ callbacks.remove(callBack)
+ }
+
+ fun release(context: Context) {
+ callbacks.clear()
+ context.unregisterReceiver(receiver)
+ }
+
+ interface OnBatteryLevelCallback {
+ fun onLevel(level: Int)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/LztekUtil.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/LztekUtil.kt
new file mode 100644
index 0000000..162794a
--- /dev/null
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/LztekUtil.kt
@@ -0,0 +1,16 @@
+package com.yinuo.safetywatcher.watcher.utils
+
+import com.lztek.toolkit.Lztek
+
+object LztekUtil {
+
+ private var mLztek: Lztek? = null;
+
+ fun setObject(value: Lztek) {
+ mLztek = value
+ }
+
+ fun getLztek(): Lztek {
+ return mLztek!!
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/WifiHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/WifiHelper.kt
new file mode 100644
index 0000000..5dc5077
--- /dev/null
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/WifiHelper.kt
@@ -0,0 +1,49 @@
+package com.yinuo.safetywatcher.watcher.utils
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
+import android.net.wifi.WifiManager
+import android.util.Log
+
+object WifiHelper {
+ private var callbacks = mutableListOf()
+
+ private val receiver = object : BroadcastReceiver() {
+ override fun onReceive(context: Context?, intent: Intent?) {
+ val wifiState = intent?.getIntExtra(WifiManager.EXTRA_WIFI_STATE, -1)
+ Log.i(this@WifiHelper.javaClass.name, "onReceive wifiState = $wifiState")
+ callbacks.forEach {
+ it.onEnable(wifiState == WifiManager.WIFI_STATE_ENABLED)
+ }
+ }
+ }
+
+ fun init(context: Context) {
+ watchWifi(context)
+ }
+
+ private fun watchWifi(context: Context) {
+ val filter = IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)
+ context.registerReceiver(receiver, filter)
+ }
+
+ fun addCallBack(callBack: OnWifiLevelCallback) {
+ callbacks.add(callBack)
+ }
+
+ fun removeCallback(callBack: OnWifiLevelCallback) {
+ callbacks.remove(callBack)
+ }
+
+ fun release(context: Context) {
+ callbacks.clear()
+ context.unregisterReceiver(receiver)
+ }
+
+ interface OnWifiLevelCallback {
+ fun onEnable(enable: Boolean)
+ fun onLevel(level: Int)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/view/CommonTopBar.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/view/CommonTopBar.kt
index 5358f52..d6fa510 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/view/CommonTopBar.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/view/CommonTopBar.kt
@@ -2,13 +2,14 @@ package com.yinuo.safetywatcher.watcher.view
import android.app.Activity
import android.content.Context
-import android.graphics.Color
-import android.opengl.Visibility
import android.util.AttributeSet
+import android.util.Log
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.LayoutTopbarBinding
+import com.yinuo.safetywatcher.watcher.utils.BatteryHelper
+import com.yinuo.safetywatcher.watcher.utils.WifiHelper
class CommonTopBar : LinearLayout {
constructor(context: Context?) : this(context, null)
@@ -33,12 +34,47 @@ class CommonTopBar : LinearLayout {
(context as Activity).finish()
}
}
+
+ post {
+ // watch battery
+ watchBattery()
+ watchWifi()
+ }
+ }
+
+ private val batteryCallback = object : BatteryHelper.OnBatteryLevelCallback {
+ override fun onLevel(level: Int) {
+ Log.i(this@CommonTopBar.javaClass.name, "batteryCallback onLevel = $level")
+ mBinding?.battery?.visibility = if (level > 80) VISIBLE else GONE
+ }
+ }
+
+ private fun watchBattery() {
+ BatteryHelper.addCallBack(batteryCallback)
}
+ private val wifiCallback = object : WifiHelper.OnWifiLevelCallback {
+ override fun onEnable(enable: Boolean) {
+ Log.i(this@CommonTopBar.javaClass.name, "wifiCallback onEnable = $enable")
+ mBinding?.wifi?.visibility = if (enable) VISIBLE else GONE
+ }
+
+ override fun onLevel(level: Int) {
+ Log.i(this@CommonTopBar.javaClass.name, "wifiCallback onEnable = $level")
+ }
+ }
+
+ private fun watchWifi() {
+ WifiHelper.addCallBack(wifiCallback)
+ }
open fun setTitle(title: String) {
mBinding?.backArea?.visibility = VISIBLE
mBinding?.title?.text = title
}
+ override fun onDetachedFromWindow() {
+ super.onDetachedFromWindow()
+ BatteryHelper.removeCallback(batteryCallback)
+ }
}
\ No newline at end of file