Skip to content

Commit a39f7f6

Browse files
implement DisableSwapAnimation
1 parent 8fb9ff9 commit a39f7f6

File tree

8 files changed

+62
-2
lines changed

8 files changed

+62
-2
lines changed

SplitScreenMods/Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ since previous versions did not force a split resize in this situation.
2121

2222
Keep the split ratio while swapping sides.
2323

24+
## DisableSwapAnimation
25+
26+
Disable the swapping animation.
27+
2428
## SnapMode
2529

2630
Change the snap mode used by the system:

SplitScreenMods/src/main/assets/xposed_init

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ com.programminghoch10.SplitScreenMods.AdditionalSnapTargetsHook
22
com.programminghoch10.SplitScreenMods.AlwaysAllowMultiInstanceSplitHook
33
com.programminghoch10.SplitScreenMods.CalculateRatiosHook
44
com.programminghoch10.SplitScreenMods.CustomFixedRatioHook
5+
com.programminghoch10.SplitScreenMods.DisableSwapAnimationHook
56
com.programminghoch10.SplitScreenMods.FreeSnapHook
67
com.programminghoch10.SplitScreenMods.KeepSplitScreenRatioHook
78
com.programminghoch10.SplitScreenMods.KeepSwapRatioHook
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.programminghoch10.SplitScreenMods
2+
3+
import android.animation.Animator
4+
import android.os.Build
5+
import com.programminghoch10.SplitScreenMods.BuildConfig.SHARED_PREFERENCES_NAME
6+
import com.programminghoch10.SplitScreenMods.DisableSwapAnimationHookConfig.enabled
7+
import de.binarynoise.logger.Logger.log
8+
import de.robv.android.xposed.IXposedHookLoadPackage
9+
import de.robv.android.xposed.XC_MethodHook
10+
import de.robv.android.xposed.XSharedPreferences
11+
import de.robv.android.xposed.XposedBridge
12+
import de.robv.android.xposed.XposedHelpers
13+
import de.robv.android.xposed.callbacks.XC_LoadPackage
14+
15+
object DisableSwapAnimationHookConfig {
16+
@JvmField
17+
val enabled = Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM
18+
}
19+
20+
class DisableSwapAnimationHook : IXposedHookLoadPackage {
21+
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
22+
if (lpparam.packageName != "com.android.systemui") return
23+
if (!enabled) return
24+
log("handleLoadPackage(${lpparam.packageName} in process ${lpparam.processName})")
25+
val preferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
26+
val enabled = preferences.getBoolean("DisableSwapAnimation", false)
27+
if (!enabled) return
28+
29+
val SplitLayoutClass = XposedHelpers.findClass("com.android.wm.shell.common.split.SplitLayout", lpparam.classLoader)
30+
val playSwapAnimationMethod = SplitLayoutClass.declaredMethods.single { it.name == "playSwapAnimation" }
31+
32+
XposedBridge.hookMethod(playSwapAnimationMethod, object : XC_MethodHook(PRIORITY_LOWEST) {
33+
override fun afterHookedMethod(param: MethodHookParam) {
34+
log("skipping scheduled swap animation")
35+
val mSwapAnimator = XposedHelpers.getObjectField(param.thisObject, "mSwapAnimator") as Animator
36+
mSwapAnimator.end()
37+
}
38+
})
39+
}
40+
}

