|
@@ -85,12 +85,16 @@ public class FloatService extends Service {
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- Message message = handler.obtainMessage(1);
|
|
|
|
|
- message.obj = count;
|
|
|
|
|
- handler.sendMessage(message);
|
|
|
|
|
|
|
+ if(isShowFloat) {
|
|
|
|
|
+ Message message = handler.obtainMessage(1);
|
|
|
|
|
+ message.obj = count;
|
|
|
|
|
+ handler.sendMessage(message);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- removeMessages();
|
|
|
|
|
- mHandler.sendEmptyMessage(OPERATION_HIDE);
|
|
|
|
|
|
|
+ if(isShowFloat) {
|
|
|
|
|
+ removeMessages();
|
|
|
|
|
+ mHandler.sendEmptyMessage(OPERATION_HIDE);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -112,20 +116,23 @@ public class FloatService extends Service {
|
|
|
@Override
|
|
@Override
|
|
|
public void onCreate() {
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
super.onCreate();
|
|
|
- createFloatView();
|
|
|
|
|
|
|
+ if(isShowFloat)
|
|
|
|
|
+ createFloatView();
|
|
|
startTimer();
|
|
startTimer();
|
|
|
}
|
|
}
|
|
|
private Handler handler = new Handler(Looper.getMainLooper()){
|
|
private Handler handler = new Handler(Looper.getMainLooper()){
|
|
|
@Override
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
public void handleMessage(Message msg) {
|
|
|
- try {
|
|
|
|
|
- switch (msg.what) {
|
|
|
|
|
- case 1:
|
|
|
|
|
- onHandleMessage1();
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(isShowFloat) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ switch (msg.what) {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ onHandleMessage1();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -175,20 +182,23 @@ public class FloatService extends Service {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
-// int operation = intent.getIntExtra(OPERATION, OPERATION_SHOW);
|
|
|
|
|
- if(intent != null) {
|
|
|
|
|
- if(intent.getBooleanExtra("isShow", true)){
|
|
|
|
|
- mHandler.sendEmptyMessageDelayed(OPERATION_SHOW, 1000L);
|
|
|
|
|
- } else {
|
|
|
|
|
- removeMessages();
|
|
|
|
|
- mHandler.sendEmptyMessage(OPERATION_HIDE);
|
|
|
|
|
|
|
+ if(isShowFloat) {
|
|
|
|
|
+ if (intent != null) {
|
|
|
|
|
+ if (intent.getBooleanExtra("isShow", true)) {
|
|
|
|
|
+ mHandler.sendEmptyMessageDelayed(OPERATION_SHOW, 1000L);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ removeMessages();
|
|
|
|
|
+ mHandler.sendEmptyMessage(OPERATION_HIDE);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return super.onStartCommand(intent, flags, startId);
|
|
return super.onStartCommand(intent, flags, startId);
|
|
|
}
|
|
}
|
|
|
private void removeMessages(){
|
|
private void removeMessages(){
|
|
|
- mHandler.removeMessages(OPERATION_HIDE);
|
|
|
|
|
- mHandler.removeMessages(OPERATION_SHOW);
|
|
|
|
|
|
|
+ if(isShowFloat) {
|
|
|
|
|
+ mHandler.removeMessages(OPERATION_HIDE);
|
|
|
|
|
+ mHandler.removeMessages(OPERATION_SHOW);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private Handler mHandler = new TwHandler(this);
|
|
private Handler mHandler = new TwHandler(this);
|
|
@@ -202,36 +212,39 @@ public class FloatService extends Service {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
public void handleMessage(Message msg) {
|
|
|
- switch (msg.what) {
|
|
|
|
|
- case OPERATION_SHOW:
|
|
|
|
|
- if (!service.isAdded) {
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ if(service.isShowFloat) {
|
|
|
|
|
+ switch (msg.what) {
|
|
|
|
|
+ case OPERATION_SHOW:
|
|
|
|
|
+ if (!service.isAdded) {
|
|
|
|
|
+ try {
|
|
|
// service.floatView.setAlpha(1.0f);
|
|
// service.floatView.setAlpha(1.0f);
|
|
|
// wm.updateViewLayout(service.floatView, params);
|
|
// wm.updateViewLayout(service.floatView, params);
|
|
|
- wm.addView(service.floatView, params);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ wm.addView(service.floatView, params);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ service.isAdded = true;
|
|
|
}
|
|
}
|
|
|
- service.isAdded = true;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- case OPERATION_HIDE:
|
|
|
|
|
- case HANDLE_CHECK_ACTIVITY:
|
|
|
|
|
- if (service.isAdded) {
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ case OPERATION_HIDE:
|
|
|
|
|
+ case HANDLE_CHECK_ACTIVITY:
|
|
|
|
|
+ if (service.isAdded) {
|
|
|
|
|
+ try {
|
|
|
// service.floatView.setAlpha(0.0f);
|
|
// service.floatView.setAlpha(0.0f);
|
|
|
// wm.updateViewLayout(service.floatView, params);
|
|
// wm.updateViewLayout(service.floatView, params);
|
|
|
- wm.removeViewImmediate(service.floatView);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ wm.removeViewImmediate(service.floatView);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ service.isAdded = false;
|
|
|
}
|
|
}
|
|
|
- service.isAdded = false;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
private boolean canTouchWindow = false;//是否可以操作悬浮窗
|
|
private boolean canTouchWindow = false;//是否可以操作悬浮窗
|
|
|
|
|
+ private boolean isShowFloat = false;//是否显示悬浮窗
|
|
|
|
|
|
|
|
public void setCanTouchWindow(boolean canTouchWindow) {
|
|
public void setCanTouchWindow(boolean canTouchWindow) {
|
|
|
this.canTouchWindow = canTouchWindow;
|
|
this.canTouchWindow = canTouchWindow;
|