Update settings

This commit is contained in:
NekoInverter 2021-01-25 19:37:38 +08:00
parent ad19c1b1f6
commit d7a3520857
No known key found for this signature in database
GPG Key ID: 280D6CCCF95715F9
2 changed files with 26 additions and 222 deletions

View File

@ -1,28 +1,20 @@
package org.meowcat.edxposed.manager.ui.activity; package org.meowcat.edxposed.manager.ui.activity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat; import androidx.preference.SwitchPreferenceCompat;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.takisoft.preferencex.PreferenceFragmentCompat; import com.takisoft.preferencex.PreferenceFragmentCompat;
import com.topjohnwu.superuser.Shell;
import org.meowcat.edxposed.manager.Constants; import org.meowcat.edxposed.manager.Constants;
import org.meowcat.edxposed.manager.R; import org.meowcat.edxposed.manager.R;
@ -31,9 +23,6 @@ import org.meowcat.edxposed.manager.ui.widget.IntegerListPreference;
import org.meowcat.edxposed.manager.util.RepoLoader; import org.meowcat.edxposed.manager.util.RepoLoader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class SettingsActivity extends BaseActivity { public class SettingsActivity extends BaseActivity {
private static final String KEY_PREFIX = SettingsActivity.class.getName() + '.'; private static final String KEY_PREFIX = SettingsActivity.class.getName() + '.';
@ -111,34 +100,16 @@ public class SettingsActivity extends BaseActivity {
@SuppressWarnings({"ResultOfMethodCallIgnored"}) @SuppressWarnings({"ResultOfMethodCallIgnored"})
public static class SettingsFragment extends PreferenceFragmentCompat { public static class SettingsFragment extends PreferenceFragmentCompat {
private static final File enableResourcesFlag = new File(Constants.getBaseDir() + "conf/enable_resources"); private static final File enableResourcesFlag = new File(Constants.getBaseDir() + "conf/enable_resources");
private static final File dynamicModulesFlag = new File(Constants.getBaseDir() + "conf/dynamicmodules");
private static final File deoptBootFlag = new File(Constants.getBaseDir() + "conf/deoptbootimage"); private static final File deoptBootFlag = new File(Constants.getBaseDir() + "conf/deoptbootimage");
private static final File whiteListModeFlag = new File(Constants.getBaseDir() + "conf/usewhitelist"); private static final File whiteListModeFlag = new File(Constants.getBaseDir() + "conf/usewhitelist");
private static final File disableVerboseLogsFlag = new File(Constants.getBaseDir() + "conf/disable_verbose_log"); private static final File disableVerboseLogsFlag = new File(Constants.getBaseDir() + "conf/disable_verbose_log");
private static final File disableModulesLogsFlag = new File(Constants.getBaseDir() + "conf/disable_modules_log"); private static final File disableModulesLogsFlag = new File(Constants.getBaseDir() + "conf/disable_modules_log");
private static final File verboseLogProcessID = new File(Constants.getBaseDir() + "log/all.pid");
private static final File modulesLogProcessID = new File(Constants.getBaseDir() + "log/error.pid");
@SuppressLint({"ObsoleteSdkInt", "WorldReadableFiles"}) @SuppressLint({"ObsoleteSdkInt", "WorldReadableFiles"})
@Override @Override
public void onCreatePreferencesFix(Bundle savedInstanceState, String rootKey) { public void onCreatePreferencesFix(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.prefs); addPreferencesFromResource(R.xml.prefs);
Preference stopVerboseLog = findPreference("stop_verbose_log");
if (stopVerboseLog != null) {
stopVerboseLog.setOnPreferenceClickListener(preference -> {
areYouSure(R.string.stop_verbose_log_summary, (dialog, which) -> Shell.su("pkill -P $(cat " + verboseLogProcessID.getAbsolutePath() + ")").exec());
return true;
});
}
Preference stopLog = findPreference("stop_log");
if (stopLog != null) {
stopLog.setOnPreferenceClickListener(preference -> {
areYouSure(R.string.stop_log_summary, (dialog, which) -> Shell.su("pkill -P $(cat " + modulesLogProcessID.getAbsolutePath() + ")").exec());
return true;
});
}
Preference releaseType = findPreference("release_type_global"); Preference releaseType = findPreference("release_type_global");
if (releaseType != null) { if (releaseType != null) {
releaseType.setOnPreferenceChangeListener((preference, newValue) -> { releaseType.setOnPreferenceChangeListener((preference, newValue) -> {
@ -150,193 +121,31 @@ public class SettingsActivity extends BaseActivity {
SwitchPreferenceCompat prefWhiteListMode = findPreference("white_list_switch"); SwitchPreferenceCompat prefWhiteListMode = findPreference("white_list_switch");
if (prefWhiteListMode != null) { if (prefWhiteListMode != null) {
prefWhiteListMode.setChecked(whiteListModeFlag.exists()); prefWhiteListMode.setChecked(whiteListModeFlag.exists());
prefWhiteListMode.setOnPreferenceChangeListener((preference, newValue) -> { prefWhiteListMode.setOnPreferenceChangeListener(new OnFlagChangeListener(whiteListModeFlag));
boolean enabled = (Boolean) newValue;
if (enabled) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(whiteListModeFlag.getPath());
} catch (FileNotFoundException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
try {
whiteListModeFlag.createNewFile();
} catch (IOException e1) {
Toast.makeText(getActivity(), e1.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}
} else {
whiteListModeFlag.delete();
}
return (enabled == whiteListModeFlag.exists());
});
} }
SwitchPreferenceCompat prefVerboseLogs = findPreference("disable_verbose_log"); SwitchPreferenceCompat prefVerboseLogs = findPreference("disable_verbose_log");
if (prefVerboseLogs != null) { if (prefVerboseLogs != null) {
prefVerboseLogs.setChecked(disableVerboseLogsFlag.exists()); prefVerboseLogs.setChecked(disableVerboseLogsFlag.exists());
prefVerboseLogs.setOnPreferenceChangeListener((preference, newValue) -> { prefVerboseLogs.setOnPreferenceChangeListener(new OnFlagChangeListener(disableVerboseLogsFlag));
boolean enabled = (Boolean) newValue;
if (enabled) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(disableVerboseLogsFlag.getPath());
} catch (FileNotFoundException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
try {
disableVerboseLogsFlag.createNewFile();
} catch (IOException e1) {
Toast.makeText(getActivity(), e1.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}
} else {
disableVerboseLogsFlag.delete();
}
return (enabled == disableVerboseLogsFlag.exists());
});
} }
SwitchPreferenceCompat prefModulesLogs = findPreference("disable_modules_log"); SwitchPreferenceCompat prefModulesLogs = findPreference("disable_modules_log");
if (prefModulesLogs != null) { if (prefModulesLogs != null) {
prefModulesLogs.setChecked(disableModulesLogsFlag.exists()); prefModulesLogs.setChecked(disableModulesLogsFlag.exists());
prefModulesLogs.setOnPreferenceChangeListener((preference, newValue) -> { prefModulesLogs.setOnPreferenceChangeListener(new OnFlagChangeListener(disableModulesLogsFlag));
boolean enabled = (Boolean) newValue;
if (enabled) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(disableModulesLogsFlag.getPath());
} catch (FileNotFoundException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
try {
disableModulesLogsFlag.createNewFile();
} catch (IOException e1) {
Toast.makeText(getActivity(), e1.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}
} else {
disableModulesLogsFlag.delete();
}
return (enabled == disableModulesLogsFlag.exists());
});
} }
SwitchPreferenceCompat prefEnableDeopt = findPreference("enable_boot_image_deopt"); SwitchPreferenceCompat prefEnableDeopt = findPreference("enable_boot_image_deopt");
if (prefEnableDeopt != null) { if (prefEnableDeopt != null) {
prefEnableDeopt.setChecked(deoptBootFlag.exists()); prefEnableDeopt.setChecked(deoptBootFlag.exists());
prefEnableDeopt.setOnPreferenceChangeListener((preference, newValue) -> { prefEnableDeopt.setOnPreferenceChangeListener(new OnFlagChangeListener(deoptBootFlag));
boolean enabled = (Boolean) newValue;
if (enabled) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(deoptBootFlag.getPath());
} catch (FileNotFoundException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
try {
deoptBootFlag.createNewFile();
} catch (IOException e1) {
Toast.makeText(getActivity(), e1.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}
} else {
deoptBootFlag.delete();
}
return (enabled == deoptBootFlag.exists());
});
}
SwitchPreferenceCompat prefDynamicResources = findPreference("is_dynamic_modules");
if (prefDynamicResources != null) {
prefDynamicResources.setChecked(dynamicModulesFlag.exists());
prefDynamicResources.setOnPreferenceChangeListener((preference, newValue) -> {
boolean enabled = (Boolean) newValue;
if (enabled) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(dynamicModulesFlag.getPath());
} catch (FileNotFoundException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
try {
dynamicModulesFlag.createNewFile();
} catch (IOException e1) {
Toast.makeText(getActivity(), e1.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}
} else {
dynamicModulesFlag.delete();
}
return (enabled == dynamicModulesFlag.exists());
});
} }
SwitchPreferenceCompat prefDisableResources = findPreference("disable_resources"); SwitchPreferenceCompat prefDisableResources = findPreference("disable_resources");
if (prefDisableResources != null) { if (prefDisableResources != null) {
prefDisableResources.setChecked(!enableResourcesFlag.exists()); prefDisableResources.setChecked(!enableResourcesFlag.exists());
prefDisableResources.setOnPreferenceChangeListener((preference, newValue) -> { prefDisableResources.setOnPreferenceChangeListener(new OnFlagChangeListener(enableResourcesFlag));
boolean enabled = (Boolean) newValue;
if (!enabled) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(enableResourcesFlag.getPath());
} catch (FileNotFoundException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
try {
enableResourcesFlag.createNewFile();
} catch (IOException e1) {
Toast.makeText(getActivity(), e1.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}
} else {
enableResourcesFlag.delete();
}
return (enabled != enableResourcesFlag.exists());
});
} }
SwitchPreferenceCompat transparent = findPreference("transparent_status_bar"); SwitchPreferenceCompat transparent = findPreference("transparent_status_bar");
@ -421,18 +230,6 @@ public class SettingsActivity extends BaseActivity {
} }
} }
private void areYouSure(int contentTextId, DialogInterface.OnClickListener listener) {
Activity activity = getActivity();
if (activity != null) {
new MaterialAlertDialogBuilder(activity)
.setTitle(R.string.areyousure)
.setMessage(contentTextId)
.setPositiveButton(android.R.string.ok, listener)
.setNegativeButton(android.R.string.cancel, null)
.show();
}
}
private void updatePreference(boolean show) { private void updatePreference(boolean show) {
Preference black_dark_theme = findPreference("black_dark_theme"); Preference black_dark_theme = findPreference("black_dark_theme");
if (black_dark_theme != null) { if (black_dark_theme != null) {
@ -448,13 +245,27 @@ public class SettingsActivity extends BaseActivity {
} }
} }
private class OnFlagChangeListener implements Preference.OnPreferenceChangeListener {
private final File flag;
OnFlagChangeListener(File flag) {
this.flag = flag;
}
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public boolean onPreferenceChange(Preference preference, Object newValue) {
super.onViewCreated(view, savedInstanceState); boolean enabled = (Boolean) newValue;
((LinearLayout) view).setClipToPadding(false); if (enabled) {
((LinearLayout) view).setClipChildren(false); try {
((FrameLayout) getListView().getParent()).setClipChildren(false); flag.createNewFile();
((FrameLayout) getListView().getParent()).setClipToPadding(false); } catch (Exception e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
} else {
flag.delete();
}
return (enabled == flag.exists());
}
} }
} }
} }

View File

@ -122,13 +122,6 @@
android:title="@string/white_list_mode_title" android:title="@string/white_list_mode_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="is_dynamic_modules"
android:summary="@string/pref_dynamic_modules_summary"
android:title="@string/pref_title_dynamic_modules"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="enable_boot_image_deopt" android:key="enable_boot_image_deopt"