java: updated sdl files to 2.0.10 version

This commit is contained in:
rafal1137 2019-08-04 14:32:47 +02:00
parent def9eccd9d
commit 7f6d4c2ec8
5 changed files with 374 additions and 326 deletions

View file

@ -12,12 +12,11 @@ import android.bluetooth.BluetoothGattService;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.os.*;
//import com.android.internal.util.HexDump; //import com.android.internal.util.HexDump;
import java.lang.Runnable; import java.lang.Runnable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.UUID; import java.util.UUID;
@ -186,10 +185,13 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
// Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead // Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
// of TRANSPORT_LE. Let's force ourselves to connect low energy. // of TRANSPORT_LE. Let's force ourselves to connect low energy.
private BluetoothGatt connectGatt(boolean managed) { private BluetoothGatt connectGatt(boolean managed) {
try { if (Build.VERSION.SDK_INT >= 23) {
Method m = mDevice.getClass().getDeclaredMethod("connectGatt", Context.class, boolean.class, BluetoothGattCallback.class, int.class); try {
return (BluetoothGatt) m.invoke(mDevice, mManager.getContext(), managed, this, TRANSPORT_LE); return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE);
} catch (Exception e) { } catch (Exception e) {
return mDevice.connectGatt(mManager.getContext(), managed, this);
}
} else {
return mDevice.connectGatt(mManager.getContext(), managed, this); return mDevice.connectGatt(mManager.getContext(), managed, this);
} }
} }

View file

@ -411,7 +411,7 @@ public class HIDDeviceManager {
if (mIsChromebook) { if (mIsChromebook) {
mHandler = new Handler(Looper.getMainLooper()); mHandler = new Handler(Looper.getMainLooper());
mLastBluetoothDevices = new ArrayList<>(); mLastBluetoothDevices = new ArrayList<BluetoothDevice>();
// final HIDDeviceManager finalThis = this; // final HIDDeviceManager finalThis = this;
// mHandler.postDelayed(new Runnable() { // mHandler.postDelayed(new Runnable() {
@ -439,8 +439,8 @@ public class HIDDeviceManager {
return; return;
} }
ArrayList<BluetoothDevice> disconnected = new ArrayList<>(); ArrayList<BluetoothDevice> disconnected = new ArrayList<BluetoothDevice>();
ArrayList<BluetoothDevice> connected = new ArrayList<>(); ArrayList<BluetoothDevice> connected = new ArrayList<BluetoothDevice>();
List<BluetoothDevice> currentConnected = mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT); List<BluetoothDevice> currentConnected = mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT);

View file

