@@ -27,12 +27,30 @@ import android.os.Looper
2727import android.view.HapticFeedbackConstants
2828import android.view.MotionEvent
2929import android.view.View
30+ import android.view.ViewGroup
31+ import com.sevtinge.hyperceiler.hook.utils.callMethod
32+ import com.sevtinge.hyperceiler.hook.utils.getBooleanField
33+ import com.sevtinge.hyperceiler.hook.utils.getFloatField
34+ import com.sevtinge.hyperceiler.hook.utils.getObjectField
35+ import com.sevtinge.hyperceiler.hook.utils.getObjectFieldAs
3036import com.sevtinge.hyperceiler.hook.utils.log.XposedLogUtils.logD
37+ import com.sevtinge.hyperceiler.hook.utils.replaceMethod
38+ import com.sevtinge.hyperceiler.hook.utils.setLongField
39+ import com.sevtinge.hyperceiler.hook.utils.setObjectField
3140import de.robv.android.xposed.XC_MethodHook
3241import de.robv.android.xposed.XC_MethodReplacement
3342import de.robv.android.xposed.XposedBridge
3443import de.robv.android.xposed.XposedHelpers
44+ import io.github.kyuubiran.ezxhelper.core.finder.MethodFinder.`-Static`.methodFinder
3545import io.github.kyuubiran.ezxhelper.core.util.ClassUtil.loadClass
46+ import io.github.kyuubiran.ezxhelper.xposed.dsl.HookFactory.`-Static`.createAfterHook
47+ import io.github.kyuubiran.ezxhelper.xposed.dsl.HookFactory.`-Static`.createBeforeHook
48+ import kotlinx.coroutines.CoroutineScope
49+ import kotlinx.coroutines.Dispatchers
50+ import kotlinx.coroutines.Job
51+ import kotlinx.coroutines.delay
52+ import kotlinx.coroutines.launch
53+ import kotlin.collections.get
3654
3755object StartCollpasedColumnPress {
3856 fun initLoaderHook (classLoader : ClassLoader ) {
@@ -46,122 +64,101 @@ object StartCollpasedColumnPress {
4664 loadClass(" com.android.systemui.miui.volume.MiuiVolumeSeekBar" , classLoader)
4765 }
4866
49- XposedHelpers .findAndHookMethod(
50- miuiVolumeDialogView, " onFinishInflate" ,
51- object : XC_MethodHook () {
52- override fun afterHookedMethod (param : MethodHookParam ? ) {
53- val thisObj = param?.thisObject
54- val mExpandButton =
55- XposedHelpers .getObjectField(thisObj, " mExpandButton" ) as View
56- mExpandButton.setOnClickListener(null )
57- mExpandButton.alpha = 0f
58- mExpandButton.isClickable = false
59- mExpandButton.visibility = View .GONE
60- }
61- })
62-
63- XposedHelpers .findAndHookMethod(
64- miuiVolumeDialogView, " notifyAccessibilityChanged" , Boolean ::class .java,
65- object : XC_MethodHook () {
66- override fun afterHookedMethod (param : MethodHookParam ? ) {
67- val thisObj = param?.thisObject
68- val mExpandButton =
69- XposedHelpers .getObjectField(thisObj, " mExpandButton" ) as View
70-
71- mExpandButton.setOnClickListener(null )
72- mExpandButton.isClickable = false
73- mExpandButton.visibility = View .GONE
74- }
75- })
76-
77- XposedBridge .hookAllConstructors(miuiVolumeDialogMotion, object : XC_MethodHook () {
78- override fun afterHookedMethod (param : MethodHookParam ? ) {
79- val thisObj = param?.thisObject
80- val mExpandButton = XposedHelpers .getObjectField(thisObj, " mExpandButton" ) as View
81-
82- mExpandButton.setOnTouchListener(null )
83- }
84- })
67+ var longClick = false
68+ var longPressJob: Job ? = null
69+
70+ fun View.startScaleAnimation () {
71+ longClick = true
72+ animate()
73+ .scaleX(0.92f )
74+ .scaleY(0.92f )
75+ .setDuration(300 )
76+ .start()
77+ }
8578
79+ fun View.stopScaleAnimation () {
80+ longClick = false
81+ animate()
82+ .scaleX(1.0f )
83+ .scaleY(1.0f )
84+ .setDuration(300 )
85+ .start()
86+ }
8687
87- var longClick = false
88- XposedHelpers .findAndHookMethod(
89- miuiVolumeDialogMotion, " lambda\$ processExpandTouch\$ 1" ,
90- object : XC_MethodReplacement () {
91- override fun replaceHookedMethod (param : MethodHookParam ? ): Any? {
92- val thisObj = param?.thisObject
93- if (XposedHelpers .getBooleanField(thisObj, " mExpanded" ) || ! longClick) return null
94- val mVolumeView = XposedHelpers .getObjectField(thisObj, " mVolumeView" ) as View
95-
96- logD(" StartCollpasedColumnPress" , " miui.systemui.plugin" , " processExpandTouch" )
97-
98- with (AnimatorSet ()) {
99- playTogether(
100- ObjectAnimator .ofFloat(mVolumeView, " scaleX" , 0.95f ),
101- ObjectAnimator .ofFloat(mVolumeView, " scaleY" , 0.95f )
102- )
103- duration = 100L
104- addListener(object : AnimatorListenerAdapter () {
105- override fun onAnimationEnd (animation : Animator ) {
106- super .onAnimationEnd(animation)
107- mVolumeView.performHapticFeedback(HapticFeedbackConstants .LONG_PRESS );
108- val mVolumeExpandCollapsedAnimator =
109- XposedHelpers .getObjectField(thisObj, " mVolumeExpandCollapsedAnimator" )
110- val mCallback = XposedHelpers .getObjectField(thisObj, " mCallback" )
111- XposedHelpers .callMethod(mVolumeExpandCollapsedAnimator, " calculateFromViewValues" , true )
112- XposedHelpers .callMethod(mCallback, " onExpandClicked" )
113-
114- mVolumeView.scaleX = 1f
115- mVolumeView.scaleY = 1f
116- }
117- })
118- start()
88+ miuiVolumeDialogView.methodFinder().apply {
89+ filterByName(" onFinishInflate" )
90+ .first().createAfterHook {
91+ it.thisObject.getObjectFieldAs<View >(" mExpandButton" ).apply {
92+ alpha = 0f
93+ isClickable = false
94+ visibility = View .GONE
95+ setOnClickListener(null )
11996 }
120- return null
121- }
12297
123- })
124-
125- XposedHelpers .findAndHookMethod(
126- miuiVolumeSeekBar, " onTouchEvent" , MotionEvent ::class .java,
127- object : XC_MethodHook () {
128- override fun afterHookedMethod (param : MethodHookParam ? ) {
129- super .afterHookedMethod(param)
130- val thisObj = param?.thisObject
131- val mSeekBarOnclickListener =
132- XposedHelpers .getObjectField(thisObj, " mSeekBarOnclickListener" )
133-
134- val handler = Handler (Looper .getMainLooper())
135- val mLongPressRunnable = Runnable {
136- val mMoveY = XposedHelpers .getFloatField(thisObj, " mMoveY" )
137- if (longClick) {
138- thisObj as View
139- XposedHelpers .callMethod(mSeekBarOnclickListener, " onClick" )
140- }
98+ }
99+ filterByName(" notifyAccessibilityChanged" )
100+ .filterByParamTypes {
101+ it[0 ] == Boolean ::class .java
102+ }.first().createAfterHook {
103+ it.thisObject.getObjectFieldAs<View >(" mExpandButton" ).apply {
104+ isClickable = false
105+ visibility = View .GONE
106+ setOnClickListener(null )
141107 }
108+ }
109+ }
142110
143- if (mSeekBarOnclickListener != null ) {
144- val motionEvent = param?.args?.get(0 ) as MotionEvent
145-
146- val action = motionEvent.action
147- when (action) {
148- 0 -> {
149- longClick = true
150- XposedHelpers .setLongField(thisObj, " mCurrentMS" , 0L )
151- handler.postDelayed(mLongPressRunnable, 300L )
152- }
153-
154- 1 -> {
155- longClick = false
156- XposedHelpers .setLongField(thisObj, " mCurrentMS" , 0L )
157- }
158-
159- 2 -> {
160- longClick = false
111+ miuiVolumeDialogMotion.methodFinder().apply {
112+ filterByName(" lambda\$ processExpandTouch\$ 1" )
113+ .first().createBeforeHook {
114+ it.thisObject.setObjectField(" mIsExpandButton" ,true )
115+ }
116+ }
117+ miuiVolumeSeekBar.methodFinder()
118+ .filterByName(" onTouchEvent" )
119+ .filterByParamTypes {
120+ it[0 ] == MotionEvent ::class .java
121+ }.first().createAfterHook {
122+ val mSeekBarOnclickListener = it.thisObject.getObjectField(" mSeekBarOnclickListener" )
123+ val mSeekBarAnimListener = it.thisObject.getObjectField(" mSeekBarAnimListener" )!!
124+ val volumePanelViewController = mSeekBarAnimListener.getObjectField(" this\$ 0" )!!
125+ val mVolumeView = volumePanelViewController.getObjectFieldAs<View >(" mVolumeView" )
126+
127+ it.thisObject.setLongField(" mCurrentMS" ,0L )
128+ if (mSeekBarOnclickListener != null ) {
129+ val motionEvent = it.args?.get(0 ) as MotionEvent
130+ when (motionEvent.action) {
131+ MotionEvent .ACTION_DOWN -> {
132+ if ( ! volumePanelViewController.getBooleanField(" mExpanded" ) ){
133+ longPressJob = CoroutineScope (Dispatchers .Main ).launch {
134+ mVolumeView.startScaleAnimation()
135+ delay(300 )
136+ val mMoveY = it.thisObject.getFloatField(" mMoveY" )
137+ if (longClick && mMoveY < 10f ){
138+ mVolumeView.apply {
139+ scaleY = 1f
140+ scaleX = 1f
141+ performHapticFeedback(HapticFeedbackConstants .LONG_PRESS )
142+ }
143+ mSeekBarOnclickListener.callMethod( " onClick" )
144+
145+ }
146+
147+ }
161148 }
162149 }
150+ MotionEvent .ACTION_UP -> {
151+ mVolumeView.stopScaleAnimation()
152+ longPressJob?.cancel()
153+ }
154+ MotionEvent .ACTION_CANCEL -> {
155+ mVolumeView.stopScaleAnimation()
156+ longPressJob?.cancel()
157+ }
163158 }
159+
164160 }
165- })
161+ }
162+
166163 }
167164}
0 commit comments