26
26
import android .content .Intent ;
27
27
import android .util .Log ;
28
28
import android .widget .Toast ;
29
+ import android .os .AsyncTask ;
29
30
import android .os .Bundle ;
30
31
import android .os .PowerManager ;
31
32
import android .graphics .PixelFormat ;
32
33
import android .view .SurfaceHolder ;
33
34
import android .content .Context ;
35
+ import android .content .pm .ActivityInfo ;
34
36
import android .content .pm .PackageManager ;
35
37
import android .content .pm .ApplicationInfo ;
36
38
import android .content .Intent ;
37
39
import android .widget .ImageView ;
38
40
import java .io .InputStream ;
39
41
import android .graphics .Bitmap ;
40
42
import android .graphics .BitmapFactory ;
43
+ import android .graphics .Color ;
41
44
42
45
import android .widget .AbsoluteLayout ;
43
46
import android .view .ViewGroup .LayoutParams ;
@@ -73,6 +76,11 @@ public class PythonActivity extends Activity {
73
76
private Bundle mMetaData = null ;
74
77
private PowerManager .WakeLock mWakeLock = null ;
75
78
79
+ public String getAppRoot () {
80
+ String app_root = getFilesDir ().getAbsolutePath () + "/app" ;
81
+ return app_root ;
82
+ }
83
+
76
84
public static void initialize () {
77
85
// The static nature of the singleton and Android quirkyness force us to initialize everything here
78
86
// Otherwise, when exiting the app and returning to it, these variables *keep* their pre exit values
@@ -87,13 +95,20 @@ protected void onCreate(Bundle savedInstanceState) {
87
95
resourceManager = new ResourceManager (this );
88
96
89
97
Log .v (TAG , "Ready to unpack" );
90
- unpackData ("private" , getFilesDir ());
98
+ File app_root_file = new File (getAppRoot ());
99
+ unpackData ("private" , app_root_file );
91
100
92
- this .mActivity = this ;
101
+ Log .v (TAG , "About to do super onCreate" );
102
+ super .onCreate (savedInstanceState );
103
+ Log .v (TAG , "Did super onCreate" );
93
104
105
+ this .mActivity = this ;
106
+ //this.showLoadingScreen();
94
107
Log .v ("Python" , "Device: " + android .os .Build .DEVICE );
95
108
Log .v ("Python" , "Model: " + android .os .Build .MODEL );
96
- super .onCreate (savedInstanceState );
109
+
110
+ //Log.v(TAG, "Ready to unpack");
111
+ //new UnpackFilesTask().execute(getAppRoot());
97
112
98
113
PythonActivity .initialize ();
99
114
@@ -134,10 +149,12 @@ public void onClick(DialogInterface dialog,int id) {
134
149
}
135
150
136
151
// Set up the webview
152
+ String app_root_dir = getAppRoot ();
153
+
137
154
mWebView = new WebView (this );
138
155
mWebView .getSettings ().setJavaScriptEnabled (true );
139
156
mWebView .getSettings ().setDomStorageEnabled (true );
140
- mWebView .loadUrl ("file:///" + mActivity . getFilesDir (). getAbsolutePath () + "/_load.html" );
157
+ mWebView .loadUrl ("file:///" + app_root_dir + "/_load.html" );
141
158
142
159
mWebView .setLayoutParams (new LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .FILL_PARENT ));
143
160
mWebView .setWebViewClient (new WebViewClient () {
@@ -147,30 +164,32 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
147
164
return false ;
148
165
}
149
166
});
150
-
151
167
mLayout = new AbsoluteLayout (this );
152
168
mLayout .addView (mWebView );
153
169
154
170
setContentView (mLayout );
155
171
156
172
String mFilesDirectory = mActivity .getFilesDir ().getAbsolutePath ();
173
+
157
174
Log .v (TAG , "Setting env vars for start.c and Python to use" );
158
- PythonActivity .nativeSetEnv ("ANDROID_PRIVATE" , mFilesDirectory );
159
- PythonActivity .nativeSetEnv ("ANDROID_ARGUMENT" , mFilesDirectory );
160
- PythonActivity .nativeSetEnv ("ANDROID_APP_PATH" , mFilesDirectory );
161
- PythonActivity .nativeSetEnv ("ANDROID_UNPACK" , mFilesDirectory );
162
175
PythonActivity .nativeSetEnv ("ANDROID_ENTRYPOINT" , "main.pyo" );
163
- PythonActivity .nativeSetEnv ("PYTHONHOME" , mFilesDirectory );
164
- PythonActivity .nativeSetEnv ("PYTHONPATH" , mFilesDirectory + ":" + mFilesDirectory + "/lib" );
176
+ PythonActivity .nativeSetEnv ("ANDROID_ARGUMENT" , app_root_dir );
177
+ PythonActivity .nativeSetEnv ("ANDROID_APP_PATH" , app_root_dir );
178
+ PythonActivity .nativeSetEnv ("ANDROID_PRIVATE" , mFilesDirectory );
179
+ PythonActivity .nativeSetEnv ("ANDROID_UNPACK" , app_root_dir );
180
+ PythonActivity .nativeSetEnv ("PYTHONHOME" , app_root_dir );
181
+ PythonActivity .nativeSetEnv ("PYTHONPATH" , app_root_dir + ":" + app_root_dir + "/lib" );
182
+ PythonActivity .nativeSetEnv ("PYTHONOPTIMIZE" , "2" );
165
183
166
184
try {
167
185
Log .v (TAG , "Access to our meta-data..." );
168
- this .mMetaData = this . mActivity .getPackageManager ().getApplicationInfo (
169
- this . mActivity .getPackageName (), PackageManager .GET_META_DATA ).metaData ;
186
+ mActivity .mMetaData = mActivity .getPackageManager ().getApplicationInfo (
187
+ mActivity .getPackageName (), PackageManager .GET_META_DATA ).metaData ;
170
188
171
- PowerManager pm = (PowerManager ) this .mActivity .getSystemService (Context .POWER_SERVICE );
172
- if ( this .mMetaData .getInt ("wakelock" ) == 1 ) {
173
- this .mWakeLock = pm .newWakeLock (PowerManager .SCREEN_BRIGHT_WAKE_LOCK , "Screen On" );
189
+ PowerManager pm = (PowerManager ) mActivity .getSystemService (Context .POWER_SERVICE );
190
+ if ( mActivity .mMetaData .getInt ("wakelock" ) == 1 ) {
191
+ mActivity .mWakeLock = pm .newWakeLock (PowerManager .SCREEN_BRIGHT_WAKE_LOCK , "Screen On" );
192
+ mActivity .mWakeLock .acquire ();
174
193
}
175
194
} catch (PackageManager .NameNotFoundException e ) {
176
195
}
@@ -181,19 +200,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
181
200
182
201
final Thread wvThread = new Thread (new WebViewLoaderMain (), "WvThread" );
183
202
wvThread .start ();
184
- }
185
203
186
- @ Override
187
- public void onDestroy () {
188
- Log .i ("Destroy" , "end of app" );
189
- super .onDestroy ();
190
-
191
- // make sure all child threads (python_thread) are stopped
192
- android .os .Process .killProcess (android .os .Process .myPid ());
193
204
}
194
205
195
206
public void loadLibraries () {
196
- PythonUtil .loadLibraries (getFilesDir ());
207
+ String app_root = new String (getAppRoot ());
208
+ File app_root_file = new File (app_root );
209
+ PythonUtil .loadLibraries (app_root_file );
197
210
}
198
211
199
212
public void recursiveDelete (File f ) {
@@ -402,12 +415,13 @@ public static void start_service(String serviceTitle, String serviceDescription,
402
415
Intent serviceIntent = new Intent (PythonActivity .mActivity , PythonService .class );
403
416
String argument = PythonActivity .mActivity .getFilesDir ().getAbsolutePath ();
404
417
String filesDirectory = argument ;
418
+ String app_root_dir = PythonActivity .mActivity .getAppRoot ();
405
419
serviceIntent .putExtra ("androidPrivate" , argument );
406
- serviceIntent .putExtra ("androidArgument" , argument );
420
+ serviceIntent .putExtra ("androidArgument" , app_root_dir );
407
421
serviceIntent .putExtra ("serviceEntrypoint" , "service/main.pyo" );
408
422
serviceIntent .putExtra ("pythonName" , "python" );
409
- serviceIntent .putExtra ("pythonHome" , argument );
410
- serviceIntent .putExtra ("pythonPath" , argument + ":" + filesDirectory + "/lib" );
423
+ serviceIntent .putExtra ("pythonHome" , app_root_dir );
424
+ serviceIntent .putExtra ("pythonPath" , app_root_dir + ":" + app_root_dir + "/lib" );
411
425
serviceIntent .putExtra ("serviceTitle" , serviceTitle );
412
426
serviceIntent .putExtra ("serviceDescription" , serviceDescription );
413
427
serviceIntent .putExtra ("pythonServiceArgument" , pythonServiceArgument );
0 commit comments