mirror of https://github.com/encounter/SDL.git
[Android] #2759: Show a message on failure to load a .so library (by Sylvain)
This commit is contained in:
parent
96fd9cefc8
commit
34a85f4de6
|
@ -37,6 +37,7 @@ public class SDLActivity extends Activity {
|
||||||
// Keep track of the paused state
|
// Keep track of the paused state
|
||||||
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus;
|
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus;
|
||||||
public static boolean mExitCalledFromJava;
|
public static boolean mExitCalledFromJava;
|
||||||
|
public static boolean mBrokenLibraries;
|
||||||
|
|
||||||
// Main components
|
// Main components
|
||||||
protected static SDLActivity mSingleton;
|
protected static SDLActivity mSingleton;
|
||||||
|
@ -52,13 +53,19 @@ public class SDLActivity extends Activity {
|
||||||
protected static AudioTrack mAudioTrack;
|
protected static AudioTrack mAudioTrack;
|
||||||
|
|
||||||
// Load the .so
|
// Load the .so
|
||||||
static {
|
public void loadLibraries() {
|
||||||
System.loadLibrary("SDL2");
|
String AppLibraries[] = {
|
||||||
//System.loadLibrary("SDL2_image");
|
"SDL2",
|
||||||
//System.loadLibrary("SDL2_mixer");
|
// "SDL2_image",
|
||||||
//System.loadLibrary("SDL2_net");
|
// "SDL2_mixer",
|
||||||
//System.loadLibrary("SDL2_ttf");
|
// "SDL2_net",
|
||||||
System.loadLibrary("main");
|
// "SDL2_ttf",
|
||||||
|
"main"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String lib : AppLibraries) {
|
||||||
|
System.loadLibrary(lib);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,6 +90,7 @@ public class SDLActivity extends Activity {
|
||||||
mSDLThread = null;
|
mSDLThread = null;
|
||||||
mAudioTrack = null;
|
mAudioTrack = null;
|
||||||
mExitCalledFromJava = false;
|
mExitCalledFromJava = false;
|
||||||
|
mBrokenLibraries = false;
|
||||||
mIsPaused = false;
|
mIsPaused = false;
|
||||||
mIsSurfaceReady = false;
|
mIsSurfaceReady = false;
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
|
@ -98,6 +106,35 @@ public class SDLActivity extends Activity {
|
||||||
// So we can call stuff from static callbacks
|
// So we can call stuff from static callbacks
|
||||||
mSingleton = this;
|
mSingleton = this;
|
||||||
|
|
||||||
|
// Load shared libraries
|
||||||
|
try {
|
||||||
|
loadLibraries();
|
||||||
|
} catch(UnsatisfiedLinkError e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
mBrokenLibraries = true;
|
||||||
|
} catch(Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
mBrokenLibraries = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mBrokenLibraries)
|
||||||
|
{
|
||||||
|
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
|
||||||
|
dlgAlert.setMessage("An error occurred while try to start the application. Please try again and/or reinstall.");
|
||||||
|
dlgAlert.setTitle("SDL Error");
|
||||||
|
dlgAlert.setPositiveButton("EXIT",
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog,int id) {
|
||||||
|
// if this button is clicked, close current activity
|
||||||
|
SDLActivity.mSingleton.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dlgAlert.setCancelable(true);
|
||||||
|
dlgAlert.create().show();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the surface
|
// Set up the surface
|
||||||
mSurface = new SDLSurface(getApplication());
|
mSurface = new SDLSurface(getApplication());
|
||||||
|
|
||||||
|
@ -119,6 +156,11 @@ public class SDLActivity extends Activity {
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.v("SDL", "onPause()");
|
Log.v("SDL", "onPause()");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
|
if (SDLActivity.mBrokenLibraries) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SDLActivity.handlePause();
|
SDLActivity.handlePause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +168,11 @@ public class SDLActivity extends Activity {
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.v("SDL", "onResume()");
|
Log.v("SDL", "onResume()");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
if (SDLActivity.mBrokenLibraries) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SDLActivity.handleResume();
|
SDLActivity.handleResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +182,10 @@ public class SDLActivity extends Activity {
|
||||||
super.onWindowFocusChanged(hasFocus);
|
super.onWindowFocusChanged(hasFocus);
|
||||||
Log.v("SDL", "onWindowFocusChanged(): " + hasFocus);
|
Log.v("SDL", "onWindowFocusChanged(): " + hasFocus);
|
||||||
|
|
||||||
|
if (SDLActivity.mBrokenLibraries) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SDLActivity.mHasFocus = hasFocus;
|
SDLActivity.mHasFocus = hasFocus;
|
||||||
if (hasFocus) {
|
if (hasFocus) {
|
||||||
SDLActivity.handleResume();
|
SDLActivity.handleResume();
|
||||||
|
@ -145,12 +196,25 @@ public class SDLActivity extends Activity {
|
||||||
public void onLowMemory() {
|
public void onLowMemory() {
|
||||||
Log.v("SDL", "onLowMemory()");
|
Log.v("SDL", "onLowMemory()");
|
||||||
super.onLowMemory();
|
super.onLowMemory();
|
||||||
|
|
||||||
|
if (SDLActivity.mBrokenLibraries) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SDLActivity.nativeLowMemory();
|
SDLActivity.nativeLowMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
Log.v("SDL", "onDestroy()");
|
Log.v("SDL", "onDestroy()");
|
||||||
|
|
||||||
|
if (SDLActivity.mBrokenLibraries) {
|
||||||
|
super.onDestroy();
|
||||||
|
// Reset everything in case the user re opens the app
|
||||||
|
SDLActivity.initialize();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Send a quit message to the application
|
// Send a quit message to the application
|
||||||
SDLActivity.mExitCalledFromJava = true;
|
SDLActivity.mExitCalledFromJava = true;
|
||||||
SDLActivity.nativeQuit();
|
SDLActivity.nativeQuit();
|
||||||
|
@ -174,6 +238,11 @@ public class SDLActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
|
|
||||||
|
if (SDLActivity.mBrokenLibraries) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int keyCode = event.getKeyCode();
|
int keyCode = event.getKeyCode();
|
||||||
// Ignore certain special keys so they're handled by Android
|
// Ignore certain special keys so they're handled by Android
|
||||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
|
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
|
||||||
|
|
Loading…
Reference in New Issue