6
6
import java .io .FileOutputStream ;
7
7
import java .io .FileWriter ;
8
8
import java .io .File ;
9
+ import java .util .Collections ;
10
+ import java .util .Iterator ;
11
+ import java .util .List ;
12
+ import java .util .ArrayList ;
9
13
10
14
import android .view .ViewGroup ;
11
15
import android .view .SurfaceView ;
12
16
import android .app .Activity ;
17
+ import android .content .Intent ;
13
18
import android .util .Log ;
14
19
import android .widget .Toast ;
15
20
import android .os .Bundle ;
@@ -30,7 +35,7 @@ public class PythonActivity extends SDLActivity {
30
35
private static final String TAG = "PythonActivity" ;
31
36
32
37
public static PythonActivity mActivity = null ;
33
-
38
+
34
39
private ResourceManager resourceManager = null ;
35
40
private Bundle mMetaData = null ;
36
41
private PowerManager .WakeLock mWakeLock = null ;
@@ -46,9 +51,9 @@ protected void onCreate(Bundle savedInstanceState) {
46
51
Log .v (TAG , "About to do super onCreate" );
47
52
super .onCreate (savedInstanceState );
48
53
Log .v (TAG , "Did super onCreate" );
49
-
54
+
50
55
this .mActivity = this ;
51
-
56
+
52
57
String mFilesDirectory = mActivity .getFilesDir ().getAbsolutePath ();
53
58
Log .v (TAG , "Setting env vars for start.c and Python to use" );
54
59
SDLActivity .nativeSetEnv ("ANDROID_PRIVATE" , mFilesDirectory );
@@ -57,7 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {
57
62
SDLActivity .nativeSetEnv ("PYTHONHOME" , mFilesDirectory );
58
63
SDLActivity .nativeSetEnv ("" , mFilesDirectory + ":" + mFilesDirectory + "/lib" );
59
64
60
-
65
+
61
66
// nativeSetEnv("ANDROID_ARGUMENT", getFilesDir());
62
67
63
68
try {
@@ -79,7 +84,7 @@ protected void onCreate(Bundle savedInstanceState) {
79
84
} catch (PackageManager .NameNotFoundException e ) {
80
85
}
81
86
}
82
-
87
+
83
88
// This is just overrides the normal SDLActivity, which just loads
84
89
// SDL2 and main
85
90
protected String [] getLibraries () {
@@ -92,16 +97,16 @@ protected String[] getLibraries() {
92
97
"main"
93
98
};
94
99
}
95
-
100
+
96
101
public void loadLibraries () {
97
102
// AND: This should probably be replaced by a call to super
98
103
for (String lib : getLibraries ()) {
99
104
System .loadLibrary (lib );
100
105
}
101
-
106
+
102
107
System .load (getFilesDir () + "/lib/python2.7/lib-dynload/_io.so" );
103
108
System .load (getFilesDir () + "/lib/python2.7/lib-dynload/unicodedata.so" );
104
-
109
+
105
110
try {
106
111
// System.loadLibrary("ctypes");
107
112
System .load (getFilesDir () + "/lib/python2.7/lib-dynload/_ctypes.so" );
@@ -111,7 +116,7 @@ public void loadLibraries() {
111
116
112
117
Log .v (TAG , "Loaded everything!" );
113
118
}
114
-
119
+
115
120
public void recursiveDelete (File f ) {
116
121
if (f .isDirectory ()) {
117
122
for (File r : f .listFiles ()) {
@@ -143,15 +148,15 @@ public void run() {
143
148
}
144
149
}
145
150
}
146
-
151
+
147
152
public void unpackData (final String resource , File target ) {
148
-
153
+
149
154
Log .v (TAG , "UNPACKING!!! " + resource + " " + target .getName ());
150
-
155
+
151
156
// The version of data in memory and on disk.
152
157
String data_version = resourceManager .getString (resource + "_version" );
153
158
String disk_version = null ;
154
-
159
+
155
160
Log .v (TAG , "Data version is " + data_version );
156
161
157
162
// If no version, no unpacking is necessary.
@@ -200,12 +205,82 @@ public void unpackData(final String resource, File target) {
200
205
}
201
206
}
202
207
}
203
-
208
+
204
209
public static ViewGroup getLayout () {
205
210
return mLayout ;
206
211
}
207
212
208
213
public static SurfaceView getSurface () {
209
214
return mSurface ;
210
215
}
216
+
217
+ //----------------------------------------------------------------------------
218
+ // Listener interface for onNewIntent
219
+ //
220
+
221
+ public interface NewIntentListener {
222
+ void onNewIntent (Intent intent );
223
+ }
224
+
225
+ private List <NewIntentListener > newIntentListeners = null ;
226
+
227
+ public void registerNewIntentListener (NewIntentListener listener ) {
228
+ if ( this .newIntentListeners == null )
229
+ this .newIntentListeners = Collections .synchronizedList (new ArrayList <NewIntentListener >());
230
+ this .newIntentListeners .add (listener );
231
+ }
232
+
233
+ public void unregisterNewIntentListener (NewIntentListener listener ) {
234
+ if ( this .newIntentListeners == null )
235
+ return ;
236
+ this .newIntentListeners .remove (listener );
237
+ }
238
+
239
+ @ Override
240
+ protected void onNewIntent (Intent intent ) {
241
+ if ( this .newIntentListeners == null )
242
+ return ;
243
+ this .onResume ();
244
+ synchronized ( this .newIntentListeners ) {
245
+ Iterator <NewIntentListener > iterator = this .newIntentListeners .iterator ();
246
+ while ( iterator .hasNext () ) {
247
+ (iterator .next ()).onNewIntent (intent );
248
+ }
249
+ }
250
+ }
251
+
252
+ //----------------------------------------------------------------------------
253
+ // Listener interface for onActivityResult
254
+ //
255
+
256
+ public interface ActivityResultListener {
257
+ void onActivityResult (int requestCode , int resultCode , Intent data );
258
+ }
259
+
260
+ private List <ActivityResultListener > activityResultListeners = null ;
261
+
262
+ public void registerActivityResultListener (ActivityResultListener listener ) {
263
+ if ( this .activityResultListeners == null )
264
+ this .activityResultListeners = Collections .synchronizedList (new ArrayList <ActivityResultListener >());
265
+ this .activityResultListeners .add (listener );
266
+ }
267
+
268
+ public void unregisterActivityResultListener (ActivityResultListener listener ) {
269
+ if ( this .activityResultListeners == null )
270
+ return ;
271
+ this .activityResultListeners .remove (listener );
272
+ }
273
+
274
+ @ Override
275
+ protected void onActivityResult (int requestCode , int resultCode , Intent intent ) {
276
+ if ( this .activityResultListeners == null )
277
+ return ;
278
+ this .onResume ();
279
+ synchronized ( this .activityResultListeners ) {
280
+ Iterator <ActivityResultListener > iterator = this .activityResultListeners .iterator ();
281
+ while ( iterator .hasNext () )
282
+ (iterator .next ()).onActivityResult (requestCode , resultCode , intent );
283
+ }
284
+ }
285
+
211
286
}
0 commit comments