SplitScreenMods/src/main/java/com/programminghoch10/SplitScreenMods/KeepSwapRatioHook.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class KeepSwapRatioHook : IXposedHookLoadPackage {
3434
val preferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
3535
val enabled = preferences.getBoolean("KeepSwapRatio", false)
3636
if (!enabled) return
37+
val disableAnimation = preferences.getBoolean("DisableSwapAnimation", false)
3738

3839
val SplitLayoutClass = XposedHelpers.findClass("com.android.wm.shell.common.split.SplitLayout", lpparam.classLoader)
3940
val playSwapAnimationMethod =
@@ -56,8 +57,11 @@ class KeepSwapRatioHook : IXposedHookLoadPackage {
5657
if (mIsLeftRightSplit) insets.right else 0,
5758
if (mIsLeftRightSplit) 0 else insets.bottom,
5859
)
59-
//finishCallback.accept(insets)
60-
log("replaced ${playSwapAnimationMethod.name} with dummy implementation to prevent swapping")
60+
log("running own implementation of ${playSwapAnimationMethod.name} to prevent swapping")
61+
if (disableAnimation) {
62+
finishCallback.accept(insets)
63+
return null
64+
}
6165

6266
val t = param.args[0] as SurfaceControl.Transaction
6367
val topLeftStage = param.args[1]

SplitScreenMods/src/main/java/com/programminghoch10/SplitScreenMods/SettingsActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SettingsActivity : FragmentActivity() {
4040
val alwaysAllowMultiInstanceSplitPreference = preferenceScreen.findPreference<SwitchPreference>("AlwaysAllowMultiInstanceSplit")!!
4141
val keepSplitScreenRatioPreference = preferenceScreen.findPreference<SwitchPreference>("KeepSplitScreenRatio")!!
4242
val keepSwapRatioPreference = preferenceScreen.findPreference<SwitchPreference>("KeepSwapRatio")!!
43+
val disableSwapAnimationPreference = preferenceScreen.findPreference<SwitchPreference>("DisableSwapAnimation")!!
4344
val snapModePreference = preferenceScreen.findPreference<ListPreference>("SnapMode")!!
4445
val freeSnapPreference = preferenceScreen.findPreference<SwitchPreference>("FreeSnap")!!
4546
val snapTargetsPreference = preferenceScreen.findPreference<ListPreference>("SnapTargets")!!
@@ -51,6 +52,7 @@ class SettingsActivity : FragmentActivity() {
5152
alwaysAllowMultiInstanceSplitPreference.setEnabledAndVisible(AlwaysAllowMultiInstanceSplitHookConfig.enabled)
5253
keepSplitScreenRatioPreference.setEnabledAndVisible(KeepSplitScreenRatioHookConfig.enabled)
5354
keepSwapRatioPreference.setEnabledAndVisible(KeepSwapRatioHookConfig.enabled)
55+
disableSwapAnimationPreference.setEnabledAndVisible(DisableSwapAnimationHookConfig.enabled || (KeepSwapRatioHookConfig.enabled && keepSwapRatioPreference.isChecked))
5456
snapModePreference.setEnabledAndVisible(SnapModeHookConfig.enabled)
5557
val is1_1SnapMode = snapModePreference.value == SNAP_MODE.SNAP_ONLY_1_1.key
5658
val isFixedRatioSnapMode = snapModePreference.value == SNAP_MODE.SNAP_FIXED_RATIO.key

SplitScreenMods/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@
4040
<string name="CustomRatio_title">Custom Fixed Ratio</string>
4141
<string name="keepswapratio_summary">Keep split ratio when swapping sides</string>
4242
<string name="keepswapratio_title">KeepSwapRatio</string>
43+
<string name="disableswapanimation_title">DisableSwapAnimation</string>
44+
<string name="disableswapanimation_summary">Disable swapping animation</string>
4345
</resources>

SplitScreenMods/src/main/res/xml/root_preferences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
app:summary="@string/keepswapratio_summary"
2525
app:title="@string/keepswapratio_title"
2626
/>
27+
<SwitchPreference
28+
app:iconSpaceReserved="false"
29+
app:key="DisableSwapAnimation"
30+
app:summary="@string/disableswapanimation_summary"
31+
app:title="@string/disableswapanimation_title"
32+
/>
2733
</PreferenceCategory>
2834
<PreferenceCategory
2935
app:iconSpaceReserved="false"

metadata/com.programminghoch10.SplitScreenMods/en-US/full_description.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ A collection of various SplitScreen modifications.
33
* AlwaysAllowMultiInstanceSplit
44
* KeepSplitScreenRatio
55
* KeepSwapRatio
6+
* DisableSwapAnimation
67
* SnapMode
78
* FreeSnap
89
* AdditionalSnapTargets

0 commit comments

Comments
 (0)