1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package net.sourceforge.subsonic.androidapp.util; |
20 |
|
|
21 |
|
import java.io.FileNotFoundException; |
22 |
|
import java.io.IOException; |
23 |
|
|
24 |
|
import org.xmlpull.v1.XmlPullParserException; |
25 |
|
|
26 |
|
import android.app.Activity; |
27 |
|
import android.os.Handler; |
28 |
|
import android.util.Log; |
29 |
|
import net.sourceforge.subsonic.androidapp.R; |
30 |
|
|
31 |
|
|
32 |
|
@author |
33 |
|
|
|
|
| 25,7% |
Uncovered Elements: 26 (35) |
Complexity: 12 |
Complexity Density: 0,63 |
|
34 |
|
public abstract class BackgroundTask<T> implements ProgressListener { |
35 |
|
|
36 |
|
private static final String TAG = BackgroundTask.class.getSimpleName(); |
37 |
|
private final Activity activity; |
38 |
|
private final Handler handler; |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
40 |
23
|
public BackgroundTask(Activity activity) {... |
41 |
23
|
this.activity = activity; |
42 |
23
|
handler = new Handler(); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
2
|
protected Activity getActivity() {... |
46 |
2
|
return activity; |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
84
|
protected Handler getHandler() {... |
50 |
84
|
return handler; |
51 |
|
} |
52 |
|
|
53 |
|
public abstract void execute(); |
54 |
|
|
55 |
|
protected abstract T doInBackground() throws Throwable; |
56 |
|
|
57 |
|
protected abstract void done(T result); |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
59 |
0
|
protected void error(Throwable error) {... |
60 |
0
|
Log.w(TAG, "Got exception: " + error, error); |
61 |
0
|
new ErrorDialog(activity, getErrorMessage(error), true); |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 7 |
Complexity Density: 0,58 |
|
64 |
0
|
protected String getErrorMessage(Throwable error) {... |
65 |
|
|
66 |
0
|
if (error instanceof IOException && !Util.isNetworkConnected(activity)) { |
67 |
0
|
return activity.getResources().getString(R.string.background_task_no_network); |
68 |
|
} |
69 |
|
|
70 |
0
|
if (error instanceof FileNotFoundException) { |
71 |
0
|
return activity.getResources().getString(R.string.background_task_not_found); |
72 |
|
} |
73 |
|
|
74 |
0
|
if (error instanceof IOException) { |
75 |
0
|
return activity.getResources().getString(R.string.background_task_network_error); |
76 |
|
} |
77 |
|
|
78 |
0
|
if (error instanceof XmlPullParserException) { |
79 |
0
|
return activity.getResources().getString(R.string.background_task_parse_error); |
80 |
|
} |
81 |
|
|
82 |
0
|
String message = error.getMessage(); |
83 |
0
|
if (message != null) { |
84 |
0
|
return message; |
85 |
|
} |
86 |
0
|
return error.getClass().getSimpleName(); |
87 |
|
} |
88 |
|
|
89 |
|
@Override |
90 |
|
public abstract void updateProgress(final String message); |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
58
|
@Override... |
93 |
|
public void updateProgress(int messageId) { |
94 |
58
|
updateProgress(activity.getResources().getString(messageId)); |
95 |
|
} |
96 |
|
} |