Skip to content

Commit

Permalink
弹窗代码模块化,其他代码优化。
Browse files Browse the repository at this point in the history
Signed-off-by: HChenX <[email protected]>
  • Loading branch information
HChenX committed Sep 22, 2023
1 parent 58be314 commit d893829
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 29 deletions.
47 changes: 47 additions & 0 deletions app/src/main/java/Com/HChen/Hook/Base/AlertDialogFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package Com.HChen.Hook.Base;

import android.content.Context;

import moralnorm.appcompat.app.AlertDialog;

public class AlertDialogFactory {

public void makeAlertDialog(Context context, String mTitle, String mMessage, Runnable mCode, Runnable mCodeT) {
new AlertDialog.Builder(context)
.setCancelable(true)
.setTitle(mTitle)
.setMessage(mMessage)
.setHapticFeedbackEnabled(true)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (mCode != null) mCode.run();
})
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
if (mCodeT != null) mCodeT.run();
})
.show();
}

public void makeAlertDialog(Context context, String mTitle, String mMessage, Runnable mCode) {
new AlertDialog.Builder(context)
.setCancelable(true)
.setTitle(mTitle)
.setMessage(mMessage)
.setHapticFeedbackEnabled(true)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (mCode != null) mCode.run();
})
.show();
}

public void makeAlertDialog(Context context, String mTitle, String mMessage, Runnable mCodeT, boolean needT) {
new AlertDialog.Builder(context)
.setCancelable(true)
.setTitle(mTitle)
.setMessage(mMessage)
.setHapticFeedbackEnabled(true)
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
if (mCodeT != null) mCodeT.run();
})
.show();
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/Com/HChen/Hook/Base/BaseGetKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.Map;

import Com.HChen.Hook.BuildConfig;
import Com.HChen.Hook.SystemLog;
import Com.HChen.Hook.Utils.GetKey;
import Com.HChen.Hook.Utils.SystemLog;
import de.robv.android.xposed.XSharedPreferences;

public class BaseGetKey extends SystemLog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.Objects;

import Com.HChen.Hook.SystemLog;
import Com.HChen.Hook.Utils.SystemLog;
import moralnorm.preference.Preference;
import moralnorm.preference.PreferenceManager;
import moralnorm.preference.compat.PreferenceFragment;
Expand All @@ -28,7 +28,7 @@ public void onCreatePreferences(Bundle bundle, String s) {
PreferenceManager mPreferenceManager = getPreferenceManager();
mPreferenceManager.setSharedPreferencesName(mPrefsName);
mPreferenceManager.setSharedPreferencesMode(Context.MODE_WORLD_READABLE);
mPreferenceManager.setStorageDeviceProtected();
mPreferenceManager.setStorageDefault();
systemLog.logI(TAG, "onCreatePreferences: " + mPreferenceManager);
}

Expand Down
28 changes: 10 additions & 18 deletions app/src/main/java/Com/HChen/Hook/Base/BaseSettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import java.util.Objects;

import Com.HChen.Hook.R;
import Com.HChen.Hook.SystemLog;
import Com.HChen.Hook.Utils.ShellUtils;
import moralnorm.appcompat.app.AlertDialog;
import Com.HChen.Hook.Utils.SystemLog;
import moralnorm.appcompat.app.AppCompatActivity;

