update:2021.01.29
fix:锁屏界面修改为全屏,屏蔽导航栏和通知栏 add:
This commit is contained in:
@@ -3,18 +3,22 @@ package com.info.sn.activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.info.sn.R;
|
||||
|
||||
|
||||
public class TopActivity extends AppCompatActivity {
|
||||
public class ScreenLockActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_top);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||
setContentView(R.layout.activity_screen_lock);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,4 +34,9 @@ public class TopActivity extends AppCompatActivity {
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import android.util.Log;
|
||||
import com.info.sn.service.GuardService;
|
||||
import com.info.sn.service.InitJpushServer;
|
||||
import com.info.sn.service.MyDownloadService;
|
||||
import com.info.sn.service.ScreenLockService;
|
||||
import com.info.sn.service.StepService;
|
||||
|
||||
|
||||
@@ -35,6 +36,8 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
context.startService(new Intent(context, StepService.class));
|
||||
context.startService(new Intent(context, InitJpushServer.class));
|
||||
context.startService(new Intent(context, MyDownloadService.class));
|
||||
context.startService(new Intent(context, ScreenLockService.class));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user