Skip to content

Commit

Permalink
优化系统浮窗的管理方式
Browse files Browse the repository at this point in the history
  • Loading branch information
princekin-f committed Dec 8, 2019
1 parent a965280 commit 50ea802
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 337 deletions.
2 changes: 1 addition & 1 deletion .idea/markdown-navigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 6 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- **支持默认位置的设定,支持对齐方式和偏移量的设定**
- **支持创建多个单页面浮窗、多个系统浮窗,Tag进行区分**
- **支持出入动画的设定,有默认动画,可自行替换(策略模式)**
- **根据浮窗复杂度、重要性,可自主选择前后台Service**
- **使用简单、链式调用、可轻松修改浮窗View**
- **支持Kotlin DSL,可按需回调状态,摆脱Java的繁琐**
- **支持xml直接使用,满足拖拽控件的需求**
Expand Down Expand Up @@ -45,7 +44,7 @@ allprojects {
- **在应用模块的`build.gradle`添加:**
```
dependencies {
implementation 'com.github.princekin-f:EasyFloat:1.1.3'
implementation 'com.github.princekin-f:EasyFloat:1.2.0'
}
```

Expand All @@ -56,31 +55,19 @@ EasyFloat.with(this).setLayout(R.layout.float_test).show()

## 关于初始化:
- 全局初始化为非必须;
- 当浮窗为仅前台显示,或者设置了浮窗过滤页面;
- **当浮窗为仅前台显示,或者设置了浮窗过滤页面;**
- 需要在项目的`Application`中进行全局初始化,进行页面生命周期检测。
```
EasyFloat.init(this, isDebug)
```

## 关于权限声明:
- 权限声明为非必须;
- 如果使用到系统浮窗`ShowPattern.ALL_TIME``ShowPattern.FOREGROUND`);
- **当使用到系统浮窗`ShowPattern.ALL_TIME``ShowPattern.FOREGROUND`);**
- 需要在`AndroidManifest.xml`进行权限声明。
```
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
```
- 在使用到系统浮窗的情况下,不仅要声明浮窗权限,还要声明启动系统浮窗的服务;
- **该服务和上述系统浮窗权限,成对出现。**
```
<service android:name="com.lzf.easyfloat.service.FloatService" />
```
### 关于前台Service:
- 可根据系统浮窗的重要性和复杂度,选择是否开启前台Service(默认后台Service);
-`Android 9.0`开始,前台Service需要在`AndroidManifest.xml`进行权限声明。
```
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
```
**PS:前台Service会在通知栏创建一条消息,有默认实现,也可进行消息自定义。**

## 完整使用示例:
```
Expand Down Expand Up @@ -109,8 +96,6 @@ EasyFloat.with(this)
.setAppFloatAnimator(AppFloatDefaultAnimator())
// 设置系统浮窗的不需要显示的页面
.setFilter(MainActivity::class.java, SecondActivity::class.java)
// 是否启动前台Service,仅针对系统浮窗;有默认的Notification,可不传
.startForeground(true, floatNotification(this))
// 浮窗的一些状态回调,如:创建结果、显示、隐藏、销毁、touchEvent、拖拽过程、拖拽结束。
// ps:通过Kotlin DSL实现的回调,可以按需复写方法,用到哪个写哪个
.registerCallback {
Expand Down Expand Up @@ -188,13 +173,13 @@ getFloatView(activity: Activity? = null, tag: String? = null)
### 系统浮窗的相关API:
```
// 关闭浮窗
dismissAppFloat(context: Context, tag: String? = null)
dismissAppFloat(tag: String? = null)
// 隐藏浮窗
hideAppFloat(context: Context, tag: String? = null)
hideAppFloat(tag: String? = null)
// 显示浮窗
showAppFloat(context: Context, tag: String? = null)
showAppFloat(tag: String? = null)
// 设置是否可拖拽
appFloatDragEnable(dragEnable: Boolean, tag: String? = null)
Expand Down Expand Up @@ -247,10 +232,6 @@ InputMethodUtils.closedInputMethod(tag)
</com.lzf.easyfloat.widget.activityfloat.FloatingView>
```
- `1.0.4`及以下需要为FloatingView设置点击事件,不然无法拖拽:
```
floatingView.setOnClickListener {}
```

## 关于混淆:
```
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.0:
- 优化系统浮窗的管理方式。

#### v 1.1.3:
- 优化部分全面屏手机,系统浮窗不能拖到底部的问题。

