Browse Source

All da mods

Code cleaning
pull/109/head
Mikanoshi 2 years ago
parent
commit
623ba43cdd
171 changed files with 2834 additions and 3615 deletions
  1. +19
    -1
      .idea/inspectionProfiles/Project_Default.xml
  2. +36
    -1
      .idea/misc.xml
  3. +6
    -0
      .idea/vcs.xml
  4. +14
    -1
      app/build.gradle
  5. +20
    -0
      app/src/main/AndroidManifest.xml
  6. +48
    -0
      app/src/main/java/name/mikanoshi/customiuizer/AboutFragment.java
  7. +13
    -1
      app/src/main/java/name/mikanoshi/customiuizer/ActivityEx.java
  8. +379
    -0
      app/src/main/java/name/mikanoshi/customiuizer/CrashReportDialog.java
  9. +2
    -9
      app/src/main/java/name/mikanoshi/customiuizer/MainActivity.java
  10. +52
    -0
      app/src/main/java/name/mikanoshi/customiuizer/MainApplication.java
  11. +73
    -102
      app/src/main/java/name/mikanoshi/customiuizer/MainFragment.java
  12. +46
    -188
      app/src/main/java/name/mikanoshi/customiuizer/MainModule.java
  13. +10
    -26
      app/src/main/java/name/mikanoshi/customiuizer/PreferenceFragmentBase.java
  14. +74
    -0
      app/src/main/java/name/mikanoshi/customiuizer/SharedPrefsProvider.java
  15. +5
    -44
      app/src/main/java/name/mikanoshi/customiuizer/SubFragment.java
  16. +0
    -1
      app/src/main/java/name/mikanoshi/customiuizer/SubFragmentWithSearch.java
  17. +179
    -0
      app/src/main/java/name/mikanoshi/customiuizer/mods/Controls.java
  18. +113
    -93
      app/src/main/java/name/mikanoshi/customiuizer/mods/Launcher.java
  19. +328
    -0
      app/src/main/java/name/mikanoshi/customiuizer/mods/System.java
  20. +112
    -0
      app/src/main/java/name/mikanoshi/customiuizer/mods/Various.java
  21. +8
    -23
      app/src/main/java/name/mikanoshi/customiuizer/prefs/CheckBoxPreferenceEx.java
  22. +0
    -35
      app/src/main/java/name/mikanoshi/customiuizer/prefs/LinearLayoutEx.java
  23. +22
    -49
      app/src/main/java/name/mikanoshi/customiuizer/prefs/ListPreferenceEx.java
  24. +26
    -0
      app/src/main/java/name/mikanoshi/customiuizer/prefs/PreferenceEx.java
  25. +249
    -0
      app/src/main/java/name/mikanoshi/customiuizer/prefs/SeekBarPreference.java
  26. +12
    -88
      app/src/main/java/name/mikanoshi/customiuizer/prefs/SpinnerEx.java
  27. +2
    -2
      app/src/main/java/name/mikanoshi/customiuizer/subs/AppSelector.java
  28. +14
    -0
      app/src/main/java/name/mikanoshi/customiuizer/subs/Controls.java
  29. +9
    -5
      app/src/main/java/name/mikanoshi/customiuizer/subs/Launcher.java
  30. +1
    -1
      app/src/main/java/name/mikanoshi/customiuizer/subs/ShortcutSelector.java
  31. +2
    -3
      app/src/main/java/name/mikanoshi/customiuizer/subs/SwipeGesture.java
  32. +14
    -0
      app/src/main/java/name/mikanoshi/customiuizer/subs/System.java
  33. +48
    -0
      app/src/main/java/name/mikanoshi/customiuizer/subs/Various.java
  34. +1
    -1
      app/src/main/java/name/mikanoshi/customiuizer/utils/AppDataAdapter.java
  35. +1
    -1
      app/src/main/java/name/mikanoshi/customiuizer/utils/AppResolveAdapter.java
  36. +0
    -220
      app/src/main/java/name/mikanoshi/customiuizer/utils/DownloadAndUnZip.java
  37. +210
    -130
      app/src/main/java/name/mikanoshi/customiuizer/utils/GlobalActions.java
  38. +214
    -305
      app/src/main/java/name/mikanoshi/customiuizer/utils/Helpers.java
  39. +0
    -248
      app/src/main/java/name/mikanoshi/customiuizer/utils/MaterialColorPicker.java
  40. +4
    -6
      app/src/main/java/name/mikanoshi/customiuizer/utils/PackagePermissions.java
  41. +1
    -1
      app/src/main/java/name/mikanoshi/customiuizer/utils/ShakeManager.java
  42. +0
    -2
      app/src/main/res/anim/accelerate_interpolator.xml
  43. +0
    -2
      app/src/main/res/anim/accelerate_quart.xml
  44. +0
    -2
      app/src/main/res/anim/decelerate_quart.xml
  45. +0
    -12
      app/src/main/res/anim/dialog_enter.xml
  46. +0
    -12
      app/src/main/res/anim/dialog_exit.xml
  47. +0
    -5
      app/src/main/res/color/action_bar_title_text_light.xml
  48. +0
    -6
      app/src/main/res/color/action_mode_title_button_text_light.xml
  49. +0
    -6
      app/src/main/res/color/action_mode_title_default_button_text_light.xml
  50. +0
    -5
      app/src/main/res/color/button_text_color_guide_light.xml
  51. +0
    -5
      app/src/main/res/color/button_text_color_positive_light.xml
  52. +0
    -5
      app/src/main/res/color/button_text_dialog_light.xml
  53. +0
    -8
      app/src/main/res/color/button_text_light.xml
  54. +0
    -9
      app/src/main/res/color/checkable_btn_text_color_stable_light.xml
  55. +0
    -9
      app/src/main/res/color/dialog_list_text_light_single_choice.xml
  56. +6
    -6
      app/src/main/res/color/preference_secondary_text_light.xml
  57. BIN
      app/src/main/res/drawable-xxhdpi/right_arrow.png
  58. BIN
      app/src/main/res/drawable-xxhdpi/theme_selected.png
  59. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_bar_back_search_normal_light.png
  60. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_bar_back_search_pressed_light.png
  61. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_bar_stack_bg_light.9.png
  62. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_bg_dialog_light.9.png
  63. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_button_bg_disable_light.9.png
  64. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_button_bg_normal_light.9.png
  65. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_button_bg_pressed_light.9.png
  66. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_default_button_bg_disable_light.9.png
  67. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_default_button_bg_normal_light.9.png
  68. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_default_button_bg_pressed_light.9.png
  69. BIN
      app/src/main/res/drawable-xxxhdpi-v4/arrow_right_disable.png
  70. BIN
      app/src/main/res/drawable-xxxhdpi-v4/arrow_right_normal.png
  71. BIN
      app/src/main/res/drawable-xxxhdpi-v4/arrow_right_pressed.png
  72. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_off_disabled_light.png
  73. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_off_normal_light.png
  74. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_on_disabled_light.png
  75. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_on_normal_light.png
  76. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_first_normal_light.9.png
  77. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_first_pressed_light.9.png
  78. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_last_normal_light.9.png
  79. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_last_pressed_light.9.png
  80. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_middle_normal_light.9.png
  81. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_middle_pressed_light.9.png
  82. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_single_normal_light.9.png
  83. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_single_pressed_light.9.png
  84. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_overstepped_pressed_light.9.png
  85. BIN
      app/src/main/res/drawable-xxxhdpi-v4/spinner_bg_normal_light.9.png
  86. BIN
      app/src/main/res/drawable-xxxhdpi-v4/spinner_bg_pressed_light.9.png
  87. +0
    -5
      app/src/main/res/drawable/action_bar_back_search_light.xml
  88. +0
    -11
      app/src/main/res/drawable/action_bar_split_bg_light.xml
  89. +0
    -4
      app/src/main/res/drawable/action_mode_split_bg_dialog_light.xml
  90. +0
    -6
      app/src/main/res/drawable/action_mode_title_button_bg_light.xml
  91. +0
    -6
      app/src/main/res/drawable/action_mode_title_default_button_bg_light.xml
  92. +0
    -6
      app/src/main/res/drawable/arrow_right.xml
  93. +0
    -13
      app/src/main/res/drawable/btn_bg_dialog_first_normal_light.xml
  94. +0
    -13
      app/src/main/res/drawable/btn_bg_dialog_first_pressed_light.xml
  95. +0
    -16
      app/src/main/res/drawable/btn_bg_dialog_last_normal_light.xml
  96. +0
    -16
      app/src/main/res/drawable/btn_bg_dialog_last_pressed_light.xml
  97. +0
    -19
      app/src/main/res/drawable/btn_bg_dialog_light.xml
  98. +0
    -15
      app/src/main/res/drawable/btn_bg_dialog_middle_normal_light.xml
  99. +0
    -15
      app/src/main/res/drawable/btn_bg_dialog_middle_pressed_light.xml
  100. +0
    -15
      app/src/main/res/drawable/btn_bg_dialog_single_normal_light.xml

