mFloatWindowMap;
38 |
39 | public static IFloatWindow get() {
40 | return get(mDefaultTag);
41 | }
42 |
43 | public static IFloatWindow get(@NonNull String tag) {
44 | return mFloatWindowMap == null ? null : mFloatWindowMap.get(tag);
45 | }
46 |
47 | private static B mBuilder = null;
48 |
49 | @MainThread
50 | public static B with(@NonNull Context applicationContext) {
51 | return mBuilder = new B(applicationContext);
52 | }
53 |
54 | public static void destroy() {
55 | destroy(mDefaultTag);
56 | }
57 |
58 | public static void destroy(String tag) {
59 | if (mFloatWindowMap == null || !mFloatWindowMap.containsKey(tag)) {
60 | return;
61 | }
62 | mFloatWindowMap.get(tag).dismiss();
63 | mFloatWindowMap.remove(tag);
64 | }
65 |
66 | public static class B {
67 | Context mApplicationContext;
68 | View mView;
69 | private int mLayoutId;
70 | int mWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
71 | int mHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
72 | int gravity = Gravity.TOP | Gravity.START;
73 | int xOffset;
74 | int yOffset;
75 | boolean mShow = true;
76 | Class[] mActivities;
77 | int mMoveType = MoveType.slide;
78 | int mSlideLeftMargin;
79 | int mSlideRightMargin;
80 | long mDuration = 300;
81 | TimeInterpolator mInterpolator;
82 | private String mTag = mDefaultTag;
83 | boolean mDesktopShow;
84 | PermissionListener mPermissionListener;
85 | ViewStateListener mViewStateListener;
86 |
87 | private B() {
88 |
89 | }
90 |
91 | B(Context applicationContext) {
92 | mApplicationContext = applicationContext;
93 | }
94 |
95 | public B setView(@NonNull View view) {
96 | mView = view;
97 | return this;
98 | }
99 |
100 | public B setView(@LayoutRes int layoutId) {
101 | mLayoutId = layoutId;
102 | return this;
103 | }
104 |
105 | public B setWidth(int width) {
106 | mWidth = width;
107 | return this;
108 | }
109 |
110 | public B setHeight(int height) {
111 | mHeight = height;
112 | return this;
113 | }
114 |
115 | public B setWidth(@Screen.screenType int screenType, float ratio) {
116 | mWidth = (int) ((screenType == Screen.width ?
117 | Util.getScreenWidth(mApplicationContext) :
118 | Util.getScreenHeight(mApplicationContext)) * ratio);
119 | return this;
120 | }
121 |
122 |
123 | public B setHeight(@Screen.screenType int screenType, float ratio) {
124 | mHeight = (int) ((screenType == Screen.width ?
125 | Util.getScreenWidth(mApplicationContext) :
126 | Util.getScreenHeight(mApplicationContext)) * ratio);
127 | return this;
128 | }
129 |
130 |
131 | public B setX(int x) {
132 | xOffset = x;
133 | return this;
134 | }
135 |
136 | public B setY(int y) {
137 | yOffset = y;
138 | return this;
139 | }
140 |
141 | public B setX(@Screen.screenType int screenType, float ratio) {
142 | xOffset = (int) ((screenType == Screen.width ?
143 | Util.getScreenWidth(mApplicationContext) :
144 | Util.getScreenHeight(mApplicationContext)) * ratio);
145 | return this;
146 | }
147 |
148 | public B setY(@Screen.screenType int screenType, float ratio) {
149 | yOffset = (int) ((screenType == Screen.width ?
150 | Util.getScreenWidth(mApplicationContext) :
151 | Util.getScreenHeight(mApplicationContext)) * ratio);
152 | return this;
153 | }
154 |
155 |
156 | /**
157 | * 设置 Activity 过滤器,用于指定在哪些界面显示悬浮窗,默认全部界面都显示
158 | *
159 | * @param show 过滤类型,子类类型也会生效
160 | * @param activities 过滤界面
161 | */
162 | public B setFilter(boolean show, @NonNull Class... activities) {
163 | mShow = show;
164 | mActivities = activities;
165 | return this;
166 | }
167 |
168 | public B setMoveType(@MoveType.MOVE_TYPE int moveType) {
169 | return setMoveType(moveType, 0, 0);
170 | }
171 |
172 |
173 | /**
174 | * 设置带边距的贴边动画,只有 moveType 为 MoveType.slide,设置边距才有意义,这个方法不标准,后面调整
175 | *
176 | * @param moveType 贴边动画 MoveType.slide
177 | * @param slideLeftMargin 贴边动画左边距,默认为 0
178 | * @param slideRightMargin 贴边动画右边距,默认为 0
179 | */
180 | public B setMoveType(@MoveType.MOVE_TYPE int moveType, int slideLeftMargin, int slideRightMargin) {
181 | mMoveType = moveType;
182 | mSlideLeftMargin = slideLeftMargin;
183 | mSlideRightMargin = slideRightMargin;
184 | return this;
185 | }
186 |
187 | public B setMoveStyle(long duration, @Nullable TimeInterpolator interpolator) {
188 | mDuration = duration;
189 | mInterpolator = interpolator;
190 | return this;
191 | }
192 |
193 | public B setTag(@NonNull String tag) {
194 | mTag = tag;
195 | return this;
196 | }
197 |
198 | public B setDesktopShow(boolean show) {
199 | mDesktopShow = show;
200 | return this;
201 | }
202 |
203 | public B setPermissionListener(PermissionListener listener) {
204 | mPermissionListener = listener;
205 | return this;
206 | }
207 |
208 | public B setViewStateListener(ViewStateListener listener) {
209 | mViewStateListener = listener;
210 | return this;
211 | }
212 |
213 | public void build() {
214 | if (mFloatWindowMap == null) {
215 | mFloatWindowMap = new HashMap<>();
216 | }
217 | if (mFloatWindowMap.containsKey(mTag)) {
218 | throw new IllegalArgumentException("FloatWindow of this tag has been added, Please set a new tag for the new FloatWindow");
219 | }
220 | if (mView == null && mLayoutId == 0) {
221 | throw new IllegalArgumentException("View has not been set!");
222 | }
223 | if (mView == null) {
224 | mView = Util.inflate(mApplicationContext, mLayoutId);
225 | }
226 | IFloatWindow floatWindowImpl = new IFloatWindowImpl(this);
227 | mFloatWindowMap.put(mTag, floatWindowImpl);
228 | }
229 |
230 | }
231 | }
232 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindow.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by yhao on 2017/12/22.
7 | * https://github.com/yhaolpz
8 | */
9 |
10 | public abstract class IFloatWindow {
11 | public abstract void show();
12 |
13 | public abstract void hide();
14 |
15 | public abstract boolean isShowing();
16 |
17 | public abstract int getX();
18 |
19 | public abstract int getY();
20 |
21 | public abstract void updateX(int x);
22 |
23 | public abstract void updateX(@Screen.screenType int screenType,float ratio);
24 |
25 | public abstract void updateY(int y);
26 |
27 | public abstract void updateY(@Screen.screenType int screenType,float ratio);
28 |
29 | public abstract View getView();
30 |
31 | abstract void dismiss();
32 | }
33 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/IFloatWindowImpl.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ObjectAnimator;
6 | import android.animation.PropertyValuesHolder;
7 | import android.animation.TimeInterpolator;
8 | import android.animation.ValueAnimator;
9 | import android.annotation.SuppressLint;
10 | import android.app.Activity;
11 | import android.os.Build;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 | import android.view.ViewConfiguration;
15 | import android.view.animation.DecelerateInterpolator;
16 |
17 | /**
18 | * Created by yhao on 2017/12/22.
19 | * https://github.com/yhaolpz
20 | */
21 |
22 | public class IFloatWindowImpl extends IFloatWindow {
23 | private FloatWindow.B mB;
24 | private FloatView mFloatView;
25 | private boolean isShow;
26 | private boolean once = true;
27 | private ValueAnimator mAnimator;
28 | private TimeInterpolator mDecelerateInterpolator;
29 | private float downX;
30 | private float downY;
31 | private float upX;
32 | private float upY;
33 | private boolean mClick = false;
34 | private int mSlop;
35 |
36 | private IFloatWindowImpl() {
37 |
38 | }
39 |
40 | IFloatWindowImpl(FloatWindow.B b) {
41 | mB = b;
42 | if (mB.mMoveType == MoveType.fixed) {
43 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
44 | mFloatView = new FloatPhone(b.mApplicationContext, mB.mPermissionListener);
45 | } else {
46 | mFloatView = new FloatToast(b.mApplicationContext);
47 | }
48 | } else {
49 | mFloatView = new FloatPhone(b.mApplicationContext, mB.mPermissionListener);
50 | initTouchEvent();
51 | }
52 | mFloatView.setSize(mB.mWidth, mB.mHeight);
53 | mFloatView.setGravity(mB.gravity, mB.xOffset, mB.yOffset);
54 | mFloatView.setView(mB.mView);
55 | FloatLifecycle.register(this);
56 | }
57 |
58 | @Override
59 | public void show() {
60 | if (once) {
61 | mFloatView.init();
62 | once = false;
63 | isShow = true;
64 | } else {
65 | if (isShow) {
66 | return;
67 | }
68 | getView().setVisibility(View.VISIBLE);
69 | isShow = true;
70 | }
71 | if (mB.mViewStateListener != null) {
72 | mB.mViewStateListener.onShow();
73 | }
74 | }
75 |
76 | @Override
77 | public void hide() {
78 | if (once || !isShow) {
79 | return;
80 | }
81 | getView().setVisibility(View.INVISIBLE);
82 | isShow = false;
83 | if (mB.mViewStateListener != null) {
84 | mB.mViewStateListener.onHide();
85 | }
86 | }
87 |
88 | @Override
89 | public boolean isShowing() {
90 | return isShow;
91 | }
92 |
93 | @Override
94 | void dismiss() {
95 | mFloatView.dismiss();
96 | isShow = false;
97 | if (mB.mViewStateListener != null) {
98 | mB.mViewStateListener.onDismiss();
99 | }
100 | FloatLifecycle.unregister(this);
101 | }
102 |
103 | @Override
104 | public void updateX(int x) {
105 | checkMoveType();
106 | mB.xOffset = x;
107 | mFloatView.updateX(x);
108 | }
109 |
110 | @Override
111 | public void updateY(int y) {
112 | checkMoveType();
113 | mB.yOffset = y;
114 | mFloatView.updateY(y);
115 | }
116 |
117 | @Override
118 | public void updateX(int screenType, float ratio) {
119 | checkMoveType();
120 | mB.xOffset = (int) ((screenType == Screen.width ?
121 | Util.getScreenWidth(mB.mApplicationContext) :
122 | Util.getScreenHeight(mB.mApplicationContext)) * ratio);
123 | mFloatView.updateX(mB.xOffset);
124 |
125 | }
126 |
127 | @Override
128 | public void updateY(int screenType, float ratio) {
129 | checkMoveType();
130 | mB.yOffset = (int) ((screenType == Screen.width ?
131 | Util.getScreenWidth(mB.mApplicationContext) :
132 | Util.getScreenHeight(mB.mApplicationContext)) * ratio);
133 | mFloatView.updateY(mB.yOffset);
134 |
135 | }
136 |
137 | @Override
138 | public int getX() {
139 | return mFloatView.getX();
140 | }
141 |
142 | @Override
143 | public int getY() {
144 | return mFloatView.getY();
145 | }
146 |
147 |
148 | @Override
149 | public View getView() {
150 | mSlop = ViewConfiguration.get(mB.mApplicationContext).getScaledTouchSlop();
151 | return mB.mView;
152 | }
153 |
154 |
155 | private void checkMoveType() {
156 | if (mB.mMoveType == MoveType.fixed) {
157 | throw new IllegalArgumentException("FloatWindow of this tag is not allowed to move!");
158 | }
159 | }
160 |
161 |
162 | private void initTouchEvent() {
163 | switch (mB.mMoveType) {
164 | case MoveType.inactive:
165 | break;
166 | default:
167 | getView().setOnTouchListener(new View.OnTouchListener() {
168 | float lastX, lastY, changeX, changeY;
169 | int newX, newY;
170 |
171 | @SuppressLint("ClickableViewAccessibility")
172 | @Override
173 | public boolean onTouch(View v, MotionEvent event) {
174 |
175 | switch (event.getAction()) {
176 | case MotionEvent.ACTION_DOWN:
177 | downX = event.getRawX();
178 | downY = event.getRawY();
179 | lastX = event.getRawX();
180 | lastY = event.getRawY();
181 | cancelAnimator();
182 | break;
183 | case MotionEvent.ACTION_MOVE:
184 | changeX = event.getRawX() - lastX;
185 | changeY = event.getRawY() - lastY;
186 | newX = (int) (mFloatView.getX() + changeX);
187 | newY = (int) (mFloatView.getY() + changeY);
188 | mFloatView.updateXY(newX, newY);
189 | if (mB.mViewStateListener != null) {
190 | mB.mViewStateListener.onPositionUpdate(newX, newY);
191 | }
192 | lastX = event.getRawX();
193 | lastY = event.getRawY();
194 | break;
195 | case MotionEvent.ACTION_UP:
196 | upX = event.getRawX();
197 | upY = event.getRawY();
198 | mClick = (Math.abs(upX - downX) > mSlop) || (Math.abs(upY - downY) > mSlop);
199 | switch (mB.mMoveType) {
200 | case MoveType.slide:
201 | int startX = mFloatView.getX();
202 | int endX = (startX * 2 + v.getWidth() > Util.getScreenWidth(mB.mApplicationContext)) ?
203 | Util.getScreenWidth(mB.mApplicationContext) - v.getWidth() - mB.mSlideRightMargin :
204 | mB.mSlideLeftMargin;
205 | mAnimator = ObjectAnimator.ofInt(startX, endX);
206 | mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
207 | @Override
208 | public void onAnimationUpdate(ValueAnimator animation) {
209 | int x = (int) animation.getAnimatedValue();
210 | mFloatView.updateX(x);
211 | if (mB.mViewStateListener != null) {
212 | mB.mViewStateListener.onPositionUpdate(x, (int) upY);
213 | }
214 | }
215 | });
216 | startAnimator();
217 | break;
218 | case MoveType.back:
219 | PropertyValuesHolder pvhX = PropertyValuesHolder.ofInt("x", mFloatView.getX(), mB.xOffset);
220 | PropertyValuesHolder pvhY = PropertyValuesHolder.ofInt("y", mFloatView.getY(), mB.yOffset);
221 | mAnimator = ObjectAnimator.ofPropertyValuesHolder(pvhX, pvhY);
222 | mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
223 | @Override
224 | public void onAnimationUpdate(ValueAnimator animation) {
225 | int x = (int) animation.getAnimatedValue("x");
226 | int y = (int) animation.getAnimatedValue("y");
227 | mFloatView.updateXY(x, y);
228 | if (mB.mViewStateListener != null) {
229 | mB.mViewStateListener.onPositionUpdate(x, y);
230 | }
231 | }
232 | });
233 | startAnimator();
234 | break;
235 | default:
236 | break;
237 | }
238 | break;
239 | default:
240 | break;
241 | }
242 | return mClick;
243 | }
244 | });
245 | }
246 | }
247 |
248 |
249 | private void startAnimator() {
250 | if (mB.mInterpolator == null) {
251 | if (mDecelerateInterpolator == null) {
252 | mDecelerateInterpolator = new DecelerateInterpolator();
253 | }
254 | mB.mInterpolator = mDecelerateInterpolator;
255 | }
256 | mAnimator.setInterpolator(mB.mInterpolator);
257 | mAnimator.addListener(new AnimatorListenerAdapter() {
258 | @Override
259 | public void onAnimationEnd(Animator animation) {
260 | mAnimator.removeAllUpdateListeners();
261 | mAnimator.removeAllListeners();
262 | mAnimator = null;
263 | if (mB.mViewStateListener != null) {
264 | mB.mViewStateListener.onMoveAnimEnd();
265 | }
266 | }
267 | });
268 | mAnimator.setDuration(mB.mDuration).start();
269 | if (mB.mViewStateListener != null) {
270 | mB.mViewStateListener.onMoveAnimStart();
271 | }
272 | }
273 |
274 | private void cancelAnimator() {
275 | if (mAnimator != null && mAnimator.isRunning()) {
276 | mAnimator.cancel();
277 | }
278 | }
279 |
280 | public boolean needShow(Activity activity) {
281 | if (mB.mActivities == null) {
282 | return true;
283 | }
284 | for (Class a : mB.mActivities) {
285 | if (a.isInstance(activity)) {
286 | return mB.mShow;
287 | }
288 | }
289 | return !mB.mShow;
290 | }
291 |
292 | public void onBackToDesktop() {
293 | if (!mB.mDesktopShow) {
294 | hide();
295 | }
296 | if (mB.mViewStateListener != null) {
297 | mB.mViewStateListener.onBackToDesktop();
298 | }
299 | }
300 | }
301 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/LifecycleListener.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | /**
4 | * Created by yhao on 2017/12/22.
5 | * https://github.com/yhaolpz
6 | */
7 |
8 | interface LifecycleListener {
9 |
10 | void onShow();
11 |
12 | void onHide();
13 |
14 | void onBackToDesktop();
15 | }
16 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/LogUtil.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.util.Log;
4 |
5 |
6 | /**
7 | * Created by yhao on 2017/12/29.
8 | * https://github.com/yhaolpz
9 | */
10 |
11 | class LogUtil {
12 |
13 | private static final String TAG = "FloatWindow";
14 |
15 |
16 | static void e(String message) {
17 |
18 | Log.e(TAG, message);
19 | }
20 |
21 |
22 | static void d(String message) {
23 |
24 | Log.d(TAG, message);
25 | }
26 |
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/Miui.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Build;
7 | import android.provider.Settings;
8 | import android.view.View;
9 | import android.view.WindowManager;
10 |
11 | import java.lang.reflect.Field;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | import static com.yhao.floatwindow.Rom.isIntentAvailable;
16 |
17 | /**
18 | * Created by yhao on 2017/12/30.
19 | * https://github.com/yhaolpz
20 | *
21 | * 需要清楚:一个MIUI版本对应小米各种机型,基于不同的安卓版本,但是权限设置页跟MIUI版本有关
22 | * 测试TYPE_TOAST类型:
23 | * 7.0:
24 | * 小米 5 MIUI8 -------------------- 失败
25 | * 小米 Note2 MIUI9 -------------------- 失败
26 | * 6.0.1
27 | * 小米 5 -------------------- 失败
28 | * 小米 红米note3 -------------------- 失败
29 | * 6.0:
30 | * 小米 5 -------------------- 成功
31 | * 小米 红米4A MIUI8 -------------------- 成功
32 | * 小米 红米Pro MIUI7 -------------------- 成功
33 | * 小米 红米Note4 MIUI8 -------------------- 失败
34 | *
35 | * 经过各种横向纵向测试对比,得出一个结论,就是小米对TYPE_TOAST的处理机制毫无规律可言!
36 | * 跟Android版本无关,跟MIUI版本无关,addView方法也不报错
37 | * 所以最后对小米6.0以上的适配方法是:不使用 TYPE_TOAST 类型,统一申请权限
38 | */
39 |
40 | class Miui {
41 |
42 | private static final String miui = "ro.miui.ui.version.name";
43 | private static final String miui5 = "V5";
44 | private static final String miui6 = "V6";
45 | private static final String miui7 = "V7";
46 | private static final String miui8 = "V8";
47 | private static final String miui9 = "V9";
48 | private static List mPermissionListenerList;
49 | private static PermissionListener mPermissionListener;
50 |
51 |
52 | static boolean rom() {
53 | LogUtil.d(" Miui : " + Miui.getProp());
54 | return Build.MANUFACTURER.equals("Xiaomi");
55 | }
56 |
57 | private static String getProp() {
58 | return Rom.getProp(miui);
59 | }
60 |
61 | /**
62 | * Android6.0以下申请权限
63 | */
64 | static void req(final Context context, PermissionListener permissionListener) {
65 | if (PermissionUtil.hasPermission(context)) {
66 | permissionListener.onSuccess();
67 | return;
68 | }
69 | if (mPermissionListenerList == null) {
70 | mPermissionListenerList = new ArrayList<>();
71 | mPermissionListener = new PermissionListener() {
72 | @Override
73 | public void onSuccess() {
74 | for (PermissionListener listener : mPermissionListenerList) {
75 | listener.onSuccess();
76 | }
77 | mPermissionListenerList.clear();
78 | }
79 | @Override
80 | public void onFail() {
81 | for (PermissionListener listener : mPermissionListenerList) {
82 | listener.onFail();
83 | }
84 | mPermissionListenerList.clear();
85 | }
86 | };
87 | req_(context);
88 | }
89 | mPermissionListenerList.add(permissionListener);
90 | }
91 |
92 |
93 | private static void req_(final Context context) {
94 | switch (getProp()) {
95 | case miui5:
96 | reqForMiui5(context);
97 | break;
98 | case miui6:
99 | case miui7:
100 | reqForMiui67(context);
101 | break;
102 | case miui8:
103 | case miui9:
104 | reqForMiui89(context);
105 | break;
106 | }
107 | FloatLifecycle.setResumedListener(new ResumedListener() {
108 | @Override
109 | public void onResumed() {
110 | if (PermissionUtil.hasPermission(context)) {
111 | mPermissionListener.onSuccess();
112 | } else {
113 | mPermissionListener.onFail();
114 | }
115 | }
116 | });
117 | }
118 |
119 |
120 | private static void reqForMiui5(Context context) {
121 | String packageName = context.getPackageName();
122 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
123 | Uri uri = Uri.fromParts("package", packageName, null);
124 | intent.setData(uri);
125 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
126 | if (isIntentAvailable(intent, context)) {
127 | context.startActivity(intent);
128 | } else {
129 | LogUtil.e("intent is not available!");
130 | }
131 | }
132 |
133 | private static void reqForMiui67(Context context) {
134 | Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
135 | intent.setClassName("com.miui.securitycenter",
136 | "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
137 | intent.putExtra("extra_pkgname", context.getPackageName());
138 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
139 | if (isIntentAvailable(intent, context)) {
140 | context.startActivity(intent);
141 | } else {
142 | LogUtil.e("intent is not available!");
143 | }
144 | }
145 |
146 | private static void reqForMiui89(Context context) {
147 | Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
148 | intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
149 | intent.putExtra("extra_pkgname", context.getPackageName());
150 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
151 | if (isIntentAvailable(intent, context)) {
152 | context.startActivity(intent);
153 | } else {
154 | intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
155 | intent.setPackage("com.miui.securitycenter");
156 | intent.putExtra("extra_pkgname", context.getPackageName());
157 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
158 | if (isIntentAvailable(intent, context)) {
159 | context.startActivity(intent);
160 | } else {
161 | LogUtil.e("intent is not available!");
162 | }
163 | }
164 | }
165 |
166 |
167 | /**
168 | * 有些机型在添加TYPE-TOAST类型时会自动改为TYPE_SYSTEM_ALERT,通过此方法可以屏蔽修改
169 | * 但是...即使成功显示出悬浮窗,移动的话也会崩溃
170 | */
171 | private static void addViewToWindow(WindowManager wm, View view, WindowManager.LayoutParams params) {
172 | setMiUI_International(true);
173 | wm.addView(view, params);
174 | setMiUI_International(false);
175 | }
176 |
177 |
178 | private static void setMiUI_International(boolean flag) {
179 | try {
180 | Class BuildForMi = Class.forName("miui.os.Build");
181 | Field isInternational = BuildForMi.getDeclaredField("IS_INTERNATIONAL_BUILD");
182 | isInternational.setAccessible(true);
183 | isInternational.setBoolean(null, flag);
184 | } catch (Exception e) {
185 | e.printStackTrace();
186 | }
187 | }
188 |
189 |
190 | }
191 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/MoveType.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.support.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 |
8 | /**
9 | * Created by yhao on 2017/12/22.
10 | * https://github.com/yhaolpz
11 | */
12 |
13 | public class MoveType {
14 | static final int fixed = 0;
15 | public static final int inactive = 1;
16 | public static final int active = 2;
17 | public static final int slide = 3;
18 | public static final int back = 4;
19 |
20 | @IntDef({fixed, inactive, active, slide, back})
21 | @Retention(RetentionPolicy.SOURCE)
22 | @interface MOVE_TYPE {
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/PermissionListener.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | /**
4 | * Created by yhao on 2017/11/14.
5 | * https://github.com/yhaolpz
6 | */
7 | public interface PermissionListener {
8 | void onSuccess();
9 |
10 | void onFail();
11 | }
12 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/PermissionUtil.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.app.AppOpsManager;
4 | import android.content.Context;
5 | import android.graphics.PixelFormat;
6 | import android.os.Binder;
7 | import android.os.Build;
8 | import android.provider.Settings;
9 | import android.support.annotation.RequiresApi;
10 | import android.view.View;
11 | import android.view.WindowManager;
12 |
13 | import java.lang.reflect.Method;
14 |
15 | /**
16 | * Created by yhao on 2017/12/29.
17 | * https://github.com/yhaolpz
18 | */
19 |
20 | class PermissionUtil {
21 |
22 | static boolean hasPermission(Context context) {
23 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
24 | return Settings.canDrawOverlays(context);
25 | } else {
26 | return hasPermissionBelowMarshmallow(context);
27 | }
28 | }
29 |
30 | static boolean hasPermissionOnActivityResult(Context context) {
31 | if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
32 | return hasPermissionForO(context);
33 | }
34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
35 | return Settings.canDrawOverlays(context);
36 | } else {
37 | return hasPermissionBelowMarshmallow(context);
38 | }
39 | }
40 |
41 | /**
42 | * 6.0以下判断是否有权限
43 | * 理论上6.0以上才需处理权限,但有的国内rom在6.0以下就添加了权限
44 | * 其实此方式也可以用于判断6.0以上版本,只不过有更简单的canDrawOverlays代替
45 | */
46 | static boolean hasPermissionBelowMarshmallow(Context context) {
47 | try {
48 | AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
49 | Method dispatchMethod = AppOpsManager.class.getMethod("checkOp", int.class, int.class, String.class);
50 | //AppOpsManager.OP_SYSTEM_ALERT_WINDOW = 24
51 | return AppOpsManager.MODE_ALLOWED == (Integer) dispatchMethod.invoke(
52 | manager, 24, Binder.getCallingUid(), context.getApplicationContext().getPackageName());
53 | } catch (Exception e) {
54 | return false;
55 | }
56 | }
57 |
58 |
59 | /**
60 | * 用于判断8.0时是否有权限,仅用于OnActivityResult
61 | * 针对8.0官方bug:在用户授予权限后Settings.canDrawOverlays或checkOp方法判断仍然返回false
62 | */
63 | @RequiresApi(api = Build.VERSION_CODES.M)
64 | private static boolean hasPermissionForO(Context context) {
65 | try {
66 | WindowManager mgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
67 | if (mgr == null) return false;
68 | View viewToAdd = new View(context);
69 | WindowManager.LayoutParams params = new WindowManager.LayoutParams(0, 0,
70 | android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O ?
71 | WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
72 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
73 | PixelFormat.TRANSPARENT);
74 | viewToAdd.setLayoutParams(params);
75 | mgr.addView(viewToAdd, params);
76 | mgr.removeView(viewToAdd);
77 | return true;
78 | } catch (Exception e) {
79 | LogUtil.e("hasPermissionForO e:" + e.toString());
80 | }
81 | return false;
82 | }
83 |
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/ResumedListener.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | /**
4 | * Created by yhao on 2017/12/30.
5 | * https://github.com/yhaolpz
6 | */
7 |
8 | interface ResumedListener {
9 | void onResumed();
10 | }
11 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/Rom.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 |
7 | import java.io.BufferedReader;
8 | import java.io.IOException;
9 | import java.io.InputStreamReader;
10 |
11 | /**
12 | * Created by yhao on 2017/12/30.
13 | * https://github.com/yhaolpz
14 | */
15 |
16 | class Rom {
17 |
18 | static boolean isIntentAvailable(Intent intent, Context context) {
19 | return intent != null && context.getPackageManager().queryIntentActivities(
20 | intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
21 | }
22 |
23 |
24 | static String getProp(String name) {
25 | BufferedReader input = null;
26 | try {
27 | Process p = Runtime.getRuntime().exec("getprop " + name);
28 | input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
29 | String line = input.readLine();
30 | input.close();
31 | return line;
32 | } catch (IOException ex) {
33 | return null;
34 | } finally {
35 | if (input != null) {
36 | try {
37 | input.close();
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | }
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/Screen.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.support.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 |
8 | /**
9 | * Created by yhao on 2017/12/23.
10 | * https://github.com/yhaolpz
11 | */
12 |
13 | public class Screen {
14 | public static final int width = 0;
15 | public static final int height = 1;
16 |
17 | @IntDef({width, height})
18 | @Retention(RetentionPolicy.SOURCE)
19 | @interface screenType {
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/Util.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | import android.content.Context;
4 | import android.graphics.PixelFormat;
5 | import android.graphics.Point;
6 | import android.graphics.Rect;
7 | import android.os.Build;
8 | import android.provider.Settings;
9 | import android.support.annotation.RequiresApi;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.WindowManager;
13 |
14 | import java.lang.reflect.Method;
15 |
16 | /**
17 | * Created by yhao on 2017/12/22.
18 | * https://github.com/yhaolpz
19 | */
20 |
21 | class Util {
22 |
23 |
24 | static View inflate(Context applicationContext, int layoutId) {
25 | LayoutInflater inflate = (LayoutInflater) applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
26 | return inflate.inflate(layoutId, null);
27 | }
28 |
29 | private static Point sPoint;
30 |
31 | static int getScreenWidth(Context context) {
32 | if (sPoint == null) {
33 | sPoint = new Point();
34 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
35 | wm.getDefaultDisplay().getSize(sPoint);
36 | }
37 | return sPoint.x;
38 | }
39 |
40 | static int getScreenHeight(Context context) {
41 | if (sPoint == null) {
42 | sPoint = new Point();
43 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
44 | wm.getDefaultDisplay().getSize(sPoint);
45 | }
46 | return sPoint.y;
47 | }
48 |
49 | static boolean isViewVisible(View view) {
50 | return view.getGlobalVisibleRect(new Rect());
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListener.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | /**
4 | * Created by yhao on 2018/5/5
5 | * https://github.com/yhaolpz
6 | */
7 | public interface ViewStateListener {
8 | void onPositionUpdate(int x, int y);
9 |
10 | void onShow();
11 |
12 | void onHide();
13 |
14 | void onDismiss();
15 |
16 | void onMoveAnimStart();
17 |
18 | void onMoveAnimEnd();
19 |
20 | void onBackToDesktop();
21 | }
22 |
--------------------------------------------------------------------------------
/floatwindow/src/main/java/com/yhao/floatwindow/ViewStateListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yhao.floatwindow;
2 |
3 | /**
4 | * Created by yhao on 2018/5/5.
5 | * https://github.com/yhaolpz
6 | */
7 | public class ViewStateListenerAdapter implements ViewStateListener{
8 | @Override
9 | public void onPositionUpdate(int x, int y) {
10 |
11 | }
12 |
13 | @Override
14 | public void onShow() {
15 |
16 | }
17 |
18 | @Override
19 | public void onHide() {
20 |
21 | }
22 |
23 | @Override
24 | public void onDismiss() {
25 |
26 | }
27 |
28 | @Override
29 | public void onMoveAnimStart() {
30 |
31 | }
32 |
33 | @Override
34 | public void onMoveAnimEnd() {
35 |
36 | }
37 |
38 | @Override
39 | public void onBackToDesktop() {
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/floatwindow/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FFWindow
3 |
4 |
--------------------------------------------------------------------------------
/floatwindow/src/main/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/floatwindow/src/test/java/com/example/fixedfloatwindow/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.fixedfloatwindow;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 14 22:07:14 GMT+08:00 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/img.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/img.gif
--------------------------------------------------------------------------------
/pay.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/pay.jpg
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.example.yhao.fixedfloatwindow"
9 | minSdkVersion 19
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile project(':floatwindow')
26 | compile 'com.android.support:appcompat-v7:26.+'
27 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/example/yhao/fixedfloatwindow/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.yhao.fixedfloatwindow;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.yhao.fixedfloatwindow", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/yhao/floatwindow/A_Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.yhao.floatwindow;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.view.animation.BounceInterpolator;
8 | import android.widget.ImageView;
9 | import android.widget.Toast;
10 |
11 | import com.example.yhao.fixedfloatwindow.R;
12 | import com.yhao.floatwindow.FloatWindow;
13 | import com.yhao.floatwindow.MoveType;
14 | import com.yhao.floatwindow.Screen;
15 |
16 | public class A_Activity extends AppCompatActivity {
17 |
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_a);
23 | setTitle("A");
24 | }
25 |
26 | public void change(View view) {
27 | startActivity(new Intent(this, B_Activity.class));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/yhao/floatwindow/B_Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.yhao.floatwindow;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import com.example.yhao.fixedfloatwindow.R;
8 |
9 | public class B_Activity extends BaseActivity {
10 |
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_b);
16 | setTitle("B");
17 | }
18 |
19 | public void change(View view) {
20 | startActivity(new Intent(this, C_Activity.class));
21 | }
22 |
23 | public void back(View view) {
24 | finish();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/yhao/floatwindow/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.yhao.floatwindow;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | import com.example.yhao.fixedfloatwindow.R;
7 |
8 | public class BaseActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_d);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/yhao/floatwindow/BaseApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.yhao.floatwindow;
2 |
3 | import android.app.Application;
4 | import android.os.Build;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.view.animation.BounceInterpolator;
8 | import android.widget.ImageView;
9 | import android.widget.Toast;
10 |
11 | import com.example.yhao.fixedfloatwindow.R;
12 | import com.yhao.floatwindow.FloatWindow;
13 | import com.yhao.floatwindow.MoveType;
14 | import com.yhao.floatwindow.PermissionListener;
15 | import com.yhao.floatwindow.Screen;
16 | import com.yhao.floatwindow.ViewStateListener;
17 |
18 | /**
19 | * Created by yhao on 2017/12/18.
20 | * https://github.com/yhaolpz
21 | */
22 |
23 | public class BaseApplication extends Application {
24 |
25 |
26 | private static final String TAG = "FloatWindow";
27 |
28 | @Override
29 | public void onCreate() {
30 | super.onCreate();
31 |
32 | ImageView imageView = new ImageView(getApplicationContext());
33 | imageView.setImageResource(R.drawable.icon);
34 |
35 | // 分离生命周期和创建浮动框
36 | FloatWindow.initLifecycle(this);
37 | FloatWindow
38 | .with(getApplicationContext())
39 | .setView(imageView)
40 | .setWidth(Screen.width, 0.2f) //设置悬浮控件宽高
41 | .setHeight(Screen.width, 0.2f)
42 | .setX(Screen.width, 0.8f)
43 | .setY(Screen.height, 0.3f)
44 | .setMoveType(MoveType.slide,100,-100)
45 | .setMoveStyle(500, new BounceInterpolator())
46 | .setFilter(true, A_Activity.class, C_Activity.class)
47 | .setViewStateListener(mViewStateListener)
48 | .setPermissionListener(mPermissionListener)
49 | .setDesktopShow(true)
50 | .build();
51 |
52 |
53 | imageView.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | Toast.makeText(BaseApplication.this, "onClick", Toast.LENGTH_SHORT).show();
57 | }
58 | });
59 | }
60 |
61 | private PermissionListener mPermissionListener = new PermissionListener() {
62 | @Override
63 | public void onSuccess() {
64 | Log.d(TAG, "onSuccess");
65 | }
66 |
67 | @Override
68 | public void onFail() {
69 | Log.d(TAG, "onFail");
70 | }
71 | };
72 |
73 | private ViewStateListener mViewStateListener = new ViewStateListener() {
74 | @Override
75 | public void onPositionUpdate(int x, int y) {
76 | Log.d(TAG, "onPositionUpdate: x=" + x + " y=" + y);
77 | }
78 |
79 | @Override
80 | public void onShow() {
81 | Log.d(TAG, "onShow");
82 | }
83 |
84 | @Override
85 | public void onHide() {
86 | Log.d(TAG, "onHide");
87 | }
88 |
89 | @Override
90 | public void onDismiss() {
91 | Log.d(TAG, "onDismiss");
92 | }
93 |
94 | @Override
95 | public void onMoveAnimStart() {
96 | Log.d(TAG, "onMoveAnimStart");
97 | }
98 |
99 | @Override
100 | public void onMoveAnimEnd() {
101 | Log.d(TAG, "onMoveAnimEnd");
102 | }
103 |
104 | @Override
105 | public void onBackToDesktop() {
106 | Log.d(TAG, "onBackToDesktop");
107 | }
108 | };
109 | }
110 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/yhao/floatwindow/C_Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.yhao.floatwindow;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.example.yhao.fixedfloatwindow.R;
7 |
8 | public class C_Activity extends BaseActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_c);
14 | setTitle("C");
15 |
16 | }
17 |
18 | public void back(View view) {
19 | finish();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/drawable/icon.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_a.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_b.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
20 |
21 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_c.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_d.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FFWindow
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/test/java/com/example/yhao/fixedfloatwindow/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.yhao.fixedfloatwindow;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':floatwindow'
2 |
--------------------------------------------------------------------------------
/slide.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baneyue/FloatWindow/86c249edaa5f537e8a03b3a9e427090e072d0d2d/slide.gif
--------------------------------------------------------------------------------