Expand Down
30 changes: 6 additions & 24 deletions easyfloat/src/main/java/com/lzf/easyfloat/EasyFloat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ package com.lzf.easyfloat

import android.app.Activity
import android.app.Application
import android.app.Notification
import android.content.Context
import android.view.View
import com.lzf.easyfloat.data.FloatConfig
import com.lzf.easyfloat.enums.ShowPattern
import com.lzf.easyfloat.enums.SidePattern
import com.lzf.easyfloat.interfaces.*
import com.lzf.easyfloat.interfaces.OnPermissionResult
import com.lzf.easyfloat.permission.PermissionUtils
import com.lzf.easyfloat.service.FloatService
import com.lzf.easyfloat.utils.floatNotification
import com.lzf.easyfloat.utils.LifecycleUtils
import com.lzf.easyfloat.interfaces.FloatCallbacks
import com.lzf.easyfloat.utils.logger
import com.lzf.easyfloat.widget.activityfloat.ActivityFloatManager
import com.lzf.easyfloat.widget.appfloat.FloatManager
import java.lang.ref.WeakReference

/**
Expand Down Expand Up @@ -93,24 +90,21 @@ class EasyFloat {
*/
@JvmStatic
@JvmOverloads
fun dismissAppFloat(context: Context, tag: String? = null) =
FloatService.dismiss(context, tag)
fun dismissAppFloat(tag: String? = null) = FloatManager.dismiss(tag)

/**
* 隐藏系统浮窗,发送广播消息,在Service内部接收广播
*/
@JvmStatic
@JvmOverloads
fun hideAppFloat(context: Context, tag: String? = null) =
FloatService.setVisible(context, false, tag, false)
fun hideAppFloat(tag: String? = null) = FloatManager.visible(false, tag, false)

/**
* 显示系统浮窗,发送广播消息,在Service内部接收广播
*/
@JvmStatic
@JvmOverloads
fun showAppFloat(context: Context, tag: String? = null) =
FloatService.setVisible(context, true, tag)
fun showAppFloat(tag: String? = null) = FloatManager.visible(true, tag)

/**
* 设置系统浮窗是否可拖拽,先获取浮窗的config,后修改相应属性
Expand Down Expand Up @@ -164,8 +158,7 @@ class EasyFloat {
/**
* 获取系统浮窗的config
*/
private fun getConfig(tag: String?) =
FloatService.floatMap[tag ?: FloatService.DEFAULT_TAG]?.config
private fun getConfig(tag: String?) = FloatManager.getAppFloatManager(tag)?.config
}


Expand Down Expand Up @@ -275,17 +268,6 @@ class EasyFloat {
return this
}

// 是否启动前台Service,会在通知栏创建一个通知,仅针对系统浮窗有效
@JvmOverloads
fun startForeground(
startForeground: Boolean,
notification: Notification? = floatNotification(activity)
): Builder {
config.startForeground = startForeground
config.notification = notification
return this
}

/**
* 创建浮窗,包括Activity浮窗和系统浮窗,如若系统浮窗无权限,先进行权限申请
*/
Expand Down Expand Up @@ -316,7 +298,7 @@ class EasyFloat {
/**
* 通过Service创建系统浮窗
*/
private fun createAppFloat() = FloatService.startService(activity, config)
private fun createAppFloat() = FloatManager.create(activity, config)

/**
* 申请浮窗权限的结果回调
Expand Down
10 changes: 2 additions & 8 deletions easyfloat/src/main/java/com/lzf/easyfloat/data/FloatConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lzf.easyfloat.data

import android.app.Notification
import android.view.View
import com.lzf.easyfloat.anim.AppFloatDefaultAnimator
import com.lzf.easyfloat.anim.DefaultAnimator
Expand Down Expand Up @@ -69,12 +68,7 @@ data class FloatConfig(
val filterSet: MutableSet<String> = mutableSetOf(),
// 是否设置,当前创建的页面也被过滤
internal var filterSelf: Boolean = false,
// 是否需要显示,当过滤信息匹配上时,该值为false
internal var needShow: Boolean = true,

// 是否启动前台Service
var startForeground: Boolean = false,
// 用于前台Service的通知栏消息
var notification: Notification? = null
// 是否需要显示,当过滤信息匹配上时,该值为false(用户手动调用隐藏,该值也为false,相当于手动过滤)
internal var needShow: Boolean = true

)
163 changes: 0 additions & 163 deletions easyfloat/src/main/java/com/lzf/easyfloat/service/FloatService.kt

This file was deleted.

Loading

0 comments on commit 50ea802

Please sign in to comment.