Skip to content

Commit

Permalink
1. config.json 保存配置
Browse files Browse the repository at this point in the history
2. 优化悬浮窗显示时机
  • Loading branch information
1754048656 committed Jan 22, 2024
1 parent 664df5a commit 20706a2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.linsheng.FATJS.aione_editor;

import static com.linsheng.FATJS.config.GlobalVariableHolder.PATH;
import static com.linsheng.FATJS.config.GlobalVariableHolder.isOpenFloatWin;
import static com.linsheng.FATJS.node.AccUtils.moveFloatWindow;
import static com.linsheng.FATJS.node.AccUtils.printLogMsg;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
Expand All @@ -25,9 +26,7 @@
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.linsheng.FATJS.R;

import java.io.File;
Expand All @@ -38,6 +37,7 @@ public class EditorActivity extends AppCompatActivity {
private Editor ed;
private boolean isDark;
public static final String scripts_path = Environment.getExternalStorageDirectory() + PATH;
private boolean __isOpenFloatWin = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -230,17 +230,25 @@ protected void onResume() {
ed.newScript();
ed.setEditorSettings();
}
__isOpenFloatWin = isOpenFloatWin; // 备份记录悬浮窗是否打开
if (__isOpenFloatWin)
moveFloatWindow("隐藏");
super.onResume();
}

@Override
public void finish() {
printLogMsg("EditorActivity finish");
if (__isOpenFloatWin) {
isOpenFloatWin = true;
}
super.finish();
}

