mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-02-06 02:02:09 +08:00
Implement SDL_GetPenDeviceType() for Android
This commit is contained in:
@@ -229,9 +229,11 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
private static SDLFileDialogState mFileDialogState = null;
|
||||
protected static boolean mDispatchingKeyEvent = false;
|
||||
|
||||
protected static SDLGenericMotionListener_API14 getMotionListener() {
|
||||
public static SDLGenericMotionListener_API14 getMotionListener() {
|
||||
if (mMotionListener == null) {
|
||||
if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) {
|
||||
if (Build.VERSION.SDK_INT >= 29 /* Android 10 (Q) */) {
|
||||
mMotionListener = new SDLGenericMotionListener_API29();
|
||||
} else if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) {
|
||||
mMotionListener = new SDLGenericMotionListener_API26();
|
||||
} else if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
||||
mMotionListener = new SDLGenericMotionListener_API24();
|
||||
@@ -1063,7 +1065,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
public static native void onNativeTouch(int touchDevId, int pointerFingerId,
|
||||
int action, float x,
|
||||
float y, float p);
|
||||
public static native void onNativePen(int penId, int button, int action, float x, float y, float p);
|
||||
public static native void onNativePen(int penId, int device_type, int button, int action, float x, float y, float p);
|
||||
public static native void onNativeAccel(float x, float y, float z);
|
||||
public static native void onNativeClipboardChanged();
|
||||
public static native void onNativeSurfaceCreated();
|
||||
|
||||
@@ -646,6 +646,10 @@ class SDLHapticHandler {
|
||||
}
|
||||
|
||||
class SDLGenericMotionListener_API14 implements View.OnGenericMotionListener {
|
||||
protected static final int SDL_PEN_DEVICE_TYPE_UNKNOWN = 0;
|
||||
protected static final int SDL_PEN_DEVICE_TYPE_DIRECT = 1;
|
||||
protected static final int SDL_PEN_DEVICE_TYPE_INDIRECT = 2;
|
||||
|
||||
// Generic Motion (mouse hover, joystick...) events go here
|
||||
@Override
|
||||
public boolean onGenericMotion(View v, MotionEvent event) {
|
||||
@@ -697,7 +701,7 @@ class SDLGenericMotionListener_API14 implements View.OnGenericMotionListener {
|
||||
// BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4, and apply SDL_PEN_INPUT_DOWN/SDL_PEN_INPUT_ERASER_TIP
|
||||
int buttons = (event.getButtonState() >> 4) | (1 << (toolType == MotionEvent.TOOL_TYPE_STYLUS ? 0 : 30));
|
||||
|
||||
SDLActivity.onNativePen(event.getPointerId(i), buttons, action, x, y, p);
|
||||
SDLActivity.onNativePen(event.getPointerId(i), getPenDeviceType(event.getDevice()), buttons, action, x, y, p);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
@@ -735,6 +739,9 @@ class SDLGenericMotionListener_API14 implements View.OnGenericMotionListener {
|
||||
return event.getY(pointerIndex);
|
||||
}
|
||||
|
||||
int getPenDeviceType(InputDevice penDevice) {
|
||||
return SDL_PEN_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API14 {
|
||||
@@ -856,3 +863,15 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
|
||||
return event.getY(pointerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
class SDLGenericMotionListener_API29 extends SDLGenericMotionListener_API26 {
|
||||
@Override
|
||||
int getPenDeviceType(InputDevice penDevice)
|
||||
{
|
||||
if (penDevice == null) {
|
||||
return SDL_PEN_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
return penDevice.isExternal() ? SDL_PEN_DEVICE_TYPE_INDIRECT : SDL_PEN_DEVICE_TYPE_DIRECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||
// BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4, and apply SDL_PEN_INPUT_DOWN/SDL_PEN_INPUT_ERASER_TIP
|
||||
int buttonState = (event.getButtonState() >> 4) | (1 << (toolType == MotionEvent.TOOL_TYPE_STYLUS ? 0 : 30));
|
||||
|
||||
SDLActivity.onNativePen(pointerId, buttonState, action, x, y, p);
|
||||
SDLActivity.onNativePen(pointerId, SDLActivity.getMotionListener().getPenDeviceType(event.getDevice()), buttonState, action, x, y, p);
|
||||
} else { // MotionEvent.TOOL_TYPE_FINGER or MotionEvent.TOOL_TYPE_UNKNOWN
|
||||
pointerId = event.getPointerId(i);
|
||||
x = getNormalizedX(event.getX(i));
|
||||
|
||||
Reference in New Issue
Block a user