twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

GoNativeActivity.java (1879B)


      1 package org.golang.app;
      2 
      3 import android.app.Activity;
      4 import android.app.NativeActivity;
      5 import android.content.Context;
      6 import android.content.pm.ActivityInfo;
      7 import android.content.pm.PackageManager;
      8 import android.os.Bundle;
      9 import android.util.Log;
     10 import android.view.KeyCharacterMap;
     11 
     12 public class GoNativeActivity extends NativeActivity {
     13 	private static GoNativeActivity goNativeActivity;
     14 
     15 	public GoNativeActivity() {
     16 		super();
     17 		goNativeActivity = this;
     18 	}
     19 
     20 	String getTmpdir() {
     21 		return getCacheDir().getAbsolutePath();
     22 	}
     23 
     24 	static int getRune(int deviceId, int keyCode, int metaState) {
     25 		try {
     26 			int rune = KeyCharacterMap.load(deviceId).get(keyCode, metaState);
     27 			if (rune == 0) {
     28 				return -1;
     29 			}
     30 			return rune;
     31 		} catch (KeyCharacterMap.UnavailableException e) {
     32 			return -1;
     33 		} catch (Exception e) {
     34 			Log.e("Go", "exception reading KeyCharacterMap", e);
     35 			return -1;
     36 		}
     37 	}
     38 
     39 	private void load() {
     40 		// Interestingly, NativeActivity uses a different method
     41 		// to find native code to execute, avoiding
     42 		// System.loadLibrary. The result is Java methods
     43 		// implemented in C with JNIEXPORT (and JNI_OnLoad) are not
     44 		// available unless an explicit call to System.loadLibrary
     45 		// is done. So we do it here, borrowing the name of the
     46 		// library from the same AndroidManifest.xml metadata used
     47 		// by NativeActivity.
     48 		try {
     49 			ActivityInfo ai = getPackageManager().getActivityInfo(
     50 					getIntent().getComponent(), PackageManager.GET_META_DATA);
     51 			if (ai.metaData == null) {
     52 				Log.e("Go", "loadLibrary: no manifest metadata found");
     53 				return;
     54 			}
     55 			String libName = ai.metaData.getString("android.app.lib_name");
     56 			System.loadLibrary(libName);
     57 		} catch (Exception e) {
     58 			Log.e("Go", "loadLibrary failed", e);
     59 		}
     60 	}
     61 
     62 	@Override
     63 	public void onCreate(Bundle savedInstanceState) {
     64 		load();
     65 		super.onCreate(savedInstanceState);
     66 	}
     67 }