Skip to content
Permalink
Browse files

Add getFloatView.

  • Loading branch information...
princekin-f committed Sep 6, 2019
1 parent 93fdb2d commit f9b934bd223889904ca57035677c50f08715be55
@@ -1,4 +1,4 @@
## EasyFloat:Android浮窗框架
## EasyFloat:Android悬浮窗框架
[![](https://jitpack.io/v/princekin-f/EasyFloat.svg)](https://jitpack.io/#princekin-f/EasyFloat)
> [EasyFloat:浮窗从未如此简单](https://www.jianshu.com/p/7d1a7c82094a)
@@ -38,7 +38,7 @@ allprojects {
- **在应用模块的`build.gradle`添加:**
```
dependencies {
implementation 'com.github.princekin-f:EasyFloat:1.0.6'
implementation 'com.github.princekin-f:EasyFloat:1.0.7'
}
```

@@ -249,6 +249,9 @@ floatingView.setOnClickListener {}

---
## 更新日志:
#### v 1.0.7:
- 优化页面过滤细节上的不足。

#### v 1.0.6:
- 新增浮窗`View`的获取,方便`View`的修改。

@@ -252,7 +252,13 @@ class EasyFloat {

// 设置需要过滤的Activity,仅对系统浮窗有效
fun setFilter(vararg clazz: Class<*>): Builder {
clazz.forEach { config.filterSet.add(it.name) }
clazz.forEach {
config.filterSet.add(it.name)
if (it.name == activity.componentName.className) {
// 过滤掉当前Activity
config.filterSelf = true
}
}
return this
}

@@ -65,6 +65,8 @@ data class FloatConfig(

// 不需要显示系统浮窗的页面集合,参数为类名
val filterSet: MutableSet<String> = mutableSetOf(),
// 是否设置,当前创建的页面也被过滤
internal var filterSelf: Boolean = false,
// 是否需要显示,当过滤信息匹配上时,该值为false
internal var needShow: Boolean = true,

@@ -40,7 +40,7 @@ internal object LifecycleUtils {
}
}

// 当过滤信息没有匹配上时,需要发送广播,反正修改needShow为默认值
// 当过滤信息没有匹配上时,需要发送广播,反之修改needShow为默认值
if (manager.config.needShow) setVisible(tag = tag)
else manager.config.needShow = true
}
@@ -57,7 +57,13 @@ internal object LifecycleUtils {
if (isForeground()) return
// 当app处于后台时,检测是否有仅前台显示的系统浮窗
FloatService.floatMap.forEach { (tag, manager) ->
run { if (manager.config.showPattern == ShowPattern.FOREGROUND) setVisible(tag = tag) }
run {
when (manager.config.showPattern) {
ShowPattern.ALL_TIME -> setVisible(true, tag)
ShowPattern.FOREGROUND -> setVisible(tag = tag)
else -> { }
}
}
}
}

@@ -50,9 +50,9 @@ internal class AppFloatManager(val context: Context, var config: FloatConfig) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY else WindowManager.LayoutParams.TYPE_PHONE
format = PixelFormat.RGBA_8888
gravity = Gravity.START or Gravity.TOP
// 设置浮窗以外的触摸事件可以传递给后面的窗口、不自动获取焦点、可以延伸到屏幕外(设置动画时能用到,动画结束需要去除该属性,不然旋转屏幕可能置于屏幕外部)
// 设置浮窗以外的触摸事件可以传递给后面的窗口、不自动获取焦点
flags =
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
width =
if (config.widthMatch) WindowManager.LayoutParams.MATCH_PARENT else WindowManager.LayoutParams.WRAP_CONTENT
height =
@@ -89,7 +89,7 @@ internal class AppFloatManager(val context: Context, var config: FloatConfig) {
frameLayout?.layoutListener = object : ParentFrameLayout.OnLayoutListener {
override fun onLayout() {
setGravity(frameLayout)
enterAnim()
if (config.filterSelf) setVisible(View.GONE) else enterAnim()
}
}

@@ -185,16 +185,16 @@ internal class AppFloatManager(val context: Context, var config: FloatConfig) {
val manager: AppFloatAnimatorManager? =
AppFloatAnimatorManager(frameLayout!!, params, windowManager, config)
val animator: Animator? = manager?.enterAnim()
if (animator == null) {
// 不需要延伸到屏幕外了,防止屏幕旋转的时候,浮窗处于屏幕外
if (animator != null) {
// 可以延伸到屏幕外,动画结束需要去除该属性,不然旋转屏幕可能置于屏幕外部
params.flags =
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
} else {
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
animator.addListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {}

override fun onAnimationEnd(animation: Animator?) {
config.isAnim = false
// 不需要延伸到屏幕外了,防止屏幕旋转的时候,浮窗处于屏幕外
params.flags =
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
}

0 comments on commit f9b934b

Please sign in to comment.
You can’t perform that action at this time.