@ -37,7 +37,8 @@ import android.content.pm.ApplicationInfo;
public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener { public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
private static final String TAG = "SDL"; private static final String TAG = "SDL";
public static boolean mIsResumedCalled, mIsSurfaceReady, mHasFocus; public static boolean mIsResumedCalled, mHasFocus;
public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24);
// Cursor types // Cursor types
private static final int SDL_SYSTEM_CURSOR_NONE = -1; private static final int SDL_SYSTEM_CURSOR_NONE = -1;
@ -70,15 +71,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
public static NativeState mNextNativeState; public static NativeState mNextNativeState;
public static NativeState mCurrentNativeState; public static NativeState mCurrentNativeState;
public static boolean mExitCalledFromJava;
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */ /** If shared libraries (e.g. SDL or the native application) could not be loaded. */
public static boolean mBrokenLibraries; public static boolean mBrokenLibraries;
// If we want to separate mouse and touch events.
// This is only toggled in native code when a hint is set!
public static boolean mSeparateMouseAndTouch;
// Main components // Main components
protected static SDLActivity mSingleton; protected static SDLActivity mSingleton;
protected static SDLSurface mSurface; protected static SDLSurface mSurface;
@ -86,7 +81,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
protected static boolean mScreenKeyboardShown; protected static boolean mScreenKeyboardShown;
protected static ViewGroup mLayout; protected static ViewGroup mLayout;
protected static SDLClipboardHandler mClipboardHandler; protected static SDLClipboardHandler mClipboardHandler;
protected static Hashtable<Integer, Object> mCursors; protected static Hashtable<Integer, PointerIcon> mCursors;
protected static int mLastCursorID; protected static int mLastCursorID;
protected static SDLGenericMotionListener_API12 mMotionListener; protected static SDLGenericMotionListener_API12 mMotionListener;
protected static HIDDeviceManager mHIDDeviceManager; protected static HIDDeviceManager mHIDDeviceManager;
@ -142,6 +137,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
*/ */
protected String[] getLibraries() { protected String[] getLibraries() {
return new String[] { return new String[] {
"hidapi",
"SDL2", "SDL2",
// "SDL2_image", // "SDL2_image",
// "SDL2_mixer", // "SDL2_mixer",
@ -176,13 +172,11 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
mTextEdit = null; mTextEdit = null;
mLayout = null; mLayout = null;
mClipboardHandler = null; mClipboardHandler = null;
mCursors = new Hashtable<Integer, Object>(); mCursors = new Hashtable<Integer, PointerIcon>();
mLastCursorID = 0; mLastCursorID = 0;
mSDLThread = null; mSDLThread = null;
mExitCalledFromJava = false;
mBrokenLibraries = false; mBrokenLibraries = false;
mIsResumedCalled = false; mIsResumedCalled = false;
mIsSurfaceReady = false;
mHasFocus = true; mHasFocus = true;
mNextNativeState = NativeState.INIT; mNextNativeState = NativeState.INIT;
mCurrentNativeState = NativeState.INIT; mCurrentNativeState = NativeState.INIT;
@ -196,6 +190,12 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
Log.v(TAG, "onCreate()"); Log.v(TAG, "onCreate()");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
try {
Thread.currentThread().setName("SDLActivity");
} catch (Exception e) {
Log.v(TAG, "modify thread properties failed " + e.toString());
}
// Load shared libraries // Load shared libraries
String errorMsgBrokenLib = ""; String errorMsgBrokenLib = "";
try { try {
@ -243,12 +243,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
mSingleton = this; mSingleton = this;
SDL.setContext(this); SDL.setContext(this);
if (Build.VERSION.SDK_INT >= 11) { mClipboardHandler = new SDLClipboardHandler_API11();
mClipboardHandler = new SDLClipboardHandler_API11();
} else {
/* Before API 11, no clipboard notification (eg no SDL_CLIPBOARDUPDATE) */
mClipboardHandler = new SDLClipboardHandler_Old();
}
mHIDDeviceManager = HIDDeviceManager.acquire(this); mHIDDeviceManager = HIDDeviceManager.acquire(this);
@ -260,6 +255,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
// Get our current screen orientation and pass it down. // Get our current screen orientation and pass it down.
mCurrentOrientation = SDLActivity.getCurrentOrientation(); mCurrentOrientation = SDLActivity.getCurrentOrientation();
// Only record current orientation
SDLActivity.onNativeOrientationChanged(mCurrentOrientation); SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
setContentView(mLayout); setContentView(mLayout);
@ -279,16 +275,12 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
} }
} }
// Events protected void pauseNativeThread() {
@Override
protected void onPause() {
Log.v(TAG, "onPause()");
super.onPause();
mNextNativeState = NativeState.PAUSED; mNextNativeState = NativeState.PAUSED;
mIsResumedCalled = false; mIsResumedCalled = false;
if (SDLActivity.mBrokenLibraries) { if (SDLActivity.mBrokenLibraries) {
return; return;
} }
if (mHIDDeviceManager != null) { if (mHIDDeviceManager != null) {
@ -298,10 +290,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
SDLActivity.handleNativeState(); SDLActivity.handleNativeState();
} }
@Override protected void resumeNativeThread() {
protected void onResume() {
Log.v(TAG, "onResume()");
super.onResume();
mNextNativeState = NativeState.RESUMED; mNextNativeState = NativeState.RESUMED;
mIsResumedCalled = true; mIsResumedCalled = true;
@ -316,6 +305,43 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
SDLActivity.handleNativeState(); SDLActivity.handleNativeState();
} }
// Events
@Override
protected void onPause() {
Log.v(TAG, "onPause()");
super.onPause();
if (!mHasMultiWindow) {
pauseNativeThread();
}
}
@Override
protected void onResume() {
Log.v(TAG, "onResume()");
super.onResume();
if (!mHasMultiWindow) {
resumeNativeThread();
}
}
@Override
protected void onStop() {
Log.v(TAG, "onStop()");
super.onStop();
if (mHasMultiWindow) {
pauseNativeThread();
}
}
@Override
protected void onStart() {
Log.v(TAG, "onStart()");
super.onStart();
if (mHasMultiWindow) {
resumeNativeThread();
}
}
public static int getCurrentOrientation() { public static int getCurrentOrientation() {
final Context context = SDLActivity.getContext(); final Context context = SDLActivity.getContext();
final Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); final Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
@ -352,15 +378,21 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
return; return;
} }
SDLActivity.mHasFocus = hasFocus; mHasFocus = hasFocus;
if (hasFocus) { if (hasFocus) {
mNextNativeState = NativeState.RESUMED; mNextNativeState = NativeState.RESUMED;
SDLActivity.getMotionListener().reclaimRelativeMouseModeIfNeeded(); SDLActivity.getMotionListener().reclaimRelativeMouseModeIfNeeded();
} else {
mNextNativeState = NativeState.PAUSED;
}
SDLActivity.handleNativeState(); SDLActivity.handleNativeState();
nativeFocusChanged(true);
} else {
nativeFocusChanged(false);
if (!mHasMultiWindow) {
mNextNativeState = NativeState.PAUSED;
SDLActivity.handleNativeState();
}
}
} }
@Override @Override
@ -386,34 +418,25 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
if (SDLActivity.mBrokenLibraries) { if (SDLActivity.mBrokenLibraries) {
super.onDestroy(); super.onDestroy();
// Reset everything in case the user re opens the app
SDLActivity.initialize();
return; return;
} }
mNextNativeState = NativeState.PAUSED;
SDLActivity.handleNativeState();
// Send a quit message to the application
SDLActivity.mExitCalledFromJava = true;
SDLActivity.nativeQuit();
// Now wait for the SDL thread to quit
if (SDLActivity.mSDLThread != null) { if (SDLActivity.mSDLThread != null) {
// Send Quit event to "SDLThread" thread
SDLActivity.nativeSendQuit();
// Wait for "SDLThread" thread to end
try { try {
SDLActivity.mSDLThread.join(); SDLActivity.mSDLThread.join();
} catch(Exception e) { } catch(Exception e) {
Log.v(TAG, "Problem stopping thread: " + e); Log.v(TAG, "Problem stopping SDLThread: " + e);
} }
SDLActivity.mSDLThread = null;
//Log.v(TAG, "Finished waiting for SDL thread");
} }
super.onDestroy(); SDLActivity.nativeQuit();
// Reset everything in case the user re opens the app super.onDestroy();
SDLActivity.initialize();
} }
@Override @Override
@ -490,16 +513,19 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
// Try a transition to paused state // Try a transition to paused state
if (mNextNativeState == NativeState.PAUSED) { if (mNextNativeState == NativeState.PAUSED) {
nativePause(); if (mSDLThread != null) {
if (mSurface != null) nativePause();
}
if (mSurface != null) {
mSurface.handlePause(); mSurface.handlePause();
}
mCurrentNativeState = mNextNativeState; mCurrentNativeState = mNextNativeState;
return; return;
} }
// Try a transition to resumed state // Try a transition to resumed state
if (mNextNativeState == NativeState.RESUMED) { if (mNextNativeState == NativeState.RESUMED) {
if (mIsSurfaceReady && mHasFocus && mIsResumedCalled) { if (mSurface.mIsSurfaceReady && mHasFocus && mIsResumedCalled) {
if (mSDLThread == null) { if (mSDLThread == null) {
// This is the entry point to the C app. // This is the entry point to the C app.
// Start up the C app thread and enable sensor input for the first time // Start up the C app thread and enable sensor input for the first time
@ -508,28 +534,24 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
mSDLThread = new Thread(new SDLMain(), "SDLThread"); mSDLThread = new Thread(new SDLMain(), "SDLThread");
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
mSDLThread.start(); mSDLThread.start();
// No nativeResume(), don't signal Android_ResumeSem
mSurface.handleResume();
} else {
nativeResume();
mSurface.handleResume();
} }
nativeResume();
mSurface.handleResume();
mCurrentNativeState = mNextNativeState; mCurrentNativeState = mNextNativeState;
} }
} }
} }
/* The native thread has finished */
public static void handleNativeExit() {
SDLActivity.mSDLThread = null;
if (mSingleton != null) {
mSingleton.finish();
}
}
// Messages from the SDLMain thread // Messages from the SDLMain thread
static final int COMMAND_CHANGE_TITLE = 1; static final int COMMAND_CHANGE_TITLE = 1;
static final int COMMAND_CHANGE_WINDOW_STYLE = 2; static final int COMMAND_CHANGE_WINDOW_STYLE = 2;
static final int COMMAND_TEXTEDIT_HIDE = 3; static final int COMMAND_TEXTEDIT_HIDE = 3;
static final int COMMAND_CHANGE_SURFACEVIEW_FORMAT = 4;
static final int COMMAND_SET_KEEP_SCREEN_ON = 5; static final int COMMAND_SET_KEEP_SCREEN_ON = 5;
protected static final int COMMAND_USER = 0x8000; protected static final int COMMAND_USER = 0x8000;
@ -627,6 +649,32 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
} }
break; break;
} }
case COMMAND_CHANGE_SURFACEVIEW_FORMAT:
{
int format = (Integer) msg.obj;
int pf;
if (SDLActivity.mSurface == null) {
return;
}
SurfaceHolder holder = SDLActivity.mSurface.getHolder();
if (holder == null) {
return;
}
if (format == 1) {
pf = PixelFormat.RGBA_8888;
} else if (format == 2) {
pf = PixelFormat.RGBX_8888;
} else {
pf = PixelFormat.RGB_565;
}
holder.setFormat(pf);
break;
}
default: default:
if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) { if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
Log.e(TAG, "error handling message, command is " + msg.arg1); Log.e(TAG, "error handling message, command is " + msg.arg1);
@ -704,13 +752,17 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
public static native int nativeSetupJNI(); public static native int nativeSetupJNI();
public static native int nativeRunMain(String library, String function, Object arguments); public static native int nativeRunMain(String library, String function, Object arguments);
public static native void nativeLowMemory(); public static native void nativeLowMemory();
public static native void nativeSendQuit();
public static native void nativeQuit(); public static native void nativeQuit();
public static native void nativePause(); public static native void nativePause();
public static native void nativeResume(); public static native void nativeResume();
public static native void nativeFocusChanged(boolean hasFocus);
public static native void onNativeDropFile(String filename); public static native void onNativeDropFile(String filename);
public static native void onNativeResize(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, int format, float rate); public static native void nativeSetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, int format, float rate);
public static native void onNativeResize();
public static native void onNativeKeyDown(int keycode); public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode); public static native void onNativeKeyUp(int keycode);
public static native boolean onNativeSoftReturnKey();
public static native void onNativeKeyboardFocusLost(); public static native void onNativeKeyboardFocusLost();
public static native void onNativeMouse(int button, int action, float x, float y, boolean relative); public static native void onNativeMouse(int button, int action, float x, float y, boolean relative);
public static native void onNativeTouch(int touchDevId, int pointerFingerId, public static native void onNativeTouch(int touchDevId, int pointerFingerId,
@ -718,11 +770,13 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
float y, float p); float y, float p);
public static native void onNativeAccel(float x, float y, float z); public static native void onNativeAccel(float x, float y, float z);
public static native void onNativeClipboardChanged(); public static native void onNativeClipboardChanged();
public static native void onNativeSurfaceCreated();
public static native void onNativeSurfaceChanged(); public static native void onNativeSurfaceChanged();
public static native void onNativeSurfaceDestroyed(); public static native void onNativeSurfaceDestroyed();
public static native String nativeGetHint(String name); public static native String nativeGetHint(String name);
public static native void nativeSetenv(String name, String value); public static native void nativeSetenv(String name, String value);
public static native void onNativeOrientationChanged(int orientation); public static native void onNativeOrientationChanged(int orientation);
public static native void nativeAddTouch(int touchId, String name);
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
@ -792,6 +846,45 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
} }
} }
/**
* This method is called by SDL using JNI.
*/
public static void minimizeWindow() {
if (mSingleton == null) {
return;
}
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mSingleton.startActivity(startMain);
}
/**
* This method is called by SDL using JNI.
*/
public static boolean shouldMinimizeOnFocusLoss() {
/*
if (Build.VERSION.SDK_INT >= 24) {
if (mSingleton == null) {
return true;
}
if (mSingleton.isInMultiWindowMode()) {
return false;
}
if (mSingleton.isInPictureInPictureMode()) {
return false;
}
}
return true;
*/
return false;
}
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
@ -976,6 +1069,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
this.y = y; this.y = y;
this.w = w; this.w = w;
this.h = h; this.h = h;
/* Minimum size of 1 pixel, so it takes focus. */
if (this.w <= 0) {
this.w = 1;
}
if (this.h + HEIGHT_PADDING <= 0) {
this.h = 1 - HEIGHT_PADDING;
}
} }
@Override @Override
@ -1013,10 +1114,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
public static boolean isTextInputEvent(KeyEvent event) { public static boolean isTextInputEvent(KeyEvent event) {
// Key pressed with Ctrl should be sent as SDL_KEYDOWN/SDL_KEYUP and not SDL_TEXTINPUT // Key pressed with Ctrl should be sent as SDL_KEYDOWN/SDL_KEYUP and not SDL_TEXTINPUT
if (Build.VERSION.SDK_INT >= 11) { if (event.isCtrlPressed()) {
if (event.isCtrlPressed()) { return false;
return false;
}
} }
return event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE; return event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE;
@ -1032,23 +1131,28 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
return SDLActivity.mSurface.getNativeSurface(); return SDLActivity.mSurface.getNativeSurface();
} }
/**
* This method is called by SDL using JNI.
*/
public static void setSurfaceViewFormat(int format) {
mSingleton.sendCommand(COMMAND_CHANGE_SURFACEVIEW_FORMAT, format);
return;
}
// Input // Input
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
* @return an array which may be empty but is never null.
*/ */
public static int[] inputGetInputDeviceIds(int sources) { public static void initTouch() {
int[] ids = InputDevice.getDeviceIds(); int[] ids = InputDevice.getDeviceIds();
int[] filtered = new int[ids.length];
int used = 0;
for (int i = 0; i < ids.length; ++i) { for (int i = 0; i < ids.length; ++i) {
InputDevice device = InputDevice.getDevice(ids[i]); InputDevice device = InputDevice.getDevice(ids[i]);
if ((device != null) && ((device.getSources() & sources) != 0)) { if (device != null && (device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) != 0) {
filtered[used++] = device.getId(); nativeAddTouch(device.getId(), device.getName());
} }
} }
return Arrays.copyOf(filtered, used);
} }
// APK expansion files support // APK expansion files support
@ -1341,7 +1445,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
}; };
public void onSystemUiVisibilityChange(int visibility) { public void onSystemUiVisibilityChange(int visibility) {
if (SDLActivity.mFullscreenModeActive && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { if (SDLActivity.mFullscreenModeActive && ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0)) {
Handler handler = getWindow().getDecorView().getHandler(); Handler handler = getWindow().getDecorView().getHandler();
if (handler != null) { if (handler != null) {
@ -1379,13 +1483,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
public static int createCustomCursor(int[] colors, int width, int height, int hotSpotX, int hotSpotY) { public static int createCustomCursor(int[] colors, int width, int height, int hotSpotX, int hotSpotY) {
Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888); Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
++mLastCursorID; ++mLastCursorID;
// This requires API 24, so use reflection to implement this
try { if (Build.VERSION.SDK_INT >= 24) {
Class PointerIconClass = Class.forName("android.view.PointerIcon"); try {
Class[] arg_types = new Class[] { Bitmap.class, float.class, float.class }; mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY));
Method create = PointerIconClass.getMethod("create", arg_types); } catch (Exception e) {
mCursors.put(mLastCursorID, create.invoke(null, bitmap, hotSpotX, hotSpotY)); return 0;
} catch (Exception e) { }
} else {
return 0; return 0;
} }
return mLastCursorID; return mLastCursorID;
@ -1395,12 +1500,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static boolean setCustomCursor(int cursorID) { public static boolean setCustomCursor(int cursorID) {
// This requires API 24, so use reflection to implement this
try { if (Build.VERSION.SDK_INT >= 24) {
Class PointerIconClass = Class.forName("android.view.PointerIcon"); try {
Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass); mSurface.setPointerIcon(mCursors.get(cursorID));
setPointerIcon.invoke(mSurface, mCursors.get(cursorID)); } catch (Exception e) {
} catch (Exception e) { return false;
}
} else {
return false; return false;
} }
return true; return true;
@ -1449,15 +1556,12 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
cursor_type = 1002; //PointerIcon.TYPE_HAND; cursor_type = 1002; //PointerIcon.TYPE_HAND;
break; break;
} }
// This requires API 24, so use reflection to implement this if (Build.VERSION.SDK_INT >= 24) {
try { try {
Class PointerIconClass = Class.forName("android.view.PointerIcon"); mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type));
Class[] arg_types = new Class[] { Context.class, int.class }; } catch (Exception e) {
Method getSystemIcon = PointerIconClass.getMethod("getSystemIcon", arg_types); return false;
Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass); }
setPointerIcon.invoke(mSurface, getSystemIcon.invoke(null, SDL.getContext(), cursor_type));
} catch (Exception e) {
return false;
} }
return true; return true;
} }
@ -1474,14 +1578,24 @@ class SDLMain implements Runnable {
String function = SDLActivity.mSingleton.getMainFunction(); String function = SDLActivity.mSingleton.getMainFunction();
String[] arguments = SDLActivity.mSingleton.getArguments(); String[] arguments = SDLActivity.mSingleton.getArguments();
try {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
} catch (Exception e) {
Log.v("SDL", "modify thread properties failed " + e.toString());
}
Log.v("SDL", "Running main function " + function + " from library " + library); Log.v("SDL", "Running main function " + function + " from library " + library);
SDLActivity.nativeRunMain(library, function, arguments); SDLActivity.nativeRunMain(library, function, arguments);
Log.v("SDL", "Finished main function"); Log.v("SDL", "Finished main function");
// Native thread has finished, let's finish the Activity if (SDLActivity.mSingleton.isFinishing()) {
if (!SDLActivity.mExitCalledFromJava) { // Activity is already being destroyed
SDLActivity.handleNativeExit(); } else {
// Let's finish the Activity
SDLActivity.mSDLThread = null;
SDLActivity.mSingleton.finish();
} }
} }
} }
@ -1497,11 +1611,14 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
View.OnKeyListener, View.OnTouchListener, SensorEventListener { View.OnKeyListener, View.OnTouchListener, SensorEventListener {
// Sensors // Sensors
protected static SensorManager mSensorManager; protected SensorManager mSensorManager;
protected static Display mDisplay; protected Display mDisplay;
// Keep track of the surface size to normalize touch events // Keep track of the surface size to normalize touch events
protected static float mWidth, mHeight; protected float mWidth, mHeight;
// Is SurfaceView ready for rendering
public boolean mIsSurfaceReady;
// Startup // Startup
public SDLSurface(Context context) { public SDLSurface(Context context) {
@ -1517,13 +1634,13 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
if (Build.VERSION.SDK_INT >= 12) { setOnGenericMotionListener(SDLActivity.getMotionListener());
setOnGenericMotionListener(SDLActivity.getMotionListener());
}
// Some arbitrary defaults to avoid a potential division by zero // Some arbitrary defaults to avoid a potential division by zero
mWidth = 1.0f; mWidth = 1.0f;
mHeight = 1.0f; mHeight = 1.0f;
mIsSurfaceReady = false;
} }
public void handlePause() { public void handlePause() {
@ -1547,7 +1664,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
Log.v("SDL", "surfaceCreated()"); Log.v("SDL", "surfaceCreated()");
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); SDLActivity.onNativeSurfaceCreated();
} }
// Called when we lose the surface // Called when we lose the surface
@ -1559,7 +1676,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED; SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED;
SDLActivity.handleNativeState(); SDLActivity.handleNativeState();
SDLActivity.mIsSurfaceReady = false; mIsSurfaceReady = false;
SDLActivity.onNativeSurfaceDestroyed(); SDLActivity.onNativeSurfaceDestroyed();
} }
@ -1575,23 +1692,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default
switch (format) { switch (format) {
case PixelFormat.A_8:
Log.v("SDL", "pixel format A_8");
break;
case PixelFormat.LA_88:
Log.v("SDL", "pixel format LA_88");
break;
case PixelFormat.L_8:
Log.v("SDL", "pixel format L_8");
break;
case PixelFormat.RGBA_4444:
Log.v("SDL", "pixel format RGBA_4444");
sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444
break;
case PixelFormat.RGBA_5551:
Log.v("SDL", "pixel format RGBA_5551");
sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551
break;
case PixelFormat.RGBA_8888: case PixelFormat.RGBA_8888:
Log.v("SDL", "pixel format RGBA_8888"); Log.v("SDL", "pixel format RGBA_8888");
sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888 sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888
@ -1600,10 +1700,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
Log.v("SDL", "pixel format RGBX_8888"); Log.v("SDL", "pixel format RGBX_8888");
sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888 sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888
break; break;
case PixelFormat.RGB_332:
Log.v("SDL", "pixel format RGB_332");
sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332
break;
case PixelFormat.RGB_565: case PixelFormat.RGB_565:
Log.v("SDL", "pixel format RGB_565"); Log.v("SDL", "pixel format RGB_565");
sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565
@ -1640,8 +1736,11 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
Log.v("SDL", "Window size: " + width + "x" + height); Log.v("SDL", "Window size: " + width + "x" + height);
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight); Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
SDLActivity.onNativeResize(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate()); SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate());
SDLActivity.onNativeResize();
// Prevent a screen distortion glitch,
// for instance when the device is in Landscape and a Portrait App is resumed.
boolean skip = false; boolean skip = false;
int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation(); int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
@ -1671,24 +1770,39 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
} }
} }
// Don't skip in MultiWindow.
if (skip) { if (skip) {
Log.v("SDL", "Skip .. Surface is not ready."); if (Build.VERSION.SDK_INT >= 24) {
SDLActivity.mIsSurfaceReady = false; if (SDLActivity.mSingleton.isInMultiWindowMode()) {
return; Log.v("SDL", "Don't skip in Multi-Window");
skip = false;
}
}
} }
/* Surface is ready */ if (skip) {
SDLActivity.mIsSurfaceReady = true; Log.v("SDL", "Skip .. Surface is not ready.");
mIsSurfaceReady = false;
return;
}
/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */ /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
SDLActivity.onNativeSurfaceChanged(); SDLActivity.onNativeSurfaceChanged();
/* Surface is ready */
mIsSurfaceReady = true;
SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED;
SDLActivity.handleNativeState(); SDLActivity.handleNativeState();
} }
// Key events // Key events
@Override @Override
public boolean onKey(View v, int keyCode, KeyEvent event) { public boolean onKey(View v, int keyCode, KeyEvent event) {
int deviceId = event.getDeviceId();
int source = event.getSource();
// Dispatch the different events depending on where they come from // Dispatch the different events depending on where they come from
// Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
// So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
@ -1696,20 +1810,25 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// Furthermore, it's possible a game controller has SOURCE_KEYBOARD and // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
// SOURCE_JOYSTICK, while its key events arrive from the keyboard source // SOURCE_JOYSTICK, while its key events arrive from the keyboard source
// So, retrieve the device itself and check all of its sources // So, retrieve the device itself and check all of its sources
if (SDLControllerManager.isDeviceSDLJoystick(event.getDeviceId())) { if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) {
// Note that we process events with specific key codes here // Note that we process events with specific key codes here
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (SDLControllerManager.onNativePadDown(event.getDeviceId(), keyCode) == 0) { if (SDLControllerManager.onNativePadDown(deviceId, keyCode) == 0) {
return true; return true;
} }
} else if (event.getAction() == KeyEvent.ACTION_UP) { } else if (event.getAction() == KeyEvent.ACTION_UP) {
if (SDLControllerManager.onNativePadUp(event.getDeviceId(), keyCode) == 0) { if (SDLControllerManager.onNativePadUp(deviceId, keyCode) == 0) {
return true; return true;
} }
} }
} }
if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) { if (source == InputDevice.SOURCE_UNKNOWN) {
InputDevice device = InputDevice.getDevice(deviceId);
source = device.getSources();
}
if ((source & InputDevice.SOURCE_KEYBOARD) != 0) {
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
//Log.v("SDL", "key down: " + keyCode); //Log.v("SDL", "key down: " + keyCode);
if (SDLActivity.isTextInputEvent(event)) { if (SDLActivity.isTextInputEvent(event)) {
@ -1725,7 +1844,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
} }
} }
if ((event.getSource() & InputDevice.SOURCE_MOUSE) != 0) { if ((source & InputDevice.SOURCE_MOUSE) != 0) {
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
// they are ignored here because sending them as mouse input to SDL is messy // they are ignored here because sending them as mouse input to SDL is messy
if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
@ -1754,17 +1873,14 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
int i = -1; int i = -1;
float x,y,p; float x,y,p;
// !!! FIXME: dump this SDK check after 2.0.4 ships and require API14.
// 12290 = Samsung DeX mode desktop mouse // 12290 = Samsung DeX mode desktop mouse
if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == 12290) && SDLActivity.mSeparateMouseAndTouch) { // 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
if (Build.VERSION.SDK_INT < 14) { // 0x2 = SOURCE_CLASS_POINTER
mouseButton = 1; // all mouse buttons are the left button if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) {
} else { try {
try { mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event); } catch(Exception e) {
} catch(Exception e) { mouseButton = 1; // oh well.
mouseButton = 1; // oh well.
}
} }
// We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values // We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values
@ -1876,8 +1992,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE_FLIPPED; newOrientation = SDLActivity.SDL_ORIENTATION_LANDSCAPE_FLIPPED;
break; break;
case Surface.ROTATION_180: case Surface.ROTATION_180:
x = -event.values[1]; x = -event.values[0];
y = -event.values[0]; y = -event.values[1];
newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT_FLIPPED; newOrientation = SDLActivity.SDL_ORIENTATION_PORTRAIT_FLIPPED;
break; break;
default: default:
@ -2032,14 +2148,8 @@ class SDLInputConnection extends BaseInputConnection {
*/ */
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
String imeHide = SDLActivity.nativeGetHint("SDL_RETURN_KEY_HIDES_IME"); if (SDLActivity.onNativeSoftReturnKey()) {
if ((imeHide != null) && imeHide.equals("1")) { return true;
Context c = SDL.getContext();
if (c instanceof SDLActivity) {
SDLActivity activity = (SDLActivity)c;
activity.sendCommand(SDLActivity.COMMAND_TEXTEDIT_HIDE, null);
return true;
}
} }
} }
@ -2052,6 +2162,11 @@ class SDLInputConnection extends BaseInputConnection {
for (int i = 0; i < text.length(); i++) { for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i); char c = text.charAt(i);
if (c == '\n') {
if (SDLActivity.onNativeSoftReturnKey()) {
return true;
}
}
nativeGenerateScancodeForUnichar(c); nativeGenerateScancodeForUnichar(c);
} }
@ -2142,33 +2257,3 @@ class SDLClipboardHandler_API11 implements
} }
class SDLClipboardHandler_Old implements
SDLClipboardHandler {
protected android.text.ClipboardManager mClipMgrOld;
SDLClipboardHandler_Old() {
mClipMgrOld = (android.text.ClipboardManager) SDL.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
}
@Override
public boolean clipboardHasText() {
return mClipMgrOld.hasText();
}
@Override
public String clipboardGetText() {
CharSequence text;
text = mClipMgrOld.getText();
if (text != null) {
return text.toString();
}
return null;
}
@Override
public void clipboardSetText(String string) {
mClipMgrOld.setText(string);
}
}

