Use Handlers instead of Timers for one-shot events

This commit is contained in:
Cameron Gutman
2022-09-16 00:08:48 -05:00
parent 9cf27d8fb1
commit 03f9ea8435
5 changed files with 74 additions and 140 deletions

View File

@@ -95,7 +95,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private int lastButtonState = 0;
// Only 2 touches are supported
private Timer touchTimer;
private final TouchContext[] touchContextMap = new TouchContext[2];
private long threeFingerDownTime = 0;
@@ -479,15 +478,14 @@ public class Game extends Activity implements SurfaceHolder.Callback,
inputManager.registerInputDeviceListener(keyboardTranslator, null);
// Initialize touch contexts
touchTimer = new Timer("TouchTimer", true);
for (int i = 0; i < touchContextMap.length; i++) {
if (!prefConfig.touchscreenTrackpad) {
touchContextMap[i] = new AbsoluteTouchContext(conn, i, streamView, touchTimer);
touchContextMap[i] = new AbsoluteTouchContext(conn, i, streamView);
}
else {
touchContextMap[i] = new RelativeTouchContext(conn, i,
REFERENCE_HORIZ_RES, REFERENCE_VERT_RES,
streamView, prefConfig, touchTimer);
streamView, prefConfig);
}
}
@@ -1031,10 +1029,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
protected void onDestroy() {
super.onDestroy();
if (touchTimer != null) {
touchTimer.cancel();
}
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
if (controllerHandler != null) {
inputManager.unregisterInputDeviceListener(controllerHandler);