Browse Source

Initial commit

pull/109/head
Mikanoshi 2 years ago
commit
9231021d77
202 changed files with 9251 additions and 0 deletions
  1. +13
    -0
      .gitignore
  2. +29
    -0
      .idea/codeStyles/Project.xml
  3. +5
    -0
      .idea/codeStyles/codeStyleConfig.xml
  4. +15
    -0
      .idea/gradle.xml
  5. +6
    -0
      .idea/inspectionProfiles/Project_Default.xml
  6. +14
    -0
      .idea/misc.xml
  7. +12
    -0
      .idea/runConfigurations.xml
  8. +1
    -0
      app/.gitignore
  9. +26
    -0
      app/build.gradle
  10. BIN
      app/lib/miui.jar
  11. +21
    -0
      app/proguard-rules.pro
  12. +51
    -0
      app/src/main/AndroidManifest.xml
  13. +1
    -0
      app/src/main/assets/xposed_init
  14. +85
    -0
      app/src/main/java/name/mikanoshi/customiuizer/ActivityEx.java
  15. +5
    -0
      app/src/main/java/name/mikanoshi/customiuizer/GateWay.java
  16. +49
    -0
      app/src/main/java/name/mikanoshi/customiuizer/MainActivity.java
  17. +544
    -0
      app/src/main/java/name/mikanoshi/customiuizer/MainFragment.java
  18. +256
    -0
      app/src/main/java/name/mikanoshi/customiuizer/MainModule.java
  19. +492
    -0
      app/src/main/java/name/mikanoshi/customiuizer/PreferenceFragmentBase.java
  20. +202
    -0
      app/src/main/java/name/mikanoshi/customiuizer/SubFragment.java
  21. +118
    -0
      app/src/main/java/name/mikanoshi/customiuizer/SubFragmentWithSearch.java
  22. +214
    -0
      app/src/main/java/name/mikanoshi/customiuizer/mods/Launcher.java
  23. +49
    -0
      app/src/main/java/name/mikanoshi/customiuizer/prefs/CheckBoxPreferenceEx.java
  24. +35
    -0
      app/src/main/java/name/mikanoshi/customiuizer/prefs/LinearLayoutEx.java
  25. +73
    -0
      app/src/main/java/name/mikanoshi/customiuizer/prefs/ListPreferenceEx.java
  26. +146
    -0
      app/src/main/java/name/mikanoshi/customiuizer/prefs/SpinnerEx.java
  27. +53
    -0
      app/src/main/java/name/mikanoshi/customiuizer/prefs/SpinnerExFake.java
  28. +60
    -0
      app/src/main/java/name/mikanoshi/customiuizer/subs/AppSelector.java
  29. +41
    -0
      app/src/main/java/name/mikanoshi/customiuizer/subs/Launcher.java
  30. +106
    -0
      app/src/main/java/name/mikanoshi/customiuizer/subs/ShortcutSelector.java
  31. +208
    -0
      app/src/main/java/name/mikanoshi/customiuizer/subs/SwipeGesture.java
  32. +8
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/AppData.java
  33. +118
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/AppDataAdapter.java
  34. +132
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/AppResolveAdapter.java
  35. +84
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/BitmapCachedLoader.java
  36. +220
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/DownloadAndUnZip.java
  37. +910
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/GlobalActions.java
  38. +1103
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/Helpers.java
  39. +248
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/MaterialColorPicker.java
  40. +152
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/PackagePermissions.java
  41. +28
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/PrefBackupAgent.java
  42. +100
    -0
      app/src/main/java/name/mikanoshi/customiuizer/utils/ShakeManager.java
  43. +2
    -0
      app/src/main/res/anim/accelerate_interpolator.xml
  44. +2
    -0
      app/src/main/res/anim/accelerate_quart.xml
  45. +12
    -0
      app/src/main/res/anim/activity_close_enter.xml
  46. +9
    -0
      app/src/main/res/anim/activity_close_exit.xml
  47. +9
    -0
      app/src/main/res/anim/activity_open_enter.xml
  48. +15
    -0
      app/src/main/res/anim/activity_open_exit.xml
  49. +2
    -0
      app/src/main/res/anim/decelerate_interpolator.xml
  50. +2
    -0
      app/src/main/res/anim/decelerate_quart.xml
  51. +12
    -0
      app/src/main/res/anim/dialog_enter.xml
  52. +12
    -0
      app/src/main/res/anim/dialog_exit.xml
  53. +2
    -0
      app/src/main/res/animator/fragment_close_enter.xml
  54. +2
    -0
      app/src/main/res/animator/fragment_close_exit.xml
  55. +2
    -0
      app/src/main/res/animator/fragment_open_enter.xml
  56. +2
    -0
      app/src/main/res/animator/fragment_open_exit.xml
  57. +5
    -0
      app/src/main/res/color/action_bar_title_text_light.xml
  58. +6
    -0
      app/src/main/res/color/action_mode_title_button_text_light.xml
  59. +6
    -0
      app/src/main/res/color/action_mode_title_default_button_text_light.xml
  60. +5
    -0
      app/src/main/res/color/button_text_color_guide_light.xml
  61. +5
    -0
      app/src/main/res/color/button_text_color_positive_light.xml
  62. +5
    -0
      app/src/main/res/color/button_text_dialog_light.xml
  63. +8
    -0
      app/src/main/res/color/button_text_light.xml
  64. +9
    -0
      app/src/main/res/color/checkable_btn_text_color_stable_light.xml
  65. +9
    -0
      app/src/main/res/color/dialog_list_text_light_single_choice.xml
  66. +8
    -0
      app/src/main/res/color/list_secondary_text_dark.xml
  67. +8
    -0
      app/src/main/res/color/list_text_dark.xml
  68. +9
    -0
      app/src/main/res/color/preference_primary_text_light.xml
  69. +9
    -0
      app/src/main/res/color/preference_secondary_text_light.xml
  70. BIN
      app/src/main/res/drawable-xxhdpi-v4/ic_launcher.png
  71. BIN
      app/src/main/res/drawable-xxhdpi-v4/ic_miuize.png
  72. BIN
      app/src/main/res/drawable-xxhdpi/right_arrow.png
  73. BIN
      app/src/main/res/drawable-xxhdpi/theme_selected.png
  74. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_bar_back_search_normal_light.png
  75. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_bar_back_search_pressed_light.png
  76. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_bar_stack_bg_light.9.png
  77. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_bg_dialog_light.9.png
  78. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_button_bg_disable_light.9.png
  79. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_button_bg_normal_light.9.png
  80. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_button_bg_pressed_light.9.png
  81. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_default_button_bg_disable_light.9.png
  82. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_default_button_bg_normal_light.9.png
  83. BIN
      app/src/main/res/drawable-xxxhdpi-v4/action_mode_title_default_button_bg_pressed_light.9.png
  84. BIN
      app/src/main/res/drawable-xxxhdpi-v4/am_card_item_disabled.png
  85. BIN
      app/src/main/res/drawable-xxxhdpi-v4/am_list_item_background_normal.9.png
  86. BIN
      app/src/main/res/drawable-xxxhdpi-v4/arrow_right_disable.png
  87. BIN
      app/src/main/res/drawable-xxxhdpi-v4/arrow_right_normal.png
  88. BIN
      app/src/main/res/drawable-xxxhdpi-v4/arrow_right_pressed.png
  89. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_off_disabled_light.png
  90. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_off_normal_light.png
  91. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_on_disabled_light.png
  92. BIN
      app/src/main/res/drawable-xxxhdpi-v4/btn_checkbox_dialog_on_normal_light.png
  93. BIN
      app/src/main/res/drawable-xxxhdpi-v4/card_icon_default.png
  94. BIN
      app/src/main/res/drawable-xxxhdpi-v4/edit_text_search.9.png
  95. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_first_normal_light.9.png
  96. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_first_pressed_light.9.png
  97. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_last_normal_light.9.png
  98. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_last_pressed_light.9.png
  99. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_middle_normal_light.9.png
  100. BIN
      app/src/main/res/drawable-xxxhdpi-v4/list_item_bg_dialog_middle_pressed_light.9.png

