Skip to content

Commit

Permalink
优化细节
Browse files Browse the repository at this point in the history
  • Loading branch information
princekin-f committed Jan 10, 2020
1 parent 46e5d70 commit 1675059
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ allprojects {
- **在应用模块的`build.gradle`添加:**
```
dependencies {
implementation 'com.github.princekin-f:EasyFloat:1.2.7'
implementation 'com.github.princekin-f:EasyFloat:1.2.8'
}
```

Expand Down
3 changes: 3 additions & 0 deletions UpdateDoc.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 版本更新日志
#### v 1.2.8:
- 优化细节。

#### v 1.2.7:
- 优化浮窗闪烁,横屏不能拖拽到底等问题。

Expand Down
26 changes: 16 additions & 10 deletions easyfloat/src/main/java/com/lzf/easyfloat/utils/LifecycleUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,30 @@ internal object LifecycleUtils {
application.registerActivityLifecycleCallbacks(object :
Application.ActivityLifecycleCallbacks {

override fun onActivityPaused(activity: Activity?) {}
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {}

override fun onActivityStarted(activity: Activity?) {
// 计算启动的activity数目
if (activity != null) activityCount++
}

// 每次都要判断当前页面是否需要显示
override fun onActivityResumed(activity: Activity?) = checkShow(activity)

override fun onActivityStarted(activity: Activity?) {}
override fun onActivityPaused(activity: Activity?) {}

override fun onActivityStopped(activity: Activity?) {
if (activity != null) {
// 计算关闭的activity数目,并判断当前App是否处于后台
activityCount--
checkHide()
}
}

override fun onActivityDestroyed(activity: Activity?) {}

override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {}

// 主要判断当前App是否处于后台
override fun onActivityStopped(activity: Activity?) = checkHide(activity)

override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {}
})
}

Expand All @@ -44,7 +53,6 @@ internal object LifecycleUtils {
*/
private fun checkShow(activity: Activity?) {
if (activity == null) return
activityCount++
FloatManager.floatMap.forEach { (tag, manager) ->
when {
// 仅后台显示模式下,隐藏浮窗
Expand All @@ -60,9 +68,7 @@ internal object LifecycleUtils {
/**
* 判断浮窗是否需要隐藏
*/
private fun checkHide(activity: Activity?) {
if (activity == null) return
activityCount--
private fun checkHide() {
if (isForeground()) return
FloatManager.floatMap.forEach { (tag, manager) ->
// 当app处于后台时,不是仅前台显示的浮窗,都需要显示
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.lzf.easyfloat.data.FloatConfig
import com.lzf.easyfloat.enums.ShowPattern
import com.lzf.easyfloat.interfaces.OnFloatTouchListener
import com.lzf.easyfloat.utils.DisplayUtils
import com.lzf.easyfloat.utils.Logger

/**
* @author: liuzhenfeng
Expand Down Expand Up @@ -210,7 +211,10 @@ internal class AppFloatManager(val context: Context, var config: FloatConfig) {
}
})
animator.start()
} else floatingView.visibility = View.VISIBLE
} else {
floatingView.visibility = View.VISIBLE
windowManager.updateViewLayout(floatingView, params)
}
}

/**
Expand Down Expand Up @@ -242,12 +246,14 @@ internal class AppFloatManager(val context: Context, var config: FloatConfig) {
/**
* 退出动画执行结束/没有退出动画,一些回调、移除、检测是否需要关闭Service等操作
*/
private fun floatOver() {
private fun floatOver() = try {
config.isAnim = false
config.callbacks?.dismiss()
config.floatCallbacks?.builder?.dismiss?.invoke()
windowManager.removeView(frameLayout)
FloatManager.remove(config.floatTag)
windowManager.removeView(frameLayout)
} catch (e: Exception) {
Logger.e("浮窗关闭出现异常:$e")
}

}
Binary file modified example/release/EasyFloat.apk
Binary file not shown.

0 comments on commit 1675059

Please sign in to comment.