version:1.2
fix:优化卡顿 update:基本对接完成,增加指示器放大
This commit is contained in:
@@ -45,6 +45,10 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
public class ApkUtils {
|
||||
private static HashSet<String> excludePackageName = new HashSet<String>() {{
|
||||
this.add(BuildConfig.APPLICATION_ID);
|
||||
this.add("com.uiui.zysn");
|
||||
this.add("com.uiui.zyos");
|
||||
this.add("com.uiui.zybrowser");
|
||||
this.add("com.uiui.zyappstore");
|
||||
this.add("org.chromium.browser");
|
||||
this.add("com.sprd.sprdnote");
|
||||
this.add("com.android.deskclock");
|
||||
@@ -54,8 +58,11 @@ public class ApkUtils {
|
||||
this.add("com.uiui.os");
|
||||
this.add("com.uiui.health");
|
||||
this.add("com.uiui.appstore");
|
||||
// this.add("com.tencent.android.qqdownloader");
|
||||
// this.add("com.alldocube.store");
|
||||
this.add("com.tencent.android.qqdownloader");
|
||||
this.add("com.alldocube.store");
|
||||
this.add("com.joytv.live");
|
||||
this.add("com.iflytek.speechcloud");
|
||||
this.add("com.safe.uiui");
|
||||
}};
|
||||
|
||||
private static HashSet<String> excludeClassName = new HashSet<String>() {{
|
||||
@@ -63,7 +70,6 @@ public class ApkUtils {
|
||||
}};
|
||||
|
||||
private static HashSet<String> showPackageName = new HashSet<String>() {{
|
||||
this.add("com.uiui.zysn");
|
||||
this.add("com.android.dialer");
|
||||
this.add("com.android.gallery3d");
|
||||
this.add("com.android.settings");
|
||||
@@ -183,9 +189,9 @@ public class ApkUtils {
|
||||
}
|
||||
if (isSystemApp(context, pkg))//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
{
|
||||
if (showPackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
// if (showPackageName.contains(pkg)) {
|
||||
// resolveInfos.add(resolveInfo);
|
||||
// }
|
||||
} else {
|
||||
if (setting_other_appInstaller == 0) {//不显示自己安装的
|
||||
if (packageList.contains(pkg)) {
|
||||
@@ -230,17 +236,6 @@ public class ApkUtils {
|
||||
desktopIcons.add(DesktopIcon.creatDesktopIcon(context, applicationInfo));
|
||||
}
|
||||
}
|
||||
DesktopIcon familyIcon = new DesktopIcon();
|
||||
familyIcon.setIcon(context.getDrawable(R.drawable.icon_family_space));
|
||||
familyIcon.setLable("家庭空间");
|
||||
familyIcon.setPackageName("aios.family");
|
||||
desktopIcons.add(0, familyIcon);
|
||||
|
||||
DesktopIcon exitIcon = new DesktopIcon();
|
||||
exitIcon.setIcon(context.getDrawable(R.drawable.exit_icon));
|
||||
exitIcon.setLable("切换系统");
|
||||
exitIcon.setPackageName("aios.exit");
|
||||
desktopIcons.add(exitIcon);
|
||||
return desktopIcons;
|
||||
}
|
||||
|
||||
@@ -346,7 +341,11 @@ public class ApkUtils {
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (context != null) {
|
||||
context.startActivity(intent);
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "openPackage: " + e.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
218
app/src/main/java/com/uiui/zyos/utils/AppUsedTimeUtils.java
Normal file
218
app/src/main/java/com/uiui/zyos/utils/AppUsedTimeUtils.java
Normal file
@@ -0,0 +1,218 @@
|
||||
package com.uiui.zyos.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiui.zyos.bean.BaseResponse;
|
||||
import com.uiui.zyos.config.CommonConfig;
|
||||
import com.uiui.zyos.network.NetInterfaceManager;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class AppUsedTimeUtils {
|
||||
private static final String TAG = AppUsedTimeUtils.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static AppUsedTimeUtils sInstance;
|
||||
private Context mContext;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private SimpleDateFormat ruleSDF = new SimpleDateFormat("HH:mm:ss");
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private AppTimeinfo appTimeinfo;
|
||||
private static final String RUNNING_APP_INFO_KEY = "running_app_info";
|
||||
|
||||
private AppUsedTimeUtils(Context context) {
|
||||
this.mContext = context;
|
||||
appTimeinfo = getAppTimeinfo();
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AppUsedTimeUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static AppUsedTimeUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init TimeUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private static String normalStartTime = "8:00:00";
|
||||
private static String unusualStartTime = "22:00:00";
|
||||
|
||||
static class AppTimeinfo implements Serializable {
|
||||
private static final long serialVersionUID = 5373751133823666192L;
|
||||
|
||||
AppTimeinfo() {
|
||||
this.appPackageName = "";
|
||||
this.endTime = 0;
|
||||
this.startTime = 0;
|
||||
}
|
||||
|
||||
private String appPackageName;
|
||||
private long endTime;
|
||||
private long startTime;
|
||||
|
||||
public String getAppPackageName() {
|
||||
return appPackageName;
|
||||
}
|
||||
|
||||
public void setAppPackageName(String appPackageName) {
|
||||
this.appPackageName = appPackageName;
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(long endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public void setAppPackageName(String name) {
|
||||
appTimeinfo.setAppPackageName(name);
|
||||
setAppTimeinfo();
|
||||
}
|
||||
|
||||
synchronized public String getAppPackageName() {
|
||||
return appTimeinfo.getAppPackageName();
|
||||
}
|
||||
|
||||
synchronized public void setStartTime(long time) {
|
||||
appTimeinfo.setStartTime(time);
|
||||
setAppTimeinfo();
|
||||
}
|
||||
|
||||
synchronized public long getStartTime() {
|
||||
return appTimeinfo.getStartTime();
|
||||
}
|
||||
|
||||
synchronized public void setEndTime(long time) {
|
||||
appTimeinfo.setEndTime(time);
|
||||
setAppTimeinfo();
|
||||
}
|
||||
|
||||
synchronized public long getEndTime() {
|
||||
return appTimeinfo.getEndTime();
|
||||
}
|
||||
|
||||
synchronized private AppTimeinfo getAppTimeinfo() {
|
||||
String jsonString = mMMKV.decodeString(RUNNING_APP_INFO_KEY);
|
||||
if (TextUtils.isEmpty(jsonString)) {
|
||||
return new AppTimeinfo();
|
||||
}
|
||||
Log.e(TAG, "getAppTimeinfo: " + jsonString);
|
||||
Type type = new TypeToken<AppTimeinfo>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
AppTimeinfo appTimeinfo = gson.fromJson(jsonString, type);
|
||||
return appTimeinfo;
|
||||
}
|
||||
|
||||
synchronized private void setAppTimeinfo() {
|
||||
String jsonString = JsonParser.parseString(appTimeinfo.toString()).getAsJsonObject().toString();
|
||||
mMMKV.encode(RUNNING_APP_INFO_KEY, jsonString);
|
||||
}
|
||||
|
||||
private static final long DAY_TIME = 1000 * 60 * 60 * 24;
|
||||
|
||||
public boolean isNormalTime() {
|
||||
long nowTime = System.currentTimeMillis();
|
||||
String nowTimeString = ruleSDF.format(new Date(nowTime)); // 时间戳转换日期
|
||||
try {
|
||||
Date startDate = ruleSDF.parse(normalStartTime);
|
||||
Date endDate = ruleSDF.parse(unusualStartTime);
|
||||
Date now = ruleSDF.parse(nowTimeString);
|
||||
Log.e(TAG, "isScreenshot: startDate = " + startDate);
|
||||
Log.e(TAG, "isScreenshot: endDate = " + endDate);
|
||||
Log.e(TAG, "isScreenshot: now = " + now);
|
||||
if (startDate.getTime() <= now.getTime() && now.getTime() <= endDate.getTime()) {
|
||||
return true;
|
||||
} else if (endDate.getTime() < now.getTime() && now.getTime() <= startDate.getTime() + DAY_TIME) {
|
||||
return false;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "isScreenshot: " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface RunningAppCallback {
|
||||
void onComplete();
|
||||
}
|
||||
|
||||
public void sendRunningApp(RunningAppCallback runningAppCallback) {
|
||||
String packageName = getAppPackageName();
|
||||
long time = getStartTime();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("app_package", packageName);
|
||||
jsonObject.addProperty("version_name", ApkUtils.getAPPVersionName(mContext, packageName));
|
||||
jsonObject.addProperty("start_time", time / 1000);
|
||||
String jsonString = jsonObject.toString();
|
||||
Log.e(TAG, "SendRunningApp: " + jsonString);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getRunningAppObservable(jsonString)
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("SendRunningApp", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("SendRunningApp", "onSubscribe: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("SendRunningApp", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("SendRunningApp", "onComplete: ");
|
||||
if (runningAppCallback != null) {
|
||||
runningAppCallback.onComplete();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
331
app/src/main/java/com/uiui/zyos/utils/CXAESUtil.java
Normal file
331
app/src/main/java/com/uiui/zyos/utils/CXAESUtil.java
Normal file
@@ -0,0 +1,331 @@
|
||||
package com.uiui.zyos.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.CipherInputStream;
|
||||
import javax.crypto.CipherOutputStream;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class CXAESUtil {
|
||||
/**
|
||||
* 加解密算法/工作模式/填充方式
|
||||
*/
|
||||
private static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
|
||||
public final static String HEX = "0123456789ABCDEF";
|
||||
private static final int keyLenght = 16;
|
||||
private static final String defaultV = "0";
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param key 密钥
|
||||
* @param src 加密文本
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encrypt(String key, String src) {
|
||||
// /src = Base64.encodeToString(src.getBytes(), Base64.DEFAULT);
|
||||
byte[] rawKey = toMakekey(key, keyLenght, defaultV).getBytes();// key.getBytes();
|
||||
try {
|
||||
byte[] result = encrypt(rawKey, src.getBytes("utf-8"));
|
||||
// result = Base64.encode(result, Base64.DEFAULT);
|
||||
return toHex(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param key 密钥
|
||||
* @param src 加密文本
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encrypt2Java(String key, String src) throws Exception {
|
||||
// /src = Base64.encodeToString(src.getBytes(), Base64.DEFAULT);
|
||||
byte[] rawKey = toMakekey(key, keyLenght, defaultV).getBytes();// key.getBytes();
|
||||
byte[] result = encrypt2Java(rawKey, src.getBytes("utf-8"));
|
||||
// result = Base64.encode(result, Base64.DEFAULT);
|
||||
return toHex(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param key 密钥
|
||||
* @param encrypted 待揭秘文本
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decrypt(String key, String encrypted) throws Exception {
|
||||
byte[] rawKey = toMakekey(key, keyLenght, defaultV).getBytes();// key.getBytes();
|
||||
byte[] enc = toByte(encrypted);
|
||||
// enc = Base64.decode(enc, Base64.DEFAULT);
|
||||
byte[] result = decrypt(rawKey, enc);
|
||||
// /result = Base64.decode(result, Base64.DEFAULT);
|
||||
return new String(result, "utf-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 密钥key ,默认补的数字,补全16位数,以保证安全补全至少16位长度,android和ios对接通过
|
||||
*
|
||||
* @param str
|
||||
* @param strLength
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
private static String toMakekey(String str, int strLength, String val) {
|
||||
|
||||
int strLen = str.length();
|
||||
if (strLen < strLength) {
|
||||
while (strLen < strLength) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(str).append(val);
|
||||
str = buffer.toString();
|
||||
strLen = str.length();
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 真正的加密过程
|
||||
* 1.通过密钥得到一个密钥专用的对象SecretKeySpec
|
||||
* 2.Cipher 加密算法,加密模式和填充方式三部分或指定加密算 (可以只用写算法然后用默认的其他方式)Cipher.getInstance("AES");
|
||||
*
|
||||
* @param key
|
||||
* @param src
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static byte[] encrypt(byte[] key, byte[] src) throws Exception {
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
|
||||
byte[] encrypted = cipher.doFinal(src);
|
||||
return encrypted;
|
||||
}
|
||||
|
||||
/**
|
||||
* 真正的加密过程
|
||||
*
|
||||
* @param key
|
||||
* @param src
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static byte[] encrypt2Java(byte[] key, byte[] src) throws Exception {
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
|
||||
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
|
||||
byte[] encrypted = cipher.doFinal(src);
|
||||
return encrypted;
|
||||
}
|
||||
|
||||
/**
|
||||
* 真正的解密过程
|
||||
*
|
||||
* @param key
|
||||
* @param encrypted
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static byte[] decrypt(byte[] key, byte[] encrypted) throws Exception {
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
|
||||
byte[] decrypted = cipher.doFinal(encrypted);
|
||||
return decrypted;
|
||||
}
|
||||
|
||||
public static String toHex(String txt) {
|
||||
return toHex(txt.getBytes());
|
||||
}
|
||||
|
||||
public static String fromHex(String hex) {
|
||||
return new String(toByte(hex));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把16进制转化为字节数组
|
||||
*
|
||||
* @param hexString
|
||||
* @return
|
||||
*/
|
||||
public static byte[] toByte(String hexString) {
|
||||
int len = hexString.length() / 2;
|
||||
byte[] result = new byte[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16).byteValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 二进制转字符,转成了16进制
|
||||
* 0123456789abcdefg
|
||||
*
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
public static String toHex(byte[] buf) {
|
||||
if (buf == null)
|
||||
return "";
|
||||
StringBuffer result = new StringBuffer(2 * buf.length);
|
||||
for (int i = 0; i < buf.length; i++) {
|
||||
appendHex(result, buf[i]);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static void appendHex(StringBuffer sb, byte b) {
|
||||
sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 AES Cipher
|
||||
*
|
||||
* @param sKey
|
||||
* @param cipherMode
|
||||
* @return
|
||||
*/
|
||||
public static Cipher initAESCipher(String sKey, int cipherMode) {
|
||||
// 创建Key gen
|
||||
// KeyGenerator keyGenerator = null;
|
||||
Cipher cipher = null;
|
||||
try {
|
||||
/*
|
||||
* keyGenerator = KeyGenerator.getInstance("AES");
|
||||
* keyGenerator.init(128, new SecureRandom(sKey.getBytes()));
|
||||
* SecretKey secretKey = keyGenerator.generateKey(); byte[]
|
||||
* codeFormat = secretKey.getEncoded(); SecretKeySpec key = new
|
||||
* SecretKeySpec(codeFormat, "AES"); cipher =
|
||||
* Cipher.getInstance("AES"); //初始化 cipher.init(cipherMode, key);
|
||||
*/
|
||||
byte[] rawKey = toMakekey(sKey, keyLenght, defaultV).getBytes();
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES");
|
||||
cipher = Cipher.getInstance("AES");
|
||||
cipher.init(cipherMode, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use File |
|
||||
// Settings | File Templates.
|
||||
} catch (NoSuchPaddingException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use File |
|
||||
// Settings | File Templates.
|
||||
} catch (InvalidKeyException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use File |
|
||||
// Settings | File Templates.
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对文件进行AES加密
|
||||
*
|
||||
* @param sourceFile
|
||||
* @param sKey
|
||||
* @return
|
||||
*/
|
||||
public static File encryptFile(File sourceFile, String toFile, String dir, String sKey) {
|
||||
// 新建临时加密文件
|
||||
File encrypfile = null;
|
||||
InputStream inputStream = null;
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(sourceFile);
|
||||
encrypfile = new File(dir + toFile);
|
||||
outputStream = new FileOutputStream(encrypfile);
|
||||
Cipher cipher = initAESCipher(sKey, Cipher.ENCRYPT_MODE);
|
||||
// 以加密流写入文件
|
||||
CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher);
|
||||
byte[] cache = new byte[1024];
|
||||
int nRead = 0;
|
||||
while ((nRead = cipherInputStream.read(cache)) != -1) {
|
||||
outputStream.write(cache, 0, nRead);
|
||||
outputStream.flush();
|
||||
}
|
||||
cipherInputStream.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use File |
|
||||
// Settings | File Templates.
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use File |
|
||||
// Settings | File Templates.
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use
|
||||
// File | Settings | File Templates.
|
||||
}
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use
|
||||
// File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
return encrypfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* AES方式解密文件
|
||||
*
|
||||
* @param sourceFile
|
||||
* @return
|
||||
*/
|
||||
public static File decryptFile(File sourceFile, String toFile, String dir, String sKey) {
|
||||
File decryptFile = null;
|
||||
InputStream inputStream = null;
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
decryptFile = new File(dir + toFile);
|
||||
Cipher cipher = initAESCipher(sKey, Cipher.DECRYPT_MODE);
|
||||
inputStream = new FileInputStream(sourceFile);
|
||||
outputStream = new FileOutputStream(decryptFile);
|
||||
CipherOutputStream cipherOutputStream = new CipherOutputStream(outputStream, cipher);
|
||||
byte[] buffer = new byte[1024];
|
||||
int r;
|
||||
while ((r = inputStream.read(buffer)) >= 0) {
|
||||
cipherOutputStream.write(buffer, 0, r);
|
||||
}
|
||||
cipherOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use File |
|
||||
// Settings | File Templates.
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use
|
||||
// File | Settings | File Templates.
|
||||
}
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // To change body of catch statement use
|
||||
// File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
return decryptFile;
|
||||
}
|
||||
|
||||
}
|
||||
54
app/src/main/java/com/uiui/zyos/utils/FileUtil.java
Normal file
54
app/src/main/java/com/uiui/zyos/utils/FileUtil.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.uiui.zyos.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class FileUtil {
|
||||
public static String getFileType(String url) {
|
||||
if (url.indexOf("/") == -1) {
|
||||
return url.substring(url.indexOf("."), url.length());
|
||||
} else {
|
||||
String fileName = url.substring(url.lastIndexOf("/"));
|
||||
return fileName.substring(fileName.indexOf("."), fileName.length());
|
||||
}
|
||||
}
|
||||
|
||||
private static HashSet<String> videoFormat = new HashSet<String>() {{
|
||||
this.add(".mp4");
|
||||
this.add(".avi");
|
||||
this.add(".nkv");
|
||||
this.add(".flv");
|
||||
}};
|
||||
private static HashSet<String> pictureFormat = new HashSet<String>() {{
|
||||
this.add(".png");
|
||||
this.add(".jpg");
|
||||
this.add(".jpeg");
|
||||
this.add(".bmp");
|
||||
}};
|
||||
|
||||
public static boolean isVideoFile(String fileName) {
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
return false;
|
||||
} else {
|
||||
if (!fileName.startsWith(".")) {
|
||||
return videoFormat.contains(getFileType(fileName));
|
||||
} else {
|
||||
return videoFormat.contains(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPictureFile(String fileName) {
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
return false;
|
||||
} else {
|
||||
if (!fileName.startsWith(".")) {
|
||||
return pictureFormat.contains(getFileType(fileName));
|
||||
} else {
|
||||
return pictureFormat.contains(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.uiui.zyos.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
|
||||
public class GsonUtils {
|
||||
public static JsonObject getJsonObject(String jsonString) {
|
||||
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
// TODO: 2022/3/31 暂时没有实现
|
||||
public static <T> T getJsonFromType(String jsonString, Class clazz) {
|
||||
Gson gson = new Gson();
|
||||
T t = (T) gson.fromJson(jsonString, clazz);
|
||||
return t;
|
||||
}
|
||||
|
||||
public static String toJsonString(Object o) {
|
||||
return new Gson().toJson(o);
|
||||
}
|
||||
}
|
||||
232
app/src/main/java/com/uiui/zyos/utils/OpenApkUtils.java
Normal file
232
app/src/main/java/com/uiui/zyos/utils/OpenApkUtils.java
Normal file
@@ -0,0 +1,232 @@
|
||||
package com.uiui.zyos.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiui.zyos.bean.LessonJson;
|
||||
import com.uiui.zyos.config.CommonConfig;
|
||||
import com.uiui.zyos.jxw.JxwPackageConfig;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class OpenApkUtils {
|
||||
private static final String TAG = OpenApkUtils.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static OpenApkUtils sInstance;
|
||||
private Context mContext;
|
||||
private ContentResolver resolver;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private LessonJson mLessonJson;
|
||||
TimeUtils.ContralTime mContralTime;
|
||||
|
||||
private OpenApkUtils(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
this.resolver = context.getContentResolver();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new OpenApkUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static OpenApkUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init OpenApkUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public boolean openPackageWithArgs(String packageName, String className, String name, String args) {
|
||||
if (!ApkUtils.isAvailable(mContext, packageName)) {
|
||||
ToastUtil.show("应用未安装");
|
||||
return false;
|
||||
}
|
||||
ComponentName cn = new ComponentName(packageName, className);
|
||||
Intent intent = new Intent();
|
||||
intent.setComponent(cn);
|
||||
intent.putExtra(name, args);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
try {
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "openPackageWithArgs: " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
String jsonString = mMMKV.decodeString(CommonConfig.CLOUD_LESSON_SETTINGS_KEY);
|
||||
if (!TextUtils.isEmpty(jsonString)) {
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<LessonJson>() {
|
||||
}.getType();
|
||||
LessonJson lessonJson = gson.fromJson(jsonString, type);
|
||||
if (lessonJson != null) {
|
||||
this.mLessonJson = lessonJson;
|
||||
TimeUtils.ContralTime contralTime = TimeUtils.getContralTime(mContext, lessonJson.getStart_time(), lessonJson.getEnd_time());
|
||||
if (contralTime != null) {
|
||||
mContralTime = contralTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCloudLessonMod(String pkg) {
|
||||
if (mLessonJson.getIs_lesson() == 1) {
|
||||
if (mContralTime == null) {
|
||||
return false;
|
||||
} else {
|
||||
String pkgs = mLessonJson.getPkgs();
|
||||
if (mContralTime.inControlTime()) {
|
||||
return pkgs.contains(pkg);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendRuningApp(String packageName) {
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(packageName);
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
AppUsedTimeUtils.getInstance().sendRunningApp(() -> {
|
||||
});
|
||||
}
|
||||
|
||||
public void openApp(String packageName) {
|
||||
if (!ApkUtils.isAvailable(mContext, packageName)) {
|
||||
ToastUtil.show("应用未安装");
|
||||
return;
|
||||
}
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
ApkUtils.openPackage(mContext, packageName);
|
||||
sendRuningApp(packageName);
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openApp(String packageName, String className) {
|
||||
if (!ApkUtils.isAvailable(mContext, packageName)) {
|
||||
ToastUtil.show("应用未安装");
|
||||
return;
|
||||
}
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
ApkUtils.openPackage(mContext, packageName, className);
|
||||
sendRuningApp(packageName);
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void openSyncVideo(String args) {
|
||||
String packageName = JxwPackageConfig.JXW_VIDEO_PACKAGE_NAME;
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
if (openPackageWithArgs(packageName, JxwPackageConfig.JXW_VIDEO_CLASS_NAME, "StartArgs", args)) {
|
||||
sendRuningApp(packageName);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openSynchronousTutoring(String args) {
|
||||
String packageName = JxwPackageConfig.JXW_TUTORING_PACKAGE_NAME;
|
||||
String className = JxwPackageConfig.JXW_TUTORING_CLASS_NAME;
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
if (openPackageWithArgs(packageName, className, "StartArgs", args)) {
|
||||
sendRuningApp(packageName);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openSolidifiedData(String args) {
|
||||
String packageName = JxwPackageConfig.JXW_TUTORING_PACKAGE_NAME;
|
||||
String className = JxwPackageConfig.JXW_RHETORIC_CLASS_NAME;
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
if (openPackageWithArgs(packageName, className, "StartArgs", args)) {
|
||||
sendRuningApp(packageName);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openComposition() {
|
||||
String packageName = JxwPackageConfig.JXW_VIDEO_PACKAGE_NAME;
|
||||
String className = JxwPackageConfig.JXW_COMPOSITION_CLASS_NAME;
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
if (openPackageWithArgs(packageName, className, "StartArgs", "专区数据/专题精品课/语文阅读与写作/小学")) {
|
||||
sendRuningApp(packageName);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openQuality() {
|
||||
String packageName = JxwPackageConfig.JXW_VIDEO_PACKAGE_NAME;
|
||||
String className = JxwPackageConfig.JXW_Quality_CLASS_NAME;
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
if (openPackageWithArgs(packageName, className, "StartArgs", "中华文化")) {
|
||||
sendRuningApp(packageName);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openPrecision(String args) {
|
||||
String packageName = JxwPackageConfig.JXW_PRECISION_PACKAGE_NAME;
|
||||
String className = JxwPackageConfig.JXW_PRECISION_CLASS_NAME;
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
if (openPackageWithArgs(packageName, className, "tiku_func_type", args)) {
|
||||
sendRuningApp(packageName);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openAppWithoutArgs(String packageName, String className) {
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
openApp(packageName, className);
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
|
||||
public void openLaboratory(String args) {
|
||||
String packageName = JxwPackageConfig.JXW_laboratory_PACKAGE_NAME;
|
||||
String className = JxwPackageConfig.JXW_laboratory_CLASS_NAME;
|
||||
if (isCloudLessonMod(packageName)) {
|
||||
if (openPackageWithArgs(packageName, className, "StartArgs", args)) {
|
||||
sendRuningApp(packageName);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.show("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,31 @@
|
||||
package com.uiui.zyos.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class TimeUtils {
|
||||
private static final String TAG = TimeUtils.class.getSimpleName();
|
||||
|
||||
private static DateFormat df = new SimpleDateFormat("HH:mm", Locale.getDefault());
|
||||
|
||||
public static final long DAY_TIME = 60 * 60 * 24 * 1000;
|
||||
public static final long MINUTE_TIME = 60 * 1000;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public static boolean isTodayTime(long timeStamp) {
|
||||
String time = transferLongToDate(timeStamp);
|
||||
@@ -21,9 +36,148 @@ public class TimeUtils {
|
||||
return localTime.isAfter(startTime) && localTime.isBefore(endTime);
|
||||
}
|
||||
|
||||
public static String transferLongToDate(Long millSec) {
|
||||
public static String transferLongToDate(Long millisecond) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date(millSec);
|
||||
Date date = new Date(millisecond);
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public static String getDateAndWeek(Long millisecond) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
|
||||
Date date = new Date(millisecond);
|
||||
String dateString = sdf.format(date);
|
||||
return dateString + "\t" + getWeek();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否在管控时间内
|
||||
*
|
||||
* @param context
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
public static ContralTime getContralTime(Context context, String startTime, String endTime) {
|
||||
if (null == startTime || null == endTime || ("00:00".equals(startTime) && "00:00".equals(endTime))) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
Date startDate = df.parse(startTime.trim());
|
||||
Date endDate = df.parse(endTime.trim());
|
||||
ContralTime contralTime = new ContralTime();
|
||||
contralTime.setStartTime(df.format(startDate));
|
||||
contralTime.setEndTime(df.format(endDate));
|
||||
return contralTime;
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 根据日期取得星期几
|
||||
*/
|
||||
public static String getWeek() {
|
||||
Date date = new Date();
|
||||
String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
int weekIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (weekIndex < 0) {
|
||||
weekIndex = 0;
|
||||
}
|
||||
return weeks[weekIndex];
|
||||
}
|
||||
|
||||
public static class ContralTime {
|
||||
//format HH:mm
|
||||
String startTime;
|
||||
String endTime;
|
||||
|
||||
public ContralTime() {
|
||||
|
||||
}
|
||||
|
||||
public ContralTime(String startT, String endT) {
|
||||
this.startTime = startT;
|
||||
this.endTime = endT;
|
||||
}
|
||||
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
|
||||
public void setStartTime(String startT) {
|
||||
this.startTime = startT;
|
||||
}
|
||||
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(String endT) {
|
||||
this.endTime = endT;
|
||||
}
|
||||
|
||||
public static DateFormat getDf() {
|
||||
return df;
|
||||
}
|
||||
|
||||
public static void setDf(DateFormat d) {
|
||||
df = d;
|
||||
}
|
||||
|
||||
public String getNowTimeString(long time) {
|
||||
return df.format(new Date(time));
|
||||
}
|
||||
|
||||
public boolean inControlTime() {
|
||||
long time = System.currentTimeMillis();
|
||||
return inControlTime(time);
|
||||
}
|
||||
|
||||
public boolean inControlTime(long time) {
|
||||
return inControlTime(df.format(new Date(time)));
|
||||
}
|
||||
|
||||
public boolean inControlTime(String time) {
|
||||
if (TextUtils.isEmpty(time)) {
|
||||
throw new RuntimeException("Time is empty");
|
||||
} else {
|
||||
if (!time.contains(":")) {
|
||||
throw new RuntimeException("Time format error");
|
||||
}
|
||||
}
|
||||
try {
|
||||
Date startDate = df.parse(startTime);
|
||||
Date endDate = df.parse(endTime);
|
||||
Date nowDate = df.parse(time);
|
||||
if (startDate.getTime() > endDate.getTime()) {
|
||||
//开始时间大于结束时间 列 16:00-01:00
|
||||
endDate.setTime(endDate.getTime() + DAY_TIME);
|
||||
}
|
||||
Log.e(TAG, "inControlTime: " + (startDate.getTime() - MINUTE_TIME));
|
||||
assert nowDate != null;
|
||||
// if (nowDate.getTime() <= startDate.getTime() - MINUTE_TIME || nowDate.getTime() >= endDate.getTime()) {
|
||||
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return startTime + "\t-\t" + endTime;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ToastUtil {
|
||||
}
|
||||
|
||||
public static void betaShow(final String msg) {
|
||||
if ( BuildConfig.DEBUG) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
ToastUtils.make()
|
||||
// .setBgColor(ColorUtils.getColor(R.color.toast_color))
|
||||
.setTextColor(Color.RED)
|
||||
|
||||
@@ -14,15 +14,24 @@ import android.graphics.PorterDuffXfermode;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.uiui.zyos.BuildConfig;
|
||||
import com.uiui.zyos.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Utils {
|
||||
private static final String TAG = Utils.class.getSimpleName();
|
||||
@@ -141,4 +150,62 @@ public class Utils {
|
||||
// return bgBitmap;
|
||||
}
|
||||
|
||||
public static Bitmap createQRImage(String content, int widthPix, int heightPix) {
|
||||
try {
|
||||
// if (content == null || "".equals(content)) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
//配置参数
|
||||
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
|
||||
//容错级别
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
||||
//设置空白边距的宽度
|
||||
hints.put(EncodeHintType.MARGIN, 1); //default is 4
|
||||
|
||||
// 图像数据转换,使用了矩阵转换
|
||||
BitMatrix bitMatrix = null;
|
||||
try {
|
||||
bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix,
|
||||
heightPix, hints);
|
||||
} catch (WriterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int[] pixels = new int[widthPix * heightPix];
|
||||
// 下面这里按照二维码的算法,逐个生成二维码的图片,
|
||||
// 两个for循环是图片横列扫描的结果
|
||||
for (int y = 0; y < heightPix; y++) {
|
||||
for (int x = 0; x < widthPix; x++) {
|
||||
if (bitMatrix.get(x, y)) {
|
||||
pixels[y * widthPix + x] = 0xff0480ff;
|
||||
} else {
|
||||
pixels[y * widthPix + x] = 0xffffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成二维码图片的格式,使用ARGB_8888
|
||||
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
|
||||
//
|
||||
// if (logoBm != null) {
|
||||
// bitmap = addLogo(bitmap, logoBm);
|
||||
// }
|
||||
|
||||
//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,
|
||||
// 内存消耗巨大!
|
||||
return bitmap;
|
||||
// return bitmap != null && bitmap.compress(Bitmap.CompressFormat.JPEG, 100);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isScreenOn(Context context) {
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
//true为打开,false为关闭
|
||||
return powerManager.isInteractive();
|
||||
}
|
||||
}
|
||||
|
||||
119
app/src/main/java/com/uiui/zyos/utils/WakeUpUtils.java
Normal file
119
app/src/main/java/com/uiui/zyos/utils/WakeUpUtils.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package com.uiui.zyos.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
public class WakeUpUtils {
|
||||
|
||||
/**
|
||||
* 唤醒手机屏幕并解锁
|
||||
*/
|
||||
public static void wakeUpAndUnlock(Activity activity) {
|
||||
// 获取电源管理器对象
|
||||
PowerManager pm = (PowerManager) activity.getApplicationContext()
|
||||
.getSystemService(Context.POWER_SERVICE);
|
||||
boolean screenOn = pm.isScreenOn();
|
||||
Log.d("WakeScreen0", "screenOn: " + screenOn);
|
||||
if (!screenOn) {
|
||||
// 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
|
||||
@SuppressLint("InvalidWakeLockTag") PowerManager.WakeLock wl = pm.newWakeLock(
|
||||
PowerManager.ACQUIRE_CAUSES_WAKEUP |
|
||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
|
||||
wl.acquire(10000); // 点亮屏幕
|
||||
wl.release(); // 释放
|
||||
}
|
||||
// 屏幕解锁
|
||||
KeyguardManager keyguardManager = (KeyguardManager) activity.getApplicationContext()
|
||||
.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
|
||||
// 屏幕锁定
|
||||
// keyguardLock.reenableKeyguard();
|
||||
keyguardLock.disableKeyguard(); // 解锁
|
||||
unLockScreen(activity);
|
||||
}
|
||||
|
||||
private static void unLockScreen(Activity activity) {
|
||||
final Window win = activity.getWindow();
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
|
||||
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* 唤醒手机屏幕并解锁
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public static void wakeUpAndUnlockScreen(Activity activity) {
|
||||
|
||||
Window win = activity.getWindow();
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
|
||||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
|
||||
PowerManager pm = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
|
||||
@SuppressLint("InvalidWakeLockTag")
|
||||
PowerManager.WakeLock wakelock = pm.newWakeLock(
|
||||
PowerManager.FULL_WAKE_LOCK
|
||||
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "xx");
|
||||
wakelock.acquire();
|
||||
wakelock.release();
|
||||
|
||||
KeyguardManager keyguardManager = (KeyguardManager) activity.getApplicationContext()
|
||||
.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
|
||||
if (activity == null) return;
|
||||
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
|
||||
@Override
|
||||
public void onDismissError() {
|
||||
super.onDismissError();
|
||||
Log.d("xxx-->", "1 onDismissError");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissSucceeded() {
|
||||
super.onDismissSucceeded();
|
||||
Log.d("xxx-->", "1 onDismissSucceeded");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissCancelled() {
|
||||
super.onDismissCancelled();
|
||||
Log.d("xxx-->", "1 onDismissCancelled");
|
||||
}
|
||||
});
|
||||
|
||||
if (activity == null) return;
|
||||
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
|
||||
@Override
|
||||
public void onDismissError() {
|
||||
super.onDismissError();
|
||||
Log.d("xxx-->", "2 onDismissError");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissSucceeded() {
|
||||
super.onDismissSucceeded();
|
||||
Log.d("xxx-->", "2 onDismissSucceeded");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissCancelled() {
|
||||
super.onDismissCancelled();
|
||||
Log.d("xxx-->", "2 onDismissCancelled");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user