+ 13
- 0
.gitignore View File

@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild

+ 29
- 0
.idea/codeStyles/Project.xml View File

@ -0,0 +1,29 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>

+ 5
- 0
.idea/codeStyles/codeStyleConfig.xml View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

+ 15
- 0
.idea/gradle.xml View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

+ 6
- 0
.idea/inspectionProfiles/Project_Default.xml View File

@ -0,0 +1,6 @@
<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" />
</profile>
</component>

+ 14
- 0
.idea/misc.xml View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeSettings">
<configurations>
<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">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

+ 12
- 0
.idea/runConfigurations.xml View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

+ 1
- 0
app/.gitignore View File

@ -0,0 +1 @@
/build

+ 26
- 0
app/build.gradle View File

@ -0,0 +1,26 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "name.mikanoshi.customiuizer"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
compileOnly 'de.robv.android.xposed:api:82'
compileOnly files('lib/miui.jar')
implementation 'org.jetbrains:annotations-java5:15.0'
}

BIN
app/lib/miui.jar View File


+ 21
- 0
app/proguard-rules.pro View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

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

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="name.mikanoshi.customiuizer">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="false"
android:backupAgent="name.mikanoshi.customiuizer.utils.PrefBackupAgent"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:roundIcon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:label="@string/title_activity_main"
android:name=".GateWay"
android:targetActivity=".MainActivity"
android:enabled="true"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="com.android.settings.action.EXTRA_SETTINGS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data android:name="com.android.settings.category" android:value="com.android.settings.category.customiuizer" />
<meta-data android:name="com.android.settings.icon" android:resource="@drawable/ic_miuize" />
<meta-data android:name="com.android.settings.icon_tintable" android:value="true" />
<meta-data android:name="com.android.settings.title" android:resource="@string/app_name" />
</activity-alias>
<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" />
<meta-data android:name="com.google.android.backup.api_key" android:value="AEdPqrEAAAAIRIa0lKCzoQ_qe_xfqaQCC4EQhwk3CWeRwzFrww" />
</application>
</manifest>