+ 19
- 1
.idea/inspectionProfiles/Project_Default.xml View File

@ -1,6 +1,24 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintAppCompatCustomView" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="CatchMayIgnoreException" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="Convert2Diamond" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="Convert2Lambda" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="NullableProblems" enabled="false" level="WARNING" enabled_by_default="false">
<option name="REPORT_NULLABLE_METHOD_OVERRIDES_NOTNULL" value="true" />
<option name="REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL" value="true" />
<option name="REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE" value="true" />
<option name="REPORT_NOT_ANNOTATED_PARAMETER_OVERRIDES_NOTNULL" value="true" />
<option name="REPORT_NOT_ANNOTATED_GETTER" value="true" />
<option name="REPORT_NOT_ANNOTATED_SETTER_PARAMETER" value="true" />
<option name="REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS" value="true" />
<option name="REPORT_NULLS_PASSED_TO_NON_ANNOTATED_METHOD" value="true" />
</inspection_tool>
<inspection_tool class="RedundantThrows" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
</profile>
</component>

+ 36
- 1
.idea/misc.xml View File

@ -5,7 +5,42 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
<option name="myDefaultNotNull" value="androidx.annotation.RecentlyNonNull" />
<option name="myNullables">
<value>
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">


+ 6
- 0
.idea/vcs.xml View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 14
- 1
app/build.gradle View File

@ -1,5 +1,7 @@
apply plugin: 'com.android.application'
def acraVersion = '5.3.0-rc02'
android {
compileSdkVersion 28
defaultConfig {
@ -9,6 +11,11 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
buildTypes {
release {
@ -16,11 +23,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "ch.acra:acra-core:$acraVersion"
implementation "ch.acra:acra-dialog:$acraVersion"
compileOnly "com.google.auto.service:auto-service:1.0-rc4"
compileOnly 'de.robv.android.xposed:api:82'
compileOnly files('lib/miui.jar')
implementation 'org.jetbrains:annotations-java5:15.0'
}

+ 20
- 0
app/src/main/AndroidManifest.xml View File

@ -3,7 +3,12 @@
xmlns:tools="http://schemas.android.com/tools"
package="name.mikanoshi.customiuizer">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.DUMP" />
<application
android:allowBackup="false"
@ -13,6 +18,8 @@
android:roundIcon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".MainApplication"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
@ -42,6 +49,19 @@
<meta-data android:name="com.android.settings.title" android:resource="@string/app_name" />
</activity-alias>
<activity android:name=".CrashReportDialog"
android:theme="@style/Invisible"
android:launchMode="singleTask"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true"
android:configChanges="keyboardHidden|orientation|screenSize" />
<provider
android:name=".SharedPrefsProvider"
android:authorities="name.mikanoshi.customiuizer.provider.sharedprefs"
android:grantUriPermissions="true"
android:exported="true" />
<meta-data android:name="xposedmodule" android:value="true" />
<meta-data android:name="xposedminversion" android:value="82+" />
<meta-data android:name="xposeddescription" android:value="Customize MIUI to your liking" />


+ 48
- 0
app/src/main/java/name/mikanoshi/customiuizer/AboutFragment.java View File

@ -0,0 +1,48 @@
package name.mikanoshi.customiuizer;
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.widget.TextView;
import name.mikanoshi.customiuizer.utils.Helpers;
public class AboutFragment extends SubFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Activity act = getActivity();
Preference miuizerSitePreference = findPreference("pref_key_website");
miuizerSitePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference pref) {
Helpers.openURL(act, "https://code.highspec.ru/Mikanoshi/CustoMIUIzer");
return true;
}
});
Preference donatePagePreference = findPreference("pref_key_donatepage");
donatePagePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference pref) {
if (getResources().getConfiguration().locale.getISO3Language().contains("ru"))
Helpers.openURL(act, "https://mikanoshi.name/donate/");
else
Helpers.openURL(act, "https://en.mikanoshi.name/donate/");
return true;
}
});
//Add version name to support title
try {
TextView version = getView().findViewById(R.id.about_version);
version.setText(String.format(getResources().getString(R.string.about_version), act.getPackageManager().getPackageInfo(act.getPackageName(), 0).versionName));
} catch (Throwable e) {
//Shouldn't happen...
e.printStackTrace();
}
}
}

