version:1.0.1
fix: update:基本功能完成,修复闪退,更换壁纸未实现
This commit is contained in:
@@ -1,16 +1,49 @@
|
||||
package com.xwad.os.fragment.safe;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.base.mvvm.fragment.BaseMvvmFragment;
|
||||
import com.xwad.os.bean.jxw.AppInfo;
|
||||
import com.xwad.os.config.CommonConfig;
|
||||
import com.xwad.os.databinding.FragmentSafeBinding;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.jxw.AssertUtils;
|
||||
import com.xwad.os.jxw.event.GkEvent;
|
||||
import com.xwad.os.view.jxw.view.dialog.QhbzDialog;
|
||||
import com.xwad.os.jxw.StudyRecordMng;
|
||||
import com.xwad.os.jxw.ToastUtil;
|
||||
import com.xwad.os.jxw.event.UpdateColorEvent;
|
||||
import com.xwad.os.utils.OpenApkUtils;
|
||||
import com.xwad.os.view.jxw.view.dialog.RemoveAppDialog;
|
||||
import com.xwad.os.view.jxw.widget.RecyclerMarginClickHelper;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
@@ -18,10 +51,20 @@ import com.tencent.mmkv.MMKV;
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class SafeFragment extends BaseMvvmFragment<SafeViewModel, FragmentSafeBinding> {
|
||||
private static final String TAG = "PrecisionFragment";
|
||||
private static final String TAG = "SafeFragment";
|
||||
|
||||
private Activity mContext;
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private AppInfo addAppinfo;
|
||||
private AssertUtils.ZhMenuAdapter zhMenuAdapter;
|
||||
private List<AppInfo> mlistAppInfo = new ArrayList<>();
|
||||
private Handler mHandler = new Handler();
|
||||
public String file_name = "app_list_6.0";
|
||||
int len = 0;
|
||||
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
@@ -60,6 +103,7 @@ public class SafeFragment extends BaseMvvmFragment<SafeViewModel, FragmentSafeBi
|
||||
|
||||
@Override
|
||||
protected void initDataBinding() {
|
||||
mContext = getActivity();
|
||||
mViewModel.setCtx(getCtx());
|
||||
mViewModel.setLifecycle(getLifecycleSubject());
|
||||
mViewModel.setVDBinding(mViewDataBinding);
|
||||
@@ -73,6 +117,82 @@ public class SafeFragment extends BaseMvvmFragment<SafeViewModel, FragmentSafeBi
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
|
||||
mViewDataBinding.gridViewId.setLayoutManager(new GridLayoutManager(mContext, 8));
|
||||
zhMenuAdapter = new AssertUtils.ZhMenuAdapter(mContext, mlistAppInfo);
|
||||
mViewDataBinding.gridViewId.setAdapter(zhMenuAdapter);
|
||||
mViewDataBinding.relaRoot.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
zhMenuAdapter.setToDelete(false);
|
||||
}
|
||||
});
|
||||
RecyclerMarginClickHelper.setOnMarginClickListener(mViewDataBinding.gridViewId, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
zhMenuAdapter.setToDelete(false);
|
||||
}
|
||||
});
|
||||
zhMenuAdapter.setOnItemClickListener(new AssertUtils.ZhMenuAdapter.RadiaoOnItemClickListener() {
|
||||
@Override
|
||||
public void onSelectClick(int i) {
|
||||
AppInfo appInfo;
|
||||
if (mlistAppInfo == null || mlistAppInfo.size() <= 0 || (appInfo = mlistAppInfo.get(i)) == null) {
|
||||
return;
|
||||
}
|
||||
if (appInfo.appName.equals("切换壁纸")) {
|
||||
QhbzDialog qhbzDialog = new QhbzDialog(mContext);
|
||||
qhbzDialog.show();
|
||||
qhbzDialog.setOnCallback(new QhbzDialog.Callback() {
|
||||
@Override
|
||||
public void onCallback(int i2) {
|
||||
EventBus.getDefault().postSticky(new UpdateColorEvent());
|
||||
}
|
||||
});
|
||||
} else if (!TextUtils.isEmpty(appInfo.getPkgName())) {
|
||||
Log.e(TAG, "onSelectClick: onItemClick 11");
|
||||
startApkByPackName(mContext, appInfo.getPkgName());
|
||||
} else if (TextUtils.isEmpty(appInfo.mStargss)) {
|
||||
|
||||
} else {
|
||||
Log.e(TAG, "onItemClick66 " + appInfo.mStargss);
|
||||
// MyApp.getInstance().mBottomBtnOnClickListener.setContext(mContext);
|
||||
// MyApp.getInstance().mBottomBtnOnClickListener.onClick(appInfo.mStargss);
|
||||
OpenApkUtils.getInstance().openJxwApp(appInfo.mStargss);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteClick(final String str, final int i, String str2) {
|
||||
RemoveAppDialog removeAppDialog = new RemoveAppDialog(mContext, str2);
|
||||
removeAppDialog.show();
|
||||
removeAppDialog.setOnCallback(new RemoveAppDialog.Callback() {
|
||||
@Override
|
||||
public void onCallback() {
|
||||
readContent(str, i);
|
||||
if (mlistAppInfo != null) {
|
||||
mlistAppInfo.clear();
|
||||
}
|
||||
initAppData();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
zhMenuAdapter.setOnItemChildLongClickListener(new BaseQuickAdapter.OnItemChildLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemChildLongClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
|
||||
zhMenuAdapter.setToDelete(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
if (mlistAppInfo != null) {
|
||||
mlistAppInfo.clear();
|
||||
}
|
||||
initAppData();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +208,10 @@ public class SafeFragment extends BaseMvvmFragment<SafeViewModel, FragmentSafeBi
|
||||
|
||||
@Override
|
||||
public void fetchData() {
|
||||
|
||||
if (mlistAppInfo != null) {
|
||||
mlistAppInfo.clear();
|
||||
}
|
||||
initAppData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,13 +223,166 @@ public class SafeFragment extends BaseMvvmFragment<SafeViewModel, FragmentSafeBi
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
Log.e(TAG, "setUserVisibleHint: isVisibleToUser = " + isVisibleToUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
super.onActivityResult(requestCode, resultCode, intent);
|
||||
Log.e("onActivityResult: ", "resultCode=" + resultCode + ",requestCode=" + requestCode);
|
||||
if (resultCode == -1 && requestCode == 4) {
|
||||
String stringExtra = intent.getStringExtra("pkg");
|
||||
Iterator<AppInfo> it = mlistAppInfo.iterator();
|
||||
while (it.hasNext()) {
|
||||
AppInfo appInfo = it.next();
|
||||
if (!TextUtils.isEmpty(appInfo.getPkgName()) && appInfo.getPkgName().equals(stringExtra)) {
|
||||
ToastUtil.showTextToastDia("不能重复添加!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
try {
|
||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(stringExtra, PackageManager.GET_META_DATA);
|
||||
AppInfo build = new AppInfo.Builder().appLabel((String) packageManager.getApplicationLabel(applicationInfo)).pkgName(stringExtra).appIcon(packageManager.getApplicationIcon(applicationInfo)).build();
|
||||
mlistAppInfo.remove(addAppinfo);
|
||||
mlistAppInfo.add(build);
|
||||
mlistAppInfo.add(addAppinfo);
|
||||
zhMenuAdapter.setData(mlistAppInfo);
|
||||
zhMenuAdapter.notifyDataSetChanged();
|
||||
writeAppDate(stringExtra);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeAppDate(String str) {
|
||||
try {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(mContext.getFileStreamPath("app_list_6.0"), true);
|
||||
fileOutputStream.write((str + "\n").getBytes());
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(GkEvent gkEvent) {
|
||||
zhMenuAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(UpdateColorEvent updateColorEvent) {
|
||||
zhMenuAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void initAppData() {
|
||||
AppInfo build = new AppInfo.Builder().appLabel("课程表").appStargs(getResources().getString(R.string.tag_args_new_kcb)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_kcb)).build();
|
||||
AppInfo build2 = new AppInfo.Builder().appLabel("语音翻译").appStargs(getResources().getString(R.string.tag_args_new_zyhy)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_yyfy)).build();
|
||||
AppInfo build3 = new AppInfo.Builder().appLabel("使用助手").appStargs(getResources().getString(R.string.tag_args_new_sysmx)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_syzs)).build();
|
||||
AppInfo build4 = new AppInfo.Builder().appLabel("应用更新").appStargs(getResources().getString(R.string.tag_args_updae)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_yygx)).build();
|
||||
AppInfo build5 = new AppInfo.Builder().appLabel("一键加速").appStargs(getResources().getString(R.string.tag_args_new_yjjs)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_yjjs)).build();
|
||||
AppInfo build6 = new AppInfo.Builder().appLabel("下载中心").appStargs(getResources().getString(R.string.tag_args_new_download)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_xzzx)).build();
|
||||
AppInfo build7 = new AppInfo.Builder().appLabel("切换壁纸").appStargs(getResources().getString(R.string.tag_args_launcher)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_qhbz)).build();
|
||||
AppInfo build8 = new AppInfo.Builder().appLabel("安卓平台").appStargs(getResources().getString(R.string.tag_args_launcher)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_azpt)).build();
|
||||
AppInfo build9 = new AppInfo.Builder().appLabel("设置").appStargs(getResources().getString(R.string.tag_args_new_jxwSettings)).appIcon(mContext.getResources().getDrawable(R.drawable.icon_bbx_sz)).build();
|
||||
mlistAppInfo.add(build);
|
||||
mlistAppInfo.add(build2);
|
||||
mlistAppInfo.add(build3);
|
||||
mlistAppInfo.add(build4);
|
||||
mlistAppInfo.add(build5);
|
||||
mlistAppInfo.add(build6);
|
||||
mlistAppInfo.add(build7);
|
||||
mlistAppInfo.add(build8);
|
||||
mlistAppInfo.add(build9);
|
||||
getAppData();
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
zhMenuAdapter.setData(mlistAppInfo);
|
||||
zhMenuAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getAppData() {
|
||||
File fileStreamPath = mContext.getFileStreamPath(file_name);
|
||||
if (!fileStreamPath.exists()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileStreamPath));
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
while (true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine != null) {
|
||||
try {
|
||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(readLine, PackageManager.GET_META_DATA);
|
||||
mlistAppInfo.add(new AppInfo.Builder().appLabel((String) packageManager.getApplicationLabel(applicationInfo)).pkgName(readLine).appIcon(packageManager.getApplicationIcon(applicationInfo)).build());
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
bufferedReader.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e2) {
|
||||
e2.printStackTrace();
|
||||
} catch (IOException e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void startApkByPackName(Context context, String str) {
|
||||
try {
|
||||
context.startActivity(context.getPackageManager().getLaunchIntentForPackage(str));
|
||||
StudyRecordMng.startCount(context, str, "", "", true);
|
||||
} catch (Exception e) {
|
||||
Log.d("zzj", "startApkByPackName error : " + e.toString());
|
||||
ToastUtil.showTextToastDia("此应用已经被家长管控");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String readContent(String str, int i) {
|
||||
File fileStreamPath = mContext.getFileStreamPath(file_name);
|
||||
if (!fileStreamPath.exists()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileStreamPath));
|
||||
int i2 = len;
|
||||
String str2 = "";
|
||||
Log.e(TAG, "pkg = " + str + "poi=" + i);
|
||||
while (true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine != null) {
|
||||
Log.e(TAG, "line " + readLine);
|
||||
if (!readLine.equals(str)) {
|
||||
str2 = str2 + readLine + "\n";
|
||||
}
|
||||
} else {
|
||||
bufferedReader.close();
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(fileStreamPath, false);
|
||||
Log.e(TAG, "sb = " + str2);
|
||||
fileOutputStream.write(str2.getBytes());
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class BtnClick {
|
||||
public void openPrecisionHome(View view) {
|
||||
public void x(View view) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user