From 8ba9132d4e07dab17db5115ff5949cfd110b9a16 Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Sat, 12 Mar 2022 13:33:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KotlinXposedHelper=20=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/SettingsActivity.kt | 4 +- .../lt2333/simplicitytools/hook/MainHook.kt | 36 +-- .../hook/app/securitycenter/LockOneHundred.kt | 46 +-- .../app/securitycenter/SkipWaitingTime.kt | 52 ++-- .../settings/ShowNotificationImportance.kt | 81 ++---- .../app/systemui/HideNetworkSpeedSplitter.kt | 22 +- .../hook/app/systemui/NotificationWeather.kt | 13 +- .../hook/app/systemui/StatusBarCurrent.kt | 27 +- .../hook/app/systemui/StatusBarLayout.kt | 262 ++++++++---------- .../systemui/StatusBarTimeCustomization.kt | 203 ++++++-------- 10 files changed, 278 insertions(+), 468 deletions(-) diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt index 6390e1d1..8d691a08 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt @@ -206,7 +206,7 @@ class SettingsActivity : MIUIActivity() { } //关于页面 - fun aboutItems(): ArrayList { + private fun aboutItems(): ArrayList { return ArrayList().apply { add( AuthorV( @@ -894,7 +894,7 @@ class SettingsActivity : MIUIActivity() { } //其他页面 - fun otherItems(): ArrayList { + private fun otherItems(): ArrayList { return ArrayList().apply { add(TitleTextV(resId = R.string.scope_miuihome)) add( diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/MainHook.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/MainHook.kt index 87d40aa6..89998371 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/MainHook.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/MainHook.kt @@ -15,41 +15,23 @@ class MainHook : IXposedHookLoadPackage { EzXHelperInit.setEzClassLoader(lpparam.classLoader) when (lpparam.packageName) { //Android - "android" -> { - Android().handleLoadPackage(lpparam) - } + "android" -> Android().handleLoadPackage(lpparam) //系统界面 - "com.android.systemui" -> { - SystemUI().handleLoadPackage(lpparam) - } + "com.android.systemui" -> SystemUI().handleLoadPackage(lpparam) //电量与性能 - "com.miui.powerkeeper" -> { - PowerKeeper().handleLoadPackage(lpparam) - } + "com.miui.powerkeeper" -> PowerKeeper().handleLoadPackage(lpparam) //桌面 - "com.miui.home" -> { - MiuiHome().handleLoadPackage(lpparam) - } + "com.miui.home" -> MiuiHome().handleLoadPackage(lpparam) //手机管家 - "com.miui.securitycenter" -> { - SecurityCenter().handleLoadPackage(lpparam) - } + "com.miui.securitycenter" -> SecurityCenter().handleLoadPackage(lpparam) //相册编辑 - "com.miui.mediaeditor" -> { - MediaEditor().handleLoadPackage(lpparam) - } + "com.miui.mediaeditor" -> MediaEditor().handleLoadPackage(lpparam) //系统更新 - "com.android.updater" -> { - Updater().handleLoadPackage(lpparam) - } + "com.android.updater" -> Updater().handleLoadPackage(lpparam) //设置 - "com.android.settings" -> { - Settings().handleLoadPackage(lpparam) - } + "com.android.settings" -> Settings().handleLoadPackage(lpparam) //主题壁纸 - "com.android.thememanager" -> { - ThemeManager().handleLoadPackage(lpparam) - } + "com.android.thememanager" -> ThemeManager().handleLoadPackage(lpparam) } } } diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/LockOneHundred.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/LockOneHundred.kt index c99d1af3..47fd3fdf 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/LockOneHundred.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/LockOneHundred.kt @@ -2,46 +2,28 @@ package com.lt2333.simplicitytools.hook.app.securitycenter import android.view.View import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.findClass +import com.lt2333.simplicitytools.util.hookBeforeMethod import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook -import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage class LockOneHundred : IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { //防止点击重新检测 - var classIfExists = XposedHelpers.findClassIfExists( - "com.miui.securityscan.ui.main.MainContentFrame", - lpparam.classLoader - ) - XposedHelpers.findAndHookMethod( - classIfExists, - "onClick", - View::class.java, - object : XC_MethodHook() { - override fun beforeHookedMethod(param: MethodHookParam) { - if (XSPUtils.getBoolean("lock_one_hundred", false)) { - param.result = null - } - } - }) + val mainContentFrameClass = "com.miui.securityscan.ui.main.MainContentFrame".findClass(lpparam.classLoader) + mainContentFrameClass.hookBeforeMethod("onClick", View::class.java) { + if (XSPUtils.getBoolean("lock_one_hundred", false)) { + it.result = null + } + } //锁定100分 - var classIfExists2 = XposedHelpers.findClassIfExists( - "com.miui.securityscan.scanner.ScoreManager", - lpparam.classLoader - ) - XposedHelpers.findAndHookMethod( - classIfExists2, - "B", - object : XC_MethodHook() { - override fun beforeHookedMethod(param: MethodHookParam) { - if (XSPUtils.getBoolean("lock_one_hundred", false)) { - param.result = 0 - } - } - }) - + var scoreManagerClass = "com.miui.securityscan.scanner.ScoreManager".findClass(lpparam.classLoader) + scoreManagerClass.hookBeforeMethod("B") { + if (XSPUtils.getBoolean("lock_one_hundred", false)) { + it.result = 0 + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/SkipWaitingTime.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/SkipWaitingTime.kt index 930bcaf9..ad27e862 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/SkipWaitingTime.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/SkipWaitingTime.kt @@ -2,51 +2,37 @@ package com.lt2333.simplicitytools.hook.app.securitycenter import android.widget.TextView import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.findClass +import com.lt2333.simplicitytools.util.hookBeforeMethod import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook -import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage class SkipWaitingTime : IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { - var classIfExists = XposedHelpers.findClassIfExists( - "android.widget.TextView", - lpparam.classLoader - ) - XposedHelpers.findAndHookMethod( - classIfExists, + val textViewClass = "android.widget.TextView".findClass(lpparam.classLoader) + textViewClass.hookBeforeMethod( "setText", CharSequence::class.java, TextView.BufferType::class.java, Boolean::class.java, - Int::class.java, - object : XC_MethodHook() { - override fun beforeHookedMethod(param: MethodHookParam) { - if (XSPUtils.getBoolean("skip_waiting_time", false)) { - if (param.args.isNotEmpty() && param.args[0]?.toString() - ?.startsWith("确定(") == true - ) { - param.args[0] = "确定" - } - } + Int::class.java + ) { + if (XSPUtils.getBoolean("skip_waiting_time", false)) { + if (it.args.isNotEmpty() && it.args[0]?.toString()?.startsWith("确定(") == true + ) { + it.args[0] = "确定" } - }) + } + } - val classIfExists2 = XposedHelpers.findClassIfExists( - "android.widget.TextView", - lpparam.classLoader - ) - XposedHelpers.findAndHookMethod( - classIfExists2, + textViewClass.hookBeforeMethod( "setEnabled", - Boolean::class.java, - object : XC_MethodHook() { - override fun beforeHookedMethod(param: MethodHookParam) { - if (XSPUtils.getBoolean("skip_waiting_time", false)) { - param.args[0] = true - } - } - }) + Boolean::class.java + ) { + if (XSPUtils.getBoolean("skip_waiting_time", false)) { + it.args[0] = true + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt index cc1a9faa..cac0bab7 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/settings/ShowNotificationImportance.kt @@ -3,71 +3,32 @@ package com.lt2333.simplicitytools.hook.app.settings import android.app.NotificationChannel import com.lt2333.simplicitytools.util.* import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage class ShowNotificationImportance : IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { - val channelNotificationSettingsClass = XposedHelpers.findClass( - "com.android.settings.notification.ChannelNotificationSettings", - lpparam.classLoader - ) + val channelNotificationSettingsClass = "com.android.settings.notification.ChannelNotificationSettings".findClass(lpparam.classLoader) + channelNotificationSettingsClass.hookBeforeMethod("removeDefaultPrefs") { + if (!XSPUtils.getBoolean("show_notification_importance", false)) return@hookBeforeMethod + val importance = it.thisObject.callMethod("findPreference", "importance") ?: return@hookBeforeMethod + val mChannel = it.thisObject.getObjectField("mChannel") as NotificationChannel + val index = importance.callMethod("findSpinnerIndexOfValue", mChannel.importance.toString()) as Int + if (index < 0) return@hookBeforeMethod + importance.callMethod("setValueIndex", index) + XposedHelpers.setAdditionalInstanceField(importance, "channelNotificationSettings", it.thisObject) + it.result = null + } - channelNotificationSettingsClass.hookMethod("removeDefaultPrefs", - object : XC_MethodHook() { - override fun beforeHookedMethod(param: MethodHookParam) { - if (!XSPUtils.getBoolean("show_notification_importance", false)) return - - val importance = - param.thisObject.callMethod("findPreference", "importance") ?: return - val mChannel = - param.thisObject.getObjectField("mChannel") as NotificationChannel - val index = importance.callMethod( - "findSpinnerIndexOfValue", - mChannel.importance.toString() - ) as Int - if (index < 0) return - - importance.callMethod("setValueIndex", index) - - XposedHelpers.setAdditionalInstanceField( - importance, - "channelNotificationSettings", - param.thisObject - ) - - param.result = null - } - }) - - val dropDownPreferenceClass = XposedHelpers.findClass( - "androidx.preference.Preference", - lpparam.classLoader - ) - - dropDownPreferenceClass.hookMethod("callChangeListener", - Any::class.java, object : XC_MethodHook() { - override fun afterHookedMethod(param: MethodHookParam) { - val channelNotificationSettings = XposedHelpers.getAdditionalInstanceField( - param.thisObject, - "channelNotificationSettings" - ) ?: return@afterHookedMethod - - val mChannel = XposedHelpers.getObjectField( - channelNotificationSettings, - "mChannel" - ) as NotificationChannel - - mChannel.callMethod( - "setImportance", (param.args[0] as String).toInt() - ) - - val mBackend = channelNotificationSettings.getObjectField("mBackend") ?: return - val mPkg = channelNotificationSettings.getObjectField("mPkg") as String - val mUid = channelNotificationSettings.getIntField("mUid") - mBackend.callMethod("updateChannel", mPkg, mUid, mChannel) - } - }) + val dropDownPreferenceClass = XposedHelpers.findClass("androidx.preference.Preference", lpparam.classLoader) + dropDownPreferenceClass.hookAfterMethod("callChangeListener", Any::class.java) { + val channelNotificationSettings = XposedHelpers.getAdditionalInstanceField(it.thisObject, "channelNotificationSettings") ?: return@hookAfterMethod + val mChannel = channelNotificationSettings.getObjectField("mChannel") as NotificationChannel + mChannel.callMethod("setImportance", (it.args[0] as String).toInt()) + val mBackend = channelNotificationSettings.getObjectField("mBackend") ?: return@hookAfterMethod + val mPkg = channelNotificationSettings.getObjectField("mPkg") as String + val mUid = channelNotificationSettings.getIntField("mUid") + mBackend.callMethod("updateChannel", mPkg, mUid, mChannel) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/HideNetworkSpeedSplitter.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/HideNetworkSpeedSplitter.kt index 91569e67..299cff3b 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/HideNetworkSpeedSplitter.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/HideNetworkSpeedSplitter.kt @@ -2,25 +2,19 @@ package com.lt2333.simplicitytools.hook.app.systemui import android.widget.TextView import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.findClass +import com.lt2333.simplicitytools.util.hookAfterMethod import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook -import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage class HideNetworkSpeedSplitter : IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { - val classIfExists = XposedHelpers.findClassIfExists( - "com.android.systemui.statusbar.views.NetworkSpeedSplitter", - lpparam.classLoader - ) - - XposedHelpers.findAndHookMethod(classIfExists, "init", object : XC_MethodHook() { - override fun afterHookedMethod(param: MethodHookParam) { - if (XSPUtils.getBoolean("hide_network_speed_splitter", false)) { - val textView = param.thisObject as TextView - textView.text = " " - } + val networkSpeedSplitterClass = "com.android.systemui.statusbar.views.NetworkSpeedSplitter".findClass(lpparam.classLoader) + networkSpeedSplitterClass.hookAfterMethod("init") { + if (XSPUtils.getBoolean("hide_network_speed_splitter", false)) { + val textView = it.thisObject as TextView + textView.text = " " } - }) + } } } diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/NotificationWeather.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/NotificationWeather.kt index d75ea7fa..9b585f12 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/NotificationWeather.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/NotificationWeather.kt @@ -20,24 +20,15 @@ class NotificationWeather : IXposedHookLoadPackage { "com.android.systemui.qs.MiuiNotificationHeaderView".hookAfterMethod(lpparam.classLoader, "onFinishInflate") { val viewGroup = it.thisObject as ViewGroup val context = viewGroup.context - val layoutParam = loadClass("androidx.constraintlayout.widget.ConstraintLayout\$LayoutParams") - .getConstructor(Int::class.java, Int::class.java).newInstance( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) as ViewGroup.MarginLayoutParams + val layoutParam = loadClass("androidx.constraintlayout.widget.ConstraintLayout\$LayoutParams").getConstructor(Int::class.java, Int::class.java).newInstance(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) as ViewGroup.MarginLayoutParams layoutParam.setObjectField("bottomToTop", context.resources.getIdentifier("date_time", "id", context.packageName)) layoutParam.setObjectField("startToEnd", context.resources.getIdentifier("big_time", "id", context.packageName)) - - layoutParam.marginStart = context.resources.getDimensionPixelSize( - context.resources.getIdentifier("notification_panel_time_date_space", "dimen", context.packageName) - ) - + layoutParam.marginStart = context.resources.getDimensionPixelSize(context.resources.getIdentifier("notification_panel_time_date_space", "dimen", context.packageName)) mWeatherView = WeatherView(context, isDisplayCity).apply { setTextAppearance(context.resources.getIdentifier("TextAppearance.QSControl.Date", "style", context.packageName)) layoutParams = layoutParam } viewGroup.addView(mWeatherView) - (mWeatherView as WeatherView).setOnClickListener { try { val intent = Intent().apply { diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarCurrent.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarCurrent.kt index a6133e2d..1740d061 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarCurrent.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarCurrent.kt @@ -2,27 +2,22 @@ package com.lt2333.simplicitytools.hook.app.systemui import android.view.ViewGroup import android.widget.TextView +import com.lt2333.simplicitytools.util.findClass +import com.lt2333.simplicitytools.util.hookAfterMethod import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook -import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage class StatusBarCurrent :IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { - val classIfExists = XposedHelpers.findClassIfExists( - "com.android.systemui.statusbar.phone.MiuiPhoneStatusBarView", - lpparam.classLoader - ) - XposedHelpers.findAndHookMethod(classIfExists, "onFinishInflate", object : XC_MethodHook() { - override fun afterHookedMethod(param: MethodHookParam) { - val viewGroup = param.thisObject as ViewGroup - - val textView = TextView(viewGroup.context).also { - it.text = "Text" - it.textSize=14F - } - viewGroup.addView(textView) + val miuiPhoneStatusBarViewClass = + "com.android.systemui.statusbar.phone.MiuiPhoneStatusBarView".findClass(lpparam.classLoader) + miuiPhoneStatusBarViewClass.hookAfterMethod("onFinishInflate") { param -> + val viewGroup = param.thisObject as ViewGroup + val textView = TextView(viewGroup.context).also { + it.text = "Text" + it.textSize = 14F } - }) + viewGroup.addView(textView) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarLayout.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarLayout.kt index cb891e12..c5915b17 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarLayout.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarLayout.kt @@ -11,9 +11,10 @@ import android.widget.FrameLayout import android.widget.LinearLayout import androidx.constraintlayout.widget.ConstraintLayout import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.findClass +import com.lt2333.simplicitytools.util.getObjectField +import com.lt2333.simplicitytools.util.hookAfterMethod import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook -import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage class StatusBarLayout : IXposedHookLoadPackage { @@ -31,164 +32,125 @@ class StatusBarLayout : IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { if (!XSPUtils.getBoolean("status_bar_time_center", false)) return - val classIfExists = XposedHelpers.findClassIfExists( - "com.android.systemui.statusbar.phone.CollapsedStatusBarFragment", - lpparam.classLoader - ) + val collapsedStatusBarFragmentClass = + "com.android.systemui.statusbar.phone.CollapsedStatusBarFragment".findClass(lpparam.classLoader) - XposedHelpers.findAndHookMethod( - classIfExists, + collapsedStatusBarFragmentClass.hookAfterMethod( "onViewCreated", View::class.java, - Bundle::class.java, - object : XC_MethodHook() { - @Throws(Throwable::class) - override fun afterHookedMethod(param: MethodHookParam) { - super.afterHookedMethod(param) - val MiuiPhoneStatusBarView: ViewGroup = - XposedHelpers.getObjectField( - param.thisObject, - "mStatusBar" - ) as ViewGroup - val context: Context = MiuiPhoneStatusBarView.context - val res: Resources = MiuiPhoneStatusBarView.resources - val status_bar_ID: Int = - res.getIdentifier("status_bar", "id", "com.android.systemui") - val status_bar_contents_ID: Int = - res.getIdentifier("status_bar_contents", "id", "com.android.systemui") - val system_icon_area_ID: Int = - res.getIdentifier("system_icon_area", "id", "com.android.systemui") + Bundle::class.java + ) { param -> + val MiuiPhoneStatusBarView: ViewGroup = + param.thisObject.getObjectField("mStatusBar") as ViewGroup + val context: Context = MiuiPhoneStatusBarView.context + val res: Resources = MiuiPhoneStatusBarView.resources + val status_bar_ID: Int = res.getIdentifier("status_bar", "id", "com.android.systemui") + val status_bar_contents_ID: Int = + res.getIdentifier("status_bar_contents", "id", "com.android.systemui") + val system_icon_area_ID: Int = + res.getIdentifier("system_icon_area", "id", "com.android.systemui") + val clock_ID: Int = res.getIdentifier("clock", "id", "com.android.systemui") + val phone_status_bar_left_container_ID: Int = + res.getIdentifier("phone_status_bar_left_container", "id", "com.android.systemui") + val fullscreen_notification_icon_area_ID: Int = + res.getIdentifier("fullscreen_notification_icon_area", "id", "com.android.systemui") + status_bar = MiuiPhoneStatusBarView.findViewById(status_bar_ID) + val status_bar_contents: ViewGroup = + MiuiPhoneStatusBarView.findViewById(status_bar_contents_ID) + if (status_bar == null) return@hookAfterMethod + val Clock: View = MiuiPhoneStatusBarView.findViewById(clock_ID) + val phone_status_bar_left_container: ViewGroup = + MiuiPhoneStatusBarView.findViewById(phone_status_bar_left_container_ID) + val fullscreen_notification_icon_area: ViewGroup = + MiuiPhoneStatusBarView.findViewById(fullscreen_notification_icon_area_ID) + val system_icon_area: ViewGroup = + MiuiPhoneStatusBarView.findViewById(system_icon_area_ID) - val clock_ID: Int = res.getIdentifier("clock", "id", "com.android.systemui") - val phone_status_bar_left_container_ID: Int = res.getIdentifier( - "phone_status_bar_left_container", - "id", - "com.android.systemui" - ) - val fullscreen_notification_icon_area_ID: Int = res.getIdentifier( - "fullscreen_notification_icon_area", - "id", - "com.android.systemui" - ) - status_bar = - MiuiPhoneStatusBarView.findViewById(status_bar_ID) - val status_bar_contents: ViewGroup = - MiuiPhoneStatusBarView.findViewById(status_bar_contents_ID) - if (status_bar == null) return - val Clock: View = MiuiPhoneStatusBarView.findViewById(clock_ID) - val phone_status_bar_left_container: ViewGroup = - MiuiPhoneStatusBarView.findViewById(phone_status_bar_left_container_ID) - val fullscreen_notification_icon_area: ViewGroup = - MiuiPhoneStatusBarView.findViewById(fullscreen_notification_icon_area_ID) - val system_icon_area: ViewGroup = - MiuiPhoneStatusBarView.findViewById(system_icon_area_ID) + (Clock.parent as ViewGroup).removeView(Clock) + (phone_status_bar_left_container.parent as ViewGroup).removeView( + phone_status_bar_left_container + ) + (fullscreen_notification_icon_area.parent as ViewGroup).removeView( + fullscreen_notification_icon_area + ) + (system_icon_area.parent as ViewGroup).removeView(system_icon_area) + + val mConstraintLayoutLp = ConstraintLayout.LayoutParams( + ConstraintLayout.LayoutParams.MATCH_PARENT, + ConstraintLayout.LayoutParams.MATCH_PARENT + ) + + val mConstraintLayout = + ConstraintLayout(context).also { it.layoutParams = mConstraintLayoutLp } + + mConstraintLayout.addView(fullscreen_notification_icon_area) + + val fullscreen_notification_icon_area_lp = FrameLayout.LayoutParams( + ConstraintLayout.LayoutParams.MATCH_PARENT, + ConstraintLayout.LayoutParams.MATCH_PARENT + ) + + fullscreen_notification_icon_area.layoutParams = fullscreen_notification_icon_area_lp + + //增加一个左对齐布局 + mLeftLayout = LinearLayout(context) + val LeftLp: LinearLayout.LayoutParams = + LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f) + mLeftLayout!!.layoutParams = LeftLp + mLeftLayout!!.gravity = Gravity.START or Gravity.CENTER_VERTICAL + + //增加一个居中布局 + mCenterLayout = LinearLayout(context) + val CenterLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.MATCH_PARENT + ) + mCenterLayout!!.layoutParams = CenterLp + mCenterLayout!!.gravity = Gravity.CENTER or Gravity.CENTER_VERTICAL + mRightLayout = LinearLayout(context) + val RightLp: LinearLayout.LayoutParams = + LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f) + mRightLayout!!.layoutParams = RightLp + mRightLayout!!.gravity = Gravity.END or Gravity.CENTER_VERTICAL + mLeftLayout!!.addView(phone_status_bar_left_container) + mLeftLayout!!.addView(mConstraintLayout) + + mCenterLayout!!.addView(Clock) + mRightLayout!!.addView(system_icon_area) + status_bar_contents.addView(mLeftLayout, 0) + status_bar_contents.addView(mCenterLayout) + status_bar_contents.addView(mRightLayout) + + status_bar_left = status_bar!!.paddingLeft + status_bar_top = status_bar!!.paddingTop + status_bar_right = status_bar!!.paddingRight + status_bar_bottom = status_bar!!.paddingBottom - (Clock.parent as ViewGroup).removeView(Clock) - (phone_status_bar_left_container.parent as ViewGroup).removeView( - phone_status_bar_left_container - ) - (fullscreen_notification_icon_area.parent as ViewGroup).removeView( - fullscreen_notification_icon_area - ) - (system_icon_area.parent as ViewGroup).removeView(system_icon_area) - - - val mConstraintLayoutLp = ConstraintLayout.LayoutParams( - ConstraintLayout.LayoutParams.MATCH_PARENT, - ConstraintLayout.LayoutParams.MATCH_PARENT - ) - - val mConstraintLayout = ConstraintLayout(context).also { - it.layoutParams = mConstraintLayoutLp - } - - mConstraintLayout.addView(fullscreen_notification_icon_area) - - val fullscreen_notification_icon_area_lp = FrameLayout.LayoutParams( - ConstraintLayout.LayoutParams.MATCH_PARENT, - ConstraintLayout.LayoutParams.MATCH_PARENT - ) - - fullscreen_notification_icon_area.layoutParams = - fullscreen_notification_icon_area_lp - - //增加一个左对齐布局 - mLeftLayout = LinearLayout(context) - val LeftLp: LinearLayout.LayoutParams = - LinearLayout.LayoutParams( - 0, - LinearLayout.LayoutParams.MATCH_PARENT, - 1.0f - ) - mLeftLayout!!.layoutParams = LeftLp - mLeftLayout!!.gravity = Gravity.START or Gravity.CENTER_VERTICAL - - //增加一个居中布局 - mCenterLayout = LinearLayout(context) - val CenterLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.MATCH_PARENT - ) - mCenterLayout!!.layoutParams = CenterLp - mCenterLayout!!.gravity = Gravity.CENTER or Gravity.CENTER_VERTICAL - mRightLayout = LinearLayout(context) - val RightLp: LinearLayout.LayoutParams = - LinearLayout.LayoutParams( - 0, - LinearLayout.LayoutParams.MATCH_PARENT, - 1.0f - ) - mRightLayout!!.layoutParams = RightLp - mRightLayout!!.gravity = Gravity.END or Gravity.CENTER_VERTICAL - mLeftLayout!!.addView(phone_status_bar_left_container) - mLeftLayout!!.addView(mConstraintLayout) - - mCenterLayout!!.addView(Clock) - mRightLayout!!.addView(system_icon_area) - status_bar_contents.addView(mLeftLayout, 0) - status_bar_contents.addView(mCenterLayout) - status_bar_contents.addView(mRightLayout) - - status_bar_left = status_bar!!.paddingLeft - status_bar_top = status_bar!!.paddingTop - status_bar_right = status_bar!!.paddingRight - status_bar_bottom = status_bar!!.paddingBottom - - - if (XSPUtils.getBoolean("layout_compatibility_mode", false)) { - val custom_left_margin = XSPUtils.getInt("status_bar_left_margin", 0) - if (custom_left_margin != 0) { - status_bar_left = custom_left_margin - } - - val custom_right_margin = XSPUtils.getInt("status_bar_right_margin", 0) - if (custom_right_margin != 0) { - status_bar_right = custom_right_margin - } - updateLayout(context) - } - + if (XSPUtils.getBoolean("layout_compatibility_mode", false)) { + val custom_left_margin = XSPUtils.getInt("status_bar_left_margin", 0) + if (custom_left_margin != 0) { + status_bar_left = custom_left_margin } - }) - val classIfExists2 = XposedHelpers.findClassIfExists( - "com.android.systemui.statusbar.phone.PhoneStatusBarView", - lpparam.classLoader - ) - - XposedHelpers.findAndHookMethod( - classIfExists2, - "updateLayoutForCutout", - object : XC_MethodHook() { - override fun afterHookedMethod(param: MethodHookParam) { - if (XSPUtils.getBoolean("layout_compatibility_mode", false)) { - val context = (param.thisObject as ViewGroup).context - updateLayout(context) - } + val custom_right_margin = XSPUtils.getInt("status_bar_right_margin", 0) + if (custom_right_margin != 0) { + status_bar_right = custom_right_margin } + updateLayout(context) } - ) + + } + + val phoneStatusBarViewClass = + "com.android.systemui.statusbar.phone.PhoneStatusBarView".findClass(lpparam.classLoader) + + phoneStatusBarViewClass.hookAfterMethod("updateLayoutForCutout") { + if (XSPUtils.getBoolean("layout_compatibility_mode", false)) { + val context = (it.thisObject as ViewGroup).context + updateLayout(context) + } + } } diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt index 93cebb20..77b6e9cb 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt @@ -8,161 +8,124 @@ import android.util.AttributeSet import android.util.TypedValue import android.widget.TextView import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.findClass +import com.lt2333.simplicitytools.util.hookAfterConstructor +import com.lt2333.simplicitytools.util.hookAfterMethod import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook -import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage import java.lang.reflect.Method import java.text.SimpleDateFormat import java.util.* class StatusBarTimeCustomization : IXposedHookLoadPackage { + + private val isYear = XSPUtils.getBoolean("status_bar_time_year", false) + private val isMonth = XSPUtils.getBoolean("status_bar_time_month", false) + private val isDay = XSPUtils.getBoolean("status_bar_time_day", false) + private val isWeek = XSPUtils.getBoolean("status_bar_time_week", false) + private val isHideSpace = XSPUtils.getBoolean("status_bar_time_hide_space", false) + private val isDoubleLine = XSPUtils.getBoolean("status_bar_time_double_line", false) + private val isSecond = XSPUtils.getBoolean("status_bar_time_seconds", false) + private val isDoubleHour = XSPUtils.getBoolean("status_bar_time_double_hour", false) + private val isPeriod = XSPUtils.getBoolean("status_bar_time_period", true) + private val getClockSize = XSPUtils.getInt("status_bar_clock_size", 0) + private val isOpen = XSPUtils.getBoolean("custom_clock_switch", false) + private val getClockDoubleSize = XSPUtils.getInt("status_bar_clock_double_line_size", 0) + private var now_time: Date? = null + private var str = "" - - val isYear = XSPUtils.getBoolean("status_bar_time_year", false) - val isMonth = XSPUtils.getBoolean("status_bar_time_month", false) - val isDay = XSPUtils.getBoolean("status_bar_time_day", false) - val isWeek = XSPUtils.getBoolean("status_bar_time_week", false) - val isHideSpace = XSPUtils.getBoolean("status_bar_time_hide_space", false) - val isDoubleLine = XSPUtils.getBoolean("status_bar_time_double_line", false) - val isSecond = XSPUtils.getBoolean("status_bar_time_seconds", false) - val isDoubleHour = XSPUtils.getBoolean("status_bar_time_double_hour", false) - val isPeriod = XSPUtils.getBoolean("status_bar_time_period", true) - val getClockSize = XSPUtils.getInt("status_bar_clock_size", 0) - val isOpen = XSPUtils.getBoolean("custom_clock_switch", false) - val getClockDoubleSize = XSPUtils.getInt("status_bar_clock_double_line_size", 0) - - - var now_time: Date? = null - var str = "" - + @SuppressLint("SetTextI18n") override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { if (isOpen) { var c: Context? = null - val classIfExists = XposedHelpers.findClassIfExists( - "com.android.systemui.statusbar.views.MiuiClock", - lpparam.classLoader - ) - XposedHelpers.findAndHookConstructor(classIfExists, - Context::class.java, - AttributeSet::class.java, - Integer.TYPE, - object : XC_MethodHook() { - override fun afterHookedMethod(param: MethodHookParam) { - try { - c = param.args[0] as Context - val textV = param.thisObject as TextView - textV.isSingleLine = false - - if (isDoubleLine) { - str = "\n" - var clock_double_line_size = 7F - if (getClockDoubleSize != 0) { - clock_double_line_size = - getClockDoubleSize - .toFloat() - } - textV.setTextSize( - TypedValue.COMPLEX_UNIT_DIP, - clock_double_line_size - ) - } else { - if (getClockSize != 0) { - val clock_size = - getClockSize.toFloat() - textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clock_size) - } - } - - val d: Method = textV.javaClass.getDeclaredMethod("updateTime") - val r = Runnable { - d.isAccessible = true - d.invoke(textV) - } - - class T : TimerTask() { - override fun run() { - Handler(textV.context.mainLooper).post(r) - } - } - if (textV.resources.getResourceEntryName(textV.id) == "clock") - Timer().scheduleAtFixedRate( - T(), - 1000 - System.currentTimeMillis() % 1000, - 1000 - ) - - } catch (e: java.lang.Exception) { + val miuiClockClass = "com.android.systemui.statusbar.views.MiuiClock".findClass(lpparam.classLoader) + miuiClockClass.hookAfterConstructor(Context::class.java, AttributeSet::class.java, Integer.TYPE) { + try { + c = it.args[0] as Context + val textV = it.thisObject as TextView + textV.isSingleLine = false + if (isDoubleLine) { + str = "\n" + var clock_double_line_size = 7F + if (getClockDoubleSize != 0) { + clock_double_line_size = getClockDoubleSize.toFloat() + } + textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clock_double_line_size) + } else { + if (getClockSize != 0) { + val clock_size = getClockSize.toFloat() + textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clock_size) } } + val d: Method = textV.javaClass.getDeclaredMethod("updateTime") + val r = Runnable { + d.isAccessible = true + d.invoke(textV) + } + class T : TimerTask() { + override fun run() { + Handler(textV.context.mainLooper).post(r) + } + } + if (textV.resources.getResourceEntryName(textV.id) == "clock") + Timer().scheduleAtFixedRate(T(), 1000 - System.currentTimeMillis() % 1000, 1000) + } catch (e: java.lang.Exception) { } - ) - XposedHelpers.findAndHookMethod(classIfExists, "updateTime", - object : XC_MethodHook() { - @SuppressLint("SetTextI18n", "SimpleDateFormat") - override fun afterHookedMethod(param: MethodHookParam) { - try { - val textV = param.thisObject as TextView - if (textV.resources.getResourceEntryName(textV.id) == "clock") { - val t = Settings.System.getString( - c!!.contentResolver, - Settings.System.TIME_12_24 - ) - now_time = Calendar.getInstance().time - - textV.text = getDate(c!!, t) + str + getTime(c!!, t) - } - - } catch (e: Exception) { - } + } + miuiClockClass.hookAfterMethod("updateTime") { + try { + val textV = it.thisObject as TextView + if (textV.resources.getResourceEntryName(textV.id) == "clock") { + val t = Settings.System.getString(c!!.contentResolver, Settings.System.TIME_12_24) + now_time = Calendar.getInstance().time + textV.text = getDate(c!!, t) + str + getTime(c!!, t) } - }) + } catch (e: Exception) { + } + } } } @SuppressLint("SimpleDateFormat") private fun getDate(context: Context, t: String): String { - var DatePattern = "" + var datePattern = "" val isZh = isZh(context) if (isYear) { if (isZh) { - DatePattern += "YY年" -// if (!isHideSpace) DatePattern = "$DatePattern " + datePattern += "YY年" +// if (!isHideSpace) datePattern = "$datePattern " } else { - DatePattern += "YY" - if (isMonth || isDay) DatePattern += "/" + datePattern += "YY" + if (isMonth || isDay) datePattern += "/" } } if (isMonth) { if (isZh) { - DatePattern += "M月" -// if (!isHideSpace) DatePattern = "$DatePattern " + datePattern += "M月" +// if (!isHideSpace) datePattern = "$datePattern " } else { - DatePattern += "M" - if (isDay) DatePattern += "/" + datePattern += "M" + if (isDay) datePattern += "/" } } if (isDay) { - if (isZh) { - DatePattern += "d日" + datePattern += if (isZh) { + "d日" } else { - DatePattern += "d" + "d" } } - if (isWeek) { - if (!isHideSpace) DatePattern = "$DatePattern " - DatePattern += "E" + if (!isHideSpace) datePattern = "$datePattern " + datePattern += "E" if (!isDoubleLine) { - if (!isHideSpace) DatePattern = "$DatePattern " + if (!isHideSpace) datePattern = "$datePattern " } } - - DatePattern = SimpleDateFormat(DatePattern).format(now_time) - - return DatePattern + datePattern = SimpleDateFormat(datePattern).format(now_time) + return datePattern } @SuppressLint("SimpleDateFormat") @@ -171,13 +134,9 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage { val isZh = isZh(context) timePattern += if (t == "24") "HH:mm" else "h:mm" if (isSecond) timePattern += ":ss" - timePattern = SimpleDateFormat(timePattern).format(now_time) - if (isZh) timePattern = getPeriod(isZh) + timePattern else timePattern += getPeriod(isZh) - timePattern = getDoubleHour() + timePattern - return timePattern } @@ -186,8 +145,7 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage { var period = "" if (isPeriod) { if (isZh) { - val now = SimpleDateFormat("HH").format(now_time) - when (now) { + when (SimpleDateFormat("HH").format(now_time)) { "00", "01", "02", "03", "04", "05" -> { period = "凌晨" } @@ -222,8 +180,7 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage { private fun getDoubleHour(): String { var doubleHour = "" if (isDoubleHour) { - val now = SimpleDateFormat("HH").format(now_time) - when (now) { + when (SimpleDateFormat("HH").format(now_time)) { "23", "00" -> { doubleHour = "子时" } @@ -268,7 +225,7 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage { return doubleHour } - fun isZh(context: Context): Boolean { + private fun isZh(context: Context): Boolean { val locale = context.resources.configuration.locale val language = locale.language return language.endsWith("zh") From 0a8b43c344bafae2d898234d042f2a9d7f2c01c9 Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Sat, 12 Mar 2022 15:39:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A3=81=E7=BA=B8=E7=BC=A9=E6=94=BE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/proguard-rules.pro | 8 ---- app/src/main/AndroidManifest.xml | 17 ++++---- .../activity/SettingsActivity.kt | 42 +++++++++++++++++-- .../simplicitytools/hook/app/Android.kt | 3 ++ .../hook/app/android/DisableFlagSecure.kt | 2 +- .../hook/app/android/MaxWallpaperScale.kt | 23 ++++++++++ .../securitycenter/ShowBatteryTemperature.kt | 8 +++- .../util/KotlinXposedHelper.kt | 4 ++ .../lt2333/simplicitytools/util/XSPUtils.kt | 9 +++- app/src/main/res/values-night/styles.xml | 8 ++-- app/src/main/res/values-zh-rCN/strings.xml | 3 ++ app/src/main/res/values-zh-rHK/strings.xml | 3 ++ app/src/main/res/values-zh-rTW/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/values/styles.xml | 9 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 16 files changed, 110 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hook/app/android/MaxWallpaperScale.kt diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 6102543f..50e3228e 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -23,14 +23,6 @@ public void *(de.robv.android.xposed.callbacks.XC_LoadPackage$LoadPackageParam); } --keep class * implements de.robv.android.xposed.IXposedHookInitPackageResources { - public void *(de.robv.android.xposed.callbacks.XC_InitPackageResources$InitPackageResourcesParam); -} - --keep class * implements de.robv.android.xposed.IXposedHookZygoteInit { - public void *(de.robv.android.xposed.IXposedHookZygoteInit$StartupParam); -} - -assumenosideeffects class kotlin.jvm.internal.Intrinsics { public static void check*(...); public static void throw*(...); diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c8eb5804..02018f52 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,15 +2,14 @@ - + + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/AppTheme"> - - + + @@ -52,7 +51,7 @@ android:label="@string/lock_max" android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> - + @@ -63,7 +62,7 @@ android:label="@string/allow_screenshots" android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> - + diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt index 8d691a08..d91e44a4 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt @@ -12,6 +12,7 @@ import android.view.View import android.widget.Switch import android.widget.Toast import cn.fkj233.ui.activity.MIUIActivity +import cn.fkj233.ui.activity.OwnSP import cn.fkj233.ui.activity.view.* import cn.fkj233.ui.dialog.MIUIDialog import com.lt2333.simplicitytools.BuildConfig @@ -436,6 +437,23 @@ class SettingsActivity : MIUIActivity() { SwitchV("remove_small_window_restrictions") ) ) + add(TextSummaryArrowV(TextSummaryV(textId = R.string.max_wallpaper_scale, onClickListener = { + MIUIDialog(activity).apply { + setTitle(R.string.max_wallpaper_scale) + setEditText("", "${activity.getString(R.string.def)}1.1, ${activity.getString(R.string.current)}${OwnSP.ownSP.getFloat("max_wallpaper_scale", 1.1f)}") + setLButton(textId = R.string.cancel) { + dismiss() + } + setRButton(textId = R.string.Done) { + OwnSP.ownSP.edit().run { + putFloat("max_wallpaper_scale", getEditText().toFloat()) + apply() + } + dismiss() + } + show() + } + }))) } } @@ -677,7 +695,12 @@ class SettingsActivity : MIUIActivity() { SwitchV("hide_battery_charging_icon") ) ) - add(TextWithSwitchV(TextV(resId = R.string.hide_gps_icon), SwitchV("hide_gps_icon"))) + add( + TextWithSwitchV( + TextV(resId = R.string.hide_gps_icon), + SwitchV("hide_gps_icon") + ) + ) add( TextWithSwitchV( TextV(resId = R.string.hide_bluetooth_icon), @@ -732,7 +755,12 @@ class SettingsActivity : MIUIActivity() { SwitchV("hide_mobile_type_icon") ) ) - add(TextWithSwitchV(TextV(resId = R.string.hide_wifi_icon), SwitchV("hide_wifi_icon"))) + add( + TextWithSwitchV( + TextV(resId = R.string.hide_wifi_icon), + SwitchV("hide_wifi_icon") + ) + ) add( TextWithSwitchV( TextV(resId = R.string.hide_wifi_activity_icon), @@ -757,7 +785,12 @@ class SettingsActivity : MIUIActivity() { SwitchV("hide_hotspot_icon") ) ) - add(TextWithSwitchV(TextV(resId = R.string.hide_vpn_icon), SwitchV("hide_vpn_icon"))) + add( + TextWithSwitchV( + TextV(resId = R.string.hide_vpn_icon), + SwitchV("hide_vpn_icon") + ) + ) add( TextWithSwitchV( TextV(resId = R.string.hide_airplane_icon), @@ -941,7 +974,8 @@ class SettingsActivity : MIUIActivity() { intent.component = comp startActivity(intent) } catch (e: Exception) { - Toast.makeText(activity, "启动失败,可能是不支持", Toast.LENGTH_LONG).show() + Toast.makeText(activity, "启动失败,可能是不支持", Toast.LENGTH_LONG) + .show() } }) ) diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/Android.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/Android.kt index 8cd5deec..6f8bf2a9 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/Android.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/Android.kt @@ -2,6 +2,7 @@ package com.lt2333.simplicitytools.hook.app import com.lt2333.simplicitytools.hook.app.android.DeleteOnPostNotification import com.lt2333.simplicitytools.hook.app.android.DisableFlagSecure +import com.lt2333.simplicitytools.hook.app.android.MaxWallpaperScale import com.lt2333.simplicitytools.hook.app.android.RemoveSmallWindowRestrictions import com.lt2333.simplicitytools.hook.app.android.corepatch.CorePatch import de.robv.android.xposed.IXposedHookLoadPackage @@ -19,5 +20,7 @@ class Android : IXposedHookLoadPackage { DeleteOnPostNotification().handleLoadPackage(lpparam) //解除小窗限制 RemoveSmallWindowRestrictions().handleLoadPackage(lpparam) + //壁纸缩放比例 + MaxWallpaperScale().handleLoadPackage(lpparam) } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt index 611b1e69..75fdbd8b 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt @@ -5,7 +5,7 @@ import com.lt2333.simplicitytools.util.hookBeforeMethod import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.callbacks.XC_LoadPackage -class DisableFlagSecure :IXposedHookLoadPackage { +class DisableFlagSecure : IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { "com.android.server.wm.WindowState".hookBeforeMethod(lpparam.classLoader, "isSecureLocked") { hasEnable("disable_flag_secure") { diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/MaxWallpaperScale.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/MaxWallpaperScale.kt new file mode 100644 index 00000000..4cc82a16 --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/MaxWallpaperScale.kt @@ -0,0 +1,23 @@ +package com.lt2333.simplicitytools.hook.app.android + +import android.app.Service +import android.icu.text.DisplayContext +import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.hookAfterMethod +import com.lt2333.simplicitytools.util.hookBeforeMethod +import com.lt2333.simplicitytools.util.setFloatField +import de.robv.android.xposed.IXposedHookLoadPackage +import de.robv.android.xposed.callbacks.XC_LoadPackage + +class MaxWallpaperScale : IXposedHookLoadPackage { + override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { + val value = XSPUtils.getFloat("max_wallpaper_scale", 1.1f) + "com.android.server.wm.WallpaperController".hookAfterMethod(lpparam.classLoader, "WallpaperController", Service::class.java, DisplayContext::class.java + ) { + it.thisObject.setFloatField("mMaxWallpaperScale", value) + } + "com.android.server.wm.WallpaperController".hookBeforeMethod(lpparam.classLoader, "zoomOutToScale", Float::class.java) { + it.thisObject.setFloatField("mMaxWallpaperScale", value) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt index 66fd0f3e..ac5b569a 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt @@ -13,7 +13,10 @@ import android.view.View import android.widget.LinearLayout import android.widget.TextView import cn.fkj233.ui.activity.dp2px -import com.lt2333.simplicitytools.util.* +import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.findClass +import com.lt2333.simplicitytools.util.hookAfterMethod +import com.lt2333.simplicitytools.util.hookBeforeMethod import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.callbacks.XC_LoadPackage import java.lang.reflect.Field @@ -36,6 +39,7 @@ class ShowBatteryTemperature: IXposedHookLoadPackage { val textView = view.findViewById(currentTemperatureValue) textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36.399998f) textView.gravity = Gravity.NO_GRAVITY + textView.typeface = Typeface.create(null, 400, false) textView.setPadding(0, 0, 0, 0) textView.height = dp2px(context, 49.099983f) textView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START @@ -48,7 +52,7 @@ class ShowBatteryTemperature: IXposedHookLoadPackage { tempView.setPadding(0, dp2px(context, 25f), 0, 0) tempView.text = "℃" tempView.setTextColor(Color.parseColor(if (isDarkMode) "#e6e6e6" else "#333333")) - tempView.typeface = Typeface.create(null, 500, false) + tempView.typeface = Typeface.create(null, 400, false) tempView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START val tempeValueContainer = context.resources.getIdentifier("tempe_value_container", "id", "com.miui.securitycenter") val linearLayout = view.findViewById(tempeValueContainer) diff --git a/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt b/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt index d22161e9..fa2edf5d 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt @@ -395,6 +395,10 @@ fun T.setLongField(field: String?, value: Long) = apply { XposedHelpers.setLongField(this, field, value) } +fun T.setFloatField(field: String?, value: Float) = apply { + XposedHelpers.setFloatField(this, field, value) +} + fun T.setObjectField(field: String?, value: Any?) = apply { XposedHelpers.setObjectField(this, field, value) } diff --git a/app/src/main/java/com/lt2333/simplicitytools/util/XSPUtils.kt b/app/src/main/java/com/lt2333/simplicitytools/util/XSPUtils.kt index 9b5521e1..7b5bd829 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/util/XSPUtils.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/util/XSPUtils.kt @@ -4,7 +4,7 @@ import com.lt2333.simplicitytools.BuildConfig import de.robv.android.xposed.XSharedPreferences object XSPUtils { - var prefs = XSharedPreferences(BuildConfig.APPLICATION_ID, "config") + private var prefs = XSharedPreferences(BuildConfig.APPLICATION_ID, "config") fun getBoolean(key: String, defValue: Boolean): Boolean { if (prefs.hasFileChanged()) { @@ -18,6 +18,13 @@ object XSPUtils { } return prefs.getInt(key, defValue) } + + fun getFloat(key: String, defValue: Float): Float { + if (prefs.hasFileChanged()) { + prefs.reload() + } + return prefs.getFloat(key, defValue) + } } inline fun hasEnable(key: String, default: Boolean = false, noinline extraCondition: (() -> Boolean)? = null, crossinline block: () -> Unit) { diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index 641cbec0..ad38ea98 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -1,4 +1,4 @@ - + - - \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 8d65f5a0..8b882e16 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -151,4 +151,7 @@ 移除主题壁纸的广告 电池页面显示当前温度 启用Alpha充电动画 + 壁纸缩放比例 + 默认值: + 当前值: diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 41a93650..b2010fca 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -151,4 +151,7 @@ 拿掉主題壁紙的廣告 電池頁面展示當前溫度 啟用Alpha充電動畫 + 壁紙縮放比例 + 默認值: + 當前值: diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 338bee8f..001d1f54 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -151,4 +151,7 @@ 拿掉主題壁紙的廣告 電池頁面展示當前溫度 啟用Alpha充電動畫 + 壁紙縮放比例 + 默認值: + 當前值: diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6e44d351..feb12cfa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -151,4 +151,7 @@ Remove ads for theme manager Battery page shows the current temperature Enable wave charge animation + Max wallpaper scale + "Default: " + Current: diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 072abf83..c9f26e38 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,5 +1,5 @@ - + - - - \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f37c82dd..c4a685e2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sun Feb 13 16:53:34 CST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME