update:2021.01.29

fix:锁屏界面修改为全屏,屏蔽导航栏和通知栏
add:
This commit is contained in:
2021-01-29 16:40:05 +08:00
parent 32a61c38c3
commit 299ada5a6f
9 changed files with 88 additions and 26 deletions

View File

@@ -15,6 +15,7 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
@@ -27,8 +28,7 @@ import com.info.sn.bean.BaseResponse;
import com.info.sn.network.HTTPInterface;
import com.info.sn.network.NetWorkManager;
import com.info.sn.network.api.ScreenLock;
import com.info.sn.utils.ApkUtils;
import com.info.sn.utils.ForegroundAppUtil;
import com.info.sn.utils.SPUtils;
import com.info.sn.utils.TimeUtils;
import com.info.sn.utils.Utils;
@@ -103,23 +103,38 @@ public class InitJpushServer extends Service {
showFloatingWindow("屏幕已锁定");
}
screenlocked = true;
SPUtils.put(InitJpushServer.this, LOCK_STATE, 1);
} else {
if (!timelocked) {
hideFloatingWindow();
}
screenlocked = false;
SPUtils.put(InitJpushServer.this, LOCK_STATE, 0);
}
} else {
if (!timelocked) {
hideFloatingWindow();
}
screenlocked = false;
SPUtils.put(InitJpushServer.this, LOCK_STATE, 0);
}
}
@Override
public void onError(Throwable e) {
Log.e("getScreenLockState", "onError: " + e.getMessage());
int is_screen_lock = (int) SPUtils.get(InitJpushServer.this, LOCK_STATE, 0);
if (is_screen_lock == 1) {
if (!timelocked) {
showFloatingWindow("屏幕已锁定");
}
screenlocked = true;
} else {
if (!timelocked) {
hideFloatingWindow();
}
screenlocked = false;
}
}
@Override
@@ -137,6 +152,8 @@ public class InitJpushServer extends Service {
boolean screenlocked = false;
boolean timelocked = false;
private static final String LOCK_STATE = "SCRENN_LOOCKED_STATE";
private void showFloatingWindow(String name) {
if (Settings.canDrawOverlays(this)) {
// 获取WindowManager服务
@@ -159,7 +176,7 @@ public class InitJpushServer extends Service {
}
});
if (null == topView) {
topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_top, null);
topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_screen_lock, null);
TextView textView = topView.findViewById(R.id.textView);
textView.setText(name);
} else {
@@ -173,17 +190,26 @@ public class InitJpushServer extends Service {
// 设置LayoutParam
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
layoutParams.type = WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
//TYPE_SYSTEM_OVERLAY可以下滑通知栏
// layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
} else {
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
}
layoutParams.flags = WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
layoutParams.flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
layoutParams.format = PixelFormat.RGBA_8888;
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
//systemUiVisibility 关闭通知栏和导航栏
layoutParams.systemUiVisibility =
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
layoutParams.x = 0;
layoutParams.y = 0;
// 将悬浮窗控件添加到WindowManager
windowManager.addView(topView, layoutParams);
topView.setTag("added");