mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 23:28:52 -04:00
Remove dedicated thread from Touchpad
This commit is contained in:
parent
d3d1b5a0fb
commit
b9529a5f59
@ -40,6 +40,20 @@ public class Touchpad extends FrameLayout {
|
|||||||
private float mPrevX, mPrevY;
|
private float mPrevX, mPrevY;
|
||||||
/* Last first pointer positions non-scaled, used to scroll distance */
|
/* Last first pointer positions non-scaled, used to scroll distance */
|
||||||
private float mScrollLastInitialX, mScrollLastInitialY;
|
private float mScrollLastInitialX, mScrollLastInitialY;
|
||||||
|
/* Handler and message to check if we are grabbing */
|
||||||
|
private final Runnable mGrabRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!CallbackBridge.isGrabbing() && mDisplayState && getVisibility() != VISIBLE) {
|
||||||
|
enable();
|
||||||
|
}else{
|
||||||
|
if ((CallbackBridge.isGrabbing() && getVisibility() != View.GONE) || !mDisplayState && getVisibility() == VISIBLE) {
|
||||||
|
disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
postDelayed(this, 250);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public Touchpad(@NonNull Context context) {
|
public Touchpad(@NonNull Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@ -170,20 +184,7 @@ public class Touchpad extends FrameLayout {
|
|||||||
// When the game is grabbing, we should not display the mouse
|
// When the game is grabbing, we should not display the mouse
|
||||||
disable();
|
disable();
|
||||||
mDisplayState = false;
|
mDisplayState = false;
|
||||||
Thread virtualMouseGrabThread = new Thread(() -> {
|
postDelayed(mGrabRunnable, 250);
|
||||||
while (true) {
|
|
||||||
if (!CallbackBridge.isGrabbing() && mDisplayState && getVisibility() != VISIBLE) {
|
|
||||||
post(this::enable);
|
|
||||||
}else{
|
|
||||||
if ((CallbackBridge.isGrabbing() && getVisibility() != View.GONE) || !mDisplayState && getVisibility() == VISIBLE) {
|
|
||||||
post(this::disable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}, "VirtualMouseGrabThread");
|
|
||||||
virtualMouseGrabThread.setPriority(Thread.MIN_PRIORITY);
|
|
||||||
virtualMouseGrabThread.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user