+ 1
- 0
app/src/main/assets/xposed_init View File

@ -0,0 +1 @@
name.mikanoshi.customiuizer.MainModule

+ 85
- 0
app/src/main/java/name/mikanoshi/customiuizer/ActivityEx.java View File

@ -0,0 +1,85 @@
package name.mikanoshi.customiuizer;
import android.app.Activity;
import android.app.Fragment;
import android.app.backup.BackupManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import name.mikanoshi.customiuizer.utils.Helpers;
public class ActivityEx extends Activity {
public int mThemeBackground = 1;
public boolean launch = true;
SharedPreferences.OnSharedPreferenceChangeListener prefsChanged;
protected void onCreate(Bundle savedInstanceState) {
setTheme(getResources().getIdentifier("Theme.Light.Settings", "style", "miui"));
getTheme().applyStyle(R.style.MIUIPrefs, true);
super.onCreate(savedInstanceState);
Helpers.prefs = getSharedPreferences(Helpers.prefsName, Context.MODE_PRIVATE);
prefsChanged = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.w("prefs", "Changed: " + key);
requestBackup();
}
};
Helpers.prefs.registerOnSharedPreferenceChangeListener(prefsChanged);
mThemeBackground = Integer.parseInt(Helpers.prefs.getString("pref_key_miuizer_material_background", "1"));
//if (mThemeBackground == 2) getTheme().applyStyle(R.style.MaterialThemeDark, true);
setContentView(R.layout.activity_main);
}
@Override
public void onBackPressed() {
Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container);
if (fragment != null)
if (((PreferenceFragmentBase)fragment).isAnimating) return;
super.onBackPressed();
}
protected void onDestroy() {
Helpers.prefs.unregisterOnSharedPreferenceChangeListener(prefsChanged);
super.onDestroy();
}
public void updateTheme(int newBkg) {
int newThemeBackground;
if (newBkg == 0)
newThemeBackground = Integer.parseInt(Helpers.prefs.getString("pref_key_miuizer_material_background", "1"));
else
newThemeBackground = newBkg;
if (newThemeBackground != mThemeBackground) recreate();
}
@Override
protected void onResume() {
super.onResume();
if (launch) updateTheme(0);
}
@Override
protected void onPause() {
super.onPause();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public void requestBackup() {
BackupManager bm = new BackupManager(getApplicationContext());
bm.dataChanged();
}
}

+ 5
- 0
app/src/main/java/name/mikanoshi/customiuizer/GateWay.java View File

@ -0,0 +1,5 @@
package name.mikanoshi.customiuizer;
import android.app.Activity;
public class GateWay extends Activity {}

+ 49
- 0
app/src/main/java/name/mikanoshi/customiuizer/MainActivity.java View File

@ -0,0 +1,49 @@
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 {
public static final int REQUEST_BACKUP_PERMISSIONS = 1;
MainFragment mainFrag = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Helpers.dataPath = getFilesDir().getPath();
Helpers.backupPath = 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) {
switch (requestCode) {
case REQUEST_BACKUP_PERMISSIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
mainFrag.backupSettings(this);
else if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE))
Toast.makeText(this, "Do you want to write backup or not?", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "You'll have to manually enable permission for this option now. Good job!", Toast.LENGTH_LONG).show();
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

+ 544
- 0
app/src/main/java/name/mikanoshi/customiuizer/MainFragment.java View File

