version:1.2
fix:优化卡顿 update:基本对接完成,增加指示器放大
This commit is contained in:
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("网课模式只允许使用指定应用");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user