|
@@ -37,7 +37,7 @@ import android.content.pm.ApplicationInfo;
|
|
|
public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
|
|
|
private static final String TAG = "SDL";
|
|
|
|
|
|
- public static boolean mIsResumedCalled, mIsSurfaceReady, mHasFocus;
|
|
|
+ public static boolean mIsResumedCalled, mHasFocus;
|
|
|
|
|
|
// Cursor types
|
|
|
private static final int SDL_SYSTEM_CURSOR_NONE = -1;
|
|
@@ -70,8 +70,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
public static NativeState mNextNativeState;
|
|
|
public static NativeState mCurrentNativeState;
|
|
|
|
|
|
- public static boolean mExitCalledFromJava;
|
|
|
-
|
|
|
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
|
|
|
public static boolean mBrokenLibraries;
|
|
|
|
|
@@ -98,7 +96,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
if (mMotionListener == null) {
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
mMotionListener = new SDLGenericMotionListener_API26();
|
|
|
- } else
|
|
|
+ } else
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
mMotionListener = new SDLGenericMotionListener_API24();
|
|
|
} else {
|
|
@@ -179,10 +177,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
mCursors = new Hashtable<Integer, PointerIcon>();
|
|
|
mLastCursorID = 0;
|
|
|
mSDLThread = null;
|
|
|
- mExitCalledFromJava = false;
|
|
|
mBrokenLibraries = false;
|
|
|
mIsResumedCalled = false;
|
|
|
- mIsSurfaceReady = false;
|
|
|
mHasFocus = true;
|
|
|
mNextNativeState = NativeState.INIT;
|
|
|
mCurrentNativeState = NativeState.INIT;
|
|
@@ -196,6 +192,12 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
Log.v(TAG, "onCreate()");
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
+ try {
|
|
|
+ Thread.currentThread().setName("SDLActivity");
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.v(TAG, "modify thread properties failed " + e.toString());
|
|
|
+ }
|
|
|
+
|
|
|
// Load shared libraries
|
|
|
String errorMsgBrokenLib = "";
|
|
|
try {
|
|
@@ -243,12 +245,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
mSingleton = this;
|
|
|
SDL.setContext(this);
|
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= 11) {
|
|
|
- mClipboardHandler = new SDLClipboardHandler_API11();
|
|
|
- } else {
|
|
|
- /* Before API 11, no clipboard notification (eg no SDL_CLIPBOARDUPDATE) */
|
|
|
- mClipboardHandler = new SDLClipboardHandler_Old();
|
|
|
- }
|
|
|
+ mClipboardHandler = new SDLClipboardHandler_API11();
|
|
|
|
|
|
mHIDDeviceManager = HIDDeviceManager.acquire(this);
|
|
|
|
|
@@ -260,6 +257,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
|
|
|
// Get our current screen orientation and pass it down.
|
|
|
mCurrentOrientation = SDLActivity.getCurrentOrientation();
|
|
|
+ // Only record current orientation
|
|
|
SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
|
|
|
|
|
|
setContentView(mLayout);
|
|
@@ -326,15 +324,15 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
case Surface.ROTATION_0:
|
|
|
result = SDL_ORIENTATION_PORTRAIT;
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case Surface.ROTATION_90:
|
|
|
result = SDL_ORIENTATION_LANDSCAPE;
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case Surface.ROTATION_180:
|
|
|
result = SDL_ORIENTATION_PORTRAIT_FLIPPED;
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
case Surface.ROTATION_270:
|
|
|
result = SDL_ORIENTATION_LANDSCAPE_FLIPPED;
|
|
|
break;
|
|
@@ -386,34 +384,25 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
|
|
|
if (SDLActivity.mBrokenLibraries) {
|
|
|
super.onDestroy();
|
|
|
- // Reset everything in case the user re opens the app
|
|
|
- SDLActivity.initialize();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- mNextNativeState = NativeState.PAUSED;
|
|
|
- SDLActivity.handleNativeState();
|
|
|
+ if (SDLActivity.mSDLThread != null) {
|
|
|
|
|
|
- // Send a quit message to the application
|
|
|
- SDLActivity.mExitCalledFromJava = true;
|
|
|
- SDLActivity.nativeQuit();
|
|
|
+ // Send Quit event to "SDLThread" thread
|
|
|
+ SDLActivity.nativeSendQuit();
|
|
|
|
|
|
- // Now wait for the SDL thread to quit
|
|
|
- if (SDLActivity.mSDLThread != null) {
|
|
|
+ // Wait for "SDLThread" thread to end
|
|
|
try {
|
|
|
SDLActivity.mSDLThread.join();
|
|
|
} 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
|
|
|
- SDLActivity.initialize();
|
|
|
+ super.onDestroy();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -490,16 +479,19 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
|
|
|
// Try a transition to paused state
|
|
|
if (mNextNativeState == NativeState.PAUSED) {
|
|
|
- nativePause();
|
|
|
- if (mSurface != null)
|
|
|
+ if (mSDLThread != null) {
|
|
|
+ nativePause();
|
|
|
+ }
|
|
|
+ if (mSurface != null) {
|
|
|
mSurface.handlePause();
|
|
|
+ }
|
|
|
mCurrentNativeState = mNextNativeState;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Try a transition to resumed state
|
|
|
if (mNextNativeState == NativeState.RESUMED) {
|
|
|
- if (mIsSurfaceReady && mHasFocus && mIsResumedCalled) {
|
|
|
+ if (mSurface.mIsSurfaceReady && mHasFocus && mIsResumedCalled) {
|
|
|
if (mSDLThread == null) {
|
|
|
// This is the entry point to the C app.
|
|
|
// Start up the C app thread and enable sensor input for the first time
|
|
@@ -508,28 +500,24 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
mSDLThread = new Thread(new SDLMain(), "SDLThread");
|
|
|
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
|
|
|
mSDLThread.start();
|
|
|
+
|
|
|
+ // No nativeResume(), don't signal Android_ResumeSem
|
|
|
+ mSurface.handleResume();
|
|
|
+ } else {
|
|
|
+ nativeResume();
|
|
|
+ mSurface.handleResume();
|
|
|
}
|
|
|
|
|
|
- nativeResume();
|
|
|
- mSurface.handleResume();
|
|
|
mCurrentNativeState = mNextNativeState;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /* The native thread has finished */
|
|
|
- public static void handleNativeExit() {
|
|
|
- SDLActivity.mSDLThread = null;
|
|
|
- if (mSingleton != null) {
|
|
|
- mSingleton.finish();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
// Messages from the SDLMain thread
|
|
|
static final int COMMAND_CHANGE_TITLE = 1;
|
|
|
static final int COMMAND_CHANGE_WINDOW_STYLE = 2;
|
|
|
static final int COMMAND_TEXTEDIT_HIDE = 3;
|
|
|
+ static final int COMMAND_CHANGE_SURFACEVIEW_FORMAT = 4;
|
|
|
static final int COMMAND_SET_KEEP_SCREEN_ON = 5;
|
|
|
|
|
|
protected static final int COMMAND_USER = 0x8000;
|
|
@@ -584,7 +572,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
|
|
|
- window.getDecorView().setSystemUiVisibility(flags);
|
|
|
+ window.getDecorView().setSystemUiVisibility(flags);
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
|
|
SDLActivity.mFullscreenModeActive = true;
|
|
@@ -609,7 +597,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
|
|
|
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
|
|
|
-
|
|
|
+
|
|
|
mScreenKeyboardShown = false;
|
|
|
}
|
|
|
break;
|
|
@@ -627,6 +615,32 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
+ case COMMAND_CHANGE_SURFACEVIEW_FORMAT:
|
|
|
+ {
|
|
|
+ int format = ((int)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:
|
|
|
if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
|
|
|
Log.e(TAG, "error handling message, command is " + msg.arg1);
|
|
@@ -650,14 +664,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
// or 500ms have passed.
|
|
|
|
|
|
boolean bShouldWait = false;
|
|
|
-
|
|
|
+
|
|
|
if (data instanceof Integer) {
|
|
|
// Let's figure out if we're already laid out fullscreen or not.
|
|
|
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
|
|
android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics();
|
|
|
display.getRealMetrics( realMetrics );
|
|
|
-
|
|
|
- boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) &&
|
|
|
+
|
|
|
+ boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) &&
|
|
|
(realMetrics.heightPixels == mSurface.getHeight()));
|
|
|
|
|
|
if (((Integer)data).intValue() == 1) {
|
|
@@ -682,7 +696,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
// size we need, instead of grabbing a size that's still got
|
|
|
// the navigation and/or status bars before they're hidden.
|
|
|
//
|
|
|
- // We'll wait for up to half a second, because some devices
|
|
|
+ // We'll wait for up to half a second, because some devices
|
|
|
// take a surprisingly long time for the surface resize, but
|
|
|
// then we'll just give up and return.
|
|
|
//
|
|
@@ -704,11 +718,13 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
public static native int nativeSetupJNI();
|
|
|
public static native int nativeRunMain(String library, String function, Object arguments);
|
|
|
public static native void nativeLowMemory();
|
|
|
+ public static native void nativeSendQuit();
|
|
|
public static native void nativeQuit();
|
|
|
public static native void nativePause();
|
|
|
public static native void nativeResume();
|
|
|
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 onNativeKeyUp(int keycode);
|
|
|
public static native void onNativeKeyboardFocusLost();
|
|
@@ -718,11 +734,13 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
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();
|
|
|
public static native void onNativeSurfaceChanged();
|
|
|
public static native void onNativeSurfaceDestroyed();
|
|
|
public static native String nativeGetHint(String name);
|
|
|
public static native void nativeSetenv(String name, String value);
|
|
|
public static native void onNativeOrientationChanged(int orientation);
|
|
|
+ public static native void nativeAddTouch(int touchId, String name);
|
|
|
|
|
|
/**
|
|
|
* This method is called by SDL using JNI.
|
|
@@ -743,7 +761,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
/**
|
|
|
* This method is called by SDL using JNI.
|
|
|
* This is a static method for JNI convenience, it calls a non-static method
|
|
|
- * so that is can be overridden
|
|
|
+ * so that is can be overridden
|
|
|
*/
|
|
|
public static void setOrientation(int w, int h, boolean resizable, String hint)
|
|
|
{
|
|
@@ -751,11 +769,11 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
mSingleton.setOrientationBis(w, h, resizable, hint);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* This can be overridden
|
|
|
*/
|
|
|
- public void setOrientationBis(int w, int h, boolean resizable, String hint)
|
|
|
+ public void setOrientationBis(int w, int h, boolean resizable, String hint)
|
|
|
{
|
|
|
int orientation = -1;
|
|
|
|
|
@@ -795,7 +813,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
/**
|
|
|
* This method is called by SDL using JNI.
|
|
|
*/
|
|
|
- public static boolean isScreenKeyboardShown()
|
|
|
+ public static boolean isScreenKeyboardShown()
|
|
|
{
|
|
|
if (mTextEdit == null) {
|
|
|
return false;
|
|
@@ -820,7 +838,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // DeX mode in Samsung Experience 9.0 and earlier doesn't support relative mice properly under
|
|
|
+ // DeX mode in Samsung Experience 9.0 and earlier doesn't support relative mice properly under
|
|
|
// Android 7 APIs, and simply returns no data under Android 8 APIs.
|
|
|
//
|
|
|
// This is fixed in Samsung Experience 9.5, which corresponds to Android 8.1.0, and
|
|
@@ -902,7 +920,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
*/
|
|
|
public static boolean isChromebook() {
|
|
|
return getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management");
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* This method is called by SDL using JNI.
|
|
@@ -948,7 +966,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
}
|
|
|
}
|
|
|
/* environment variables set! */
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
} catch (Exception e) {
|
|
|
Log.v("SDL", "exception " + e.toString());
|
|
|
}
|
|
@@ -956,7 +974,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
}
|
|
|
|
|
|
// This method is called by SDLControllerManager's API 26 Generic Motion Handler.
|
|
|
- public static View getContentView()
|
|
|
+ public static View getContentView()
|
|
|
{
|
|
|
return mSingleton.mLayout;
|
|
|
}
|
|
@@ -1011,12 +1029,10 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
}
|
|
|
|
|
|
public static boolean isTextInputEvent(KeyEvent event) {
|
|
|
-
|
|
|
+
|
|
|
// 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()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if (event.isCtrlPressed()) {
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
return event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE;
|
|
@@ -1032,23 +1048,28 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
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
|
|
|
|
|
|
/**
|
|
|
* 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[] filtered = new int[ids.length];
|
|
|
- int used = 0;
|
|
|
+
|
|
|
for (int i = 0; i < ids.length; ++i) {
|
|
|
InputDevice device = InputDevice.getDevice(ids[i]);
|
|
|
- if ((device != null) && ((device.getSources() & sources) != 0)) {
|
|
|
- filtered[used++] = device.getId();
|
|
|
+ if (device != null && (device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) != 0) {
|
|
|
+ nativeAddTouch(device.getId(), device.getName());
|
|
|
}
|
|
|
}
|
|
|
- return Arrays.copyOf(filtered, used);
|
|
|
}
|
|
|
|
|
|
// APK expansion files support
|
|
@@ -1341,7 +1362,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
};
|
|
|
|
|
|
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();
|
|
|
if (handler != null) {
|
|
@@ -1350,7 +1371,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* This method is called by SDL using JNI.
|
|
@@ -1474,14 +1495,24 @@ class SDLMain implements Runnable {
|
|
|
String function = SDLActivity.mSingleton.getMainFunction();
|
|
|
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);
|
|
|
+
|
|
|
SDLActivity.nativeRunMain(library, function, arguments);
|
|
|
|
|
|
Log.v("SDL", "Finished main function");
|
|
|
|
|
|
- // Native thread has finished, let's finish the Activity
|
|
|
- if (!SDLActivity.mExitCalledFromJava) {
|
|
|
- SDLActivity.handleNativeExit();
|
|
|
+ if (SDLActivity.mSingleton.isFinishing()) {
|
|
|
+ // Activity is already being destroyed
|
|
|
+ } else {
|
|
|
+ // Let's finish the Activity
|
|
|
+ SDLActivity.mSDLThread = null;
|
|
|
+ SDLActivity.mSingleton.finish();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1497,11 +1528,14 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
View.OnKeyListener, View.OnTouchListener, SensorEventListener {
|
|
|
|
|
|
// Sensors
|
|
|
- protected static SensorManager mSensorManager;
|
|
|
- protected static Display mDisplay;
|
|
|
+ protected SensorManager mSensorManager;
|
|
|
+ protected Display mDisplay;
|
|
|
|
|
|
// 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
|
|
|
public SDLSurface(Context context) {
|
|
@@ -1517,13 +1551,13 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
|
|
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
|
|
|
mWidth = 1.0f;
|
|
|
mHeight = 1.0f;
|
|
|
+
|
|
|
+ mIsSurfaceReady = false;
|
|
|
}
|
|
|
|
|
|
public void handlePause() {
|
|
@@ -1547,7 +1581,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
@Override
|
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
|
Log.v("SDL", "surfaceCreated()");
|
|
|
- holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
|
|
|
+ SDLActivity.onNativeSurfaceCreated();
|
|
|
}
|
|
|
|
|
|
// Called when we lose the surface
|
|
@@ -1559,7 +1593,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED;
|
|
|
SDLActivity.handleNativeState();
|
|
|
|
|
|
- SDLActivity.mIsSurfaceReady = false;
|
|
|
+ mIsSurfaceReady = false;
|
|
|
SDLActivity.onNativeSurfaceDestroyed();
|
|
|
}
|
|
|
|
|
@@ -1575,23 +1609,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
|
|
|
int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default
|
|
|
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:
|
|
|
Log.v("SDL", "pixel format RGBA_8888");
|
|
|
sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888
|
|
@@ -1600,10 +1617,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
Log.v("SDL", "pixel format RGBX_8888");
|
|
|
sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888
|
|
|
break;
|
|
|
- case PixelFormat.RGB_332:
|
|
|
- Log.v("SDL", "pixel format RGB_332");
|
|
|
- sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332
|
|
|
- break;
|
|
|
case PixelFormat.RGB_565:
|
|
|
Log.v("SDL", "pixel format RGB_565");
|
|
|
sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565
|
|
@@ -1640,7 +1653,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
|
|
|
Log.v("SDL", "Window size: " + width + "x" + height);
|
|
|
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();
|
|
|
|
|
|
boolean skip = false;
|
|
|
int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
|
|
@@ -1673,16 +1687,17 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
|
|
|
if (skip) {
|
|
|
Log.v("SDL", "Skip .. Surface is not ready.");
|
|
|
- SDLActivity.mIsSurfaceReady = false;
|
|
|
+ mIsSurfaceReady = false;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- /* Surface is ready */
|
|
|
- SDLActivity.mIsSurfaceReady = true;
|
|
|
-
|
|
|
/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
|
|
|
SDLActivity.onNativeSurfaceChanged();
|
|
|
|
|
|
+ /* Surface is ready */
|
|
|
+ mIsSurfaceReady = true;
|
|
|
+
|
|
|
+ SDLActivity.mNextNativeState = SDLActivity.NativeState.RESUMED;
|
|
|
SDLActivity.handleNativeState();
|
|
|
}
|
|
|
|
|
@@ -1754,17 +1769,15 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
int i = -1;
|
|
|
float x,y,p;
|
|
|
|
|
|
- // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14.
|
|
|
// 12290 = Samsung DeX mode desktop mouse
|
|
|
- if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == 12290) && SDLActivity.mSeparateMouseAndTouch) {
|
|
|
- if (Build.VERSION.SDK_INT < 14) {
|
|
|
- mouseButton = 1; // all mouse buttons are the left button
|
|
|
- } else {
|
|
|
- try {
|
|
|
- mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
|
|
|
- } catch(Exception e) {
|
|
|
- mouseButton = 1; // oh well.
|
|
|
- }
|
|
|
+ // 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
|
|
|
+ // 0x2 = SOURCE_CLASS_POINTER
|
|
|
+ if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN))
|
|
|
+ && SDLActivity.mSeparateMouseAndTouch) {
|
|
|
+ try {
|
|
|
+ mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
|
|
|
+ } catch(Exception e) {
|
|
|
+ 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
|
|
@@ -1862,7 +1875,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
// Since we may have an orientation set, we won't receive onConfigurationChanged events.
|
|
|
// We thus should check here.
|
|
|
int newOrientation = SDLActivity.SDL_ORIENTATION_UNKNOWN;
|
|
|
-
|
|
|
+
|
|
|
float x, y;
|
|
|
switch (mDisplay.getRotation()) {
|
|
|
case Surface.ROTATION_90:
|
|
@@ -1896,7 +1909,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
y / SensorManager.GRAVITY_EARTH,
|
|
|
event.values[2] / SensorManager.GRAVITY_EARTH);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1964,7 +1977,7 @@ class DummyEdit extends View implements View.OnKeyListener {
|
|
|
|
|
|
@Override
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
- /*
|
|
|
+ /*
|
|
|
* This handles the hardware keyboard input
|
|
|
*/
|
|
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
@@ -2084,7 +2097,7 @@ class SDLInputConnection extends BaseInputConnection {
|
|
|
while (beforeLength-- > 0) {
|
|
|
boolean ret_key = sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
|
|
|
&& sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
|
|
|
- ret = ret && ret_key;
|
|
|
+ ret = ret && ret_key;
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
@@ -2103,7 +2116,7 @@ interface SDLClipboardHandler {
|
|
|
|
|
|
|
|
|
class SDLClipboardHandler_API11 implements
|
|
|
- SDLClipboardHandler,
|
|
|
+ SDLClipboardHandler,
|
|
|
android.content.ClipboardManager.OnPrimaryClipChangedListener {
|
|
|
|
|
|
protected android.content.ClipboardManager mClipMgr;
|
|
@@ -2134,7 +2147,7 @@ class SDLClipboardHandler_API11 implements
|
|
|
mClipMgr.setText(string);
|
|
|
mClipMgr.addPrimaryClipChangedListener(this);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void onPrimaryClipChanged() {
|
|
|
SDLActivity.onNativeClipboardChanged();
|
|
@@ -2142,33 +2155,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);
|
|
|
- }
|
|
|
-}
|
|
|
-
|