Skip to content

Commit

Permalink
update to v1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
yhaolpz committed Dec 30, 2017
1 parent ddd05ee commit 0d76c80
Show file tree
Hide file tree
Showing 19 changed files with 536 additions and 122 deletions.
84 changes: 48 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

4.应用退到后台时,悬浮窗会自动隐藏

5.位置不可变的悬浮窗无需权限申请
5.除小米外,4.4~7.0 无需权限申请

6.位置及宽高可设置百分比值,轻松适配各分辨率

Expand All @@ -37,7 +37,7 @@

```
dependencies {
compile 'com.github.yhaolpz:FloatWindow:1.0.7'
compile 'com.github.yhaolpz:FloatWindow:1.0.8'
}
```

Expand All @@ -64,35 +64,24 @@

setView 方法可设置 View 子类或 xml 布局。

**2.控件宽高**
**2.设置宽高及显示位置**

```java
FloatWindow
.with(getApplicationContext())
.setView(view)
.setWidth(100) //100px
.setHeight(Screen.width,0.2f) //屏幕宽度的 20%
.setX(100) //100px
.setY(Screen.height,0.3f) //屏幕高度的 30%
.build();

```

可设置具体数值或屏幕宽/高百分比,默认为 wrap_content。
可设置具体数值或屏幕宽/高百分比,默认宽高为 wrap_content;默认位置为屏幕左上角,x、y 为偏移量

**3.显示位置**

```java
FloatWindow
.with(getApplicationContext())
.setView(view)
.setX(100) //100px
.setY(Screen.height,0.3f) //屏幕高度的 30%
.build();

```

可设置具体数值或屏幕宽/高百分比,默认为 0,以屏幕左上角为原点。

**4.指定界面显示**
**3.指定界面显示**

```java
FloatWindow
Expand All @@ -117,6 +106,17 @@ setView 方法可设置 View 子类或 xml 布局。
.setFilter(true, BaseActivity.class)
```

**4.桌面显示**

```java
FloatWindow
.with(getApplicationContext())
.setView(view)
.setDesktopShow(true) //默认 false
.build();

```

**5.可拖动悬浮窗**

```java
Expand All @@ -130,15 +130,14 @@ setView 方法可设置 View 子类或 xml 布局。

共提供 4 种 MoveType :

MoveType.slide : 可拖动,释放后自动贴边
MoveType.slide : 可拖动,释放后自动贴边 (默认)

MoveType.back : 可拖动,释放后自动回到原位置
MoveType.back : 可拖动,释放后自动回到原位置

MoveType.active : 可拖动
MoveType.active : 可拖动

MoveType.free : 不可拖动,但可改变位置
MoveType.inactive : 不可拖动

如不设置,则为 fixed 模式,不可改变位置。

**6.悬浮窗动画**

Expand Down Expand Up @@ -171,7 +170,7 @@ MoveType.free : 不可拖动,但可改变位置

```

以上操作应待悬浮窗初始化后进行,注意不能对 fixed 模式悬浮窗修改显示位置
以上操作应待悬浮窗初始化后进行。


**8.多个悬浮窗**
Expand Down Expand Up @@ -224,46 +223,59 @@ MoveType.free : 不可拖动,但可改变位置