@Override
protected void onDestroy() {
ed.setEditorSettings();
printLogMsg("EditorActivity onDestroy");
super.onDestroy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (__mHeight == -1) {
initDisplay();
}
reviewConfig(); // 回显 config 数据
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.linsheng.FATJS.config;

import static com.linsheng.FATJS.node.AccUtils.printLogMsg;

import android.content.Context;
import android.os.Environment;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson2.JSONObject;
import com.caoccao.javet.interop.V8Runtime;
import com.linsheng.FATJS.aione_editor.MainActivity;
import com.linsheng.FATJS.utils.FileUtils;
import com.linsheng.FATJS.utils.StringUtils;

import java.util.HashMap;

Expand Down Expand Up @@ -59,4 +65,24 @@ public class GlobalVariableHolder {
public static boolean isRunning = false; // 是否有任务在运行
public static boolean killThread = false; // 是否强制关闭
public static boolean isOpenFloatWin = false; // 悬浮窗是否打开
public static void saveConfig() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("DEV_MODE", DEV_MODE);
jsonObject.put("CHECKED_FILE_NAME", checkedFileName);
String config_string = jsonObject.toString();
printLogMsg(config_string, 0);
FileUtils.writeToTxt("/sdcard/FATJS_DIR/config.json", config_string);
}

public static void reviewConfig() {
String readFile = FileUtils.readFile("/sdcard/FATJS_DIR/config.json");
if (StringUtils.isEmpty(readFile)) {
printLogMsg("reviewConfig empty", 0);
saveConfig();
return;
}
JSONObject parseObject = JSONObject.parseObject(readFile);
DEV_MODE = parseObject.getBoolean("DEV_MODE");
checkedFileName = parseObject.getString("CHECKED_FILE_NAME");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,25 @@
import static com.linsheng.FATJS.config.GlobalVariableHolder.DEV_MODE;
import static com.linsheng.FATJS.config.GlobalVariableHolder.PATH;
import static com.linsheng.FATJS.config.GlobalVariableHolder.context;
import static com.linsheng.FATJS.config.GlobalVariableHolder.tag;
import static com.linsheng.FATJS.config.GlobalVariableHolder.reviewConfig;
import static com.linsheng.FATJS.config.GlobalVariableHolder.saveConfig;
import static com.linsheng.FATJS.node.AccUtils.printLogMsg;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.media.projection.MediaProjectionManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

Expand All @@ -39,16 +31,13 @@
import com.linsheng.FATJS.R;
import com.linsheng.FATJS.activitys.FloatingButton;
import com.linsheng.FATJS.activitys.FloatingWindow;
import com.linsheng.FATJS.activitys.MainActivity;
import com.linsheng.FATJS.config.GlobalVariableHolder;
import com.linsheng.FATJS.config.WindowPermissionCheck;
import com.linsheng.FATJS.databinding.FragmentDashboardBinding;
import com.linsheng.FATJS.findColor.config.CaptureScreenService;
import com.linsheng.FATJS.findColor.config.ScreenCaptureManager;
import com.linsheng.FATJS.utils.FileUtils;
import com.linsheng.FATJS.utils.StringUtils;

import java.io.File;
import java.util.List;

public class DashboardFragment extends Fragment {
Expand All @@ -63,16 +52,12 @@ public View onCreateView(@NonNull LayoutInflater inflater,
View root = binding.getRoot();

permissions(root); // 赋予权限

// final TextView textView = binding.textDashboard;
// dashboardViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
return root;
}

@Override
public void onResume() {
super.onResume();
//printLogMsg("permissions onResume");
}

@RequiresApi(api = Build.VERSION_CODES.R)
Expand Down Expand Up @@ -150,6 +135,14 @@ public void onGranted(@NonNull List<String> permissions, boolean allGranted) {
FileUtils.writeToTxt(
Environment.getExternalStorageDirectory() + PATH + "version.txt",
"test");
String config = FileUtils.readFile(Environment.getExternalStorageDirectory() + PATH + "config.json");
if (StringUtils.isEmpty(config)) {
printLogMsg("config is empty", 0);
saveConfig();
}else {
printLogMsg("config is not empty, review config", 0);
reviewConfig();
}
}
@Override
public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
Expand Down Expand Up @@ -331,8 +324,6 @@ public void onClick(View v) {
public void onClick(View v) {
if (_screen) {
printLogMsg("switch_screen already True", 0);
// switch_screen.setChecked(_screen);
// Toast.makeText(context, "switch_screen already True", Toast.LENGTH_SHORT).show();
_screen = false;
ScreenCaptureManager.getInstance().stop();
return;
Expand All @@ -346,6 +337,7 @@ public void onClick(View v) {
public void onClick(View v) {
DEV_MODE = !DEV_MODE;
switch_dev.setChecked(DEV_MODE);
saveConfig();
printLogMsg("DEV_MODE => " + DEV_MODE, 0);
Toast.makeText(context, "DEV_MODE => " + DEV_MODE, Toast.LENGTH_SHORT).show();
}
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/com/linsheng/FATJS/ui/home/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.os.Environment;
import android.provider.Settings;
import android.text.InputType;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -39,7 +38,6 @@
import com.linsheng.FATJS.aione_editor.EditorActivity;
import com.linsheng.FATJS.aione_editor.Scripts;

import com.linsheng.FATJS.config.GlobalVariableHolder;
import com.linsheng.FATJS.databinding.FragmentHomeBinding;
import com.linsheng.FATJS.node.TaskBase;
import com.linsheng.FATJS.utils.ExceptionUtil;
Expand Down Expand Up @@ -92,7 +90,7 @@ public void onStart() {
getFileList(0);
// 备份记录悬浮窗是否打开
__isOpenFloatWin = isOpenFloatWin;
if (DEV_MODE && __isOpenFloatWin) {
if (DEV_MODE) {
moveFloatWindow("隐藏");
}
}
Expand Down Expand Up @@ -173,8 +171,12 @@ public MyRecyclerAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int v
public void onBindViewHolder(MyRecyclerAdapter.MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
final String name = list.get(position);
holder.file_name.setText(name);

holder.radio_button.setChecked(position == checkedPosition);
// 根据 file_name 判断是否选中
if (name.equals(checkedFileName)) {
holder.radio_button.setChecked(true);
checkedPosition = position;
}
holder.radio_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -183,6 +185,7 @@ public void onClick(View view) {
checkedPosition = position;
checkedFileName = name;
notifyItemChanged(checkedPosition);
saveConfig();
printLogMsg("已选中 " + checkedFileName, 0);
Toast.makeText(context, "已选中 " + checkedFileName, Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -255,6 +258,7 @@ private void getFileList(int show) { // 获取并刷新脚本文件列表
for (String name : files) {
if (name.endsWith(".js")
|| name.endsWith(".txt")
|| name.endsWith(".json")
|| name.endsWith(".py")
|| name.endsWith(".java")
|| name.endsWith(".class")
Expand Down

0 comments on commit 20706a2

Please sign in to comment.