mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-17 14:21:08 +00:00
Consolidate OSC timers
This commit is contained in:
+1
-12
@@ -14,7 +14,6 @@ import android.view.MotionEvent;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +56,6 @@ public class DigitalButton extends VirtualControllerElement {
|
|||||||
private String text = "";
|
private String text = "";
|
||||||
private int icon = -1;
|
private int icon = -1;
|
||||||
private long timerLongClickTimeout = 3000;
|
private long timerLongClickTimeout = 3000;
|
||||||
private Timer timerLongClick = null;
|
|
||||||
private TimerLongClickTimerTask longClickTimerTask = null;
|
private TimerLongClickTimerTask longClickTimerTask = null;
|
||||||
|
|
||||||
private final Paint paint = new Paint();
|
private final Paint paint = new Paint();
|
||||||
@@ -177,18 +175,13 @@ public class DigitalButton extends VirtualControllerElement {
|
|||||||
listener.onClick();
|
listener.onClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timerLongClick != null) {
|
|
||||||
timerLongClick.cancel();
|
|
||||||
timerLongClick = null;
|
|
||||||
}
|
|
||||||
if (longClickTimerTask != null) {
|
if (longClickTimerTask != null) {
|
||||||
longClickTimerTask.cancel();
|
longClickTimerTask.cancel();
|
||||||
longClickTimerTask = null;
|
longClickTimerTask = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
timerLongClick = new Timer();
|
|
||||||
longClickTimerTask = new TimerLongClickTimerTask();
|
longClickTimerTask = new TimerLongClickTimerTask();
|
||||||
timerLongClick.schedule(longClickTimerTask, timerLongClickTimeout);
|
virtualController.getTimer().schedule(longClickTimerTask, timerLongClickTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLongClickCallback() {
|
private void onLongClickCallback() {
|
||||||
@@ -207,10 +200,6 @@ public class DigitalButton extends VirtualControllerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We may be called for a release without a prior click
|
// We may be called for a release without a prior click
|
||||||
if (timerLongClick != null) {
|
|
||||||
timerLongClick.cancel();
|
|
||||||
timerLongClick = null;
|
|
||||||
}
|
|
||||||
if (longClickTimerTask != null) {
|
if (longClickTimerTask != null) {
|
||||||
longClickTimerTask.cancel();
|
longClickTimerTask.cancel();
|
||||||
longClickTimerTask = null;
|
longClickTimerTask = null;
|
||||||
|
|||||||
+11
-6
@@ -41,11 +41,11 @@ public class VirtualController {
|
|||||||
|
|
||||||
private final ControllerHandler controllerHandler;
|
private final ControllerHandler controllerHandler;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
private final Timer timer;
|
||||||
|
|
||||||
|
private TimerTask retransmitTimerTask;
|
||||||
private FrameLayout frame_layout = null;
|
private FrameLayout frame_layout = null;
|
||||||
|
|
||||||
private Timer retransmitTimer;
|
|
||||||
|
|
||||||
ControllerMode currentMode = ControllerMode.Active;
|
ControllerMode currentMode = ControllerMode.Active;
|
||||||
ControllerInputContext inputContext = new ControllerInputContext();
|
ControllerInputContext inputContext = new ControllerInputContext();
|
||||||
|
|
||||||
@@ -57,6 +57,7 @@ public class VirtualController {
|
|||||||
this.controllerHandler = controllerHandler;
|
this.controllerHandler = controllerHandler;
|
||||||
this.frame_layout = layout;
|
this.frame_layout = layout;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.timer = new Timer("OSC timer", true);
|
||||||
|
|
||||||
buttonConfigure = new Button(context);
|
buttonConfigure = new Button(context);
|
||||||
buttonConfigure.setAlpha(0.25f);
|
buttonConfigure.setAlpha(0.25f);
|
||||||
@@ -91,8 +92,12 @@ public class VirtualController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer getTimer() {
|
||||||
|
return timer;
|
||||||
|
}
|
||||||
|
|
||||||
public void hide() {
|
public void hide() {
|
||||||
retransmitTimer.cancel();
|
retransmitTimerTask.cancel();
|
||||||
|
|
||||||
for (VirtualControllerElement element : elements) {
|
for (VirtualControllerElement element : elements) {
|
||||||
element.setVisibility(View.INVISIBLE);
|
element.setVisibility(View.INVISIBLE);
|
||||||
@@ -112,13 +117,13 @@ public class VirtualController {
|
|||||||
// very shortly after another. This can be critical if an axis zeroing packet
|
// very shortly after another. This can be critical if an axis zeroing packet
|
||||||
// is lost and causes an analog stick to get stuck. To avoid this, we send
|
// is lost and causes an analog stick to get stuck. To avoid this, we send
|
||||||
// a gamepad input packet every 100 ms to ensure any loss can be recovered.
|
// a gamepad input packet every 100 ms to ensure any loss can be recovered.
|
||||||
retransmitTimer = new Timer("OSC timer", true);
|
retransmitTimerTask = new TimerTask() {
|
||||||
retransmitTimer.schedule(new TimerTask() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sendControllerInputContext();
|
sendControllerInputContext();
|
||||||
}
|
}
|
||||||
}, 100, 100);
|
};
|
||||||
|
timer.schedule(retransmitTimerTask, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeElements() {
|
public void removeElements() {
|
||||||
|
|||||||
Reference in New Issue
Block a user