1
1
package org .droidplanner .android .activities ;
2
2
3
3
import android .app .ProgressDialog ;
4
- import android .content .Context ;
5
4
import android .content .Intent ;
6
5
import android .location .Location ;
7
6
import android .location .LocationListener ;
8
- import android .net .Uri ;
9
7
import android .os .AsyncTask ;
10
8
import android .os .Bundle ;
11
- import android .os .ParcelFileDescriptor ;
12
9
import android .support .v4 .app .FragmentManager ;
13
- import android .util .Log ;
14
10
import android .view .Menu ;
15
11
import android .view .MenuItem ;
16
12
import android .view .View ;
21
17
import com .MAVLink .common .msg_global_position_int ;
22
18
import com .o3dr .android .client .data .tlog .TLogPicker ;
23
19
import com .o3dr .services .android .lib .coordinate .LatLong ;
20
+ import com .o3dr .services .android .lib .data .ServiceDataContract ;
24
21
import com .o3dr .services .android .lib .util .MathUtils ;
25
22
26
23
import org .beyene .sius .unit .length .LengthUnit ;
27
24
import org .droidplanner .android .R ;
28
- import org .droidplanner .android .dialogs .openfile .OpenFileDialog ;
29
- import org .droidplanner .android .dialogs .openfile .OpenTLogDialog ;
30
25
import org .droidplanner .android .fragments .LocatorListFragment ;
31
26
import org .droidplanner .android .fragments .LocatorMapFragment ;
32
27
import org .droidplanner .android .utils .file .IO .TLogReader ;
28
+ import org .droidplanner .android .utils .file .IO .TLogReader .Event ;
33
29
import org .droidplanner .android .utils .prefs .AutoPanMode ;
30
+ import org .droidplanner .android .utils .unit .providers .length .LengthUnitProvider ;
34
31
35
- import java .io .FileDescriptor ;
36
- import java .io .FileNotFoundException ;
37
32
import java .lang .ref .WeakReference ;
38
33
import java .util .LinkedList ;
39
34
import java .util .List ;
@@ -50,22 +45,24 @@ public class LocatorActivity extends DrawerNavigationUI implements LocatorListFr
50
45
private static final String STATE_LAST_SELECTED_POSITION = "STATE_LAST_SELECTED_POSITION" ;
51
46
private static final int TLOG_PICKER_REQUEST_CODE = 101 ;
52
47
53
- private final static List <msg_global_position_int > lastPositions = new LinkedList <>();
48
+ private final static List <TLogReader .Event > lastPositions = new LinkedList <>();
49
+
50
+ private OpenTLogFileAsyncTask tlogOpener ;
54
51
55
52
/*
56
53
View widgets.
57
54
*/
58
55
private LocatorMapFragment locatorMapFragment ;
59
56
private LocatorListFragment locatorListFragment ;
60
57
private LinearLayout statusView ;
61
- private TextView latView , lonView , distanceView , azimuthView ;
58
+ private TextView latView , lonView , distanceView , azimuthView , altitudeView ;
62
59
63
60
private msg_global_position_int selectedMsg ;
64
61
private LatLong lastGCSPosition ;
65
62
private float lastGCSBearingTo = Float .MAX_VALUE ;
66
63
private double lastGCSAzimuth = Double .MAX_VALUE ;
67
64
68
- public List <msg_global_position_int > getLastPositions () {
65
+ public List <Event > getLastPositions () {
69
66
return lastPositions ;
70
67
}
71
68
@@ -84,6 +81,7 @@ public void onCreate(Bundle savedInstanceState) {
84
81
lonView = (TextView ) findViewById (R .id .lonView );
85
82
distanceView = (TextView ) findViewById (R .id .distanceView );
86
83
azimuthView = (TextView ) findViewById (R .id .azimuthView );
84
+ altitudeView = (TextView ) findViewById (R .id .altitudeView );
87
85
88
86
final ImageButton zoomToFit = (ImageButton ) findViewById (R .id .zoom_to_fit_button );
89
87
zoomToFit .setVisibility (View .VISIBLE );
@@ -152,7 +150,7 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) {
152
150
153
151
final int lastSelectedPosition = savedInstanceState .getInt (STATE_LAST_SELECTED_POSITION , -1 );
154
152
if (lastSelectedPosition != -1 && lastSelectedPosition < lastPositions .size ())
155
- setSelectedMsg (lastPositions .get (lastSelectedPosition ));
153
+ setSelectedMsg (( msg_global_position_int ) lastPositions .get (lastSelectedPosition ). getMavLinkMessage ( ));
156
154
}
157
155
158
156
@ Override
@@ -187,16 +185,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent returnInten
187
185
return ;
188
186
}
189
187
190
- //Get the file's content uri from the incoming intent
191
- Uri returnUri = returnIntent .getData ( );
188
+ //Get the file's absolute path from the incoming intent
189
+ final String tlogAbsolutePath = returnIntent .getStringExtra ( ServiceDataContract . EXTRA_TLOG_ABSOLUTE_PATH );
192
190
193
- try {
194
- ParcelFileDescriptor inputFd = getContentResolver ().openFileDescriptor (returnUri , "r" );
195
- FileDescriptor fd = inputFd .getFileDescriptor ();
196
- new OpenTLogFileAsyncTask (this ).execute (fd );
197
- } catch (FileNotFoundException e ) {
198
- Log .e (TAG , "File not found." );
199
- }
191
+ if (tlogOpener != null )
192
+ tlogOpener .cancel (true );
193
+
194
+ tlogOpener = new OpenTLogFileAsyncTask (this );
195
+ tlogOpener .execute (tlogAbsolutePath );
200
196
}
201
197
202
198
/*
@@ -208,7 +204,7 @@ private void loadLastPositions(List<TLogReader.Event> logEvents) {
208
204
for (TLogReader .Event event : logEvents ) {
209
205
final msg_global_position_int message = (msg_global_position_int ) event .getMavLinkMessage ();
210
206
if (message .lat != 0 || message .lon != 0 )
211
- lastPositions .add (message );
207
+ lastPositions .add (event );
212
208
}
213
209
214
210
setSelectedMsg (null );
@@ -262,6 +258,12 @@ private void updateInfo() {
262
258
if (selectedMsg != null ) {
263
259
statusView .setVisibility (View .VISIBLE );
264
260
261
+ final LengthUnitProvider lengthUnitProvider = unitSystem .getLengthUnitProvider ();
262
+
263
+ final double altitude = selectedMsg .alt / 1000 ; //meters
264
+ LengthUnit convertedAltitude = lengthUnitProvider .boxBaseValueToTarget (altitude );
265
+ altitudeView .setText ("Altitude: " + convertedAltitude .toString ());
266
+
265
267
// coords
266
268
final LatLong msgCoord = coordFromMsgGlobalPositionInt (selectedMsg );
267
269
@@ -272,7 +274,7 @@ private void updateInfo() {
272
274
azimuthView .setText ("" );
273
275
} else {
274
276
final double distance = MathUtils .getDistance (lastGCSPosition , msgCoord );
275
- final LengthUnit convertedDistance = unitSystem . getLengthUnitProvider () .boxBaseValueToTarget (distance );
277
+ final LengthUnit convertedDistance = lengthUnitProvider .boxBaseValueToTarget (distance );
276
278
String distanceText = getString (R .string .editor_info_window_distance , convertedDistance .toString ());
277
279
if (lastGCSBearingTo != Float .MAX_VALUE ) {
278
280
final String bearing = String .format (" @ %.0f°" , lastGCSBearingTo );
@@ -294,6 +296,7 @@ private void updateInfo() {
294
296
lonView .setText ("" );
295
297
distanceView .setText ("" );
296
298
azimuthView .setText ("" );
299
+ altitudeView .setText ("" );
297
300
}
298
301
}
299
302
@@ -340,44 +343,44 @@ public void onProviderEnabled(String provider) {
340
343
public void onProviderDisabled (String provider ) {
341
344
}
342
345
343
- private static class OpenTLogFileAsyncTask extends AsyncTask <FileDescriptor , Void , List <TLogReader .Event >>{
346
+ private static class OpenTLogFileAsyncTask extends AsyncTask <String , Void , List <TLogReader .Event >> {
344
347
345
348
private final WeakReference <LocatorActivity > activityRef ;
346
349
private final ProgressDialog progressDialog ;
347
350
348
- public OpenTLogFileAsyncTask (LocatorActivity activity ){
351
+ public OpenTLogFileAsyncTask (LocatorActivity activity ) {
349
352
activityRef = new WeakReference <>(activity );
350
353
progressDialog = new ProgressDialog (activity );
351
- progressDialog .setTitle ("Processing ..." );
354
+ progressDialog .setTitle ("Loading data ..." );
352
355
progressDialog .setMessage ("Please wait." );
353
356
progressDialog .setIndeterminate (true );
354
357
}
355
358
356
359
@ Override
357
- protected void onPreExecute (){
360
+ protected void onPreExecute () {
358
361
progressDialog .show ();
359
362
}
360
363
361
364
@ Override
362
- protected List <TLogReader .Event > doInBackground (FileDescriptor ... params ) {
363
- FileDescriptor fd = params [0 ];
365
+ protected List <TLogReader .Event > doInBackground (String ... params ) {
366
+ final String filename = params [0 ];
364
367
365
368
TLogReader tlogReader = new TLogReader (msg_global_position_int .MAVLINK_MSG_ID_GLOBAL_POSITION_INT );
366
- tlogReader .openTLog (fd );
369
+ tlogReader .openTLog (filename );
367
370
368
371
return tlogReader .getLogEvents ();
369
372
}
370
373
371
374
@ Override
372
- protected void onCancelled (){
375
+ protected void onCancelled () {
373
376
progressDialog .dismiss ();
374
377
}
375
378
376
379
@ Override
377
- protected void onPostExecute (List <TLogReader .Event > events ){
380
+ protected void onPostExecute (List <TLogReader .Event > events ) {
378
381
progressDialog .dismiss ();
379
382
final LocatorActivity activity = activityRef .get ();
380
- if (activity == null )
383
+ if (activity == null )
381
384
return ;
382
385
383
386
activity .loadLastPositions (events );
0 commit comments