forked from labexp/osmtracker-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrack.java
More file actions
298 lines (232 loc) · 7.09 KB
/
Copy pathTrack.java
File metadata and controls
298 lines (232 loc) · 7.09 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
package net.osmtracker.db.model;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import net.osmtracker.R;
import net.osmtracker.db.TrackContentProvider;
import android.content.ContentResolver;
import android.database.Cursor;
/**
* Represents a Track
* @author Nicolas Guillaumin
*
*/
public class Track {
private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance();
public enum OSMVisibility {
Private(0, R.string.osm_visibility_private),
Public(1, R.string.osm_visibility_public),
Trackable(2, R.string.osm_visibility_trackable),
Identifiable(3, R.string.osm_visibility_identifiable);
public final int position;
public final int resId;
private OSMVisibility(int position, int resId) {
this.position = position;
this.resId = resId;
}
public static OSMVisibility fromPosition(int position) {
for (OSMVisibility v: values()) {
if (v.position == position) {
return v;
}
}
throw new IllegalArgumentException();
}
}
private String name;
private String description;
private OSMVisibility visibility;
private List<String> tags = new ArrayList<String>();
private int tpCount, wpCount, noteCount;
private long trackDate;
private long trackId;
private long maxSegId;
private Long startDate=null, endDate=null;
private Float startLat=null, startLong=null, endLat=null, endLong=null;
private boolean extraInformationRead = false;
private ContentResolver cr;
/**
* build a track object with the given cursor
*
* @param trackId id of the track that will be built
* @param tc cursor that is used to build the track
* @param cr the content resolver to use
* @param withExtraInformation if additional informations (startDate, endDate, first and last track point will be loaded from the database
* @return Track
*/
public static Track build(final long trackId, Cursor tc, ContentResolver cr, boolean withExtraInformation) {
Track out = new Track();
out.trackId = trackId;
out.cr = cr;
out.trackDate = tc.getLong(tc.getColumnIndex(TrackContentProvider.Schema.COL_START_DATE));
out.name = tc.getString(tc.getColumnIndex(TrackContentProvider.Schema.COL_NAME));
out.description = tc.getString(tc.getColumnIndex(TrackContentProvider.Schema.COL_DESCRIPTION));
String tags = tc.getString(tc.getColumnIndex(TrackContentProvider.Schema.COL_TAGS));
//TODO: use out.setTags(tags)
if (tags != null && ! "".equals(tags)) {
out.tags.addAll(Arrays.asList(tags.split(",")));
}
out.visibility = OSMVisibility.valueOf(tc.getString(tc.getColumnIndex(TrackContentProvider.Schema.COL_OSM_VISIBILITY)));
out.tpCount = tc.getInt(tc.getColumnIndex(TrackContentProvider.Schema.COL_TRACKPOINT_COUNT));
out.wpCount = tc.getInt(tc.getColumnIndex(TrackContentProvider.Schema.COL_WAYPOINT_COUNT));
out.noteCount = tc.getInt(tc.getColumnIndex(TrackContentProvider.Schema.COL_NOTE_COUNT));
out.maxSegId = tc.getLong(tc.getColumnIndex(TrackContentProvider.Schema.COL_SEG_ID_MAX));
if(withExtraInformation){
out.readExtraInformation();
}
return out;
}
private void readExtraInformation(){
if(!extraInformationRead){
Cursor startCursor = cr.query(TrackContentProvider.trackStartUri(trackId), null, null, null, null);
if(startCursor.moveToFirst()){
startDate = startCursor.getLong(startCursor.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP));
startLat = startCursor.getFloat(startCursor.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE));
startLong = startCursor.getFloat(startCursor.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE));
}
startCursor.close();
Cursor endCursor = cr.query(TrackContentProvider.trackEndUri(trackId), null, null, null, null);
if(endCursor.moveToFirst()){
endDate = endCursor.getLong(endCursor.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP));
endLat = endCursor.getFloat(endCursor.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE));
endLong = endCursor.getFloat(endCursor.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE));
}
endCursor.close();
extraInformationRead = true;
}
}
public void setName(String name) {
this.name = name;
}
public void setTrackId(long trackId) {
}
public long getTrackId() {
return this.trackId;
}
public void setDescription(String description) {
this.description = description;
}
public void setTpCount(int tpCount) {
this.tpCount = tpCount;
}
public void setWpCount(int wpCount) {
this.wpCount = wpCount;
}
public void setNoteCount(int noteCount) {
this.noteCount = noteCount;
}
public void setTracktDate(long tracktDate) {
this.trackDate = tracktDate;
}
public void setEndDate(long endDate) {
this.endDate = endDate;
}
public void setStartLat(float startLat) {
this.startLat = startLat;
}
public void setTrackDate(long trackDate) { this.trackDate = trackDate; }
public long getTrackDate() {
return trackDate;
}
public void setStartDate(long startDate) {
this.startDate = startDate;
}
public long getStartDate() {
return startDate;
}
public void setStartLong(float startLong) {
this.startLong = startLong;
}
public void setEndLat(float endLat) {
this.endLat = endLat;
}
public void setEndLong(float endLong) {
this.endLong = endLong;
}
public Integer getWpCount() {
return wpCount;
}
public long getMaxSegId() {
return maxSegId;
}
public Integer getTpCount() {
return tpCount;
}
public Integer getNoteCount() {
return noteCount;
}
// @deprecated
public String getDisplayName() {
if (name != null && name.length() > 0) {
return name;
} else {
// Use start date as name
return DATE_FORMAT.format(new Date(trackDate));
}
}
public String getName() { return name; }
public String getDescription() {
return description;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
public void setTags(String tags) {
if (tags != null && ! "".equals(tags)) {
this.tags.addAll(Arrays.asList(tags.split(",")));
}
}
public List<String> getTags() {
return tags;
}
public void setVisibility(OSMVisibility visibility) {
this.visibility = visibility;
}
public OSMVisibility getVisibility() {
return visibility;
}
public String getCommaSeparatedTags() {
StringBuilder sb = new StringBuilder();
for (int i=0; i<tags.size(); i++) {
sb.append(tags.get(i));
if (i+1 < tags.size()) {
sb.append(",");
}
}
return sb.toString();
}
public String getStartDateAsString() {
readExtraInformation();
if (startDate != null) {
return DATE_FORMAT.format(new Date(startDate));
} else {
return "";
}
}
public String getEndDateAsString() {
readExtraInformation();
if (endDate != null) {
return DATE_FORMAT.format(new Date(endDate));
} else {
return "";
}
}
public Float getStartLat() {
readExtraInformation();
return startLat;
}
public Float getStartLong() {
readExtraInformation();
return startLong;
}
public Float getEndLat() {
readExtraInformation();
return endLat;
}
public Float getEndLong() {
readExtraInformation();
return endLong;
}
}