public class BaseSettingsActivity extends AppCompatActivity {

private String initialFragmentName;
AppCompatActivity context;
SystemLog systemLog = new SystemLog();
AlertDialogFactory alertDialogFactory = new AlertDialogFactory();
public final String TAG = "BaseSettingsActivity";
// public static List<BaseSettingsActivity> mActivityList = new ArrayList<>();

Expand Down Expand Up @@ -113,15 +114,11 @@ public void showRestartDialog(String appLabel, String packagename) {
}

public void showRestartDialog(boolean isRestartSystem, String appLabel, String packagename) {
new AlertDialog.Builder(this)
.setCancelable(true)
.setTitle(getResources().getString(R.string.soft_reboot) + " " + appLabel)
.setMessage(getResources().getString(R.string.restart_app_desc1
) + appLabel + getResources().getString(R.string.restart_app_desc2))
.setHapticFeedbackEnabled(true)
.setPositiveButton(android.R.string.ok, (dialog, which) -> doRestart(packagename, isRestartSystem))
.setNegativeButton(android.R.string.cancel, (dialog, which) -> Toast.makeText(this, getResources().getString(R.string.cancel), Toast.LENGTH_SHORT).show())
.show();
alertDialogFactory.makeAlertDialog(this,
getResources().getString(R.string.soft_reboot) + " " + appLabel,
getResources().getString(R.string.restart_app_desc1) + appLabel + getResources().getString(R.string.restart_app_desc2),
() -> doRestart(packagename, isRestartSystem),
() -> Toast.makeText(this, getResources().getString(R.string.cancel), Toast.LENGTH_SHORT).show());
}

public void doRestart(String packagename, boolean isRestartSystem) {
Expand All @@ -133,13 +130,8 @@ public void doRestart(String packagename, boolean isRestartSystem) {
result = ShellUtils.RootCommand("killall " + packagename);
}
if (!result) {
new AlertDialog.Builder(this)
.setCancelable(false)
.setTitle(getResources().getString(R.string.tip))
.setMessage(isRestartSystem ? getResources().getString(R.string.reboot_failed) : getResources().getString(R.string.kill_failed))
.setHapticFeedbackEnabled(true)
.setPositiveButton(android.R.string.ok, null)
.show();
alertDialogFactory.makeAlertDialog(this, getResources().getString(R.string.tip),
isRestartSystem ? getResources().getString(R.string.reboot_failed) : getResources().getString(R.string.kill_failed), null);
} else {
Toast.makeText(this, getResources().getString(R.string.sucess) + packagename, Toast.LENGTH_SHORT).show();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/Com/HChen/Hook/Base/SettingLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import androidx.fragment.app.Fragment;

import Com.HChen.Hook.SystemLog;
import Com.HChen.Hook.Utils.SystemLog;

public class SettingLauncher extends SystemLog {
public final String TAG = "SettingLauncher";
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/Com/HChen/Hook/Base/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ public void onStartSettingsForArguments(Class<?> cls, Preference preference, boo
}
String mFragmentName = preference.getFragment();
String mTitle = Objects.requireNonNull(preference.getTitle()).toString();
onStartSettingsForArguments(context, cls, mFragmentName, args, 0, mTitle);
if (args == null) args = new Bundle();
// onStartSettingsForArguments(context, cls, mFragmentName, args, 0, mTitle);
onStartSettings(context, cls, mFragmentName, null, args, 0, mTitle);
}

public static void onStartSettingsForArguments(Context context, Class<?> cls, String fragment, Bundle args, int titleResId, String title) {
/*public static void onStartSettingsForArguments(Context context, Class<?> cls, String fragment, Bundle args, int titleResId, String title) {
if (args == null) args = new Bundle();
onStartSettings(context, cls, fragment, null, args, titleResId, title);
}
}*/

public static void onStartSettings(Context context, Class<?> cls, String fragment, Bundle extras, Bundle args, int titleResId, String title) {
new SettingLauncher(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.text.TextUtils;
import android.view.View;

import Com.HChen.Hook.SystemLog;
import Com.HChen.Hook.Utils.SystemLog;

public abstract class SettingsPreferenceFragment extends BasePreferenceFragment {
public final String TAG = "SettingsPreferenceFragment";
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/Com/HChen/Hook/Mode/HookMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public abstract class HookMode extends HookLog {
GetKey<String, Object> mPrefsMap = BaseGetKey.mPrefsMap;
public final GetKey<String, Object> mPrefsMap = BaseGetKey.mPrefsMap;
LoadPackageParam loadPackageParam;

public abstract void init();
Expand Down Expand Up @@ -215,7 +215,6 @@ public void getDeclaredField(XC_MethodHook.MethodHookParam param, String iNeedSt
setString.set(param.thisObject, iNeedTo);
Object result = setString.get(param.thisObject);
checkLast("getDeclaredField", iNeedString, iNeedTo, result);

} catch (IllegalAccessException e) {
logE("IllegalAccessException to: " + iNeedString + " Need to: " + iNeedTo + " Code:" + e);
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/Com/HChen/Hook/Mode/HookRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class HookRun extends HookLog {
public final String TAG = "HookRun";
LoadPackageParam loadPackageParam;

public final GetKey<String, Object> mPrefsMap = BaseGetKey.mPrefsMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Com.HChen.Hook;
package Com.HChen.Hook.Utils;

import android.util.Log;

Expand Down

0 comments on commit d893829

Please sign in to comment.