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

@@ -112,6 +112,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly files('src/main/libs/classes.jar')
implementation 'androidx.appcompat:appcompat:1.2.0'
//implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

View File

@@ -11,10 +11,11 @@
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.MASTER_CLEAR" />
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" /> <!-- 系统权限,有系统签名可以使用 -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!-- Required -->
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<!-- 系统权限,有系统签名可以使用 -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <!-- Required -->
<permission
android:name="com.info.sn.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" /> <!-- Required 一些系统要求的权限,如访问网络等 -->
@@ -56,6 +57,16 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service
android:name=".service.ScreenLockService"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
</intent-filter>
</service>
<service
android:name=".service.InitJpushServer"
android:enabled="true"
@@ -69,7 +80,8 @@
</intent-filter>
</service>
<activity android:name=".activity.MainActivity"
<activity
android:name=".activity.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="sensor">
<intent-filter>
@@ -207,7 +219,14 @@
<category android:name="com.info.sn" />
</intent-filter>
</activity>
<activity android:name=".activity.TopActivity" /> <!-- Since JCore2.0.0 Required SDK核心功能 -->
<activity
android:name=".activity.ScreenLockActivity"
android:taskAffinity=".activity.ScreenLockActivity">
</activity>
<!-- Since JCore2.0.0 Required SDK核心功能 -->
<!-- 这个Service要继承JCommonService -->
<service
android:name=".jpush.PushService"
@@ -220,7 +239,7 @@
<service android:name=".service.MyDownloadService" />
<service android:name=".service.StepService" /> <!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver
android:name="com.info.sn.jpush.MyReceiver"
android:name=".jpush.MyReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
@@ -242,15 +261,13 @@
<receiver
android:name=".receiver.InstallResultReceiver"
android:enabled="true"
android:exported="true" />
<!-- Required . Enable it you can get statistics data with channel -->
android:exported="true" /> <!-- Required . Enable it you can get statistics data with channel -->
<meta-data
android:name="JPUSH_CHANNEL"
android:value="developer-default" />
<meta-data
android:name="JPUSH_APPKEY"
android:value="edf9cec22731b8b2fed56ee6" />
<!-- 设置key -->
android:value="edf9cec22731b8b2fed56ee6" /> <!-- 设置key -->
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="83869aed8624eb00615c2b6d3d15d777" />

View File

@@ -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() {
}
}

View File

@@ -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));
}
}
}

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");

Binary file not shown.

View File

@@ -5,13 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray"
tools:context=".activity.TopActivity">
tools:context=".activity.ScreenLockActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:text="屏幕已锁定"
android:textSize="20sp"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"

View File

@@ -5,13 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray"
tools:context=".activity.TopActivity">
tools:context=".activity.ScreenLockActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:text="屏幕已锁定"
android:textSize="20sp"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"

View File

@@ -20,6 +20,12 @@ allprojects {
jcenter()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
//设置jar相对包路径或绝对路径
options.compilerArgs.add('-Xbootclasspath/p:app/src/main/libs/classes.jar')
}
}
}
task clean(type: Delete) {