-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAppAndroidInterface.java
More file actions
120 lines (89 loc) · 2.88 KB
/
Copy pathAppAndroidInterface.java
File metadata and controls
120 lines (89 loc) · 2.88 KB
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
package yourcompany.androidsample;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.util.Log;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import bind.Support;
/**
* Java/Android interface
*/
public class AppAndroidInterface {
static final String TAG = "AppJavaInterface";
static AppAndroidInterface sSharedInterface = null;
/**
* Get shared instance
*/
public static AppAndroidInterface sharedInterface() {
if (sSharedInterface == null) sSharedInterface = new AppAndroidInterface();
return sSharedInterface;
} //sharedInterface
/** Constructor */
public AppAndroidInterface() {
} //SharedInterface
/**
* If provided, will be called when main activity is paused
*/
public Runnable onPause = null;
/**
* If provided, will be called when main activity is resumed
*/
public Runnable onResume = null;
/**
* Define a last name for hello()
*/
public String lastName = null;
/**
* Say hello to `name` with a native Android dialog. Add a last name if any is known.
*/
public void hello(String name, final Runnable done) {
String sentence = "Hello " + name;
if (lastName != null) {
sentence += " " + lastName;
}
AlertDialog.Builder builder = new AlertDialog.Builder(Support.getContext());
builder.setTitle("Native Android")
.setMessage(sentence)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Pressed OK
if (done != null) done.run();
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
} //hello
/**
* Get Android version string
*/
public String androidVersionString() {
return Build.VERSION.RELEASE;
} //androidVersionString
/**
* Get Android version number
*/
public int androidVersionNumber() {
return Build.VERSION.SDK_INT;
} //androidVersionNumber
/**
* Dummy method to get Haxe types converted to Java types that then get returned back as an array.
*/
public List<Object> testTypes(boolean aBool, int anInt, float aFloat, List<Object> aList, Map <String, Object> aMap) {
Log.i(TAG, "Java types:");
Log.i(TAG, " Bool: " + aBool);
Log.i(TAG, " Int: " + anInt);
Log.i(TAG, " Float: " + aFloat);
Log.i(TAG, " List: " + aList);
Log.i(TAG, " Map: " + aMap);
return Arrays.asList(
aBool,
anInt,
aFloat,
aList,
aMap
);
} //testTypes
}