Clean up captured pointer code to avoid logcat clutter on pre-8.0 systems (thanks Rachel!)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 5dbe5ac..fd95b0f 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -1382,10 +1382,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
setOnGenericMotionListener(SDLActivity.getMotionListener());
}
- if ((Build.VERSION.SDK_INT >= 26) && !SDLActivity.isDeXMode()) {
- setOnCapturedPointerListener(new SDLCapturedPointerListener_API26());
- }
-
// Some arbitrary defaults to avoid a potential division by zero
mWidth = 1.0f;
mHeight = 1.0f;
@@ -1740,6 +1736,49 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
event.values[2] / SensorManager.GRAVITY_EARTH);
}
}
+
+ // Captured pointer events for API 26.
+ public boolean onCapturedPointerEvent(MotionEvent event)
+ {
+ int action = event.getActionMasked();
+
+ float x, y;
+ switch (action) {
+ case MotionEvent.ACTION_SCROLL:
+ x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
+ y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
+ SDLActivity.onNativeMouse(0, action, x, y, false);
+ return true;
+
+ case MotionEvent.ACTION_HOVER_MOVE:
+ case MotionEvent.ACTION_MOVE:
+ x = event.getX(0);
+ y = event.getY(0);
+ SDLActivity.onNativeMouse(0, action, x, y, true);
+ return true;
+
+ case MotionEvent.ACTION_BUTTON_PRESS:
+ case MotionEvent.ACTION_BUTTON_RELEASE:
+
+ // Change our action value to what SDL's code expects.
+ if (action == MotionEvent.ACTION_BUTTON_PRESS) {
+ action = MotionEvent.ACTION_DOWN;
+ }
+ else if (action == MotionEvent.ACTION_BUTTON_RELEASE) {
+ action = MotionEvent.ACTION_UP;
+ }
+
+ x = event.getX(0);
+ y = event.getY(0);
+ int button = event.getButtonState();
+
+ SDLActivity.onNativeMouse(button, action, x, y, true);
+ return true;
+ }
+
+ return false;
+ }
+
}
/* This is a fake invisible editor view that receives the input and defines the
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
index bd6a2ad..3e1e40f 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
@@ -749,7 +749,7 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
@Override
public boolean supportsRelativeMouse() {
- return true;
+ return !SDLActivity.isDeXMode();
}
@Override
@@ -759,20 +759,26 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
@Override
public boolean setRelativeMouseEnabled(boolean enabled) {
- if (enabled) {
- SDLActivity.getContentView().requestPointerCapture();
+ if (!SDLActivity.isDeXMode()) {
+ if (enabled) {
+ SDLActivity.getContentView().requestPointerCapture();
+ }
+ else {
+ SDLActivity.getContentView().releasePointerCapture();
+ }
+ mRelativeModeEnabled = enabled;
+ return true;
}
- else {
- SDLActivity.getContentView().releasePointerCapture();
+ else
+ {
+ return false;
}
- mRelativeModeEnabled = enabled;
- return true;
}
@Override
public void reclaimRelativeMouseModeIfNeeded()
{
- if (mRelativeModeEnabled) {
+ if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) {
SDLActivity.getContentView().requestPointerCapture();
}
}
@@ -788,51 +794,4 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
// Relative mouse in capture mode will only have relative for X/Y
return event.getY(0);
}
-}
-
-class SDLCapturedPointerListener_API26 implements View.OnCapturedPointerListener
-{
- @Override
- public boolean onCapturedPointer(View view, MotionEvent event)
- {
- int action = event.getActionMasked();
-
- float x, y;
- switch (action) {
- case MotionEvent.ACTION_SCROLL:
- x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
- y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
- SDLActivity.onNativeMouse(0, action, x, y, false);
- return true;
-
- case MotionEvent.ACTION_HOVER_MOVE:
- case MotionEvent.ACTION_MOVE:
- x = event.getX(0);
- y = event.getY(0);
- SDLActivity.onNativeMouse(0, action, x, y, true);
- return true;
-
- case MotionEvent.ACTION_BUTTON_PRESS:
- case MotionEvent.ACTION_BUTTON_RELEASE:
-
- // Change our action value to what SDL's code expects.
- if (action == MotionEvent.ACTION_BUTTON_PRESS) {
- action = MotionEvent.ACTION_DOWN;
- }
- else if (action == MotionEvent.ACTION_BUTTON_RELEASE) {
- action = MotionEvent.ACTION_UP;
- }
-
- x = event.getX(0);
- y = event.getY(0);
- int button = event.getButtonState();
-
- SDLActivity.onNativeMouse(button, action, x, y, true);
- return true;
-
- }
-
- return false;
- }
-}
-
+}
\ No newline at end of file