|
1 | 1 | package com.parallelc.micts.hooker |
2 | 2 |
|
| 3 | +import android.view.MotionEvent |
3 | 4 | import android.view.View |
4 | 5 | import android.view.ViewConfiguration |
5 | 6 | import com.parallelc.micts.module |
6 | 7 | import com.parallelc.micts.triggerCircleToSearch |
7 | 8 | import io.github.libxposed.api.XposedInterface.AfterHookCallback |
8 | 9 | import io.github.libxposed.api.XposedInterface.Hooker |
| 10 | +import io.github.libxposed.api.XposedModuleInterface.PackageLoadedParam |
9 | 11 | import io.github.libxposed.api.annotations.AfterInvocation |
10 | 12 | import io.github.libxposed.api.annotations.XposedHooker |
| 13 | +import java.lang.reflect.Field |
| 14 | +import kotlin.math.abs |
11 | 15 |
|
12 | 16 | @XposedHooker |
13 | | -class NavStubViewHooker : Hooker { |
| 17 | +class NavStubViewHooker { |
14 | 18 | companion object { |
15 | | - private val mCheckLongPress = Runnable { |
16 | | - runCatching { |
17 | | - triggerCircleToSearch() |
18 | | - }.onFailure { e -> |
19 | | - module.log("NavStubViewHooker mCheckLongPress fail", e) |
20 | | - } |
| 19 | + private lateinit var mCurrAction: Field |
| 20 | + private lateinit var mCurrX: Field |
| 21 | + private lateinit var mInitX: Field |
| 22 | + private lateinit var mCurrY: Field |
| 23 | + private lateinit var mInitY: Field |
| 24 | + |
| 25 | + fun hook(param: PackageLoadedParam) { |
| 26 | + val navStubView = param.classLoader.loadClass("com.miui.home.recents.NavStubView") |
| 27 | + runCatching { navStubView.getDeclaredField("mCheckLongPress") } |
| 28 | + .onSuccess { throw Exception("mCheckLongPress exists") } |
| 29 | + .onFailure { |
| 30 | + mCurrAction = navStubView.getDeclaredField("mCurrAction") |
| 31 | + mCurrAction.isAccessible = true |
| 32 | + mCurrX = navStubView.getDeclaredField("mCurrX") |
| 33 | + mCurrX.isAccessible = true |
| 34 | + mInitX = navStubView.getDeclaredField("mInitX") |
| 35 | + mInitX.isAccessible = true |
| 36 | + mCurrY = navStubView.getDeclaredField("mCurrY") |
| 37 | + mCurrY.isAccessible = true |
| 38 | + mInitY = navStubView.getDeclaredField("mInitY") |
| 39 | + mInitY.isAccessible = true |
| 40 | + module.hook(navStubView.getDeclaredMethod("onTouchEvent", MotionEvent::class.java), OnTouchEventHooker::class.java) |
| 41 | + } |
21 | 42 | } |
22 | 43 |
|
23 | | - @JvmStatic |
24 | | - @AfterInvocation |
25 | | - fun after(callback: AfterHookCallback) { |
26 | | - val view = callback.thisObject as View |
27 | | - view.removeCallbacks(this.mCheckLongPress) |
28 | | - runCatching { |
29 | | - val mCurrAction = callback.thisObject!!.javaClass.getDeclaredField("mCurrAction") |
30 | | - mCurrAction.isAccessible = true |
31 | | - if (mCurrAction.getInt(callback.thisObject) == 0) { |
32 | | - view.postDelayed(this.mCheckLongPress, ViewConfiguration.getLongPressTimeout().toLong()) |
| 44 | + class OnTouchEventHooker : Hooker { |
| 45 | + companion object { |
| 46 | + private val mCheckLongPress = Runnable { |
| 47 | + runCatching { |
| 48 | + triggerCircleToSearch() |
| 49 | + }.onFailure { e -> |
| 50 | + module.log("NavStubViewHooker mCheckLongPress fail", e) |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @JvmStatic |
| 55 | + @AfterInvocation |
| 56 | + fun after(callback: AfterHookCallback) { |
| 57 | + runCatching { |
| 58 | + val view = callback.thisObject as View |
| 59 | + when(mCurrAction.getInt(callback.thisObject)) { |
| 60 | + 0 -> view.postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout().toLong()) // DOWN |
| 61 | + 2 -> { // HOLD |
| 62 | + if (abs(mCurrX.getFloat(callback.thisObject) - mInitX.getFloat(callback.thisObject)) > 4 || |
| 63 | + abs(mCurrY.getFloat(callback.thisObject) - mInitY.getFloat(callback.thisObject)) > 4) |
| 64 | + view.removeCallbacks(mCheckLongPress) |
| 65 | + else {} |
| 66 | + } |
| 67 | + else -> view.removeCallbacks(mCheckLongPress) |
| 68 | + } |
| 69 | + }.onFailure { e -> |
| 70 | + module.log("NavStubViewHooker onTouchEvent fail", e) |
| 71 | + } |
33 | 72 | } |
34 | | - }.onFailure { e -> |
35 | | - module.log("NavStubViewHooker onTouchEvent fail", e) |
36 | 73 | } |
37 | 74 | } |
38 | 75 | } |
|
0 commit comments