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
|
package cgeo.geocaching;
import java.io.File;
import java.util.ArrayList;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import cgeo.geocaching.files.FileList;
import cgeo.geocaching.files.GPXParser;
import cgeo.geocaching.files.LocParser;
public class cgeogpxes extends FileList<cgGPXListAdapter> {
private static final String EXTRAS_LIST_ID = "list";
public cgeogpxes() {
super(new String[] {"gpx"
// TODO , "loc"
});
}
private ProgressDialog parseDialog = null;
private int listId = 1;
private int imported = 0;
final private Handler changeParseDialogHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.obj != null && parseDialog != null) {
parseDialog.setMessage(res.getString(R.string.gpx_import_loading_stored) + " " + (Integer) msg.obj);
}
}
};
final private Handler loadCachesHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
try {
if (parseDialog != null) {
parseDialog.dismiss();
}
helpDialog(res.getString(R.string.gpx_import_title_caches_imported), imported + " " + res.getString(R.string.gpx_import_caches_imported));
imported = 0;
} catch (Exception e) {
if (parseDialog != null) {
parseDialog.dismiss();
}
}
}
};
@Override
protected cgGPXListAdapter getAdapter(ArrayList<File> files) {
return new cgGPXListAdapter(this, getSettings(), files);
}
@Override
protected String[] getBaseFolders() {
String base = Environment.getExternalStorageDirectory().toString();
return new String[]{base + "/gpx"};
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
listId = extras.getInt(EXTRAS_LIST_ID);
}
if (listId <= 0) {
listId = 1;
}
}
@Override
protected void setTitle() {
setTitle(res.getString(R.string.gpx_import_title));
}
public void loadGPX(File file) {
parseDialog = ProgressDialog.show(
this,
res.getString(R.string.gpx_import_title_reading_file),
res.getString(R.string.gpx_import_loading),
true,
false);
new loadCaches(file).start();
}
private class loadCaches extends Thread {
File file = null;
public loadCaches(File fileIn) {
file = fileIn;
}
@Override
public void run() {
final long searchId;
String name = file.getName().toLowerCase();
if (name.endsWith("gpx")) {
searchId = GPXParser.parseGPX(app, file, listId, changeParseDialogHandler);
}
else {
searchId = LocParser.parseLoc(app, file, listId, changeParseDialogHandler);
}
imported = app.getCount(searchId);
loadCachesHandler.sendMessage(new Message());
}
}
public static void startSubActivity(Activity fromActivity, int listId) {
final Intent intent = new Intent(fromActivity, cgeogpxes.class);
intent.putExtra(EXTRAS_LIST_ID, listId);
fromActivity.startActivityForResult(intent, 0);
}
}
|