-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGoNativeActivity.java
121 lines (97 loc) · 3.5 KB
/
GoNativeActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package org.golang.app;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.pm.ActivityInfo;
import android.app.NativeActivity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.content.Intent;
import android.net.Uri;
import android.app.PendingIntent;
import android.content.Context;
import android.widget.Toast;
import android.app.TaskStackBuilder;
//import android.support.v4.app.NotificationCompat;
import android.view.KeyCharacterMap;
public class GoNativeActivity extends NativeActivity {
private static GoNativeActivity goNativeActivity;
public GoNativeActivity() {
super();
Log.d("JavaGo", "GoNativeActivity");
goNativeActivity = this;
}
public void openBrowser(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("http://localhost:8089");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(data);
startActivity(intent);
}
public void notif(String title, String text) {
Log.d("JavaGo", "GoNativeActivity notif");
Intent intent = new Intent("org.golang.app.MainActivity");
/////
Notification.Builder builder = new Notification.Builder(this);
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, resultIntent, 0);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
builder.setAutoCancel(true);
builder.setContentTitle(title);
builder.setContentText(text);
builder.setSmallIcon(R.drawable.icon);
builder.setContentIntent(pIntent);
builder.setContentText("Dcoin is running");
builder.build();
Notification notif = builder.getNotification();
////
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(2, notif);
}
String getTmpdir() {
return getCacheDir().getAbsolutePath();
}
String getFilesdir() {
return getExternalFilesDir(null).getAbsolutePath();
}
int getRune(int deviceId, int keyCode, int metaState) {
try {
int rune = KeyCharacterMap.load(deviceId).get(keyCode, metaState);
if (rune == 0) {
return -1;
}
return rune;
} catch (KeyCharacterMap.UnavailableException e) {
return -1;
} catch (Exception e) {
Log.e("JavaGo", "exception reading KeyCharacterMap", e);
return -1;
}
}
public static void load() {
Log.d("JavaGo", "GoNativeActivity load");
// Interestingly, NativeActivity uses a different method
// to find native code to execute, avoiding
// System.loadLibrary. The result is Java methods
// implemented in C with JNIEXPORT (and JNI_OnLoad) are not
// available unless an explicit call to System.loadLibrary
// is done. So we do it here, borrowing the name of the
// library from the same AndroidManifest.xml metadata used
// by NativeActivity.
try {
System.loadLibrary("dcoin");
} catch (Exception e) {
Log.e("JavaGo", "loadLibrary failed", e);
}
}
public void onStart(Bundle savedInstanceState) {
Log.d("JavaGo", "GoNativeActivity onStart");
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d("JavaGo", "GoNativeActivity onCreate");
super.onCreate(savedInstanceState);
}
}