View file

@ -364,5 +364,24 @@ public class SDLAudioManager
} }
} }
/** This method is called by SDL using JNI. */
public static void audioSetThreadPriority(boolean iscapture, int device_id) {
try {
/* Set thread name */
if (iscapture) {
Thread.currentThread().setName("SDLAudioC" + device_id);
} else {
Thread.currentThread().setName("SDLAudioP" + device_id);
}
/* Set thread priority */
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
} catch (Exception e) {
Log.v(TAG, "modify thread properties failed " + e.toString());
}
}
public static native int nativeSetupJNI(); public static native int nativeSetupJNI();
} }

View file

@ -39,12 +39,8 @@ public class SDLControllerManager
if (mJoystickHandler == null) { if (mJoystickHandler == null) {
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19) {
mJoystickHandler = new SDLJoystickHandler_API19(); mJoystickHandler = new SDLJoystickHandler_API19();
} else if (Build.VERSION.SDK_INT >= 16) {
mJoystickHandler = new SDLJoystickHandler_API16();
} else if (Build.VERSION.SDK_INT >= 12) {
mJoystickHandler = new SDLJoystickHandler_API12();
} else { } else {
mJoystickHandler = new SDLJoystickHandler(); mJoystickHandler = new SDLJoystickHandler_API16();
} }
} }
@ -103,8 +99,8 @@ public class SDLControllerManager
/* This is called for every button press, so let's not spam the logs */ /* This is called for every button press, so let's not spam the logs */
/** /**
if ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) { if ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
Log.v(TAG, "Input device " + device.getName() + " is a joystick."); Log.v(TAG, "Input device " + device.getName() + " has class joystick.");
} }
if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) { if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) {
Log.v(TAG, "Input device " + device.getName() + " is a dpad."); Log.v(TAG, "Input device " + device.getName() + " is a dpad.");
@ -114,7 +110,7 @@ public class SDLControllerManager
} }
**/ **/
return (((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) || return ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 ||
((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) || ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
); );
@ -122,7 +118,6 @@ public class SDLControllerManager
} }
/* A null joystick handler for API level < 12 devices (the accelerometer is handled separately) */
class SDLJoystickHandler { class SDLJoystickHandler {
/** /**
@ -142,7 +137,7 @@ class SDLJoystickHandler {
} }
/* Actual joystick functionality available for API >= 12 devices */ /* Actual joystick functionality available for API >= 12 devices */
class SDLJoystickHandler_API12 extends SDLJoystickHandler { class SDLJoystickHandler_API16 extends SDLJoystickHandler {
static class SDLJoystick { static class SDLJoystick {
public int device_id; public int device_id;
@ -174,7 +169,7 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
private ArrayList<SDLJoystick> mJoysticks; private ArrayList<SDLJoystick> mJoysticks;
public SDLJoystickHandler_API12() { public SDLJoystickHandler_API16() {
mJoysticks = new ArrayList<SDLJoystick>(); mJoysticks = new ArrayList<SDLJoystick>();
} }
@ -278,6 +273,12 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
} }
public String getJoystickDescriptor(InputDevice joystickDevice) { public String getJoystickDescriptor(InputDevice joystickDevice) {
String desc = joystickDevice.getDescriptor();
if (desc != null && !desc.isEmpty()) {
return desc;
}
return joystickDevice.getName(); return joystickDevice.getName();
} }
public int getProductId(InputDevice joystickDevice) { public int getProductId(InputDevice joystickDevice) {
@ -291,20 +292,6 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
} }
} }
class SDLJoystickHandler_API16 extends SDLJoystickHandler_API12 {
@Override
public String getJoystickDescriptor(InputDevice joystickDevice) {
String desc = joystickDevice.getDescriptor();
if (desc != null && !desc.isEmpty()) {
return desc;
}
return super.getJoystickDescriptor(joystickDevice);
}
}
class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 { class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 {
@Override @Override
@ -482,21 +469,18 @@ class SDLHapticHandler {
// so the first controller seen by SDL matches what the receiver // so the first controller seen by SDL matches what the receiver
// considers to be the first controller // considers to be the first controller
if (Build.VERSION.SDK_INT >= 16) for (int i = deviceIds.length - 1; i > -1; i--) {
{ SDLHaptic haptic = getHaptic(deviceIds[i]);
for (int i = deviceIds.length - 1; i > -1; i--) { if (haptic == null) {
SDLHaptic haptic = getHaptic(deviceIds[i]); InputDevice device = InputDevice.getDevice(deviceIds[i]);
if (haptic == null) { Vibrator vib = device.getVibrator();
InputDevice device = InputDevice.getDevice(deviceIds[i]); if (vib.hasVibrator()) {
Vibrator vib = device.getVibrator(); haptic = new SDLHaptic();
if (vib.hasVibrator()) { haptic.device_id = deviceIds[i];
haptic = new SDLHaptic(); haptic.name = device.getName();
haptic.device_id = deviceIds[i]; haptic.vib = vib;
haptic.name = device.getName(); mHaptics.add(haptic);
haptic.vib = vib; SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
mHaptics.add(haptic);
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
}
} }
} }
} }
@ -504,11 +488,7 @@ class SDLHapticHandler {
/* Check VIBRATOR_SERVICE */ /* Check VIBRATOR_SERVICE */
Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE); Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
if (vib != null) { if (vib != null) {
if (Build.VERSION.SDK_INT >= 11) { hasVibratorService = vib.hasVibrator();
hasVibratorService = vib.hasVibrator();
} else {
hasVibratorService = true;
}
if (hasVibratorService) { if (hasVibratorService) {
SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE); SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
@ -575,9 +555,6 @@ class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener {
return SDLControllerManager.handleJoystickMotionEvent(event); return SDLControllerManager.handleJoystickMotionEvent(event);
case InputDevice.SOURCE_MOUSE: case InputDevice.SOURCE_MOUSE:
if (!SDLActivity.mSeparateMouseAndTouch) {
break;
}
action = event.getActionMasked(); action = event.getActionMasked();
switch (action) { switch (action) {
case MotionEvent.ACTION_SCROLL: case MotionEvent.ACTION_SCROLL:
@ -640,51 +617,22 @@ class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API12 {
@Override @Override
public boolean onGenericMotion(View v, MotionEvent event) { public boolean onGenericMotion(View v, MotionEvent event) {
float x, y;
int action;
switch ( event.getSource() ) { // Handle relative mouse mode
case InputDevice.SOURCE_JOYSTICK: if (mRelativeModeEnabled) {
case InputDevice.SOURCE_GAMEPAD: if (event.getSource() == InputDevice.SOURCE_MOUSE) {
case InputDevice.SOURCE_DPAD: int action = event.getActionMasked();
return SDLControllerManager.handleJoystickMotionEvent(event); if (action == MotionEvent.ACTION_HOVER_MOVE) {
float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
case InputDevice.SOURCE_MOUSE: float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
if (!SDLActivity.mSeparateMouseAndTouch) { SDLActivity.onNativeMouse(0, action, x, y, true);
break; return true;
} }
action = event.getActionMasked(); }
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:
if (mRelativeModeEnabled) {
x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
}
else {
x = event.getX(0);
y = event.getY(0);
}
SDLActivity.onNativeMouse(0, action, x, y, mRelativeModeEnabled);
return true;
default:
break;
}
break;
default:
break;
} }
// Event was not managed // Event was not managed, call SDLGenericMotionListener_API12 method
return false; return super.onGenericMotion(v, event);
} }
@Override @Override
@ -741,11 +689,8 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
return SDLControllerManager.handleJoystickMotionEvent(event); return SDLControllerManager.handleJoystickMotionEvent(event);
case InputDevice.SOURCE_MOUSE: case InputDevice.SOURCE_MOUSE:
case 12290: // DeX desktop mouse cursor is a separate non-standard input type. // DeX desktop mouse cursor is a separate non-standard input type.
if (!SDLActivity.mSeparateMouseAndTouch) { case InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN:
break;
}
action = event.getActionMasked(); action = event.getActionMasked();
switch (action) { switch (action) {
case MotionEvent.ACTION_SCROLL: case MotionEvent.ACTION_SCROLL:
@ -766,9 +711,6 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
break; break;
case InputDevice.SOURCE_MOUSE_RELATIVE: case InputDevice.SOURCE_MOUSE_RELATIVE:
if (!SDLActivity.mSeparateMouseAndTouch) {
break;
}
action = event.getActionMasked(); action = event.getActionMasked();
switch (action) { switch (action) {
case MotionEvent.ACTION_SCROLL: case MotionEvent.ACTION_SCROLL: