mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-02-16 10:31:07 +00:00
Split ControllerHandler teardown into stop() and destroy() functions
This commit is contained in:
@@ -1093,6 +1093,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
||||
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
|
||||
if (controllerHandler != null) {
|
||||
inputManager.unregisterInputDeviceListener(controllerHandler);
|
||||
controllerHandler.destroy();
|
||||
}
|
||||
if (keyboardTranslator != null) {
|
||||
inputManager.unregisterInputDeviceListener(keyboardTranslator);
|
||||
|
||||
@@ -118,6 +118,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
private final SceManager sceManager;
|
||||
private final Handler handler;
|
||||
private boolean hasGameController;
|
||||
private boolean stopped = false;
|
||||
|
||||
private final PreferenceConfiguration prefConfig;
|
||||
private short currentControllers, initialControllers;
|
||||
@@ -249,6 +250,9 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
// Stop new device contexts from being created or used
|
||||
stopped = true;
|
||||
|
||||
for (int i = 0; i < inputDeviceContexts.size(); i++) {
|
||||
InputDeviceContext deviceContext = inputDeviceContexts.valueAt(i);
|
||||
deviceContext.destroy();
|
||||
@@ -259,10 +263,17 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
deviceContext.destroy();
|
||||
}
|
||||
|
||||
sceManager.stop();
|
||||
deviceVibrator.cancel();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (!stopped) {
|
||||
stop();
|
||||
}
|
||||
|
||||
sceManager.stop();
|
||||
}
|
||||
|
||||
public void disableSensors() {
|
||||
for (int i = 0; i < inputDeviceContexts.size(); i++) {
|
||||
InputDeviceContext deviceContext = inputDeviceContexts.valueAt(i);
|
||||
@@ -892,8 +903,12 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
}
|
||||
|
||||
private InputDeviceContext getContextForEvent(InputEvent event) {
|
||||
// Unknown devices use the default context
|
||||
if (event.getDeviceId() == 0) {
|
||||
// Don't return a context if we're stopped
|
||||
if (stopped) {
|
||||
return null;
|
||||
}
|
||||
else if (event.getDeviceId() == 0) {
|
||||
// Unknown devices use the default context
|
||||
return defaultContext;
|
||||
}
|
||||
else if (event.getDevice() == null) {
|
||||
@@ -2647,6 +2662,10 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
||||
|
||||
@Override
|
||||
public void deviceAdded(AbstractController controller) {
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
UsbDeviceContext context = createUsbDeviceContextForDevice(controller);
|
||||
usbDeviceContexts.put(controller.getControllerId(), context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user