@ -0,0 +1,544 @@
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;
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;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
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.Launcher;
import name.mikanoshi.customiuizer.utils.Helpers;
public class MainFragment extends PreferenceFragmentBase {
public boolean miuizerModuleActive = false;
public MainFragment() {
super();
this.setRetainInstance(true);
}
private Runnable showUpdateNotification = new Runnable() {
@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));
FrameLayout updateFrame = (FrameLayout)getActivity().findViewById(R.id.updateFrame);
updateFrame.setLayoutTransition(new LayoutTransition());
updateFrame.setVisibility(View.VISIBLE);
updateFrame.setBackgroundColor(0xff252525);
updateFrame.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent detailsIntent = new Intent();
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) {
Helpers.openURL(getActivity(), "http://sensetoolbox.com/6/download");
}
}
});
} catch (Exception e) {}
}
};
private Runnable hideUpdateNotification = new Runnable() {
@Override
public void run() {
if (isFragmentReady(getActivity())) try {
FrameLayout updateFrame = getActivity().findViewById(R.id.updateFrame);
updateFrame.setVisibility(View.GONE);
} catch (Exception e) {}
}
};
private boolean isFragmentReady(Activity act) {
return act != null && !act.isFinishing() && MainFragment.this.isAdded();
}
@Override
@SuppressLint("MissingSuperCall")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.xml.preferences);
addPreferencesFromResource(R.xml.preferences);
}
private void setupImmersiveMenu() {
ActionBar actionBar = getActionBar();
if (actionBar != null) actionBar.showSplitActionBar(false, false);
setImmersionMenuEnabled(true);
}
@Override
public void onResume() {
super.onResume();
setupImmersiveMenu();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setupImmersiveMenu();
final Activity act = getActivity();
final Handler handler = new Handler();
// Preventing launch delay
new Thread(new Runnable() {
public void run() {
if (!Helpers.isXposedInstallerInstalled(act))
act.runOnUiThread(new Runnable() {
@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);
AlertDialog dlg = builder.create();
if (isFragmentReady(act)) dlg.show();
}
}); else {
final Activity act = getActivity();
if (isFragmentReady(act) && !miuizerModuleActive)
act.runOnUiThread(new Runnable() {
public void run() {
showXposedDialog(act);
}
});
}
/*
String miuizerPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/SenseToolbox/";
HttpURLConnection connection = null;
try {
URL url = new URL("http://sensetoolbox.com/last_build");
connection = (HttpURLConnection)url.openConnection();
connection.setDefaultUseCaches(false);
connection.setUseCaches(false);
connection.setRequestProperty("Pragma", "no-cache");
connection.setRequestProperty("Cache-Control", "no-cache");
connection.setRequestProperty("Expires", "-1");
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK || connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
String last_build = "";
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
last_build = reader.readLine().trim();
} catch (Exception e) { e.printStackTrace(); }
File tmp = new File(miuizerPath);
if (!tmp.exists()) tmp.mkdirs();
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(miuizerPath + "last_build", false))) {
writer.write(last_build);
} catch (Exception e) { e.printStackTrace(); }
}
} catch (Exception e) {}
try {
if (connection != null) connection.disconnect();
} catch (Exception e) {}
try (InputStream inputFile = new FileInputStream(miuizerPath + "last_build")) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputFile));
int last_build = 0;
try {
last_build = Integer.parseInt(reader.readLine().trim());
} catch (Exception e) {}
if (last_build != 0 && Helpers.buildVersion < last_build)
handler.post(showUpdateNotification);
else
handler.post(hideUpdateNotification);
} catch (Exception e) {}
*/
}
}).start();
if (Helpers.prefs.getBoolean("pref_key_was_restore", false)) {
Helpers.prefs.edit().putBoolean("pref_key_was_restore", false).apply();
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) {
PackageManager pm = act.getPackageManager();
if ((Boolean)newValue)
pm.setComponentEnabledSetting(new ComponentName(act, GateWay.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
else
pm.setComponentEnabledSetting(new ComponentName(act, GateWay.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
return true;
}
};
ListPreference.OnPreferenceChangeListener changeBackgroundColor = new ListPreference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (act != null & !act.isFinishing()) ((ActivityEx)act).updateTheme(Integer.parseInt((String)newValue));
return true;
}
};
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);
return true;
}
};
CheckBoxPreference.OnPreferenceClickListener openFeedbackEdit = new CheckBoxPreference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
openSubFragment(new SubFragment(), null, Helpers.SettingsType.Edit, Helpers.ActionBarType.Edit, R.string.miuizer_acramail_title, R.layout.prefs_freedback);
return true;
}
};
CheckBoxPreference miuizerSettingsPreference = (CheckBoxPreference) findPreference("pref_key_miuizer_icon");
if (miuizerSettingsPreference != null)
miuizerSettingsPreference.setOnPreferenceChangeListener(toggleIcon);
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);
Preference feedbackPreference = findPreference("pref_key_miuizer_feedback");
if (feedbackPreference != null)
feedbackPreference.setOnPreferenceClickListener(openFeedbackEdit);
Preference issueTrackerPreference = findPreference("pref_key_issuetracker");
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");
return true;
}
});
Helpers.removePref(this, "pref_key_miuizer_force_material", "pref_key_miuizer");
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_mods, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
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();
return true;
}
Intent intent = getContext().getPackageManager().getLaunchIntentForPackage("com.solohsu.android.edxp.manager");
try {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
getContext().startActivity(intent);
return true;
} catch (Exception e1) {
intent = new Intent("de.robv.android.xposed.installer.OPEN_SECTION");
intent.setPackage("de.robv.android.xposed.installer");
intent.putExtra("section", "modules");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
try {
getContext().startActivity(intent);
return true;
} catch (Exception e2) {
Toast.makeText(getContext(), Helpers.l10n(getContext(), R.string.xposed_not_found), Toast.LENGTH_LONG).show();;
}
return false;
}
case R.id.backuprestore:
showBackupRestoreDialog();
return true;
case R.id.softreboot:
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.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"));
}
});
alert.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
case R.id.about:
//Intent intent = new Intent(act, MAboutScreen.class);
//act.startActivity(intent);
return true;
};
return false;
}
public void backupSettings(Activity act) {
if (!Helpers.preparePathForBackup(act, Helpers.backupPath)) return;
ObjectOutputStream output = null;
try {
output = new ObjectOutputStream(new FileOutputStream(Helpers.backupPath + Helpers.backupFile));
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.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
} catch (Exception 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.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
e.printStackTrace();
} finally {
try {
if (output != null) {
output.flush();
output.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public void restoreSettings(final Activity act) {
ObjectInputStream input = null;
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");
SharedPreferences.Editor prefEdit = Helpers.prefs.edit();
prefEdit.clear();
for (Map.Entry<String, ?> entry: entries.entrySet()) {
Object val = entry.getValue();
String key = entry.getKey();
if (val instanceof Boolean)
prefEdit.putBoolean(key, (Boolean)val);
else if (val instanceof Float)
prefEdit.putFloat(key, (Float)val);
else if (val instanceof Integer)
prefEdit.putInt(key, (Integer)val);
else if (val instanceof Long)
prefEdit.putLong(key, (Long)val);
else if (val instanceof String)
prefEdit.putString(key, ((String)val));
else if (val instanceof Set<?>)
prefEdit.putStringSet(key, ((Set<String>)val));
}
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.setCancelable(false);
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
act.finish();
act.startActivity(act.getIntent());
}
});
alert.show();
} catch (Exception 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.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
} finally {
try {
if (input != null) input.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public void showBackupRestoreDialog() {
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() {
@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() {
public void onClick(DialogInterface dialog, int whichButton) {
backupSettings(act);
}
});
alert.show();
}
// PreferenceScreens management
@Override
public boolean onPreferenceTreeClick(PreferenceScreen parentPreferenceScreen, Preference preference) {
if (preference != null) {
PreferenceCategory modsCat = (PreferenceCategory)findPreference("prefs_cat");
if (modsCat.findPreference(preference.getKey()) != null) {
switch (preference.getKey()) {
case "pref_key_system":
showNotYetDialog();
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();
break;
case "pref_key_other":
showNotYetDialog();
break;
}
}
}
return super.onPreferenceTreeClick(parentPreferenceScreen, preference);
}
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.setCancelable(true);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
});
AlertDialog dlg = builder.create();
dlg.show();
} catch (Throwable t) {
t.printStackTrace();
}
}
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.setCancelable(true);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
});
AlertDialog dlg = builder.create();
dlg.show();
} catch (Throwable t) {
t.printStackTrace();
}
}
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.setCancelable(true);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
});
AlertDialog dlg = builder.create();
dlg.show();
} catch (Throwable t) {
t.printStackTrace();
}
}
}

