|
@@ -2,26 +2,45 @@ package com.sheep.jiuyan.samllsheep.service;
|
|
|
|
|
|
|
|
import android.app.Service;
|
|
import android.app.Service;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
import android.graphics.PixelFormat;
|
|
import android.graphics.PixelFormat;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
|
|
+import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
|
|
+import android.os.Looper;
|
|
|
|
|
+import android.os.Message;
|
|
|
|
|
+import android.provider.Settings;
|
|
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
import android.view.WindowManager;
|
|
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.AppUsage;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
|
|
+import com.sheep.gamegroup.model.util.AutoTaskListUtil;
|
|
|
|
|
+import com.sheep.gamegroup.usage.AppUsageManager;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.TestUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.TimeUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.DeviceInfo;
|
|
import com.sheep.jiuyan.samllsheep.utils.DeviceInfo;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Locale;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import rx.Observable;
|
|
import rx.Observable;
|
|
@@ -35,147 +54,102 @@ import rx.schedulers.Schedulers;
|
|
|
* realicing@sina.com
|
|
* realicing@sina.com
|
|
|
*/
|
|
*/
|
|
|
public class FloatService extends Service {
|
|
public class FloatService extends Service {
|
|
|
-
|
|
|
|
|
- private static final String TAG = "MainService";
|
|
|
|
|
-
|
|
|
|
|
- LinearLayout mFloatwindow;
|
|
|
|
|
- WindowManager.LayoutParams params;
|
|
|
|
|
- WindowManager mWm;
|
|
|
|
|
-
|
|
|
|
|
- ImageView floaticon;
|
|
|
|
|
-
|
|
|
|
|
- //状态栏高度.
|
|
|
|
|
- int statusBarHeight = -1;
|
|
|
|
|
-
|
|
|
|
|
- //不与Activity进行绑定.
|
|
|
|
|
- @Override
|
|
|
|
|
- public IBinder onBind(Intent intent) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onCreate() {
|
|
|
|
|
- super.onCreate();
|
|
|
|
|
- createToucher();
|
|
|
|
|
- startTimer();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private void stopTimer() {
|
|
private void stopTimer() {
|
|
|
- if(subscription != null){
|
|
|
|
|
|
|
+ if (subscription != null) {
|
|
|
subscription.unsubscribe();
|
|
subscription.unsubscribe();
|
|
|
}
|
|
}
|
|
|
subscription = null;
|
|
subscription = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private Subscription subscription;
|
|
private Subscription subscription;
|
|
|
|
|
+
|
|
|
private void startTimer() {
|
|
private void startTimer() {
|
|
|
- if(subscription == null)
|
|
|
|
|
- subscription = Observable.interval(60_000L, TimeUnit.MILLISECONDS)
|
|
|
|
|
|
|
+ if (subscription == null)
|
|
|
|
|
+ subscription = Observable.interval(10_000L, TimeUnit.MILLISECONDS)
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(new Action1<Long>() {
|
|
.subscribe(new Action1<Long>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void call(Long count) {
|
|
public void call(Long count) {
|
|
|
- LogUtil.println("FloatService","count","=",count);
|
|
|
|
|
- try {
|
|
|
|
|
- if(!TextUtils.isEmpty(SpUtils.getOpenId(SheepApp.getInstance()))) {//登录情况下才检查是否有应用自动审核任务,是否开启辅助功能
|
|
|
|
|
- Jump2View.getInstance().startAccessibility();
|
|
|
|
|
|
|
+ LogUtil.println("FloatService", "count", "=", count);
|
|
|
|
|
+ if (!TextUtils.isEmpty(SpUtils.getOpenId(SheepApp.getInstance())) &&!AutoTaskListUtil.getInstance().isEmpty()) {//登录情况下并且有应用自动审核任务才会记录
|
|
|
|
|
+ if(count % 60 == 0){
|
|
|
|
|
+ AppUsageManager.getInstance().tryOpenLookAppUsageStatsPermisson(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ AppUsageManager.getInstance().recordCurrentAppUsage();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ Message message = handler.obtainMessage(1);
|
|
|
|
|
+ message.obj = count;
|
|
|
|
|
+ handler.sendMessage(message);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ handler.sendEmptyMessage(2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}, new Action1<Throwable>() {
|
|
}, new Action1<Throwable>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void call(Throwable throwable) {
|
|
public void call(Throwable throwable) {
|
|
|
- LogUtil.println("FloatService","Throwable","=",throwable.getMessage());
|
|
|
|
|
|
|
+ LogUtil.println("FloatService", "Throwable", "=", throwable.getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- private void createToucher() {
|
|
|
|
|
- //赋值WindowManager&LayoutParam.
|
|
|
|
|
- params = new WindowManager.LayoutParams();
|
|
|
|
|
- if(mWm==null) {
|
|
|
|
|
- mWm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
|
- }
|
|
|
|
|
- //设置type.系统提示型窗口,一般都在应用程序窗口之上.
|
|
|
|
|
- //设置效果为背景透明.
|
|
|
|
|
- params.format = PixelFormat.RGBA_8888;
|
|
|
|
|
- //设置flags.不可聚焦及不可使用按钮对悬浮窗进行操控.
|
|
|
|
|
- params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
|
|
|
|
- | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
|
-//
|
|
|
|
|
-// //设置窗口初始停靠位置.
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
|
- // 大于等于 24 即为 7.0 及以上执行内容
|
|
|
|
|
- Log.e("qx", "7.0");
|
|
|
|
|
- params.type = WindowManager.LayoutParams.TYPE_PHONE; // 7.1
|
|
|
|
|
- } else {
|
|
|
|
|
- // 低于 24 即为 7.0 以下执行内容
|
|
|
|
|
- params.type = WindowManager.LayoutParams.TYPE_TOAST; // 4.4
|
|
|
|
|
- Log.e("qx", "4.4");
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- params.gravity = Gravity.LEFT | Gravity.TOP;
|
|
|
|
|
- params.x = 0;
|
|
|
|
|
- params.y = DeviceInfo.dip2px(getApplicationContext(), 25);
|
|
|
|
|
-
|
|
|
|
|
- //设置悬浮窗口长宽数据.
|
|
|
|
|
- params.width = -2;
|
|
|
|
|
- params.height = DeviceInfo.dip2px(getApplicationContext(), 40f);
|
|
|
|
|
-
|
|
|
|
|
- LayoutInflater inflater = LayoutInflater.from(getApplication());
|
|
|
|
|
- //获取浮动窗口视图所在布局.
|
|
|
|
|
- mFloatwindow = (LinearLayout) inflater.inflate(R.layout.float_window, null);
|
|
|
|
|
- //添加toucherlayout
|
|
|
|
|
- Log.i(TAG, "toucherlayout-->left:" + mFloatwindow.getLeft());
|
|
|
|
|
- Log.i(TAG, "toucherlayout-->right:" + mFloatwindow.getRight());
|
|
|
|
|
- Log.i(TAG, "toucherlayout-->top:" + mFloatwindow.getTop());
|
|
|
|
|
- Log.i(TAG, "toucherlayout-->bottom:" + mFloatwindow.getBottom());
|
|
|
|
|
-
|
|
|
|
|
- //主动计算出当前View的宽高信息.
|
|
|
|
|
- mFloatwindow.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
|
|
|
|
-
|
|
|
|
|
- //用于检测状态栏高度.
|
|
|
|
|
- int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
|
|
|
|
- if (resourceId > 0) {
|
|
|
|
|
- statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
|
|
|
|
- }
|
|
|
|
|
- Log.i(TAG, "状态栏高度为:" + statusBarHeight);
|
|
|
|
|
-
|
|
|
|
|
- //浮动窗口按钮.
|
|
|
|
|
- floaticon = mFloatwindow.findViewById(R.id.floate_icon);
|
|
|
|
|
- floaticon.setAlpha(0.0f);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //不与Activity进行绑定.
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IBinder onBind(Intent intent) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
|
- try {
|
|
|
|
|
- if (intent != null && intent.getBooleanExtra("isShow", true)) {
|
|
|
|
|
- if (mFloatwindow != null) {
|
|
|
|
|
- mWm.addView(mFloatwindow, params);
|
|
|
|
|
|
|
+ public void onCreate() {
|
|
|
|
|
+ super.onCreate();
|
|
|
|
|
+ createFloatView();
|
|
|
|
|
+ startTimer();
|
|
|
|
|
+ }
|
|
|
|
|
+ private Handler handler = new Handler(Looper.getMainLooper()){
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ switch (msg.what) {
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ onHandleMessage1();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ onHandleMessage2();
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- if (mFloatwindow != null)
|
|
|
|
|
- mWm.removeViewImmediate(mFloatwindow);
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private void onHandleMessage1() {
|
|
|
|
|
+ AppUsage appUsage = new AppUsage();
|
|
|
|
|
+ //更新悬浮窗
|
|
|
|
|
+ long totalTimeInForeground = AppUsageManager.getInstance().getTotalTimeInForeground(appUsage);
|
|
|
|
|
+ if(!AutoTaskListUtil.getInstance().hasTask(appUsage.getPackageName())){
|
|
|
|
|
+ onHandleMessage2();
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- } catch (Exception ignore) {
|
|
|
|
|
|
|
+ btn_floatView.setText(String.format(Locale.CHINA,"约运行%s",TimeUtil.getHours(totalTimeInForeground)));
|
|
|
|
|
+ floatView.setAlpha(1.0f);
|
|
|
|
|
+ wm.updateViewLayout(floatView, params);
|
|
|
}
|
|
}
|
|
|
- return super.onStartCommand(intent, flags, START_STICKY);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private void onHandleMessage2() {
|
|
|
|
|
+ floatView.setAlpha(0.0f);
|
|
|
|
|
+ wm.updateViewLayout(floatView, params);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
@Override
|
|
@Override
|
|
|
public void onDestroy() {
|
|
public void onDestroy() {
|
|
|
- if (floaticon != null) {
|
|
|
|
|
|
|
+ if (floatView != null) {
|
|
|
try {
|
|
try {
|
|
|
- mWm.removeViewImmediate(mFloatwindow);
|
|
|
|
|
|
|
+ wm.removeViewImmediate(floatView);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
@@ -184,4 +158,156 @@ public class FloatService extends Service {
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// public static final String OPERATION = "operation";
|
|
|
|
|
+ public static final int OPERATION_SHOW = 100;
|
|
|
|
|
+ public static final int OPERATION_HIDE = 101;
|
|
|
|
|
+
|
|
|
|
|
+ private static final int HANDLE_CHECK_ACTIVITY = 200;
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isAdded = false; // 是否已增加悬浮窗
|
|
|
|
|
+ private static WindowManager wm;
|
|
|
|
|
+ private static WindowManager.LayoutParams params;
|
|
|
|
|
+ private View floatView;
|
|
|
|
|
+ private TextView btn_floatView;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
|
+// int operation = intent.getIntExtra(OPERATION, OPERATION_SHOW);
|
|
|
|
|
+ if(intent != null) {
|
|
|
|
|
+ int operation = intent.getBooleanExtra("isShow", true) ? OPERATION_SHOW : OPERATION_HIDE;
|
|
|
|
|
+ mHandler.sendEmptyMessage(operation);
|
|
|
|
|
+ }
|
|
|
|
|
+ return super.onStartCommand(intent, flags, startId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Handler mHandler = new TwHandler(this);
|
|
|
|
|
+
|
|
|
|
|
+ static class TwHandler extends Handler {
|
|
|
|
|
+ TwHandler(FloatService service) {
|
|
|
|
|
+ this.service = service;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FloatService service;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
|
+ switch (msg.what) {
|
|
|
|
|
+ case OPERATION_SHOW:
|
|
|
|
|
+ if (!service.isAdded) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ service.floatView.setAlpha(1.0f);
|
|
|
|
|
+ wm.updateViewLayout(service.floatView, params);
|
|
|
|
|
+// wm.addView(service.floatView, params);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ service.isAdded = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case OPERATION_HIDE:
|
|
|
|
|
+ case HANDLE_CHECK_ACTIVITY:
|
|
|
|
|
+ if (service.isAdded) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ service.floatView.setAlpha(0.0f);
|
|
|
|
|
+ wm.updateViewLayout(service.floatView, params);
|
|
|
|
|
+// wm.removeViewImmediate(service.floatView);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ service.isAdded = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ private boolean canTouchWindow = false;//是否可以操作悬浮窗
|
|
|
|
|
+
|
|
|
|
|
+ public void setCanTouchWindow(boolean canTouchWindow) {
|
|
|
|
|
+ this.canTouchWindow = canTouchWindow;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建悬浮窗
|
|
|
|
|
+ */
|
|
|
|
|
+ private void createFloatView() {
|
|
|
|
|
+ LayoutInflater inflater = LayoutInflater.from(getApplication());
|
|
|
|
|
+// //获取浮动窗口视图所在布局.
|
|
|
|
|
+ floatView = inflater.inflate(R.layout.float_window, null);
|
|
|
|
|
+ btn_floatView = floatView.findViewById(R.id.float_tv);
|
|
|
|
|
+
|
|
|
|
|
+ wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
|
+ params = new WindowManager.LayoutParams();
|
|
|
|
|
+
|
|
|
|
|
+ // 设置window type
|
|
|
|
|
+ params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 如果设置为params.type = WindowManager.LayoutParams.TYPE_PHONE; 那么优先级会降低一些,
|
|
|
|
|
+ * 即拉下通知栏不可见
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ params.format = PixelFormat.RGBA_8888; // 设置图片格式,效果为背景透明
|
|
|
|
|
+
|
|
|
|
|
+ if(canTouchWindow) {
|
|
|
|
|
+ // 设置Window flag
|
|
|
|
|
+ params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
|
|
|
|
+ | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
|
+ // 设置悬浮窗的Touch监听
|
|
|
|
|
+ floatView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
+ int lastX, lastY;
|
|
|
|
|
+ int paramX, paramY;
|
|
|
|
|
+ private boolean isMove = false;
|
|
|
|
|
+ private long downTime = 0;
|
|
|
|
|
+
|
|
|
|
|
+ public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
+ switch (event.getAction()) {
|
|
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
|
|
+ isMove = false;
|
|
|
|
|
+ downTime = System.currentTimeMillis();
|
|
|
|
|
+ lastX = (int) event.getRawX();
|
|
|
|
|
+ lastY = (int) event.getRawY();
|
|
|
|
|
+ paramX = params.x;
|
|
|
|
|
+ paramY = params.y;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
|
|
+ int dx = (int) event.getRawX() - lastX;
|
|
|
|
|
+ int dy = (int) event.getRawY() - lastY;
|
|
|
|
|
+ params.x = paramX + dx;
|
|
|
|
|
+ params.y = paramY + dy;
|
|
|
|
|
+ // 更新悬浮窗位置
|
|
|
|
|
+ wm.updateViewLayout(floatView, params);
|
|
|
|
|
+ isMove = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case MotionEvent.ACTION_UP:
|
|
|
|
|
+ if(!isMove && System.currentTimeMillis()-downTime < 1000L){//没有移动过并且小于1秒就弹起来就点击
|
|
|
|
|
+ v.performClick();
|
|
|
|
|
+ }
|
|
|
|
|
+ isMove = false;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ floatView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ //TODO 设置点击悬浮窗的响应
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 下面的flags属性的效果形同“锁定”。 悬浮窗不可触摸,不接受任何事件,同时不影响后面的事件响应。
|
|
|
|
|
+ */
|
|
|
|
|
+ params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置悬浮窗的长得宽
|
|
|
|
|
+ params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
|
|
+ params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
|
|
+ params.gravity = Gravity.START | Gravity.BOTTOM;
|
|
|
|
|
+
|
|
|
|
|
+ floatView.setAlpha(0.0f);
|
|
|
|
|
+ wm.addView(floatView, params);
|
|
|
|
|
+ isAdded = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|