MCPcopy Create free account
hub / github.com/golang/mobile / GoNativeActivity

Class GoNativeActivity

app/GoNativeActivity.java:12–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import android.view.KeyCharacterMap;
11
12public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected