SDL  2.0
SDL.java
Go to the documentation of this file.
1 package org.libsdl.app;
2 
3 import android.content.Context;
4 
5 import java.lang.reflect.*;
6 
7 /**
8  SDL library initialization
9 */
10 public class SDL {
11 
12  // This function should be called first and sets up the native code
13  // so it can call into the Java classes
14  public static void setupJNI() {
18  }
19 
20  // This function should be called each time the activity is started
21  public static void initialize() {
22  setContext(null);
23 
27  }
28 
29  // This function stores the current activity (SDL or not)
30  public static void setContext(Context context) {
31  mContext = context;
32  }
33 
34  public static Context getContext() {
35  return mContext;
36  }
37 
38  public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, SecurityException, NullPointerException {
39 
40  if (libraryName == null) {
41  throw new NullPointerException("No library name provided.");
42  }
43 
44  try {
45  // Let's see if we have ReLinker available in the project. This is necessary for
46  // some projects that have huge numbers of local libraries bundled, and thus may
47  // trip a bug in Android's native library loader which ReLinker works around. (If
48  // loadLibrary works properly, ReLinker will simply use the normal Android method
49  // internally.)
50  //
51  // To use ReLinker, just add it as a dependency. For more information, see
52  // https://github.com/KeepSafe/ReLinker for ReLinker's repository.
53  //
54  Class relinkClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker");
55  Class relinkListenerClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener");
56  Class contextClass = mContext.getClassLoader().loadClass("android.content.Context");
57  Class stringClass = mContext.getClassLoader().loadClass("java.lang.String");
58 
59  // Get a 'force' instance of the ReLinker, so we can ensure libraries are reinstalled if
60  // they've changed during updates.
61  Method forceMethod = relinkClass.getDeclaredMethod("force");
62  Object relinkInstance = forceMethod.invoke(null);
63  Class relinkInstanceClass = relinkInstance.getClass();
64 
65  // Actually load the library!
66  Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass);
67  loadMethod.invoke(relinkInstance, mContext, libraryName, null, null);
68  }
69  catch (final Throwable e) {
70  // Fall back
71  try {
72  System.loadLibrary(libraryName);
73  }
74  catch (final UnsatisfiedLinkError ule) {
75  throw ule;
76  }
77  catch (final SecurityException se) {
78  throw se;
79  }
80  }
81  }
82 
83  protected static Context mContext;
84 }
static native int nativeSetupJNI()
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 * e
static void loadLibrary(String libraryName)
Definition: SDL.java:38
static Context mContext
Definition: SDL.java:83
static screen_context_t context
Definition: video.c:25
static void setContext(Context context)
Definition: SDL.java:30
static native int nativeSetupJNI()
static void setupJNI()
Definition: SDL.java:14
static native int nativeSetupJNI()
static Context getContext()
Definition: SDL.java:34
static void initialize()
Definition: SDL.java:21