[sample](https://github.com/yhaolpz/FloatWindow/blob/master/sample/src/main/java/com/example/yhao/floatwindow/BaseApplication.java) 中也有示例代码。

最后:
--
![悬浮按钮图](https://raw.githubusercontent.com/yhaolpz/FixedFloatWindow/master/pay.gif)

本人已尽量去兼容更多机型,但经济有限,如果你想帮助此库,提 Issues 标出当前版本不适配的机型即可,感谢~


**更新日志**
--

**v1.0.8**

适配 4.4~8.0 及各大国产机型

支持桌面显示


**v1.0.7**

1.适配 Android 8.0
适配 Android 8.0


**v1.0.6**

1.支持悬浮窗拖动及相关动效
支持悬浮窗拖动及相关动效

2.位置及宽高可设置百分比值
位置及宽高可设置百分比值

3.更改相关类名及使用方法
更改相关类名及使用方法


**v1.0.5**

1.修复未调用show显示悬浮窗bug

修复未调用show显示悬浮窗bug


**v1.0.4**

1.返回桌面将会自动隐藏控件,无需再监听应用退到后台等操作
返回桌面将会自动隐藏控件,无需再监听应用退到后台等操作

2.新增 Activity 过滤器,可自由指定哪些界面显示,哪些界面不显示
新增 Activity 过滤器,可自由指定哪些界面显示,哪些界面不显示

3.FixedFloatWindow 类改为 FFWindow
FixedFloatWindow 类改为 FFWindow



**v1.0.3**

1.修复已知 bug
修复已知 bug

2.新增 dismiss 方法
新增 dismiss 方法

3.新增其他方案,如:所有版本都申请权限
新增其他方案,如:所有版本都申请权限



Expand Down
24 changes: 16 additions & 8 deletions floatwindow/src/main/java/com/yhao/floatwindow/FloatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
public class FloatActivity extends Activity {

private static List<PermissionListener> mPermissionListenerList;
private static PermissionListener mPermissionListener;


@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -33,23 +35,28 @@ protected void onCreate(Bundle savedInstanceState) {
private void requestAlertWindowPermission() {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 1);
startActivityForResult(intent, 756232212);
}


@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (Settings.canDrawOverlays(this)) {
mPermissionListener.onSuccess();
} else {
mPermissionListener.onFail();
if (requestCode == 756232212) {
if (PermissionUtil.hasPermissionOnActivityResult(this)) {
mPermissionListener.onSuccess();
} else {
mPermissionListener.onSuccess();
}
}
finish();
}

static synchronized void request(Context context,PermissionListener permissionListener) {
static synchronized void request(Context context, PermissionListener permissionListener) {
if (PermissionUtil.hasPermission(context)) {
permissionListener.onSuccess();
return;
}
if (mPermissionListenerList == null) {
mPermissionListenerList = new ArrayList<>();
mPermissionListener = new PermissionListener() {
Expand All @@ -58,13 +65,15 @@ public void onSuccess() {
for (PermissionListener listener : mPermissionListenerList) {
listener.onSuccess();
}
mPermissionListenerList.clear();
}

@Override
public void onFail() {
for (PermissionListener listener : mPermissionListenerList) {
listener.onFail();
}
mPermissionListenerList.clear();
}
};
Intent intent = new Intent(context, FloatActivity.class);
Expand All @@ -75,5 +84,4 @@ public void onFail() {
}


private static PermissionListener mPermissionListener;
}
29 changes: 20 additions & 9 deletions floatwindow/src/main/java/com/yhao/floatwindow/FloatLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;

/**
* Created by yhao on 17-12-1.
Expand All @@ -30,17 +31,23 @@ class FloatLifecycle extends BroadcastReceiver implements Application.ActivityLi
private int resumeCount;
private boolean appBackground;
private LifecycleListener mLifecycleListener;
private static ResumedListener sResumedListener;
private static int num = 0;


FloatLifecycle(Context applicationContext, boolean showFlag, Class[] activities,LifecycleListener lifecycleListener) {
FloatLifecycle(Context applicationContext, boolean showFlag, Class[] activities, LifecycleListener lifecycleListener) {
this.showFlag = showFlag;
this.activities = activities;
num++;
mLifecycleListener = lifecycleListener;
mHandler = new Handler();
((Application) applicationContext).registerActivityLifecycleCallbacks(this);
applicationContext.registerReceiver(this,new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
applicationContext.registerReceiver(this, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}

public static void setResumedListener(ResumedListener resumedListener) {
sResumedListener = resumedListener;
}

private boolean needShow(Activity activity) {
if (activities == null) {
Expand All @@ -57,6 +64,13 @@ private boolean needShow(Activity activity) {

@Override
public void onActivityResumed(Activity activity) {
if (sResumedListener != null) {
num--;
if (num == 0) {
sResumedListener.onResumed();
sResumedListener = null;
}
}
resumeCount++;
if (needShow(activity)) {
mLifecycleListener.onShow();
Expand All @@ -69,14 +83,14 @@ public void onActivityResumed(Activity activity) {
}

@Override
public void onActivityPaused(Activity activity) {
public void onActivityPaused(final Activity activity) {
resumeCount--;
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (resumeCount == 0) {
appBackground = true;
mLifecycleListener.onPostHide();
mLifecycleListener.onBackToDesktop();
}
}
}, delay);
Expand All @@ -93,7 +107,7 @@ public void onActivityStarted(Activity activity) {
public void onActivityStopped(Activity activity) {
startCount--;
if (startCount == 0) {
mLifecycleListener.onHide();
mLifecycleListener.onBackToDesktop();
}
}

Expand All @@ -103,7 +117,7 @@ public void onReceive(Context context, Intent intent) {
if (action != null && action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) {
mLifecycleListener.onHide();
mLifecycleListener.onBackToDesktop();
}
}
}
Expand All @@ -126,7 +140,4 @@ public void onActivityDestroyed(Activity activity) {
}





}
Loading

0 comments on commit 0d76c80

Please sign in to comment.