+ 256
- 0
app/src/main/java/name/mikanoshi/customiuizer/MainModule.java View File

@ -0,0 +1,256 @@
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.utils.GlobalActions;
import name.mikanoshi.customiuizer.utils.Helpers;
import name.mikanoshi.customiuizer.utils.PackagePermissions;
public class MainModule implements IXposedHookZygoteInit, IXposedHookLoadPackage {
public static String MODULE_PATH = null;
public static XSharedPreferences pref;
public static int pref_swipedown = 1;
public static int pref_swipeup = 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 {
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_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));
}
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
String pkg = lpparam.packageName;
if (pkg.equals("android") && lpparam.processName.equals("android")) {
PackagePermissions.init(lpparam);
GlobalActions.setupGlobalActions(lpparam);
}
if (pkg.equals(Helpers.modulePkg)) {
GlobalActions.miuizerInit(lpparam);
}
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", Context.class, UserHandle.class, Intent.class, Map.class, String.class, List.class, boolean.class, boolean.class, boolean.class, boolean.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
UserHandle uh = (UserHandle)param.args[1];
Intent intent = (Intent)param.args[2];
Map<Pair<String, String>, Object> map = (Map<Pair<String, String>, Object>)param.args[3];
String str = (String)param.args[4];
List list = (List)param.args[5];
boolean bool1 = (boolean)param.args[6];
boolean bool2 = (boolean)param.args[7];
boolean bool3 = (boolean)param.args[8];
boolean bool4 = (boolean)param.args[9];
XposedBridge.log("Tile with List:");
XposedBridge.log(uh.toString());
XposedBridge.log(intent.toString());
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("Str: " + str);
XposedBridge.log("List:");
for (Object entry: list)
XposedBridge.log(entry.toString());
XposedBridge.log("- - - - - - - - - -");
XposedBridge.log(String.valueOf(bool1));
XposedBridge.log(String.valueOf(bool2));
XposedBridge.log(String.valueOf(bool3));
XposedBridge.log(String.valueOf(bool4));
XposedBridge.log("= = = = = = = = = =");
}
});
findAndHookMethod("com.android.settingslib.drawer.l", lpparam.classLoader, "a", Context.class, "com.android.settingslib.drawer.Tile", ActivityInfo.class, ApplicationInfo.class, PackageManager.class, Map.class, boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
ApplicationInfo ai = (ApplicationInfo)param.args[3];
if (ai.packageName.equalsIgnoreCase(modulePkg) && !(boolean)XposedHelpers.callMethod(ai, "isSystemApp")) ai.flags |= 1;
}
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
Object tile = param.args[1];
ActivityInfo ai = (ActivityInfo)param.args[2];
ApplicationInfo ai2 = (ApplicationInfo)param.args[3];
Map<Pair<String, String>, Object> map = (Map<Pair<String, String>, Object>)param.args[5];
boolean bool = (boolean)param.args[6];
if (ai2.packageName.equalsIgnoreCase(modulePkg)) {
XposedBridge.log("Result: " + String.valueOf((boolean)param.getResult()));
XposedBridge.log("Title: " + XposedHelpers.getObjectField(tile, "title"));
XposedBridge.log("Summary: " + XposedHelpers.getObjectField(tile, "summary"));
XposedBridge.log("Cat: " + XposedHelpers.getObjectField(tile, "category"));
XposedBridge.log("Key: " + XposedHelpers.getObjectField(tile, "key"));
XposedBridge.log("Priority: " + String.valueOf((int)XposedHelpers.getObjectField(tile, "priority")));
XposedBridge.log("cCN: " + ((ArrayList)XposedHelpers.getObjectField(tile, "cCN")).toString());
XposedBridge.log("cCM: " + String.valueOf((boolean)XposedHelpers.getObjectField(tile, "cCM")));
XposedBridge.log("Icon: " + ((Icon)XposedHelpers.getObjectField(tile, "icon")).toString());
XposedBridge.log(ai.toString());
XposedBridge.log(ai2.toString());
//XposedBridge.log("Map:");
//for (Map.Entry<Pair<String, String>, Object> entry : map.entrySet())
//XposedBridge.log(entry.getKey().first + " = " + entry.getKey().second);
XposedBridge.log(String.valueOf(bool));
XposedBridge.log("= = = = = = = = = =");
}
}
});
findAndHookMethod("com.android.settingslib.drawer.l", lpparam.classLoader, "a", Context.class, Map.class, "com.android.settingslib.drawer.Tile", new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
Map map = (Map)param.args[1];
Object tile = (Object)param.args[2];
XposedBridge.log("Tile:");
XposedBridge.log(tile.toString());
XposedBridge.log(XposedHelpers.getObjectField(tile, "title").toString());
XposedBridge.log(XposedHelpers.getObjectField(tile, "summary").toString());
XposedBridge.log(String.valueOf((int)XposedHelpers.getObjectField(tile, "priority")));
XposedBridge.log(map.toString());
XposedBridge.log("- - - - - - - - - -");
}
});
*/
findAndHookMethod("com.android.settings.MiuiSettings", lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
Map<String, Integer> map = (Map<String, Integer>)XposedHelpers.getStaticObjectField(findClass("com.android.settings.MiuiSettings", lpparam.classLoader), "CATEGORY_MAP");
PreferenceActivity act = (PreferenceActivity)param.thisObject;
map.put("com.android.settings.category.customiuizer", act.getApplicationContext().getResources().getIdentifier("ic_miui_lab_settings", "drawable", "com.android.settings"));
XposedHelpers.setStaticObjectField(findClass("com.android.settings.MiuiSettings", lpparam.classLoader), "CATEGORY_MAP", map);
//XposedBridge.log(map.toString());
}
});
}
if (pkg.equals("com.miui.home")) {
if (pref_swipedown != 1 || pref_swipeup != 1)
Launcher.HomescreenSwipesHook(lpparam);
if (pref_swipeleft != 1 || pref_swiperight != 1)
Launcher.HotSeatSwipesHook(lpparam);
if (pref_shake != 1)
Launcher.ShakeHook(lpparam);
}
/*
if (pkg.equals("com.android.systemui"))
findAndHookMethod("com.android.keyguard.MiuiKeyguardClock", lpparam.classLoader, "onFinishInflate", new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
}
});
*/
}
}

