fix: PrefSwitch is reset to false when app exit
This commit is contained in:
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@@ -2,8 +2,8 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Auto.js.iml" filepath="$PROJECT_DIR$/Auto.js.iml" />
|
||||
<module fileurl="file://E:\YiBin\AndroidStudioProjects\NoRootScriptDroid\Auto.js.iml" filepath="E:\YiBin\AndroidStudioProjects\NoRootScriptDroid\Auto.js.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/NoRootScriptDroid.iml" filepath="$PROJECT_DIR$/NoRootScriptDroid.iml" />
|
||||
<module fileurl="file://C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" filepath="C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/autojs/autojs.iml" filepath="$PROJECT_DIR$/autojs/autojs.iml" />
|
||||
|
||||
@@ -70,10 +70,12 @@ public class DrawerMenuItemViewHolder extends BindableViewHolder<DrawerMenuItem>
|
||||
}
|
||||
mSwitchCompat.setVisibility(VISIBLE);
|
||||
int prefKey = item.getPrefKey();
|
||||
if (prefKey != 0) {
|
||||
if(prefKey == 0){
|
||||
mSwitchCompat.setChecked(item.isChecked());
|
||||
mSwitchCompat.setPrefKey(null);
|
||||
}else {
|
||||
mSwitchCompat.setPrefKey(itemView.getResources().getString(prefKey));
|
||||
}
|
||||
mSwitchCompat.setChecked(item.isChecked());
|
||||
}
|
||||
|
||||
private void onClick() {
|
||||
|
||||
@@ -69,6 +69,9 @@ public class PrefSwitch extends SwitchCompat implements SharedPreferences.OnShar
|
||||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
if(mPrefKey != null){
|
||||
setChecked(mSharedPreferences.getBoolean(mPrefKey, mDefaultChecked), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SwitchCompat extends android.support.v7.widget.SwitchCompat {
|
||||
|
||||
public void setChecked(boolean checked, boolean notify) {
|
||||
mIgnoreCheckedChange = !notify;
|
||||
setChecked(checked);
|
||||
super.setChecked(checked);
|
||||
mIgnoreCheckedChange = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var files = Object.create(com.stardust.pio.PFiles);
|
||||
var files = Object.create(com.stardust.autojs.runtime.api);
|
||||
files.cwd = function(){
|
||||
return scope.engines.myEngine().cwd();
|
||||
}
|
||||
|
||||
232
autojs/src/main/java/com/stardust/autojs/runtime/api/Files.java
Normal file
232
autojs/src/main/java/com/stardust/autojs/runtime/api/Files.java
Normal file
@@ -0,0 +1,232 @@
|
||||
package com.stardust.autojs.runtime.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import com.stardust.pio.PFileInterface;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.util.Func1;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/1/23.
|
||||
*/
|
||||
|
||||
public class Files {
|
||||
|
||||
public static PFileInterface open(String path, String mode, String encoding, int bufferSize) {
|
||||
return PFiles.open(path, mode, encoding, bufferSize);
|
||||
}
|
||||
|
||||
public static Object open(String path, String mode, String encoding) {
|
||||
return PFiles.open(path, mode, encoding);
|
||||
}
|
||||
|
||||
public static Object open(String path, String mode) {
|
||||
return PFiles.open(path, mode);
|
||||
}
|
||||
|
||||
public static Object open(String path) {
|
||||
return PFiles.open(path);
|
||||
}
|
||||
|
||||
public static boolean create(String path) {
|
||||
return PFiles.create(path);
|
||||
}
|
||||
|
||||
public static boolean createIfNotExists(String path) {
|
||||
return PFiles.createIfNotExists(path);
|
||||
}
|
||||
|
||||
public static boolean createWithDirs(String path) {
|
||||
return PFiles.createWithDirs(path);
|
||||
}
|
||||
|
||||
public static boolean exists(String path) {
|
||||
return PFiles.exists(path);
|
||||
}
|
||||
|
||||
public static boolean ensureDir(String path) {
|
||||
return PFiles.ensureDir(path);
|
||||
}
|
||||
|
||||
public static String read(String path, String encoding) {
|
||||
return PFiles.read(path, encoding);
|
||||
}
|
||||
|
||||
public static String read(String path) {
|
||||
return PFiles.read(path);
|
||||
}
|
||||
|
||||
public static String read(File file, String encoding) {
|
||||
return PFiles.read(file, encoding);
|
||||
}
|
||||
|
||||
public static String read(File file) {
|
||||
return PFiles.read(file);
|
||||
}
|
||||
|
||||
public static String read(InputStream is, String encoding) {
|
||||
return PFiles.read(is, encoding);
|
||||
}
|
||||
|
||||
public static String read(InputStream inputStream) {
|
||||
return PFiles.read(inputStream);
|
||||
}
|
||||
|
||||
public static byte[] readBytes(InputStream is) {
|
||||
return PFiles.readBytes(is);
|
||||
}
|
||||
|
||||
public static boolean copyRaw(Context context, int rawId, String path) {
|
||||
return PFiles.copyRaw(context, rawId, path);
|
||||
}
|
||||
|
||||
public static boolean copyStream(InputStream is, String path) {
|
||||
return PFiles.copyStream(is, path);
|
||||
}
|
||||
|
||||
public static void write(InputStream is, OutputStream os) {
|
||||
PFiles.write(is, os);
|
||||
}
|
||||
|
||||
public static void write(String path, String text) {
|
||||
PFiles.write(path, text);
|
||||
}
|
||||
|
||||
public static void write(String path, String text, String encoding) {
|
||||
PFiles.write(path, text, encoding);
|
||||
}
|
||||
|
||||
public static void write(File file, String text) {
|
||||
PFiles.write(file, text);
|
||||
}
|
||||
|
||||
public static void write(FileOutputStream fileOutputStream, String text) {
|
||||
PFiles.write(fileOutputStream, text);
|
||||
}
|
||||
|
||||
public static void write(OutputStream outputStream, String text, String encoding) {
|
||||
PFiles.write(outputStream, text, encoding);
|
||||
}
|
||||
|
||||
public static void append(String path, String text) {
|
||||
PFiles.append(path, text);
|
||||
}
|
||||
|
||||
public static void append(String path, String text, String encoding) {
|
||||
PFiles.append(path, text, encoding);
|
||||
}
|
||||
|
||||
public static void writeBytes(OutputStream outputStream, byte[] bytes) {
|
||||
PFiles.writeBytes(outputStream, bytes);
|
||||
}
|
||||
|
||||
public static void appendBytes(String path, byte[] bytes) {
|
||||
PFiles.appendBytes(path, bytes);
|
||||
}
|
||||
|
||||
public static void writeBytes(String path, byte[] bytes) {
|
||||
PFiles.writeBytes(path, bytes);
|
||||
}
|
||||
|
||||
public static boolean copy(String pathFrom, String pathTo) {
|
||||
return PFiles.copy(pathFrom, pathTo);
|
||||
}
|
||||
|
||||
public static boolean copyAsset(Context context, String assetFile, String path) {
|
||||
return PFiles.copyAsset(context, assetFile, path);
|
||||
}
|
||||
|
||||
public static String renameWithoutExtensionAndReturnNewPath(String path, String newName) {
|
||||
return PFiles.renameWithoutExtensionAndReturnNewPath(path, newName);
|
||||
}
|
||||
|
||||
public static boolean renameWithoutExtension(String path, String newName) {
|
||||
return PFiles.renameWithoutExtension(path, newName);
|
||||
}
|
||||
|
||||
public static boolean rename(String path, String newName) {
|
||||
return PFiles.rename(path, newName);
|
||||
}
|
||||
|
||||
public static boolean move(String path, String newPath) {
|
||||
return PFiles.move(path, newPath);
|
||||
}
|
||||
|
||||
public static String getExtension(String fileName) {
|
||||
return PFiles.getExtension(fileName);
|
||||
}
|
||||
|
||||
public static String generateNotExistingPath(String path, String extension) {
|
||||
return PFiles.generateNotExistingPath(path, extension);
|
||||
}
|
||||
|
||||
public static String getName(String filePath) {
|
||||
return PFiles.getName(filePath);
|
||||
}
|
||||
|
||||
public static String getNameWithoutExtension(String filePath) {
|
||||
return PFiles.getNameWithoutExtension(filePath);
|
||||
}
|
||||
|
||||
public static File copyAssetToTmpFile(Context context, String path) {
|
||||
return PFiles.copyAssetToTmpFile(context, path);
|
||||
}
|
||||
|
||||
public static boolean deleteRecursively(File file) {
|
||||
return PFiles.deleteRecursively(file);
|
||||
}
|
||||
|
||||
public static boolean remove(String path) {
|
||||
return PFiles.remove(path);
|
||||
}
|
||||
|
||||
public static boolean removeDir(String path) {
|
||||
return PFiles.removeDir(path);
|
||||
}
|
||||
|
||||
public static String getSdcardPath() {
|
||||
return PFiles.getSdcardPath();
|
||||
}
|
||||
|
||||
public static String readAsset(AssetManager assets, String path) {
|
||||
return PFiles.readAsset(assets, path);
|
||||
}
|
||||
|
||||
public static String[] listDir(String path) {
|
||||
return PFiles.listDir(path);
|
||||
}
|
||||
|
||||
public static String[] listDir(String path, Func1<String, Boolean> filter) {
|
||||
return PFiles.listDir(path, filter);
|
||||
}
|
||||
|
||||
public static boolean isFile(String path) {
|
||||
return PFiles.isFile(path);
|
||||
}
|
||||
|
||||
public static boolean isDir(String path) {
|
||||
return PFiles.isDir(path);
|
||||
}
|
||||
|
||||
public static boolean isEmptyDir(String path) {
|
||||
return PFiles.isEmptyDir(path);
|
||||
}
|
||||
|
||||
public static String join(String parent, String child) {
|
||||
return PFiles.join(parent, child);
|
||||
}
|
||||
|
||||
public static String getHumanReadableSize(long bytes) {
|
||||
return PFiles.getHumanReadableSize(bytes);
|
||||
}
|
||||
|
||||
public static String getSimplifiedPath(String path) {
|
||||
return PFiles.getSimplifiedPath(path);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.stardust.concurrent.VolatileDispose;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Rect;
|
||||
|
||||
Reference in New Issue
Block a user