Skip to content

Commit

Permalink
Add a way to set the context when other activities are active so many…
Browse files Browse the repository at this point in the history
… SDL API functions still work.
  • Loading branch information
slouken committed Aug 29, 2017
1 parent 130138f commit c684eb2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -56,6 +56,7 @@ public enum NativeState {
public static boolean mSeparateMouseAndTouch;

// Main components
protected static Context mContext;
protected static SDLActivity mSingleton;
protected static SDLSurface mSurface;
protected static View mTextEdit;
Expand Down Expand Up @@ -135,6 +136,7 @@ protected String[] getArguments() {
public static void initialize() {
// The static nature of the singleton and Android quirkyness force us to initialize everything here
// Otherwise, when exiting the app and returning to it, these variables *keep* their pre exit values
mContext = null;
mSingleton = null;
mSurface = null;
mTextEdit = null;
Expand All @@ -155,6 +157,9 @@ public static void initialize() {
}

// Setup
public static void setContext(Context context) {
mContext = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.v(TAG, "Device: " + android.os.Build.DEVICE);
Expand All @@ -165,7 +170,7 @@ protected void onCreate(Bundle savedInstanceState) {
SDLActivity.initialize();

// So we can call stuff from static callbacks
mSingleton = this;
mContext = mSingleton = this;

// Load shared libraries
String errorMsgBrokenLib = "";
Expand Down Expand Up @@ -564,8 +569,9 @@ public static boolean setActivityTitle(String title) {
*/
public static void setOrientation(int w, int h, boolean resizable, String hint)
{
mSingleton.setOrientationBis(w, h, resizable, hint);
return;
if (mSingleton != null) {
mSingleton.setOrientationBis(w, h, resizable, hint);
}
}

/**
Expand Down Expand Up @@ -638,14 +644,17 @@ public static boolean isScreenKeyboardShown()
* This method is called by SDL using JNI.
*/
public static boolean sendMessage(int command, int param) {
if (mSingleton == null) {
return false;
}
return mSingleton.sendCommand(command, Integer.valueOf(param));
}

/**
* This method is called by SDL using JNI.
*/
public static Context getContext() {
return mSingleton;
return mContext;
}

static class ShowTextInputTask implements Runnable {
Expand Down Expand Up @@ -716,6 +725,9 @@ public static boolean isTextInputEvent(KeyEvent event) {
* This method is called by SDL using JNI.
*/
public static Surface getNativeSurface() {
if (SDLActivity.mSurface == null) {
return null;
}
return SDLActivity.mSurface.getNativeSurface();
}

Expand Down

0 comments on commit c684eb2

Please sign in to comment.