diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/pages/t/OtherPageForT.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/pages/t/OtherPageForT.kt index 8bfef7eb..97524a9e 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/pages/t/OtherPageForT.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/pages/t/OtherPageForT.kt @@ -35,8 +35,7 @@ class OtherPageForT : BasePage() { textId = R.string.miuihome_recentwiew_wallpaper_darkening, tipsId = R.string.miuihome_recentwiew_wallpaper_darkening_summary ), SwitchV("miuihome_recentwiew_wallpaper_darkening", false) ) - //TODO:未开发完成 - /*TextSummaryWithSwitch( + TextSummaryWithSwitch( TextSummaryV( textId = R.string.miuihome_recentview_remove_card_animation, tipsId = R.string.miuihome_recentview_remove_card_animation_summary ), SwitchV("miuihome_recentview_remove_card_animation", false) @@ -44,7 +43,7 @@ class OtherPageForT : BasePage() { TextSummaryWithSwitch( TextSummaryV(textId = R.string.miuihome_shortcut_add_small_window, tipsId = R.string.miuihome_shortcut_add_small_window_summary), SwitchV("miuihome_shortcut_add_small_window", false) - )*/ + ) TextSummaryWithSwitch( TextSummaryV(textId = R.string.miuihome_scroll_icon_name, tipsId = R.string.miuihome_scroll_icon_name_summary), SwitchV("miuihome_scroll_icon_name", false) diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ModifyRecentViewRemoveCardAnimForAll.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ModifyRecentViewRemoveCardAnimForAll.kt index 395a00a4..20e1f1df 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ModifyRecentViewRemoveCardAnimForAll.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ModifyRecentViewRemoveCardAnimForAll.kt @@ -1,53 +1,45 @@ package com.lt2333.simplicitytools.hooks.rules.all.miuihome import android.animation.ObjectAnimator +import android.animation.TimeInterpolator +import android.view.MotionEvent import android.view.View -import com.github.kyuubiran.ezxhelper.utils.args -import com.github.kyuubiran.ezxhelper.utils.findMethod -import com.github.kyuubiran.ezxhelper.utils.getObject -import com.github.kyuubiran.ezxhelper.utils.hookAfter -import com.github.kyuubiran.ezxhelper.utils.hookReplace -import com.github.kyuubiran.ezxhelper.utils.invokeMethod -import com.github.kyuubiran.ezxhelper.utils.invokeStaticMethod -import com.github.kyuubiran.ezxhelper.utils.loadClass -import com.github.kyuubiran.ezxhelper.utils.putObject -import com.lt2333.simplicitytools.utils.hasEnable +import com.lt2333.simplicitytools.utils.* import com.lt2333.simplicitytools.utils.xposed.base.HookRegister +import de.robv.android.xposed.XposedHelpers object ModifyRecentViewRemoveCardAnimForAll : HookRegister() { override fun init() = hasEnable("miuihome_recentview_remove_card_animation") { - findMethod("com.miui.home.recents.views.SwipeHelperForRecents") { - name == "onTouchEvent" && parameterCount == 1 - }.hookAfter { - val mCurrView = it.thisObject.getObject("mCurrView") as View? + "com.miui.home.recents.views.SwipeHelperForRecents".hookAfterMethod("onTouchEvent", MotionEvent::class.java) { + val mCurrView = it.thisObject.getObjectField("mCurrView") as View? if (mCurrView != null) { mCurrView.alpha = 1f mCurrView.scaleX = 1f mCurrView.scaleY = 1f } } - findMethod("com.miui.home.recents.TaskStackViewLayoutStyleHorizontal") { - name == "createScaleDismissAnimation" && parameterCount == 2 - }.hookReplace { + + "com.miui.home.recents.TaskStackViewLayoutStyleHorizontal".replaceMethod("createScaleDismissAnimation", View::class.java, Float::class.java) { val view = it.args[0] as View - val getScreenHeight = loadClass("com.miui.home.launcher.DeviceConfig").invokeStaticMethod("getScreenHeight") as Int + val getScreenHeight = "com.miui.home.launcher.DeviceConfig".findClass().callStaticMethod("getScreenHeight") as Int val ofFloat = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, view.translationY, -getScreenHeight * 1.1484375f) - ofFloat.duration = 200 - return@hookReplace ofFloat + val physicBasedInterpolator = XposedHelpers.newInstance("com.miui.home.launcher.anim.PhysicBasedInterpolator".findClass(), 0.9f, 0.78f) + ofFloat.interpolator = physicBasedInterpolator as TimeInterpolator + ofFloat.duration = 400 + return@replaceMethod ofFloat } - findMethod("com.miui.home.recents.views.VerticalSwipe") { - name == "calculate" && parameterCount == 1 - }.hookAfter { + + "com.miui.home.recents.views.VerticalSwipe".hookAfterMethod("calculate", Float::class.java) { val f = it.args[0] as Float - val asScreenHeightWhenDismiss = loadClass("com.miui.home.recents.views.VerticalSwipe").invokeStaticMethod("getAsScreenHeightWhenDismiss") as Int + val asScreenHeightWhenDismiss = "com.miui.home.recents.views.VerticalSwipe".findClass().callStaticMethod("getAsScreenHeightWhenDismiss") as Int val f2 = f / asScreenHeightWhenDismiss - val mTaskViewHeight = it.thisObject.getObject("mTaskViewHeight") as Float - val mCurScale = it.thisObject.getObject("mCurScale") as Float + val mTaskViewHeight = it.thisObject.getObjectField("mTaskViewHeight") as Float + val mCurScale = it.thisObject.getObjectField("mCurScale") as Float val f3: Float = mTaskViewHeight * mCurScale val i = if (f2 > 0.0f) 1 else if (f2 == 0.0f) 0 else -1 - val afterFrictionValue: Float = it.thisObject.invokeMethod("afterFrictionValue", args(f, asScreenHeightWhenDismiss)) as Float - if (i < 0) it.thisObject.putObject("mCurTransY", (mTaskViewHeight / 2.0f + afterFrictionValue * 2) - (f3 / 2.0f)) + val afterFrictionValue: Float = it.thisObject.callMethod("afterFrictionValue", f, asScreenHeightWhenDismiss) as Float + if (i < 0) it.thisObject.setObjectField("mCurTransY", (mTaskViewHeight / 2.0f + afterFrictionValue * 2) - (f3 / 2.0f)) } } diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ScrollIconNameForAll.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ScrollIconNameForAll.kt index 4f42be66..0a76e4d0 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ScrollIconNameForAll.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ScrollIconNameForAll.kt @@ -1,8 +1,10 @@ package com.lt2333.simplicitytools.hooks.rules.all.miuihome import android.annotation.SuppressLint +import android.content.Context import android.text.TextUtils import android.view.View +import android.view.ViewGroup import android.widget.TextView import com.github.kyuubiran.ezxhelper.utils.Log import com.github.kyuubiran.ezxhelper.utils.args @@ -10,54 +12,57 @@ import com.github.kyuubiran.ezxhelper.utils.findMethod import com.github.kyuubiran.ezxhelper.utils.getObject import com.github.kyuubiran.ezxhelper.utils.hookAfter import com.github.kyuubiran.ezxhelper.utils.invokeMethod -import com.lt2333.simplicitytools.utils.hasEnable +import com.lt2333.simplicitytools.utils.* import com.lt2333.simplicitytools.utils.xposed.base.HookRegister object ScrollIconNameForAll : HookRegister() { @SuppressLint("DiscouragedApi") override fun init() = hasEnable("miuihome_scroll_icon_name") { + val launcherClass = "com.miui.home.launcher.Launcher".findClass() + val shortcutInfoClass = "com.miui.home.launcher.ShortcutInfo".findClass() + try { - findMethod("com.miui.home.launcher.ItemIcon") { - name == "onFinishInflate" - }.hookAfter { - val mTitle = it.thisObject.getObject("mTitle") as TextView + "com.miui.home.launcher.ItemIcon".hookAfterMethod( + "onFinishInflate" + ) { + val mTitle = it.thisObject.getObjectField("mTitle") as TextView mTitleScrolling(mTitle) } - findMethod("com.miui.home.launcher.maml.MaMlWidgetView") { - name == "onFinishInflate" - }.hookAfter { - val mTitle = it.thisObject.getObject("mTitle") as TextView + "com.miui.home.launcher.maml.MaMlWidgetView".hookAfterMethod( + "onFinishInflate" + ) { + val mTitle = it.thisObject.getObjectField("mTitleTextView") as TextView mTitleScrolling(mTitle) } - findMethod("com.miui.home.launcher.LauncherMtzGadgetView") { - name == "onFinishInflate" - }.hookAfter { - val mTitle = it.thisObject.getObject("mTitle") as TextView + "com.miui.home.launcher.LauncherMtzGadgetView".hookAfterMethod( + "onFinishInflate" + ) { + val mTitle = it.thisObject.getObjectField("mTitleTextView") as TextView mTitleScrolling(mTitle) } - findMethod("com.miui.home.launcher.LauncherWidgetView") { - name == "onFinishInflate" - }.hookAfter { - val mTitle = it.thisObject.getObject("mTitle") as TextView + "com.miui.home.launcher.LauncherWidgetView".hookAfterMethod( + "onFinishInflate" + ) { + val mTitle = it.thisObject.getObjectField("mTitleTextView") as TextView mTitleScrolling(mTitle) } - findMethod("com.miui.home.launcher.ShortcutIcon") { - name == "fromXml" && parameterCount == 4 - }.hookAfter { - val buddyIconView = it.args[3].invokeMethod("getBuddyIconView", args(it.args[2])) as View - val mTitle = buddyIconView.getObject("mTitle") as TextView + "com.miui.home.launcher.ShortcutIcon".hookAfterMethod( + "fromXml", Int::class.javaPrimitiveType, launcherClass, ViewGroup::class.java, shortcutInfoClass + ) { + val buddyIconView = it.args[3].callMethod("getBuddyIconView", it.args[2]) as View + val mTitle = buddyIconView.getObjectField("mTitle") as TextView mTitleScrolling(mTitle) } - findMethod("com.miui.home.launcher.ShortcutIcon") { - name == "createShortcutIcon" && parameterCount == 3 - }.hookAfter { + "com.miui.home.launcher.ShortcutIcon".hookAfterMethod( + "createShortcutIcon", Int::class.javaPrimitiveType, launcherClass, ViewGroup::class.java + ) { val buddyIcon = it.result as View - val mTitle = buddyIcon.getObject("mTitle") as TextView + val mTitle = buddyIcon.getObjectField("mTitle") as TextView mTitleScrolling(mTitle) } - findMethod("com.miui.home.launcher.common.Utilities") { - name == "adaptTitleStyleToWallpaper" && parameterCount == 4 - }.hookAfter { + "com.miui.home.launcher.common.Utilities".hookAfterMethod( + "adaptTitleStyleToWallpaper", Context::class.java, TextView::class.java, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType + ) { val mTitle = it.args[1] as TextView if (mTitle.id == mTitle.resources.getIdentifier("icon_title", "id", "com.miui.home")) { mTitleScrolling(mTitle) diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt index 4f7af06f..1d3f82f4 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt @@ -18,77 +18,71 @@ import com.github.kyuubiran.ezxhelper.utils.invokeStaticMethod import com.github.kyuubiran.ezxhelper.utils.loadClass import com.github.kyuubiran.ezxhelper.utils.putStaticObject import com.lt2333.simplicitytools.R -import com.lt2333.simplicitytools.utils.hasEnable +import com.lt2333.simplicitytools.utils.* import com.lt2333.simplicitytools.utils.xposed.base.HookRegister import de.robv.android.xposed.XposedHelpers object ShortcutAddSmallWindowForAll : HookRegister() { override fun init() = hasEnable("miuihome_shortcut_add_small_window") { - val mViewDarkModeHelper = loadClass("com.miui.home.launcher.util.ViewDarkModeHelper") - val mSystemShortcutMenu = loadClass("com.miui.home.launcher.shortcuts.SystemShortcutMenu") - val mSystemShortcutMenuItem = loadClass("com.miui.home.launcher.shortcuts.SystemShortcutMenuItem") - val mAppShortcutMenu = loadClass("com.miui.home.launcher.shortcuts.AppShortcutMenu") - val mShortcutMenuItem = loadClass("com.miui.home.launcher.shortcuts.ShortcutMenuItem") - val mAppDetailsShortcutMenuItem = loadClass("com.miui.home.launcher.shortcuts.SystemShortcutMenuItem\$AppDetailsShortcutMenuItem") - val mActivityUtilsCompat = loadClass("com.miui.launcher.utils.ActivityUtilsCompat") - findAllMethods(mViewDarkModeHelper) { - name == "onConfigurationChanged" - }.hookAfter { - mSystemShortcutMenuItem.invokeStaticMethod("createAllSystemShortcutMenuItems") + val mViewDarkModeHelper = ("com.miui.home.launcher.util.ViewDarkModeHelper").findClass() + val mSystemShortcutMenu = ("com.miui.home.launcher.shortcuts.SystemShortcutMenu").findClass() + val mSystemShortcutMenuItem = ("com.miui.home.launcher.shortcuts.SystemShortcutMenuItem").findClass() + val mAppShortcutMenu = ("com.miui.home.launcher.shortcuts.AppShortcutMenu").findClass() + val mShortcutMenuItem = ("com.miui.home.launcher.shortcuts.ShortcutMenuItem").findClass() + val mAppDetailsShortcutMenuItem = ("com.miui.home.launcher.shortcuts.SystemShortcutMenuItem\$AppDetailsShortcutMenuItem").findClass() + val mActivityUtilsCompat = ("com.miui.launcher.utils.ActivityUtilsCompat").findClass() + + mViewDarkModeHelper.hookAfterAllMethods("onConfigurationChanged") { + mSystemShortcutMenuItem.callStaticMethod("createAllSystemShortcutMenuItems") } - findAllMethods(mShortcutMenuItem) { - name == "getShortTitle" - }.hookAfter { + + mShortcutMenuItem.hookAfterAllMethods("getShortTitle") { if (it.result == "应用信息") { it.result = "信息" } } - findMethod(mAppDetailsShortcutMenuItem) { - name == "lambda\$getOnClickListener$0" && parameterCount == 2 - }.hookBefore { + + mAppDetailsShortcutMenuItem.hookBeforeMethod("lambda\$getOnClickListener$0", mAppDetailsShortcutMenuItem, View::class.java) { val obj = it.args[0] val view: View = it.args[1] as View - val mShortTitle = obj.invokeMethod("getShortTitle") as CharSequence + val mShortTitle = obj.callMethod("getShortTitle") as CharSequence if (mShortTitle == moduleRes.getString(R.string.miuihome_shortcut_add_small_window_title)) { it.result = null val intent = Intent() - val mComponentName = obj.invokeMethod("getComponentName") as ComponentName + val mComponentName = obj.callMethod("getComponentName") as ComponentName intent.action = "android.intent.action.MAIN" intent.addCategory("android.intent.category.LAUNCHER") intent.component = mComponentName intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - val callStaticMethod = mActivityUtilsCompat.invokeStaticMethod("makeFreeformActivityOptions", args(view.context, mComponentName.packageName)) + val callStaticMethod = mActivityUtilsCompat.callStaticMethod("makeFreeformActivityOptions", view.context, mComponentName.packageName) if (callStaticMethod != null) { - view.context.startActivity(intent, callStaticMethod.invokeMethod("toBundle") as Bundle) + view.context.startActivity(intent, callStaticMethod.callMethod("toBundle") as Bundle) } } } - findAllMethods(mSystemShortcutMenu) { - name == "getMaxShortcutItemCount" - }.hookAfter { + + mSystemShortcutMenu.hookAfterAllMethods("getMaxShortcutItemCount") { it.result = 5 } - findAllMethods(mAppShortcutMenu) { - name == "getMaxShortcutItemCount" - }.hookAfter { + + mAppShortcutMenu.hookAfterAllMethods("getMaxShortcutItemCount") { it.result = 5 } - findAllMethods(mSystemShortcutMenuItem) { - name == "createAllSystemShortcutMenuItems" - }.hookAfter { + + mSystemShortcutMenuItem.hookAfterAllMethods("createAllSystemShortcutMenuItems") { val isDarkMode = AndroidAppHelper.currentApplication().applicationContext.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES - val mAllSystemShortcutMenuItems = mSystemShortcutMenuItem.getStaticObject("sAllSystemShortcutMenuItems") as Collection + val mAllSystemShortcutMenuItems = mSystemShortcutMenuItem.getStaticObjectField("sAllSystemShortcutMenuItems") as Collection val mSmallWindowInstance = XposedHelpers.newInstance(mAppDetailsShortcutMenuItem) - mSmallWindowInstance.invokeMethod("setShortTitle", args(moduleRes.getString(R.string.miuihome_shortcut_add_small_window_title))) - mSmallWindowInstance.invokeMethod( + mSmallWindowInstance.callMethod("setShortTitle", moduleRes.getString(R.string.miuihome_shortcut_add_small_window_title)) + mSmallWindowInstance.callMethod( "setIconDrawable", - args(if (isDarkMode) moduleRes.getDrawable(R.drawable.ic_small_window_dark) else moduleRes.getDrawable(R.drawable.ic_small_window_light)) + if (isDarkMode) moduleRes.getDrawable(R.drawable.ic_small_window_dark) else moduleRes.getDrawable(R.drawable.ic_small_window_light) ) val sAllSystemShortcutMenuItems = ArrayList() sAllSystemShortcutMenuItems.add(mSmallWindowInstance) sAllSystemShortcutMenuItems.addAll(mAllSystemShortcutMenuItems) - mSystemShortcutMenuItem.putStaticObject("sAllSystemShortcutMenuItems", sAllSystemShortcutMenuItems) + mSystemShortcutMenuItem.setStaticObjectField("sAllSystemShortcutMenuItems", sAllSystemShortcutMenuItems) } }