project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Flib.java
changeset 10017 de822cd3df3a
parent 8062 abbcdf73327a
child 15512 45d6806548e9
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    25 
    25 
    26 import com.sun.jna.Library;
    26 import com.sun.jna.Library;
    27 import com.sun.jna.Native;
    27 import com.sun.jna.Native;
    28 
    28 
    29 public class Flib {
    29 public class Flib {
    30 	static {
    30     static {
    31 		System.loadLibrary("SDL");
    31         System.loadLibrary("SDL");
    32 		System.loadLibrary("SDL_net");
    32         System.loadLibrary("SDL_net");
    33 		System.setProperty("jna.encoding", "UTF8"); // Ugly global setting, but it seems JNA doesn't allow setting this per-library... 
    33         System.setProperty("jna.encoding", "UTF8"); // Ugly global setting, but it seems JNA doesn't allow setting this per-library...
    34 	}
    34     }
    35 	public static final Frontlib INSTANCE = (Frontlib)Native.loadLibrary("frontlib", Frontlib.class, Collections.singletonMap(Library.OPTION_TYPE_MAPPER, AndroidTypeMapper.INSTANCE));
    35     public static final Frontlib INSTANCE = (Frontlib)Native.loadLibrary("frontlib", Frontlib.class, Collections.singletonMap(Library.OPTION_TYPE_MAPPER, AndroidTypeMapper.INSTANCE));
    36 	
    36 
    37 	static {
    37     static {
    38 		// We'll just do it here and never quit it again...
    38         // We'll just do it here and never quit it again...
    39 		if(Flib.INSTANCE.flib_init() != 0) {
    39         if(Flib.INSTANCE.flib_init() != 0) {
    40 			throw new RuntimeException("Unable to initialize frontlib");
    40             throw new RuntimeException("Unable to initialize frontlib");
    41 		}
    41         }
    42 	}
    42     }
    43 	
    43 
    44 	// Hook frontlib logging into Android logging
    44     // Hook frontlib logging into Android logging
    45 	private static final Frontlib.LogCallback logCb = new Frontlib.LogCallback() {
    45     private static final Frontlib.LogCallback logCb = new Frontlib.LogCallback() {
    46 		public void callback(int level, String message) {
    46         public void callback(int level, String message) {
    47 			if(level >= Frontlib.FLIB_LOGLEVEL_ERROR) {
    47             if(level >= Frontlib.FLIB_LOGLEVEL_ERROR) {
    48 				Log.e("Frontlib", message);
    48                 Log.e("Frontlib", message);
    49 			} else if(level == Frontlib.FLIB_LOGLEVEL_WARNING){
    49             } else if(level == Frontlib.FLIB_LOGLEVEL_WARNING){
    50 				Log.w("Frontlib", message);
    50                 Log.w("Frontlib", message);
    51 			} else if(level == Frontlib.FLIB_LOGLEVEL_INFO){
    51             } else if(level == Frontlib.FLIB_LOGLEVEL_INFO){
    52 				Log.i("Frontlib", message);
    52                 Log.i("Frontlib", message);
    53 			} else if(level <= Frontlib.FLIB_LOGLEVEL_DEBUG){
    53             } else if(level <= Frontlib.FLIB_LOGLEVEL_DEBUG){
    54 				Log.d("Frontlib", message);
    54                 Log.d("Frontlib", message);
    55 			}
    55             }
    56 		}
    56         }
    57 	};
    57     };
    58 	static {
    58     static {
    59 		INSTANCE.flib_log_setLevel(Frontlib.FLIB_LOGLEVEL_INFO);
    59         INSTANCE.flib_log_setLevel(Frontlib.FLIB_LOGLEVEL_INFO);
    60 		INSTANCE.flib_log_setCallback(logCb);
    60         INSTANCE.flib_log_setCallback(logCb);
    61 	}
    61     }
    62 }
    62 }