|
|
@@ -6,6 +6,7 @@ import android.content.ComponentCallbacks
|
|
|
import android.content.res.Configuration
|
|
|
import android.content.res.Resources
|
|
|
import android.os.Build
|
|
|
+import android.os.Bundle
|
|
|
import me.jessyan.autosize.AutoSize
|
|
|
import me.jessyan.autosize.AutoSizeConfig
|
|
|
import me.jessyan.autosize.onAdaptListener
|
|
|
@@ -52,6 +53,8 @@ object ScreenAutoSizeUtil {
|
|
|
//记录当前App是否需要重启
|
|
|
private var mNeedRestart = false
|
|
|
|
|
|
+ private var mCheckNeedRestart = true
|
|
|
+
|
|
|
/**
|
|
|
* App会监听Config
|
|
|
*/
|
|
|
@@ -104,7 +107,9 @@ object ScreenAutoSizeUtil {
|
|
|
//注册配置变化监听
|
|
|
app.registerComponentCallbacks(object : ComponentCallbacks {
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
- checkIfNeedRestart(newConfig)
|
|
|
+ if (mCheckNeedRestart) {
|
|
|
+ checkIfNeedRestart(newConfig)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onLowMemory() {
|
|
|
@@ -112,9 +117,33 @@ object ScreenAutoSizeUtil {
|
|
|
}
|
|
|
})
|
|
|
AppUtil.registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacksExt {
|
|
|
+
|
|
|
+ override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
|
|
+ super.onActivityCreated(activity, savedInstanceState)
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
+ if (activity.isInPictureInPictureMode) {
|
|
|
+ //画中画
|
|
|
+ mCheckNeedRestart = false
|
|
|
+ AutoSizeConfig.getInstance().stop(activity)
|
|
|
+ AutoSizeLog.w("autoSize stop adapt")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (activity.isInMultiWindowMode) {
|
|
|
+ //多窗口
|
|
|
+ mCheckNeedRestart = false
|
|
|
+ AutoSizeConfig.getInstance().stop(activity)
|
|
|
+ AutoSizeLog.w("autoSize stop adapt")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mCheckNeedRestart = true
|
|
|
+ AutoSizeConfig.getInstance().restart()
|
|
|
+ AutoSizeLog.w("autoSize restart")
|
|
|
+ }
|
|
|
+
|
|
|
override fun onEnterForeGround() {
|
|
|
super.onEnterForeGround()
|
|
|
- if (needReStart()) {
|
|
|
+ if (mCheckNeedRestart && needReStart()) {
|
|
|
AutoSizeLog.d("AppUtil.rebootApp()")
|
|
|
AppUtil.rebootApp()
|
|
|
}
|