Skip to content

Commit 60abd21

Browse files
committed
修复外层无法传入特定类名来取消悬浮窗问题
新增判断当前是否有特定悬浮窗正在显示的 API
1 parent 46053d3 commit 60abd21

File tree

5 files changed

+88
-27
lines changed

5 files changed

+88
-27
lines changed

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* 博客地址:[悬浮窗需求终结者](https://www.jianshu.com/p/247d705b87b6)
66

7-
* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/EasyWindow/releases/download/10.6/EasyWindow.apk)
7+
* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/EasyWindow/releases/download/10.62/EasyWindow.apk)
88

99
![](picture/demo_code.png)
1010

@@ -49,7 +49,7 @@ android {
4949
5050
dependencies {
5151
// 悬浮窗框架:https://github.com/getActivity/EasyWindow
52-
implementation 'com.github.getActivity:EasyWindow:10.6'
52+
implementation 'com.github.getActivity:EasyWindow:10.62'
5353
}
5454
```
5555

@@ -183,7 +183,7 @@ public final class ActivityWindowLifecycle implements Application.ActivityLifecy
183183

184184
* 对象方法
185185

186-
```
186+
```java
187187
// 设置悬浮窗宽度
188188
setWidth(int width)
189189
// 设置悬浮窗高度
@@ -220,12 +220,12 @@ setWindowType(int type)
220220

221221
* 静态方法
222222

223-
```
223+
```java
224224
// 取消所有正在显示的悬浮窗
225225
EasyWindow.cancelAll()
226226

227227
// 取消特定类名的悬浮窗
228-
EasyWindow.cancelByClass(Class<EasyWindow<?>> clazz)
228+
EasyWindow.cancelByClass(Class<? extends EasyWindow<?>> clazz)
229229

230230
// 取消特定标记的悬浮窗
231231
EasyWindow.cancelByTag(String tag)
@@ -234,10 +234,19 @@ EasyWindow.cancelByTag(String tag)
234234
EasyWindow.recycleAll()
235235

236236
// 回收特定类名的悬浮窗
237-
EasyWindow.recycleByClass(Class<EasyWindow<?>> clazz)
237+
EasyWindow.recycleByClass(Class<? extends EasyWindow<?>> clazz)
238238

239239
// 回收特定标记的悬浮窗
240240
EasyWindow.recycleByTag(String tag)
241+
242+
// 判断当前是否有悬浮窗正在显示
243+
EasyWindow.existShowing()
244+
245+
// 判断当前是否有特定类名的悬浮窗正在显示
246+
EasyWindow.existShowingByClass(Class<? extends EasyWindow<?>> clazz)
247+
248+
// 判断当前是否有特定标记的悬浮窗正在显示
249+
EasyWindow.existShowingByTag(String tag)
241250
```
242251

243252
#### 框架混淆规则
@@ -302,18 +311,6 @@ EasyWindow.recycleByTag(String tag)
302311

303312
![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_ali.png) ![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_wechat.png)
304313

305-
#### 广告区
306-
307-
* 我现在任腾讯云服务器推广大使,大家如果有购买服务器的需求,可以通过下面的链接购买
308-
309-
[![](https://upload-dianshi-1255598498.file.myqcloud.com/upload/nodir/345X200-9ae456f58874df499adf7c331c02cb0fed12b81d.jpg)](https://curl.qcloud.com/A6cYskvv)
310-
311-
[【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中](https://curl.qcloud.com/A6cYskvv)
312-
313-
[![](https://upload-dianshi-1255598498.file.myqcloud.com/345-200-b28f7dee9552f4241ea6a543f15a9798049701d4.jpg)](https://curl.qcloud.com/up4fQsdn)
314-
315-
[【腾讯云】中小企业福利专场,多款刚需产品,满足企业通用场景需求](https://curl.qcloud.com/up4fQsdn)
316-
317314
## License
318315

319316
```text

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hjq.window.demo"
88
minSdkVersion 16
99
targetSdkVersion 33
10-
versionCode 1006
11-
versionName "10.6"
10+
versionCode 1062
11+
versionName "10.62"
1212
}
1313

1414
// 支持 Java JDK 8

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ android {
55

66
defaultConfig {
77
minSdkVersion 14
8-
versionCode 1006
9-
versionName "10.6"
8+
versionCode 1062
9+
versionName "10.62"
1010
}
1111

1212
// 支持 JDK 1.8

library/src/main/java/com/hjq/window/EasyWindow.java

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static synchronized void cancelAll() {
7777
/**
7878
* 取消特定类名的悬浮窗
7979
*/
80-
public static synchronized void cancelByClass(Class<EasyWindow<?>> clazz) {
80+
public static synchronized void cancelByClass(Class<? extends EasyWindow<?>> clazz) {
8181
if (clazz == null) {
8282
return;
8383
}
@@ -131,7 +131,7 @@ public static synchronized void recycleAll() {
131131
/**
132132
* 回收特定类名的悬浮窗
133133
*/
134-
public static void recycleByClass(Class<EasyWindow<?>> clazz) {
134+
public static synchronized void recycleByClass(Class<? extends EasyWindow<?>> clazz) {
135135
if (clazz == null) {
136136
return;
137137
}
@@ -155,7 +155,7 @@ public static void recycleByClass(Class<EasyWindow<?>> clazz) {
155155
/**
156156
* 回收特定标记的悬浮窗
157157
*/
158-
public static void recycleByTag(String tag) {
158+
public static synchronized void recycleByTag(String tag) {
159159
if (tag == null) {
160160
return;
161161
}
@@ -177,6 +177,71 @@ public static void recycleByTag(String tag) {
177177
}
178178
}
179179

180+
/**
181+
* 判断当前是否有悬浮窗正在显示
182+
*/
183+
public static synchronized boolean existShowing() {
184+
Iterator<EasyWindow<?>> iterator = sWindowInstanceSet.iterator();
185+
while (iterator.hasNext()) {
186+
EasyWindow<?> easyWindow = iterator.next();
187+
if (easyWindow == null) {
188+
continue;
189+
}
190+
191+
if (easyWindow.isShowing()) {
192+
return true;
193+
}
194+
}
195+
return false;
196+
}
197+
198+
/**
199+
* 判断当前是否有特定类名的悬浮窗正在显示
200+
*/
201+
public static synchronized boolean existShowingByClass(Class<? extends EasyWindow<?>> clazz) {
202+
if (clazz == null) {
203+
return false;
204+
}
205+
Iterator<EasyWindow<?>> iterator = sWindowInstanceSet.iterator();
206+
while (iterator.hasNext()) {
207+
EasyWindow<?> easyWindow = iterator.next();
208+
if (easyWindow == null) {
209+
continue;
210+
}
211+
if (!clazz.equals(easyWindow.getClass())) {
212+
continue;
213+
}
214+
if (easyWindow.isShowing()) {
215+
return true;
216+
}
217+
}
218+
return false;
219+
}
220+
221+
/**
222+
* 判断当前是否有特定标记的悬浮窗正在显示
223+
*/
224+
public static synchronized boolean existShowingByTag(String tag) {
225+
if (tag == null) {
226+
return false;
227+
}
228+
229+
Iterator<EasyWindow<?>> iterator = sWindowInstanceSet.iterator();
230+
while (iterator.hasNext()) {
231+
EasyWindow<?> easyWindow = iterator.next();
232+
if (easyWindow == null) {
233+
continue;
234+
}
235+
if (!tag.equals(easyWindow.getTag())) {
236+
continue;
237+
}
238+
if (easyWindow.isShowing()) {
239+
return true;
240+
}
241+
}
242+
return false;
243+
}
244+
180245
/** 上下文 */
181246
private Context mContext;
182247
/** 根布局 */
@@ -269,7 +334,6 @@ private EasyWindow(Context context) {
269334
// 需要注意的是设置了 FLAG_NOT_TOUCH_MODAL 必须要设置 FLAG_NOT_FOCUSABLE,否则就会导致用户按返回键无效
270335
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
271336
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
272-
273337
// 将当前实例添加到静态集合中
274338
sWindowInstanceSet.add(this);
275339
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app', ':library'
1+
include ':app', ':library'

0 commit comments

Comments
 (0)