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