+ 13
- 1
app/src/main/java/name/mikanoshi/customiuizer/ActivityEx.java View File

@ -1,21 +1,25 @@
package name.mikanoshi.customiuizer;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.app.backup.BackupManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import name.mikanoshi.customiuizer.utils.Helpers;
@SuppressLint("Registered")
public class ActivityEx extends Activity {
public int mThemeBackground = 1;
public boolean launch = true;
SharedPreferences.OnSharedPreferenceChangeListener prefsChanged;
@SuppressWarnings("ConstantConditions")
protected void onCreate(Bundle savedInstanceState) {
setTheme(getResources().getIdentifier("Theme.Light.Settings", "style", "miui"));
getTheme().applyStyle(R.style.MIUIPrefs, true);
@ -23,9 +27,16 @@ public class ActivityEx extends Activity {
Helpers.prefs = getSharedPreferences(Helpers.prefsName, Context.MODE_PRIVATE);
prefsChanged = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
public void onSharedPreferenceChanged(SharedPreferences sharedPrefs, String key) {
Log.w("prefs", "Changed: " + key);
requestBackup();
Object val = sharedPrefs.getAll().get(key);
String path = "/";
if (val instanceof String)
path = "/string/";
else if (val instanceof Integer)
path = "/integer/";
getContentResolver().notifyChange(Uri.parse("content://" + SharedPrefsProvider.AUTHORITY + path + key), null);
}
};
Helpers.prefs.registerOnSharedPreferenceChangeListener(prefsChanged);
@ -49,6 +60,7 @@ public class ActivityEx extends Activity {
super.onDestroy();
}
@SuppressWarnings("ConstantConditions")
public void updateTheme(int newBkg) {
int newThemeBackground;
if (newBkg == 0)


+ 379
- 0
app/src/main/java/name/mikanoshi/customiuizer/CrashReportDialog.java View File

@ -0,0 +1,379 @@
package name.mikanoshi.customiuizer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.data.CrashReportData;
import org.acra.dialog.BaseCrashReportDialog;
import org.acra.file.CrashReportPersister;
import org.acra.scheduler.SchedulerStarter;
import org.acra.sender.ReportSenderException;
import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Base64;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.EditText;
import android.widget.FrameLayout.LayoutParams;
import miui.app.AlertDialog;
import name.mikanoshi.customiuizer.utils.Helpers;
import static org.acra.ACRA.LOG_TAG;
import static org.acra.ReportField.USER_COMMENT;
import static org.acra.ReportField.USER_EMAIL;
public class CrashReportDialog extends BaseCrashReportDialog {
private File mReportFileName;
private String xposedLog;
private EditText desc;
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
private String getXposedLog() {
String errorLogPath = Helpers.getXposedInstallerErrorLog(this);
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(errorLogPath))))) {
String line;
while ((line = reader.readLine()) != null) sb.append(line).append("\n");
return sb.toString();
} catch (Throwable e) {
return null;
}
}
void showFinishDialog(boolean isOk, String details) {
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle(R.string.crash_result);
dlg.setCancelable(true);
if (isOk)
dlg.setMessage(R.string.crash_ok);
else {
String errorTxt = getResources().getString(R.string.crash_error);
if (details != null) errorTxt += ": " + details;
dlg.setMessage(errorTxt);
}
dlg.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
});
dlg.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
});
dlg.show();
}
private String getProp(String prop) {
String res = "";
Process ifc = null;
try {
ifc = Runtime.getRuntime().exec("getprop " + prop);
BufferedReader bis = new BufferedReader(new InputStreamReader(ifc.getInputStream()), 2048);
res = bis.readLine();
} catch (Throwable e) {} finally {
if (ifc != null) ifc.destroy();
}
return res;
}
private void sendCrash(final String xposedLogStr) {
String exceptionsPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/CustoMIUIzer/";
CrashReportPersister persister = new CrashReportPersister();
SharedPreferences prefs = getSharedPreferences(Helpers.prefsName, Context.MODE_PRIVATE);
final CrashReportData crashData;
try {
Log.e("crash", mReportFileName.getAbsolutePath());
crashData = persister.load(mReportFileName);
crashData.put(USER_COMMENT, desc.getText().toString());
crashData.put(USER_EMAIL, prefs.getString("acra.user.email", ""));
} catch (Throwable t) {
t.printStackTrace();
cancelReports();
showFinishDialog(false, "cannot read report file");
return;
}
try {
String ROM = getProp("ro.modversion");
String MIUI = getProp("ro.miui.ui.version.name");
String kernel = System.getProperty("os.version");
if (kernel == null) kernel = "";
JSONObject buildData = (JSONObject)crashData.get("BUILD");
buildData.put("ROM_VERSION", ROM);
buildData.put("MIUI_VERSION", MIUI);
buildData.put("KERNEL_VERSION", kernel);
crashData.put("BUILD", buildData);
StringBuilder sb = new StringBuilder();
try (FileInputStream in = new FileInputStream(new File(exceptionsPath + "uncaught_exceptions"))) {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = bufferedReader.readLine()) != null) sb.append(line).append("\n");
} catch (Throwable t) {}
} catch (Throwable t) {}
crashData.put("SHARED_PREFERENCES", new JSONObject(prefs.getAll()));
if (!sb.toString().isEmpty())
crashData.put("UNCAUGHT_EXCEPTIONS", sb.toString());
if (xposedLogStr == null || xposedLogStr.trim().equals(""))
crashData.put(ReportField.CUSTOM_DATA, "Xposed log is empty...");
else
crashData.put(ReportField.CUSTOM_DATA, xposedLogStr);
} catch (Throwable e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
crashData.put(ReportField.CUSTOM_DATA, "Retrieval failed. Stack trace:\n" + sw.toString());
}
new Thread(() -> {
boolean res;
try {
res = sendReport(crashData);
} catch (Throwable t) {
res = false;
}
boolean finalRes = res;
runOnUiThread(new Runnable() {
@Override
public void run() {
if (finalRes) {
Helpers.emptyFile(exceptionsPath + "uncaught_exceptions", true);
cancelReports();
showFinishDialog(true, null);
} else {
showFinishDialog(false, "request failed");
}
}
});
}).start();
}
protected boolean sendReport(CrashReportData report) {
try {
String json = report.toJSON();
//final String basicAuth = "Basic " + Base64.encodeToString("Sense6Toolbox:NotASecret".getBytes(), Base64.NO_WRAP);
URL url = new URL("https://code.highspec.ru/crashreports/reporter.php");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(10000);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);
conn.connect();
try (OutputStream os = conn.getOutputStream()) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8))) {
writer.write(json);
writer.flush();
} catch (Throwable t) {}
} catch (Throwable t) {}
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) throw new ReportSenderException(String.valueOf(conn.getResponseMessage()));
//Log.e("HTTP", "Report server response code: " + String.valueOf(conn.getResponseCode()));
//Log.e("HTTP", "Report server response: " + conn.getResponseMessage());
conn.disconnect();
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
protected void cancelReportsAndFinish() {
cancelReports();
finish();
}
int densify(int size) {
return Math.round(getResources().getDisplayMetrics().density * size);
}
@SuppressLint("SetTextI18n")
@Override
protected void preInit(Bundle savedInstanceState) {
try {
setTheme(getResources().getIdentifier("Theme.Light.Settings", "style", "miui"));
getTheme().applyStyle(R.style.ApplyInvisible, true);
} catch (Throwable e) {}
if (getIntent().getBooleanExtra("FORCE_CANCEL", false)) {
cancelReportsAndFinish();
return;
}
if (getIntent().getExtras().get("REPORT_FILE") == null) finish();
mReportFileName = (File)getIntent().getExtras().get("REPORT_FILE");
int title = R.string.warning;
int neutralText = R.string.crash_ignore;
int text = R.string.crash_dialog;
LinearLayout dialogView = new LinearLayout(this);
dialogView.setOrientation(LinearLayout.VERTICAL);
int tries = 5;
xposedLog = null;
while (xposedLog == null && tries > 0) try {
tries--;
xposedLog = getXposedLog();
if (xposedLog == null) Thread.sleep(500);
} catch (Throwable e) {}
try {
CrashReportPersister persister = new CrashReportPersister();
CrashReportData crashData = persister.load(mReportFileName);
String payload = crashData.toJSON();
int payloadSize = payload.getBytes(StandardCharsets.UTF_8).length;
boolean isManualReport = crashData.getString(ReportField.STACK_TRACE).contains("Report requested by developer");
Log.e("ACRA", crashData.getString(ReportField.STACK_TRACE));
TextView mainText = new TextView(this);
mainText.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
mainText.setGravity(Gravity.START);
mainText.setPadding(0, 0, 0, densify(10));
mainText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
mainText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
TextView descText = new TextView(this);
descText.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
descText.setGravity(Gravity.START);
descText.setPadding(0, 0, 0, densify(5));
descText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
descText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
desc = new EditText(this);
desc.setGravity(Gravity.TOP | Gravity.START);
desc.setInputType(EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
desc.setSingleLine(false);
desc.setPadding(densify(5), densify(5), densify(5), densify(5));
if (isManualReport) {
title = R.string.crash_confirm;
text = R.string.crash_dialog_manual;
neutralText = R.string.cancel;
descText.setText(R.string.crash_dialog_manual_desc);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, densify(80));
lp.setMargins(0, densify(5), 0, densify(10));
desc.setLayoutParams(lp);
} else {
descText.setText(R.string.crash_dialog_manual_desc2);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, densify(60));
lp.setMargins(0, densify(5), 0, densify(10));
desc.setLayoutParams(lp);
desc.setFocusable(false);
desc.setFocusableInTouchMode(false);
desc.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
v.performClick();
return false;
}
});
}
mainText.setText(text);
TextView feedbackNote = new TextView(this);
feedbackNote.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
feedbackNote.setGravity(Gravity.START);
feedbackNote.setPadding(0, 0, 0, 0);
feedbackNote.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
feedbackNote.setText(R.string.crash_dialog_note);
dialogView.addView(mainText);
dialogView.addView(descText);
dialogView.addView(desc);
if (Helpers.prefs.getString("acra.user.email", "").isEmpty())
dialogView.addView(feedbackNote);
mainText.setText(mainText.getText() + "\n" + getResources().getString(R.string.crash_dialog_manual_size) + ": " + String.valueOf(Math.round(payloadSize / 1024.0f)) + " KB");
} catch (Throwable e) {}
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(title);
alert.setView(dialogView);
alert.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
cancelReportsAndFinish();
}
});
alert.setNeutralButton(neutralText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
cancelReportsAndFinish();
}
});
alert.setPositiveButton(R.string.crash_send, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
final AlertDialog alertDlg = alert.show();
alertDlg.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (desc != null && desc.getText().toString().trim().equals("")) {
Toast.makeText(CrashReportDialog.this, R.string.crash_needs_desc, Toast.LENGTH_LONG).show();
} else if (!isNetworkAvailable()) {
Toast.makeText(CrashReportDialog.this, R.string.crash_needs_inet, Toast.LENGTH_LONG).show();
} else {
alertDlg.dismiss();
sendCrash(xposedLog);
}
}
});
}
}

