|
18 | 18 | import android.content.Intent;
|
19 | 19 | import android.util.Log;
|
20 | 20 | import android.widget.Toast;
|
| 21 | +import android.os.AsyncTask; |
21 | 22 | import android.os.Bundle;
|
22 | 23 | import android.os.PowerManager;
|
23 | 24 | import android.graphics.PixelFormat;
|
@@ -61,83 +62,15 @@ public String getAppRoot() {
|
61 | 62 | protected void onCreate(Bundle savedInstanceState) {
|
62 | 63 | Log.v(TAG, "My oncreate running");
|
63 | 64 | resourceManager = new ResourceManager(this);
|
64 |
| - this.showLoadingScreen(); |
65 |
| - File app_root_file = new File(getAppRoot()); |
66 |
| - |
67 |
| - Log.v(TAG, "Ready to unpack"); |
68 |
| - unpackData("private", app_root_file); |
69 | 65 |
|
70 | 66 | Log.v(TAG, "About to do super onCreate");
|
71 | 67 | super.onCreate(savedInstanceState);
|
72 | 68 | Log.v(TAG, "Did super onCreate");
|
73 | 69 |
|
74 | 70 | this.mActivity = this;
|
75 | 71 | this.showLoadingScreen();
|
76 |
| - |
77 |
| - // Figure out the directory where the game is. If the game was |
78 |
| - // given to us via an intent, then we use the scheme-specific |
79 |
| - // part of that intent to determine the file to launch. We |
80 |
| - // also use the android.txt file to determine the orientation. |
81 |
| - // |
82 |
| - // Otherwise, we use the public data, if we have it, or the |
83 |
| - // private data if we do not. |
84 |
| - String app_root_dir = getAppRoot(); |
85 |
| - if (getIntent() != null && getIntent().getAction() != null && |
86 |
| - getIntent().getAction().equals("org.kivy.LAUNCH")) { |
87 |
| - File path = new File(getIntent().getData().getSchemeSpecificPart()); |
88 |
| - |
89 |
| - Project p = Project.scanDirectory(path); |
90 |
| - SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", p.dir + "/main.py"); |
91 |
| - SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", p.dir); |
92 |
| - SDLActivity.nativeSetEnv("ANDROID_APP_PATH", p.dir); |
93 |
| - |
94 |
| - if (p != null) { |
95 |
| - if (p.landscape) { |
96 |
| - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
97 |
| - } else { |
98 |
| - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
99 |
| - } |
100 |
| - } |
101 |
| - |
102 |
| - // Let old apps know they started. |
103 |
| - try { |
104 |
| - FileWriter f = new FileWriter(new File(path, ".launch")); |
105 |
| - f.write("started"); |
106 |
| - f.close(); |
107 |
| - } catch (IOException e) { |
108 |
| - // pass |
109 |
| - } |
110 |
| - } else { |
111 |
| - SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", "main.pyo"); |
112 |
| - SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir); |
113 |
| - SDLActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir); |
114 |
| - } |
115 |
| - |
116 |
| - String mFilesDirectory = mActivity.getFilesDir().getAbsolutePath(); |
117 |
| - Log.v(TAG, "Setting env vars for start.c and Python to use"); |
118 |
| - SDLActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory); |
119 |
| - SDLActivity.nativeSetEnv("PYTHONHOME", app_root_dir); |
120 |
| - SDLActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib"); |
121 |
| - SDLActivity.nativeSetEnv("PYTHONOPTIMIZE", "2"); |
122 | 72 |
|
123 |
| - try { |
124 |
| - Log.v(TAG, "Access to our meta-data..."); |
125 |
| - this.mMetaData = this.mActivity.getPackageManager().getApplicationInfo( |
126 |
| - this.mActivity.getPackageName(), PackageManager.GET_META_DATA).metaData; |
127 |
| - |
128 |
| - PowerManager pm = (PowerManager) this.mActivity.getSystemService(Context.POWER_SERVICE); |
129 |
| - if ( this.mMetaData.getInt("wakelock") == 1 ) { |
130 |
| - this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Screen On"); |
131 |
| - } |
132 |
| - if ( this.mMetaData.getInt("surface.transparent") != 0 ) { |
133 |
| - Log.v(TAG, "Surface will be transparent."); |
134 |
| - getSurface().setZOrderOnTop(true); |
135 |
| - getSurface().getHolder().setFormat(PixelFormat.TRANSPARENT); |
136 |
| - } else { |
137 |
| - Log.i(TAG, "Surface will NOT be transparent"); |
138 |
| - } |
139 |
| - } catch (PackageManager.NameNotFoundException e) { |
140 |
| - } |
| 73 | + new UnpackFilesTask().execute(getAppRoot()); |
141 | 74 | }
|
142 | 75 |
|
143 | 76 | public void loadLibraries() {
|
@@ -178,6 +111,100 @@ public void run() {
|
178 | 111 | }
|
179 | 112 | }
|
180 | 113 |
|
| 114 | + private class UnpackFilesTask extends AsyncTask<String, Void, String> { |
| 115 | + @Override |
| 116 | + protected String doInBackground(String... params) { |
| 117 | + File app_root_file = new File(params[0]); |
| 118 | + Log.v(TAG, "Ready to unpack"); |
| 119 | + unpackData("private", app_root_file); |
| 120 | + return null; |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + protected void onPostExecute(String result) { |
| 125 | + // Figure out the directory where the game is. If the game was |
| 126 | + // given to us via an intent, then we use the scheme-specific |
| 127 | + // part of that intent to determine the file to launch. We |
| 128 | + // also use the android.txt file to determine the orientation. |
| 129 | + // |
| 130 | + // Otherwise, we use the public data, if we have it, or the |
| 131 | + // private data if we do not. |
| 132 | + mActivity.finishLoad(); |
| 133 | + |
| 134 | + // finishLoad called setContentView with the SDL view, which |
| 135 | + // removed the loading screen. However, we still need it to |
| 136 | + // show until the app is ready to render, so pop it back up |
| 137 | + // on top of the SDL view. |
| 138 | + this.showLoadingScreen(); |
| 139 | + |
| 140 | + String app_root_dir = getAppRoot(); |
| 141 | + if (getIntent() != null && getIntent().getAction() != null && |
| 142 | + getIntent().getAction().equals("org.kivy.LAUNCH")) { |
| 143 | + File path = new File(getIntent().getData().getSchemeSpecificPart()); |
| 144 | + |
| 145 | + Project p = Project.scanDirectory(path); |
| 146 | + SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", p.dir + "/main.py"); |
| 147 | + SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", p.dir); |
| 148 | + SDLActivity.nativeSetEnv("ANDROID_APP_PATH", p.dir); |
| 149 | + |
| 150 | + if (p != null) { |
| 151 | + if (p.landscape) { |
| 152 | + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 153 | + } else { |
| 154 | + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + // Let old apps know they started. |
| 159 | + try { |
| 160 | + FileWriter f = new FileWriter(new File(path, ".launch")); |
| 161 | + f.write("started"); |
| 162 | + f.close(); |
| 163 | + } catch (IOException e) { |
| 164 | + // pass |
| 165 | + } |
| 166 | + } else { |
| 167 | + SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", "main.pyo"); |
| 168 | + SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir); |
| 169 | + SDLActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir); |
| 170 | + } |
| 171 | + |
| 172 | + String mFilesDirectory = mActivity.getFilesDir().getAbsolutePath(); |
| 173 | + Log.v(TAG, "Setting env vars for start.c and Python to use"); |
| 174 | + SDLActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory); |
| 175 | + SDLActivity.nativeSetEnv("PYTHONHOME", app_root_dir); |
| 176 | + SDLActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib"); |
| 177 | + SDLActivity.nativeSetEnv("PYTHONOPTIMIZE", "2"); |
| 178 | + |
| 179 | + try { |
| 180 | + Log.v(TAG, "Access to our meta-data..."); |
| 181 | + mActivity.mMetaData = mActivity.getPackageManager().getApplicationInfo( |
| 182 | + mActivity.getPackageName(), PackageManager.GET_META_DATA).metaData; |
| 183 | + |
| 184 | + PowerManager pm = (PowerManager) mActivity.getSystemService(Context.POWER_SERVICE); |
| 185 | + if ( mActivity.mMetaData.getInt("wakelock") == 1 ) { |
| 186 | + mActivity.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Screen On"); |
| 187 | + } |
| 188 | + if ( mActivity.mMetaData.getInt("surface.transparent") != 0 ) { |
| 189 | + Log.v(TAG, "Surface will be transparent."); |
| 190 | + getSurface().setZOrderOnTop(true); |
| 191 | + getSurface().getHolder().setFormat(PixelFormat.TRANSPARENT); |
| 192 | + } else { |
| 193 | + Log.i(TAG, "Surface will NOT be transparent"); |
| 194 | + } |
| 195 | + } catch (PackageManager.NameNotFoundException e) { |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + @Override |
| 200 | + protected void onPreExecute() { |
| 201 | + } |
| 202 | + |
| 203 | + @Override |
| 204 | + protected void onProgressUpdate(Void... values) { |
| 205 | + } |
| 206 | + } |
| 207 | + |
181 | 208 | public void unpackData(final String resource, File target) {
|
182 | 209 |
|
183 | 210 | Log.v(TAG, "UNPACKING!!! " + resource + " " + target.getName());
|
|
0 commit comments