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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
import org.apache.commons.collections.CollectionUtils;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
public class cgeosmaps extends AbstractActivity {
private List<Bitmap> maps = new ArrayList<Bitmap>();
private String geocode = null;
private LayoutInflater inflater = null;
private ProgressDialog waitDialog = null;
private LinearLayout smapsView = null;
private BitmapFactory factory = null;
private Handler loadMapsHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
try {
if (CollectionUtils.isEmpty(maps)) {
if (waitDialog != null) {
waitDialog.dismiss();
}
showToast(res.getString(R.string.err_detail_not_load_map_static));
finish();
return;
} else {
if (waitDialog != null) {
waitDialog.dismiss();
}
if (inflater == null) {
inflater = getLayoutInflater();
}
if (smapsView == null) {
smapsView = (LinearLayout) findViewById(R.id.maps_list);
}
smapsView.removeAllViews();
for (Bitmap image : maps) {
if (image != null) {
final ImageView map = (ImageView) inflater.inflate(R.layout.map_static_item, null);
map.setImageBitmap(image);
smapsView.addView(map);
}
}
}
} catch (Exception e) {
if (waitDialog != null) {
waitDialog.dismiss();
}
Log.e(Settings.tag, "cgeosmaps.loadMapsHandler: " + e.toString());
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme();
setContentView(R.layout.map_static);
setTitle(res.getString(R.string.map_static_title));
// get parameters
Bundle extras = getIntent().getExtras();
// try to get data from extras
if (extras != null) {
geocode = extras.getString("geocode");
}
if (geocode == null) {
showToast("Sorry, c:geo forgot for what cache you want to load static maps.");
finish();
return;
}
waitDialog = ProgressDialog.show(this, null, res.getString(R.string.map_static_loading), true);
waitDialog.setCancelable(true);
(new loadMaps()).start();
}
@Override
public void onResume() {
super.onResume();
}
private class loadMaps extends Thread {
@Override
public void run() {
try {
if (factory == null) {
factory = new BitmapFactory();
}
for (int level = 1; level <= 5; level++) {
try {
final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, level, false).getPath());
if (image != null) {
maps.add(image);
}
} catch (Exception e) {
Log.e(Settings.tag, "cgeosmaps.loadMaps.run.1: " + e.toString());
}
}
if (maps.isEmpty()) {
for (int level = 1; level <= 5; level++) {
try {
final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, level, false).getPath());
if (image != null) {
maps.add(image);
}
} catch (Exception e) {
Log.e(Settings.tag, "cgeosmaps.loadMaps.run.2: " + e.toString());
}
}
}
loadMapsHandler.sendMessage(new Message());
} catch (Exception e) {
Log.e(Settings.tag, "cgeosmaps.loadMaps.run: " + e.toString());
}
}
}
}
|