|
@@ -1,10 +1,14 @@
|
|
package com.develop.common.ui
|
|
package com.develop.common.ui
|
|
|
|
|
|
|
|
+import android.content.BroadcastReceiver
|
|
import android.content.Context
|
|
import android.content.Context
|
|
|
|
+import android.content.Intent
|
|
|
|
+import android.content.IntentFilter
|
|
import android.content.res.Resources
|
|
import android.content.res.Resources
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
import android.os.IBinder
|
|
import android.os.IBinder
|
|
import android.os.Looper
|
|
import android.os.Looper
|
|
|
|
+import android.util.Log
|
|
import android.view.MotionEvent
|
|
import android.view.MotionEvent
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.view.inputmethod.InputMethodManager
|
|
import android.view.inputmethod.InputMethodManager
|
|
@@ -13,6 +17,7 @@ import androidx.viewbinding.ViewBinding
|
|
import com.develop.base.ext.navigateTo
|
|
import com.develop.base.ext.navigateTo
|
|
import com.develop.base.mvvm.BaseBindingActivity
|
|
import com.develop.base.mvvm.BaseBindingActivity
|
|
import com.develop.base.util.MMkvUtils
|
|
import com.develop.base.util.MMkvUtils
|
|
|
|
+import com.develop.base.util.TopResumedAtyHolder
|
|
import com.develop.common.R
|
|
import com.develop.common.R
|
|
import com.develop.common.dialog.CancelConfirmDialog
|
|
import com.develop.common.dialog.CancelConfirmDialog
|
|
import com.develop.common.dialog.PlainDialogView
|
|
import com.develop.common.dialog.PlainDialogView
|
|
@@ -25,13 +30,17 @@ import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevPromptEvent
|
|
import me.jessyan.autosize.AutoSizeCompat
|
|
import me.jessyan.autosize.AutoSizeCompat
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.Subscribe
|
|
import org.greenrobot.eventbus.Subscribe
|
|
-import com.develop.base.util.TopResumedAtyHolder
|
|
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 带业务逻辑的基类
|
|
* 带业务逻辑的基类
|
|
*/
|
|
*/
|
|
abstract class CommonBindingActivity<T : ViewBinding> : BaseBindingActivity<T>() {
|
|
abstract class CommonBindingActivity<T : ViewBinding> : BaseBindingActivity<T>() {
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private var screenReceiver: BroadcastReceiver? = null
|
|
|
|
+
|
|
|
|
+
|
|
protected var hasShowScreenSaver = false
|
|
protected var hasShowScreenSaver = false
|
|
|
|
|
|
private val plainDialogView by lazy {
|
|
private val plainDialogView by lazy {
|
|
@@ -52,6 +61,29 @@ abstract class CommonBindingActivity<T : ViewBinding> : BaseBindingActivity<T>()
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
EventBus.getDefault().register(this)
|
|
EventBus.getDefault().register(this)
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ screenReceiver = object : BroadcastReceiver() {
|
|
|
|
+ override fun onReceive(context: Context, intent: Intent) {
|
|
|
|
+ val action = intent.action
|
|
|
|
+
|
|
|
|
+ if (action == Intent.ACTION_SCREEN_ON) {
|
|
|
|
+ // 处理屏幕亮起事件
|
|
|
|
+ Log.i("0525","ACTION_SCREEN_ON")
|
|
|
|
+ locktime = System.currentTimeMillis()
|
|
|
|
+ } else if (action == Intent.ACTION_SCREEN_OFF) {
|
|
|
|
+ // 处理屏幕关闭事件
|
|
|
|
+ Log.i("0525","ACTION_SCREEN_OFF")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ val intentFilter = IntentFilter().apply {
|
|
|
|
+ addAction(Intent.ACTION_SCREEN_ON)
|
|
|
|
+ addAction(Intent.ACTION_SCREEN_OFF)
|
|
|
|
+ }
|
|
|
|
+ registerReceiver(screenReceiver, intentFilter)
|
|
|
|
+
|
|
val time = MMkvUtils.getInt(SCREENSAVER)
|
|
val time = MMkvUtils.getInt(SCREENSAVER)
|
|
if (time != 0) {
|
|
if (time != 0) {
|
|
screenSaverTime = time
|
|
screenSaverTime = time
|
|
@@ -76,15 +108,33 @@ abstract class CommonBindingActivity<T : ViewBinding> : BaseBindingActivity<T>()
|
|
} else {
|
|
} else {
|
|
stopScreenSaverCount()
|
|
stopScreenSaverCount()
|
|
}
|
|
}
|
|
|
|
+ val intentFilter = IntentFilter()
|
|
|
|
+ intentFilter.addAction(Intent.ACTION_SCREEN_ON)
|
|
|
|
+ intentFilter.addAction(Intent.ACTION_SCREEN_OFF)
|
|
|
|
+ registerReceiver(screenReceiver, intentFilter)
|
|
}
|
|
}
|
|
|
|
|
|
override fun onPause() {
|
|
override fun onPause() {
|
|
super.onPause()
|
|
super.onPause()
|
|
isResume = false
|
|
isResume = false
|
|
stopScreenSaverCount()
|
|
stopScreenSaverCount()
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ var lock = false
|
|
|
|
+ var locktime:Long = 0
|
|
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
|
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(((System.currentTimeMillis() - locktime) < 3000)){
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ locktime = 0L
|
|
|
|
+ lock = false
|
|
|
|
+
|
|
if (ev.x == 0f && ev.y == 0f) {
|
|
if (ev.x == 0f && ev.y == 0f) {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
@@ -264,5 +314,7 @@ abstract class CommonBindingActivity<T : ViewBinding> : BaseBindingActivity<T>()
|
|
EventBus.getDefault().unregister(this)
|
|
EventBus.getDefault().unregister(this)
|
|
GlobalDevEvent.dismissDialog()
|
|
GlobalDevEvent.dismissDialog()
|
|
dismissPlainDialog()
|
|
dismissPlainDialog()
|
|
|
|
+ if(screenReceiver != null) unregisterReceiver(screenReceiver)
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|