10000 Merge branch 'rnixx_unpack_data' into workmanager · rnixx/python-for-android@6e2b736 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e2b736

Browse files
committed
Merge branch 'rnixx_unpack_data' into workmanager
2 parents 146c781 + c0c50de commit 6e2b736

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonActivityUtil.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import android.app.Activity;
44
import android.util.Log;
5-
import android.widget.Toast;
5+
6+
import java.io.File;
67

78
import org.renpy.android.ResourceManager;
89

@@ -21,25 +22,6 @@ public PythonActivityUtil(Activity activity, ResourceManager resourceManager) {
2122
this.mResourceManager = resourceManager;
2223
}
2324

24-
/**
25-
* Show an error using a toast. (Only makes sense from non-UI threads.)
26-
*/
27-
private void toastError(final String msg) {
28-
mActivity.runOnUiThread(new Runnable () {
29-
public void run() {
30-
Toast.makeText(mActivity, msg, Toast.LENGTH_LONG).show();
31-
}
32-
});
33-
34-
// Wait to show the error.
35-
synchronized (mActivity) {
36-
try {
37-
mActivity.wait(1000);
38-
} catch (InterruptedException e) {
39-
}
40-
}
41-
}
42-
4325
public void unpackData(final String resource, File target) {
4426
Log.d(TAG, "B/C call of ``PythonActivityUtil.unpackData``. Use ``PythonUtil.unpackData`` instead.");
4527
PythonUtil.unpackData(mActivity, resource, target, true);

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
import java.io.FileOutputStream;
66
import java.io.File;
77

8+
import android.app.Activity;
9+
import android.content.Context;
10+
import android.content.res.Resources;
811
import android.util.Log;
12+
import android.widget.Toast;
13+
914
import java.util.ArrayList;
1015
import java.util.regex.Pattern;
1116

@@ -94,6 +99,25 @@ public static String getResourceString(Context ctx, String name) {
9499
return res.getString(id);
95100
}
96101

102+
/**
103+
* Show an error using a toast. (Only makes sense from non-UI threads.)
104+
*/
105+
protected static void toastError(Activity activity, final String msg) {
106+
activity.runOnUiThread(new Runnable () {
107+
public void run() {
108+
Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
109+
}
110+
});
111+
112+
// Wait to show the error.
113+
synchronized (activity) {
114+
try {
115+
activity.wait(1000);
116+
} catch (InterruptedException e) {
117+
}
118+
}
119+
}
120+
97121
protected static void recursiveDelete(File f) {
98122
if (f.isDirectory()) {
99123
for (File r : f.listFiles()) {
@@ -147,7 +171,12 @@ public static void unpackData(
147171

148172
AssetExtract ae = new AssetExtract(ctx);
149173
if (!ae.extractTar(resource + ".mp3", target.getAbsolutePath())) {
150-
toastError("Could not extract " + resource + " data.");
174+
String msg = "Could not extract " + resource + " data.";
175+
if (ctx instanceof Activity) {
176+
toastError((Activity)ctx, msg);
177+
} else {
178+
Log.v(TAG, msg);
179+
}
151180
}
152181

153182
try {

0 commit comments

Comments
 (0)
0