+ 2
- 9
app/src/main/java/name/mikanoshi/customiuizer/MainActivity.java View File

@ -1,18 +1,11 @@
package name.mikanoshi.customiuizer;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import name.mikanoshi.customiuizer.R;
import name.mikanoshi.customiuizer.utils.Helpers;
public class MainActivity extends ActivityEx {
@ -24,14 +17,14 @@ public class MainActivity extends ActivityEx {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Helpers.dataPath = getFilesDir().getPath();
Helpers.backupPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/CustoMIUIzer/";
Helpers.externalPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/CustoMIUIzer/";
if (!launch) return;
mainFrag = new MainFragment();
getFragmentManager().beginTransaction().replace(R.id.fragment_container, mainFrag).commit();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NotNull String[] permissions, @NotNull int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_BACKUP_PERMISSIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)


+ 52
- 0
app/src/main/java/name/mikanoshi/customiuizer/MainApplication.java View File

@ -0,0 +1,52 @@
package name.mikanoshi.customiuizer;
import android.app.Application;
import android.content.Context;
import com.google.auto.service.AutoService;
import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.annotation.AcraCore;
import org.acra.annotation.AcraDialog;
import org.acra.data.StringFormat;
import miui.core.SdkManager;
import static org.acra.ReportField.*;
@AcraCore(
reportContent = { REPORT_ID, APP_VERSION_CODE, APP_VERSION_NAME, PACKAGE_NAME, FILE_PATH, PHONE_MODEL, BRAND, PRODUCT, ANDROID_VERSION,
BUILD, TOTAL_MEM_SIZE, AVAILABLE_MEM_SIZE, CUSTOM_DATA, STACK_TRACE, INITIAL_CONFIGURATION, CRASH_CONFIGURATION, DISPLAY, USER_COMMENT, USER_EMAIL,
USER_APP_START_DATE, USER_CRASH_DATE, DUMPSYS_MEMINFO, LOGCAT, INSTALLATION_ID, DEVICE_FEATURES, ENVIRONMENT, SHARED_PREFERENCES,
SETTINGS_SYSTEM, SETTINGS_SECURE, SETTINGS_GLOBAL },
sharedPreferencesName = "customiuizer_prefs",
//additionalSharedPreferences = {"customiuizer_prefs"},
logcatArguments = { "-t", "500", "-v", "time" },
buildConfigClass = BuildConfig.class,
reportFormat = StringFormat.JSON
)
@AcraDialog(
reportDialogClass = CrashReportDialog.class
)
public class MainApplication extends Application {
public MainApplication() {
SdkManager.initialize(this, null);
}
public void onCreate() {
super.onCreate();
SdkManager.start(null);
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ACRA.init(this);
ACRA.DEV_LOGGING = true;
}
}

+ 73
- 102
app/src/main/java/name/mikanoshi/customiuizer/MainFragment.java View File

@ -3,16 +3,13 @@ package name.mikanoshi.customiuizer;
import android.animation.LayoutTransition;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
@ -20,7 +17,6 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -29,21 +25,29 @@ import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
import org.acra.ACRA;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import miui.app.ActionBar;
import miui.app.AlertDialog;
import name.mikanoshi.customiuizer.R;
import name.mikanoshi.customiuizer.subs.Controls;
import name.mikanoshi.customiuizer.subs.Launcher;
import name.mikanoshi.customiuizer.subs.System;
import name.mikanoshi.customiuizer.subs.Various;
import name.mikanoshi.customiuizer.utils.Helpers;
public class MainFragment extends PreferenceFragmentBase {
@ -59,11 +63,11 @@ public class MainFragment extends PreferenceFragmentBase {
@Override
public void run() {
if (isFragmentReady(getActivity())) try {
TextView update = (TextView)getActivity().findViewById(R.id.update);
update.setText(Helpers.l10n(getActivity(), R.string.update_available));
update.setTextColor(getResources().getColor(android.R.color.background_light));
TextView update = getActivity().findViewById(R.id.update);
update.setText(R.string.update_available);
update.setTextColor(getResources().getColor(android.R.color.background_light, getActivity().getTheme()));
FrameLayout updateFrame = (FrameLayout)getActivity().findViewById(R.id.updateFrame);
FrameLayout updateFrame = getActivity().findViewById(R.id.updateFrame);
updateFrame.setLayoutTransition(new LayoutTransition());
updateFrame.setVisibility(View.VISIBLE);
updateFrame.setBackgroundColor(0xff252525);
@ -75,12 +79,12 @@ public class MainFragment extends PreferenceFragmentBase {
detailsIntent.setComponent(new ComponentName("de.robv.android.xposed.installer", "de.robv.android.xposed.installer.DownloadDetailsActivity"));
detailsIntent.setData(Uri.fromParts("package", "com.sensetoolbox.six", null));
startActivity(detailsIntent);
} catch (Exception e) {
} catch (Throwable e) {
Helpers.openURL(getActivity(), "http://sensetoolbox.com/6/download");
}
}
});
} catch (Exception e) {}
} catch (Throwable e) {}
}
};
@ -90,7 +94,7 @@ public class MainFragment extends PreferenceFragmentBase {
if (isFragmentReady(getActivity())) try {
FrameLayout updateFrame = getActivity().findViewById(R.id.updateFrame);
updateFrame.setVisibility(View.GONE);
} catch (Exception e) {}
} catch (Throwable e) {}
}
};
@ -101,8 +105,8 @@ public class MainFragment extends PreferenceFragmentBase {
@Override
@SuppressLint("MissingSuperCall")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.xml.preferences);
addPreferencesFromResource(R.xml.preferences);
super.onCreate(savedInstanceState, R.xml.prefs_main);
addPreferencesFromResource(R.xml.prefs_main);
}
private void setupImmersiveMenu() {
@ -132,9 +136,9 @@ public class MainFragment extends PreferenceFragmentBase {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(act);
builder.setTitle(Helpers.l10n(act, R.string.xposed_not_found));
builder.setMessage(Helpers.l10n(act, R.string.xposed_not_found_explain));
builder.setNeutralButton(Helpers.l10n(act, R.string.okay), null);
builder.setTitle(R.string.xposed_not_found);
builder.setMessage(R.string.xposed_not_found_explain);
builder.setNeutralButton(R.string.okay, null);
AlertDialog dlg = builder.create();
if (isFragmentReady(act)) dlg.show();
}
@ -147,10 +151,8 @@ public class MainFragment extends PreferenceFragmentBase {
}
});
}
/*
String miuizerPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/SenseToolbox/";
HttpURLConnection connection = null;
HttpURLConnection connection = null;
try {
URL url = new URL("http://sensetoolbox.com/last_build");
connection = (HttpURLConnection)url.openConnection();
@ -168,9 +170,9 @@ public class MainFragment extends PreferenceFragmentBase {
last_build = reader.readLine().trim();
} catch (Exception e) { e.printStackTrace(); }
File tmp = new File(miuizerPath);
File tmp = new File(Helpers.externalPath);
if (!tmp.exists()) tmp.mkdirs();
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(miuizerPath + "last_build", false))) {
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(Helpers.externalPath + "last_build", false))) {
writer.write(last_build);
} catch (Exception e) { e.printStackTrace(); }
}
@ -180,7 +182,7 @@ public class MainFragment extends PreferenceFragmentBase {
if (connection != null) connection.disconnect();
} catch (Exception e) {}
try (InputStream inputFile = new FileInputStream(miuizerPath + "last_build")) {
try (InputStream inputFile = new FileInputStream(Helpers.externalPath + "last_build")) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputFile));
int last_build = 0;
try {
@ -192,7 +194,6 @@ public class MainFragment extends PreferenceFragmentBase {
else
handler.post(hideUpdateNotification);
} catch (Exception e) {}
*/
}
}).start();
@ -201,15 +202,6 @@ public class MainFragment extends PreferenceFragmentBase {
showRestoreInfoDialog();
}
//Add version name to support title
try {
PreferenceCategory supportCat = (PreferenceCategory) findPreference("pref_key_support");
supportCat.setTitle(String.format(Helpers.l10n(act, R.string.support_version), act.getPackageManager().getPackageInfo(act.getPackageName(), 0).versionName));
} catch (NameNotFoundException e) {
//Shouldn't happen...
e.printStackTrace();
}
CheckBoxPreference.OnPreferenceChangeListener toggleIcon = new CheckBoxPreference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
@ -230,18 +222,10 @@ public class MainFragment extends PreferenceFragmentBase {
}
};
CheckBoxPreference.OnPreferenceClickListener openLang = new CheckBoxPreference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Helpers.openLangDialog(getActivity());
return true;
}
};
CheckBoxPreference.OnPreferenceClickListener sendCrashReport = new CheckBoxPreference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
//ACRA.getErrorReporter().handleException(null);
ACRA.getErrorReporter().handleException(null);
return true;
}
};
@ -260,9 +244,6 @@ public class MainFragment extends PreferenceFragmentBase {
Preference miuizerBackgroundColorPreference = findPreference("pref_key_miuizer_material_background");
if (miuizerBackgroundColorPreference != null)
miuizerBackgroundColorPreference.setOnPreferenceChangeListener(changeBackgroundColor);
Preference miuizerLanguagePreference = findPreference("pref_key_miuizer_lang");
if (miuizerLanguagePreference != null)
miuizerLanguagePreference.setOnPreferenceClickListener(openLang);
Preference miuizerCrashReportPreference = findPreference("pref_key_miuizer_sendreport");
if (miuizerCrashReportPreference != null)
miuizerCrashReportPreference.setOnPreferenceClickListener(sendCrashReport);
@ -274,28 +255,12 @@ public class MainFragment extends PreferenceFragmentBase {
issueTrackerPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference pref) {
Helpers.openURL(act, "https://bitbucket.org/langerhans/sense-toolbox/issues/");
return true;
}
});
Preference miuizerSitePreference = findPreference("pref_key_website");
miuizerSitePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference pref) {
Helpers.openURL(act, "http://sensetoolbox.com/");
return true;
}
});
Preference donatePagePreference = findPreference("pref_key_donatepage");
donatePagePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference pref) {
Helpers.openURL(act, "http://sensetoolbox.com/donate");
Helpers.openURL(act, "https://code.highspec.ru/Mikanoshi/CustoMIUIzer/issues");
return true;
}
});
Helpers.removePref(this, "pref_key_miuizer_force_material", "pref_key_miuizer");
//Helpers.removePref(this, "pref_key_miuizer_force_material", "pref_key_miuizer");
}
public boolean onCreateOptionsMenu(Menu menu) {
@ -308,7 +273,7 @@ public class MainFragment extends PreferenceFragmentBase {
switch (item.getItemId()) {
case R.id.xposedinstaller:
if (!Helpers.isXposedInstallerInstalled(getContext())) {
Toast.makeText(getContext(), Helpers.l10n(getContext(), R.string.xposed_not_found), Toast.LENGTH_LONG).show();
Toast.makeText(getContext(), R.string.xposed_not_found, Toast.LENGTH_LONG).show();
return true;
}
@ -317,7 +282,7 @@ public class MainFragment extends PreferenceFragmentBase {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
getContext().startActivity(intent);
return true;
} catch (Exception e1) {
} catch (Throwable e1) {
intent = new Intent("de.robv.android.xposed.installer.OPEN_SECTION");
intent.setPackage("de.robv.android.xposed.installer");
intent.putExtra("section", "modules");
@ -325,8 +290,8 @@ public class MainFragment extends PreferenceFragmentBase {
try {
getContext().startActivity(intent);
return true;
} catch (Exception e2) {
Toast.makeText(getContext(), Helpers.l10n(getContext(), R.string.xposed_not_found), Toast.LENGTH_LONG).show();;
} catch (Throwable e2) {
Toast.makeText(getContext(), R.string.xposed_not_found, Toast.LENGTH_LONG).show();;
}
return false;
}
@ -334,9 +299,14 @@ public class MainFragment extends PreferenceFragmentBase {
showBackupRestoreDialog();
return true;
case R.id.softreboot:
if (!miuizerModuleActive) {
showXposedDialog(getActivity());
return true;
}
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle(Helpers.l10n(getContext(), R.string.soft_reboot));
alert.setMessage(Helpers.l10n(getContext(), R.string.soft_reboot_ask));
alert.setTitle(R.string.soft_reboot);
alert.setMessage(R.string.soft_reboot_ask);
alert.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
getContext().sendBroadcast(new Intent("name.mikanoshi.customiuizer.mods.action.FastReboot"));
@ -346,13 +316,14 @@ public class MainFragment extends PreferenceFragmentBase {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
return true;
case R.id.about:
//Intent intent = new Intent(act, MAboutScreen.class);
//act.startActivity(intent);
Bundle args = new Bundle();
args.putInt("baseResId", R.layout.fragment_about);
openSubFragment(new AboutFragment(), args, Helpers.SettingsType.Preference, Helpers.ActionBarType.HomeUp, R.string.app_about, R.xml.prefs_about);
return true;
};
return false;
return super.onOptionsItemSelected(item);
}
public void backupSettings(Activity act) {
@ -363,16 +334,16 @@ public class MainFragment extends PreferenceFragmentBase {
output.writeObject(Helpers.prefs.getAll());
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.do_backup));
alert.setMessage(Helpers.l10n(act, R.string.backup_ok));
alert.setTitle(R.string.do_backup);
alert.setMessage(R.string.backup_ok);
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
} catch (Exception e) {
} catch (Throwable e) {
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.warning));
alert.setMessage(Helpers.l10n(act, R.string.storage_cannot_backup));
alert.setTitle(R.string.warning);
alert.setMessage(R.string.storage_cannot_backup);
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
@ -385,7 +356,7 @@ public class MainFragment extends PreferenceFragmentBase {
output.flush();
output.close();
}
} catch (Exception ex) {
} catch (Throwable ex) {
ex.printStackTrace();
}
}
@ -396,7 +367,7 @@ public class MainFragment extends PreferenceFragmentBase {
try {
input = new ObjectInputStream(new FileInputStream(Helpers.backupPath + Helpers.backupFile));
Map<String, ?> entries = (Map<String, ?>)input.readObject();
if (entries == null || entries.isEmpty()) throw new Exception("Cannot read entries");
if (entries == null || entries.isEmpty()) throw new RuntimeException("Cannot read entries");
SharedPreferences.Editor prefEdit = Helpers.prefs.edit();
prefEdit.clear();
@ -420,8 +391,8 @@ public class MainFragment extends PreferenceFragmentBase {
prefEdit.apply();
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.do_restore));
alert.setMessage(Helpers.l10n(act, R.string.restore_ok));
alert.setTitle(R.string.do_restore);
alert.setMessage(R.string.restore_ok);
alert.setCancelable(false);
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
@ -430,10 +401,10 @@ public class MainFragment extends PreferenceFragmentBase {
}
});
alert.show();
} catch (Exception e) {
} catch (Throwable e) {
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.warning));
alert.setMessage(Helpers.l10n(act, R.string.storage_cannot_restore));
alert.setTitle(R.string.warning);
alert.setMessage(R.string.storage_cannot_restore);
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
@ -441,7 +412,7 @@ public class MainFragment extends PreferenceFragmentBase {
} finally {
try {
if (input != null) input.close();
} catch (Exception ex) {
} catch (Throwable ex) {
ex.printStackTrace();
}
}
@ -451,16 +422,16 @@ public class MainFragment extends PreferenceFragmentBase {
final Activity act = getActivity();
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.backup_restore));
alert.setMessage(Helpers.l10n(act, R.string.backup_restore_choose));
alert.setPositiveButton(Helpers.l10n(act, R.string.do_restore), new DialogInterface.OnClickListener() {
alert.setTitle(R.string.backup_restore);
alert.setMessage(R.string.backup_restore_choose);
alert.setPositiveButton(R.string.do_restore, new DialogInterface.OnClickListener() {
@SuppressWarnings("unchecked")
public void onClick(DialogInterface dialog, int whichButton) {
if (!Helpers.checkStorageReadable(act)) return;
restoreSettings(act);
}
});
alert.setNegativeButton(Helpers.l10n(act, R.string.do_backup), new DialogInterface.OnClickListener() {
alert.setNegativeButton(R.string.do_backup, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
backupSettings(act);
}
@ -477,16 +448,16 @@ public class MainFragment extends PreferenceFragmentBase {
switch (preference.getKey()) {
case "pref_key_system":
showNotYetDialog();
openSubFragment(new System(), null, Helpers.SettingsType.Preference, Helpers.ActionBarType.HomeUp, R.string.system_mods, R.xml.prefs_system);
break;
case "pref_key_launcher":
openSubFragment(new Launcher(), null, Helpers.SettingsType.Preference, Helpers.ActionBarType.HomeUp, R.string.launcher_mods, R.xml.prefs_launcher);
return true;
case "pref_key_controls":
showNotYetDialog();
openSubFragment(new Controls(), null, Helpers.SettingsType.Preference, Helpers.ActionBarType.HomeUp, R.string.controls_mods, R.xml.prefs_controls);
break;
case "pref_key_other":
showNotYetDialog();
case "pref_key_various":
openSubFragment(new Various(), null, Helpers.SettingsType.Preference, Helpers.ActionBarType.HomeUp, R.string.various_mods, R.xml.prefs_various);
break;
}
}
@ -497,8 +468,8 @@ public class MainFragment extends PreferenceFragmentBase {
public void showXposedDialog(Activity act) {
try {
AlertDialog.Builder builder = new AlertDialog.Builder(act);
builder.setTitle(Helpers.l10n(act, R.string.warning));
builder.setMessage(Helpers.l10n(act, R.string.module_not_active));
builder.setTitle(R.string.warning);
builder.setMessage(R.string.module_not_active);
builder.setCancelable(true);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
@ -513,8 +484,8 @@ public class MainFragment extends PreferenceFragmentBase {
private void showRestoreInfoDialog() {
try {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(Helpers.l10n(getActivity(), R.string.warning));
builder.setMessage(Helpers.l10n(getActivity(), R.string.backup_restore_info));
builder.setTitle(R.string.warning);
builder.setMessage(R.string.backup_restore_info);
builder.setCancelable(true);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
@ -529,8 +500,8 @@ public class MainFragment extends PreferenceFragmentBase {
private void showNotYetDialog() {
try {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(Helpers.l10n(getActivity(), R.string.info));
builder.setMessage(Helpers.l10n(getActivity(), R.string.not_yet));
builder.setTitle(R.string.info);
builder.setMessage(R.string.not_yet);
builder.setCancelable(true);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}


+ 46
- 188
app/src/main/java/name/mikanoshi/customiuizer/MainModule.java View File

@ -1,28 +1,18 @@
package name.mikanoshi.customiuizer;
import android.content.Context;
import android.content.res.XModuleResources;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceActivity;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import static de.robv.android.xposed.XposedHelpers.*;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import name.mikanoshi.customiuizer.mods.Launcher;
import name.mikanoshi.customiuizer.mods.Controls;
import name.mikanoshi.customiuizer.mods.System;
import name.mikanoshi.customiuizer.mods.Various;
import name.mikanoshi.customiuizer.utils.GlobalActions;
import name.mikanoshi.customiuizer.utils.Helpers;
import name.mikanoshi.customiuizer.utils.PackagePermissions;
@SuppressWarnings("WeakerAccess")
public class MainModule implements IXposedHookZygoteInit, IXposedHookLoadPackage {
public static String MODULE_PATH = null;
@ -30,52 +20,55 @@ public class MainModule implements IXposedHookZygoteInit, IXposedHookLoadPackage
public static int pref_swipedown = 1;
public static int pref_swipeup = 1;
public static int pref_swipedown2 = 1;
public static int pref_swipeup2 = 1;
public static int pref_swiperight = 1;
public static int pref_swipeleft = 1;
public static int pref_shake = 1;
public static Map<String, String> langForHooks;
public void initZygote(StartupParam startParam) throws Throwable {
public static int pref_screenanim = 0;
public static int pref_appsort = 0;
public static int pref_etoasts = 1;
public static boolean pref_powerflash = false;
public static boolean pref_nolightup = false;
public static boolean pref_appdetails = false;
public static boolean pref_scramblepin = false;
public static boolean pref_securelock = false;
public void initZygote(StartupParam startParam) {
MODULE_PATH = startParam.modulePath;
pref = new XSharedPreferences(Helpers.modulePkg, Helpers.prefsName);
pref.makeWorldReadable();
pref_swipedown = pref.getInt("pref_key_launcher_swipedown_action", 1);
pref_swipeup = pref.getInt("pref_key_launcher_swipeup_action", 1);
pref_swipedown2 = pref.getInt("pref_key_launcher_swipedown2_action", 1);
pref_swipeup2 = pref.getInt("pref_key_launcher_swipeup2_action", 1);
pref_swiperight = pref.getInt("pref_key_launcher_swiperight_action", 1);
pref_swipeleft = pref.getInt("pref_key_launcher_swipeleft_action", 1);
pref_shake = pref.getInt("pref_key_launcher_shake_action", 1);
XModuleResources modRes = XModuleResources.createInstance(MainModule.MODULE_PATH, null);
langForHooks = new HashMap<String, String>();
langForHooks.put("toggle_wifi_off", modRes.getString(R.string.toggle_wifi_off));
langForHooks.put("toggle_wifi_on", modRes.getString(R.string.toggle_wifi_on));
langForHooks.put("toggle_bt_off", modRes.getString(R.string.toggle_bt_off));
langForHooks.put("toggle_bt_on", modRes.getString(R.string.toggle_bt_on));
langForHooks.put("toggle_gps_off", modRes.getString(R.string.toggle_gps_off));
langForHooks.put("toggle_gps_on", modRes.getString(R.string.toggle_gps_on));
langForHooks.put("toggle_nfc_off", modRes.getString(R.string.toggle_nfc_off));
langForHooks.put("toggle_nfc_on", modRes.getString(R.string.toggle_nfc_on));
langForHooks.put("toggle_sound_vibrate", modRes.getString(R.string.toggle_sound_vibrate));
langForHooks.put("toggle_sound_normal", modRes.getString(R.string.toggle_sound_normal));
langForHooks.put("toggle_sound_silent", modRes.getString(R.string.toggle_sound_silent));
langForHooks.put("toggle_autobright_on", modRes.getString(R.string.toggle_autobright_on));
langForHooks.put("toggle_autobright_off", modRes.getString(R.string.toggle_autobright_off));
langForHooks.put("toggle_autorotate_on", modRes.getString(R.string.toggle_autorotate_on));
langForHooks.put("toggle_autorotate_off", modRes.getString(R.string.toggle_autorotate_off));
langForHooks.put("toggle_flash_on", modRes.getString(R.string.toggle_flash_on));
langForHooks.put("toggle_flash_off", modRes.getString(R.string.toggle_flash_off));
langForHooks.put("toggle_mobiledata_on", modRes.getString(R.string.toggle_mobiledata_on));
langForHooks.put("toggle_mobiledata_off", modRes.getString(R.string.toggle_mobiledata_off));
pref_screenanim = pref.getInt("pref_key_system_screenanim_duration", 0);
pref_powerflash = pref.getBoolean("pref_key_controls_powerflash", false);
pref_nolightup = pref.getBoolean("pref_key_system_nolightuponcharge", false);
pref_appdetails = pref.getBoolean("pref_key_various_appdetails", false);
pref_appsort = Integer.parseInt(MainModule.pref.getString("pref_key_various_appsort", "0"));
pref_scramblepin = pref.getBoolean("pref_key_system_scramblepin", false);
pref_securelock = pref.getBoolean("pref_key_system_securelock", false);
pref_etoasts = Integer.parseInt(MainModule.pref.getString("pref_key_system_iconlabletoasts", "1"));
if (pref_etoasts > 1) System.IconLabelToastsHook();
}
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
public void handleLoadPackage(final LoadPackageParam lpparam) {
String pkg = lpparam.packageName;
if (pkg.equals("android") && lpparam.processName.equals("android")) {
PackagePermissions.init(lpparam);
GlobalActions.setupGlobalActions(lpparam);
if (pref_powerflash) Controls.PowerKeyHook(lpparam);
if (pref_screenanim > 0) System.ScreenAnimHook(lpparam);
if (pref_nolightup) System.NoLightUpOnChargeHook(lpparam);
if (pref_securelock) System.EnhancedSecurityHook(lpparam);
}
if (pkg.equals(Helpers.modulePkg)) {
@ -84,160 +77,25 @@ public class MainModule implements IXposedHookZygoteInit, IXposedHookLoadPackage
if (pkg.equals("com.android.systemui")) {
GlobalActions.setupStatusBar(lpparam);
}
if (pkg.equals("com.android.settings")) {
/*
findAndHookMethod("com.android.settingslib.drawer.l", lpparam.classLoader, "a", Context.class, Map.class, boolean.class, String.class, String.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
Map<Pair<String, String>, Object> map = (Map<Pair<String, String>, Object>)param.args[1];
boolean bool = (boolean)param.args[2];
String str1 = (String)param.args[3];
String str2 = (String)param.args[4];
XposedBridge.log("Tile with Map:");
XposedBridge.log("Map:");
for (Map.Entry<Pair<String, String>, Object> entry: map.entrySet())
XposedBridge.log(entry.getKey().first + " = " + entry.getKey().second);
XposedBridge.log("- - - - - - - - - -");
XposedBridge.log(String.valueOf(bool));
XposedBridge.log("Str1: " + str1);
XposedBridge.log("Str2: " + str2);
XposedBridge.log("- - - - - - - - - -");
}
});
findAndHookMethod("com.android.settingslib.drawer.l", lpparam.classLoader, "a", Context.class, UserHandle.class, String.class, Map.class, String.class, ArrayList.class, boolean.class, boolean.class, String.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
UserHandle uh = (UserHandle)param.args[1];
String str1 = (String)param.args[2];
Map<Pair<String, String>, Object> map = (Map<Pair<String, String>, Object>)param.args[3];
String str2 = (String)param.args[4];
ArrayList list = (ArrayList)param.args[5];
boolean bool1 = (boolean)param.args[6];
boolean bool2 = (boolean)param.args[7];
String str3 = (String)param.args[8];
XposedBridge.log("Tile with ArrayList:");
XposedBridge.log(uh.toString());
XposedBridge.log("Str1: " + str1);
XposedBridge.log("Map:");
for (Map.Entry<Pair<String, String>, Object> entry: map.entrySet())
XposedBridge.log(entry.getKey().first + " = " + entry.getKey().second);
XposedBridge.log("- - - - - - - - - -");
XposedBridge.log("Str2: " + str2);
XposedBridge.log("ArrayList:");
for (Object entry: list)
XposedBridge.log(entry.toString());
XposedBridge.log("- - - - - - - - - -");
XposedBridge.log(String.valueOf(bool1));
XposedBridge.log(String.valueOf(bool2));
XposedBridge.log("Str3: " + str3);
XposedBridge.log("= = = = = = = = = =");
}
});
findAndHookMethod("com.android.settingslib.drawer.l", lpparam.classLoader, "a",