+ 492
- 0
app/src/main/java/name/mikanoshi/customiuizer/PreferenceFragmentBase.java View File

@ -0,0 +1,492 @@
package name.mikanoshi.customiuizer;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import miui.preference.PreferenceFragment;
import name.mikanoshi.customiuizer.utils.Helpers;
public class PreferenceFragmentBase extends PreferenceFragment {
/*
public Switch OnOffSwitch;
public MenuItem menuTest;
public ListView prefListView;
public LinearLayout contentsView;
public TextView themeHint;
public int rebootType = 0;
public int menuType = 0;
//public QuickTipPopup qtp = null;
*/
public boolean isAnimating = false;
public int animDur = 350;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Activity act = getActivity();
if (item.getItemId() == android.R.id.home) {
if (this instanceof MainFragment)
act.finish();
else
((SubFragment)this).finish();
return true;
}
/*
else if (item.getItemId() == R.id.backuprestore) {
final String backupPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/SenseToolbox/";
final String backupFile = "settings_backup";
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.backup_restore));
alert.setView(Helpers.createCenteredText(act, R.string.backup_restore_choose));
alert.setPositiveButton(Helpers.l10n(act, R.string.do_restore), new DialogInterface.OnClickListener() {
@SuppressWarnings("unchecked")
public void onClick(DialogInterface dialog, int whichButton) {
if (!Helpers.checkStorageReadable(act)) return;
ObjectInputStream input = null;
try {
input = new ObjectInputStream(new FileInputStream(backupPath + backupFile));
Map<String, ?> entries = (Map<String, ?>)input.readObject();
if (entries == null || entries.isEmpty()) throw new Exception("Cannot read entries");
Editor prefEdit = Helpers.prefs.edit();
prefEdit.clear();
for (Entry<String, ?> entry: entries.entrySet()) {
Object val = entry.getValue();
String key = entry.getKey();
if (val instanceof Boolean)
prefEdit.putBoolean(key, ((Boolean)val).booleanValue());
else if (val instanceof Float)
prefEdit.putFloat(key, ((Float)val).floatValue());
else if (val instanceof Integer)
prefEdit.putInt(key, ((Integer)val).intValue());
else if (val instanceof Long)
prefEdit.putLong(key, ((Long)val).longValue());
else if (val instanceof String)
prefEdit.putString(key, ((String)val));
else if (val instanceof Set<?>)
prefEdit.putStringSet(key, ((Set<String>)val));
}
prefEdit.commit();
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.do_restore));
alert.setView(Helpers.createCenteredText(act, R.string.restore_ok));
alert.setCancelable(false);
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
act.finish();
act.startActivity(act.getIntent());
}
});
alert.show();
} catch (Exception e) {
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.warning));
alert.setView(Helpers.createCenteredText(act, R.string.storage_cannot_restore));
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
} finally {
try {
if (input != null) input.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
alert.setNegativeButton(Helpers.l10n(act, R.string.do_backup), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (!Helpers.preparePathForBackup(act, backupPath)) return;
ObjectOutputStream output = null;
try {
output = new ObjectOutputStream(new FileOutputStream(backupPath + backupFile));
output.writeObject(Helpers.prefs.getAll());
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.do_backup));
alert.setView(Helpers.createCenteredText(act, 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) {
AlertDialog.Builder alert = new AlertDialog.Builder(act);
alert.setTitle(Helpers.l10n(act, R.string.warning));
alert.setView(Helpers.createCenteredText(act, R.string.storage_cannot_backup));
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
e.printStackTrace();
} finally {
try {
if (output != null) {
output.flush();
output.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
alert.setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
alert.show();
return true;
} else if (item.getItemId() == R.id.about) {
Intent intent = new Intent(act, MAboutScreen.class);
act.startActivity(intent);
}
*/
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
//getMenuInflater().inflate(R.menu.menu_mods, menu);
//menu.getItem(0).setTitle(Helpers.l10n(getActivity(), R.string.open_xposed));
//menu.getItem(1).setTitle(Helpers.l10n(getActivity(), R.string.backup_restore));
//menu.getItem(2).setTitle(Helpers.l10n(getActivity(), R.string.app_about));
return true;
}
/*
// Wake gestures
public void applyWGState(Boolean state) {
OnOffSwitch.setChecked(state);
if (state) {
prefListView.setVisibility(View.VISIBLE);
themeHint.setVisibility(View.GONE);
} else {
prefListView.setVisibility(View.GONE);
themeHint.setVisibility(View.VISIBLE);
}
}
// EPS Remap
public void applyEPSState(boolean state) {
OnOffSwitch.setChecked(state);
if (state) {
contentsView.setVisibility(View.VISIBLE);
themeHint.setVisibility(View.GONE);
} else {
contentsView.setVisibility(View.GONE);
themeHint.setVisibility(View.VISIBLE);
}
}
// Better Heads up
public void applyHeadsupState(Boolean state) {
OnOffSwitch.setChecked(state);
menuTest.setEnabled(state);
if (menuTest.isEnabled())
menuTest.getIcon().setAlpha(255);
else
menuTest.getIcon().setAlpha(127);
if (state) {
prefListView.setVisibility(View.VISIBLE);
themeHint.setVisibility(View.GONE);
} else {
prefListView.setVisibility(View.GONE);
themeHint.setVisibility(View.VISIBLE);
}
}
public void initCell(int cellnum) {
String pkgActName = Helpers.prefs.getString("eps_remap_cell" + String.valueOf(cellnum), null);
updateCell(cellnum, pkgActName);
int cellid = Helpers.cellArray[cellnum][0];
LinearLayout cell = (LinearLayout)getActivity().findViewById(cellid);
cell.setTag(cellnum);
cell.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (OnOffSwitch.isChecked())
switch (event.getAction()) {
case 0:
v.setBackgroundColor(0xff888888);
break;
case 1:
v.setBackgroundColor(0xff666666);
editApp(v, (int)v.getTag());
break;
}
v.performClick();
return true;
}
});
alignCell(cellnum);
}
public void updateCell(int cellnum, String pkgActName) {
alignCell(cellnum);
int cellimgid = Helpers.cellArray[cellnum][1];
int celltxtid = Helpers.cellArray[cellnum][2];
try {
ImageView cellimg = (ImageView)getActivity().findViewById(cellimgid);
TextView celltxt = (TextView)getActivity().findViewById(celltxtid);
if (pkgActName != null) {
final PackageManager pm = getActivity().getApplicationContext().getPackageManager();
String[] pkgActArray = pkgActName.split("\\|");
cellimg.setImageDrawable(pm.getActivityIcon(new ComponentName(pkgActArray[0], pkgActArray[1])));
celltxt.setText(Helpers.getAppName(getActivity(), pkgActName));
} else {
cellimg.setImageResource(R.drawable.question_icon);
celltxt.setText(Helpers.l10n(getActivity(), R.string.array_default));
}
} catch (Exception e) {}
}
public void alignCell(int cellnum) {
LinearLayout cell = (LinearLayout)getActivity().findViewById(Helpers.cellArray[cellnum][0]);
ImageView cellimg = (ImageView)getActivity().findViewById(Helpers.cellArray[cellnum][1]);
float density = getResources().getDisplayMetrics().density;
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)cellimg.getLayoutParams();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
cell.setOrientation(LinearLayout.HORIZONTAL);
lp.setMargins(0, 0, Math.round(20 * density), 0);
} else {
cell.setOrientation(LinearLayout.VERTICAL);
lp.setMargins(0, 0, 0, Math.round(10 * density));
}
cellimg.setLayoutParams(lp);
}
private void editApp(View cell, final int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final String title = Helpers.l10n(getActivity(), R.string.various_extremepower_cell) + " " + String.valueOf(id);
builder.setTitle(title);
TypedArray ids = getResources().obtainTypedArray(R.array.EPSRemaps);
List<String> newEntries = new ArrayList<String>();
for (int i = 0; i < ids.length(); i++) {
int itemid = ids.getResourceId(i, 0);
if (itemid != 0)
newEntries.add(Helpers.l10n(getActivity(), itemid));
else
newEntries.add("???");
}
ids.recycle();
builder.setItems(newEntries.toArray(new CharSequence[newEntries.size()]), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
Helpers.prefs.edit().putString("eps_remap_cell" + String.valueOf(id), null).commit();