blob: eee71ba4cf6ffa57c5b737d2fc7df3347e1ccbf2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
package cgeo.geocaching.utils;
import cgeo.geocaching.CacheDetailActivity;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.activity.Progress;
import android.content.res.Resources;
import android.os.Message;
import java.lang.ref.WeakReference;
public class SimpleCancellableHandler extends CancellableHandler {
public static final String MESSAGE_TEXT = "message_text";
protected final WeakReference<AbstractActivity> activityRef;
protected final WeakReference<Progress> progressDialogRef;
public SimpleCancellableHandler(final AbstractActivity activity, final Progress progress) {
this.activityRef = new WeakReference<>(activity);
this.progressDialogRef = new WeakReference<>(progress);
}
@Override
protected void handleRegularMessage(final Message msg) {
AbstractActivity activity = activityRef.get();
if (activity != null && msg.getData() != null && msg.getData().getString(MESSAGE_TEXT) != null) {
activity.showToast(msg.getData().getString(MESSAGE_TEXT));
}
dismissProgress();
}
@Override
protected void handleCancel(final Object extra) {
AbstractActivity activity = activityRef.get();
if (activity != null) {
activity.showToast((String) extra);
}
dismissProgress();
}
protected final void showToast(int resId) {
AbstractActivity activity = activityRef.get();
if (activity != null) {
Resources res = activity.getResources();
activity.showToast(res.getText(resId).toString());
}
}
protected final void dismissProgress() {
Progress progressDialog = progressDialogRef.get();
if (progressDialog != null) {
progressDialog.dismiss();
}
}
protected final void setProgressMessage(final String txt) {
Progress progressDialog = progressDialogRef.get();
if (progressDialog != null) {
progressDialog.setMessage(txt);
}
}
protected final void finishActivity() {
AbstractActivity activity = activityRef.get();
if (activity != null) {
activity.finish();
}
}
protected void updateStatusMsg(final int resId, final String msg) {
CacheDetailActivity activity = ((CacheDetailActivity) activityRef.get());
if (activity != null) {
setProgressMessage(activity.getResources().getString(resId)
+ "\n\n"
+ msg);
}
}
}
|