private void showDesk() {
if(!PerssionUtils.initAlertPermission()){
return;
}
if( mDeskView!=null){
return;
}
mDeskView = new DeskWindowView(this);
final WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
int screenWidth = 0, screenHeight = 0;
if (windowManager != null) {
//获取屏幕的宽和高
Point point = new Point();
windowManager.getDefaultDisplay().getSize(point);
screenWidth = point.x;
screenHeight = point.y;
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
// layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
// layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.width = UIUtil.dip2px(200);
layoutParams.height = UIUtil.dip2px(200);
//设置type
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//26及以上必须使用TYPE_APPLICATION_OVERLAY @deprecated TYPE_PHONE
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
}
//设置flags
layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
layoutParams.gravity = Gravity.START | Gravity.TOP;
//背景设置成透明
layoutParams.format = PixelFormat.TRANSPARENT;
layoutParams.x = screenWidth/2-UIUtil.dip2px(100);
layoutParams.y = screenHeight / 2-UIUtil.dip2px(100);
//将View添加到屏幕上
windowManager.addView(mDeskView, layoutParams);
}
mDeskView.setOnclikListen(new View.OnClickListener() {
@Override
public void onClick(View v) {
assert windowManager != null;
windowManager.removeView(mDeskView);
mDeskView=null;
}
});
}