|
|
@@ -137,12 +137,12 @@ public class FloatService extends Service {
|
|
|
}
|
|
|
LogUtil.println("FloatService", 6);
|
|
|
if(!isAdded){
|
|
|
- wm.addView(floatView, params);
|
|
|
+ windowManager.addView(floatView, params);
|
|
|
isAdded = true;
|
|
|
LogUtil.println("FloatService", 7);
|
|
|
}
|
|
|
btn_floatView.setText(String.format(Locale.CHINA,"约运行%s",TimeUtil.getHours(totalTimeInForeground)));
|
|
|
- wm.updateViewLayout(floatView, params);
|
|
|
+ windowManager.updateViewLayout(floatView, params);
|
|
|
LogUtil.println("FloatService", 8);
|
|
|
}
|
|
|
|
|
|
@@ -154,7 +154,7 @@ public class FloatService extends Service {
|
|
|
if (floatView != null) {
|
|
|
try {
|
|
|
if(isAdded)
|
|
|
- wm.removeViewImmediate(floatView);
|
|
|
+ windowManager.removeViewImmediate(floatView);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -169,8 +169,8 @@ public class FloatService extends Service {
|
|
|
private static final int HANDLE_CHECK_ACTIVITY = 200;
|
|
|
|
|
|
private boolean isAdded = false; // 是否已增加悬浮窗
|
|
|
- private static WindowManager wm;
|
|
|
- private static WindowManager.LayoutParams params;
|
|
|
+ private WindowManager windowManager;
|
|
|
+ private WindowManager.LayoutParams params;
|
|
|
private View floatView;
|
|
|
private TextView btn_floatView;
|
|
|
|
|
|
@@ -213,8 +213,8 @@ public class FloatService extends Service {
|
|
|
if (!service.isAdded) {
|
|
|
try {
|
|
|
// service.floatView.setAlpha(1.0f);
|
|
|
-// wm.updateViewLayout(service.floatView, params);
|
|
|
- wm.addView(service.floatView, params);
|
|
|
+// windowManager.updateViewLayout(service.floatView, params);
|
|
|
+ service.windowManager.addView(service.floatView, service.params);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -226,8 +226,8 @@ public class FloatService extends Service {
|
|
|
if (service.isAdded) {
|
|
|
try {
|
|
|
// service.floatView.setAlpha(0.0f);
|
|
|
-// wm.updateViewLayout(service.floatView, params);
|
|
|
- wm.removeViewImmediate(service.floatView);
|
|
|
+// windowManager.updateViewLayout(service.floatView, params);
|
|
|
+ service.windowManager.removeViewImmediate(service.floatView);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -254,7 +254,7 @@ public class FloatService extends Service {
|
|
|
floatView = inflater.inflate(R.layout.float_window, null);
|
|
|
btn_floatView = floatView.findViewById(R.id.float_tv);
|
|
|
|
|
|
- wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
|
|
+ windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
|
|
params = new WindowManager.LayoutParams();
|
|
|
|
|
|
// 设置window type
|
|
|
@@ -307,7 +307,7 @@ public class FloatService extends Service {
|
|
|
params.x = paramX + dx;
|
|
|
params.y = paramY + dy;
|
|
|
// 更新悬浮窗位置
|
|
|
- wm.updateViewLayout(floatView, params);
|
|
|
+ windowManager.updateViewLayout(floatView, params);
|
|
|
isMove = true;
|
|
|
break;
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
@@ -320,12 +320,6 @@ public class FloatService extends Service {
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
- floatView.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- //TODO 设置点击悬浮窗的响应
|
|
|
- }
|
|
|
- });
|
|
|
} else {
|
|
|
/*
|
|
|
* 下面的flags属性的效果形同“锁定”。 悬浮窗不可触摸,不接受任何事件,同时不影响后面的事件响应。
|
|
|
@@ -337,12 +331,5 @@ public class FloatService extends Service {
|
|
|
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
params.gravity = Gravity.START | Gravity.BOTTOM;
|
|
|
-
|
|
|
- try{
|
|
|
- wm.addView(floatView, params);
|
|
|
- isAdded = true;
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
}
|
|
|
}
|