Separate GPX imports for trail and dog.
This commit is contained in:
parent
36f58c3fd1
commit
14b9aae22c
|
|
@ -22,15 +22,20 @@ import java.util.List;
|
|||
public class FilePicker extends ListActivity {
|
||||
|
||||
public final static String EXTRA_FILE_PATH = "file_path";
|
||||
public final static String EXTRA_TRACE_TYPE = "trace_type";
|
||||
public final static String EXTRA_SHOW_HIDDEN_FILES = "show_hidden_files";
|
||||
public final static String EXTRA_ACCEPTED_FILE_EXTENSIONS = "accepted_file_extensions";
|
||||
private final static String DEFAULT_INITIAL_DIRECTORY = "/";
|
||||
|
||||
public static final String EXTRA_TRACE_TYPE_VALUE_DOG = "dog";
|
||||
public static final String EXTRA_TRACE_TYPE_VALUE_TRAIL = "trail";
|
||||
|
||||
protected File Directory;
|
||||
protected ArrayList<File> Files;
|
||||
protected FilePickerListAdapter Adapter;
|
||||
protected boolean ShowHiddenFiles = false;
|
||||
protected String[] acceptedFileExtensions;
|
||||
protected String traceType;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -62,6 +67,10 @@ public class FilePicker extends ListActivity {
|
|||
Directory = new File(getIntent().getStringExtra(EXTRA_FILE_PATH));
|
||||
}
|
||||
|
||||
if (getIntent().hasExtra(EXTRA_TRACE_TYPE)) {
|
||||
traceType = getIntent().getStringExtra(EXTRA_TRACE_TYPE);
|
||||
}
|
||||
|
||||
if (getIntent().hasExtra(EXTRA_SHOW_HIDDEN_FILES)) {
|
||||
ShowHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false);
|
||||
}
|
||||
|
|
@ -111,6 +120,7 @@ public class FilePicker extends ListActivity {
|
|||
if (newFile.isFile()) {
|
||||
Intent extra = new Intent();
|
||||
extra.putExtra(EXTRA_FILE_PATH, newFile.getAbsolutePath());
|
||||
extra.putExtra(EXTRA_TRACE_TYPE, traceType);
|
||||
setResult(RESULT_OK, extra);
|
||||
finish();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -361,8 +361,12 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.action_import_gpx) {
|
||||
startActivityPickFile();
|
||||
if (id == R.id.action_import_trail_gpx) {
|
||||
startActivityPickFile(FilePicker.EXTRA_TRACE_TYPE_VALUE_TRAIL);
|
||||
mDrawerLayout.closeDrawers();
|
||||
return true;
|
||||
} else if (id == R.id.action_import_dog_gpx) {
|
||||
startActivityPickFile(FilePicker.EXTRA_TRACE_TYPE_VALUE_DOG);
|
||||
mDrawerLayout.closeDrawers();
|
||||
return true;
|
||||
} else if (id == R.id.action_send_gpx_trail) {
|
||||
|
|
@ -404,9 +408,10 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void startActivityPickFile() {
|
||||
private void startActivityPickFile(String traceType) {
|
||||
Intent intent = new Intent(this, FilePicker.class);
|
||||
intent.putExtra(FilePicker.EXTRA_FILE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + appName);
|
||||
intent.putExtra(FilePicker.EXTRA_TRACE_TYPE, traceType);
|
||||
startActivityForResult(intent, ACTIVITY_REQUEST_PICK_FILE);
|
||||
}
|
||||
|
||||
|
|
@ -522,32 +527,36 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
switch (requestCode) {
|
||||
case ACTIVITY_REQUEST_PICK_FILE:
|
||||
if (data.hasExtra(FilePicker.EXTRA_FILE_PATH)) {
|
||||
serviceTrackingDog.importGpxTrace(new File(data.getStringExtra(FilePicker.EXTRA_FILE_PATH)));
|
||||
updateDogTrace();
|
||||
updateTrailTrace();
|
||||
updateSendTraceMenu();
|
||||
String traceType = data.getStringExtra(FilePicker.EXTRA_TRACE_TYPE);
|
||||
if (traceType != null && traceType.equals(FilePicker.EXTRA_TRACE_TYPE_VALUE_DOG)) {
|
||||
serviceTrackingDog.importDogGpxTrace(new File(data.getStringExtra(FilePicker.EXTRA_FILE_PATH)));
|
||||
updateDogTrace();
|
||||
|
||||
// Update distance
|
||||
distance = serviceTrackingDog.calculTrailDistance();
|
||||
if (distance != 0) {
|
||||
updatePlaceholder();
|
||||
}
|
||||
|
||||
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsTrail()) {
|
||||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), false);
|
||||
}
|
||||
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsDog()) {
|
||||
boolean isFound = false;
|
||||
if (loc instanceof WayPointLocation) {
|
||||
isFound = ((WayPointLocation) loc).isFound();
|
||||
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsDog()) {
|
||||
boolean isFound = false;
|
||||
if (loc instanceof WayPointLocation) {
|
||||
isFound = ((WayPointLocation) loc).isFound();
|
||||
}
|
||||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), isFound);
|
||||
}
|
||||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), isFound);
|
||||
}
|
||||
if (!serviceTrackingDog.getListGeoPointTraceur().isEmpty()) {
|
||||
updatePlaceholder(getTextTraceur());
|
||||
} else if (!serviceTrackingDog.getListGeoPointDog().isEmpty()) {
|
||||
updatePlaceholder(getTextDog());
|
||||
|
||||
} else if (traceType != null && traceType.equals(FilePicker.EXTRA_TRACE_TYPE_VALUE_TRAIL)) {
|
||||
serviceTrackingDog.importTrailGpxTrace(new File(data.getStringExtra(FilePicker.EXTRA_FILE_PATH)));
|
||||
updateTrailTrace();
|
||||
|
||||
// Update distance
|
||||
distance = serviceTrackingDog.calculTrailDistance();
|
||||
if (distance != 0) {
|
||||
updatePlaceholder();
|
||||
}
|
||||
|
||||
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsTrail()) {
|
||||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), false);
|
||||
}
|
||||
updatePlaceholder(getTextTraceur());
|
||||
}
|
||||
updateSendTraceMenu();
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -447,28 +447,35 @@ public class ServiceTrackingDog implements Observer {
|
|||
lastExportedTrailFile = file;
|
||||
return exportGpx.export();
|
||||
}
|
||||
public void importGpxTrace(File file) {
|
||||
public void importTrailGpxTrace(File file) {
|
||||
ImportGpx importGpx = new ImportGpx(file);
|
||||
try {
|
||||
List<MyLocation> list = importGpx.parse();
|
||||
String traceName = importGpx.getTraceName();
|
||||
if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
|
||||
lastExportedTrailFile = file;
|
||||
}
|
||||
lastExportedTrailFile = file;
|
||||
for (int i=0; i<list.size(); i++) {
|
||||
MyLocation o = list.get(i);
|
||||
if (o instanceof WayPointLocation) {
|
||||
if (traceName.equals(Gpx.DOG_TRACE_NAME)) {
|
||||
traces.addPointObjectDog((WayPointLocation) o);
|
||||
} else if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
|
||||
traces.addPointObjectTrail((WayPointLocation) o);
|
||||
}
|
||||
traces.addPointObjectTrail((WayPointLocation) o);
|
||||
} else if (o instanceof TraceLocation) {
|
||||
if (traceName.equals(Gpx.DOG_TRACE_NAME)) {
|
||||
traces.addPointDog((TraceLocation) o);
|
||||
} else if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
|
||||
traces.addPointTraceur((TraceLocation) o);
|
||||
}
|
||||
traces.addPointTraceur(o);
|
||||
}
|
||||
}
|
||||
} catch (XmlPullParserException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void importDogGpxTrace(File file) {
|
||||
ImportGpx importGpx = new ImportGpx(file);
|
||||
try {
|
||||
List<MyLocation> list = importGpx.parse();
|
||||
for (int i=0; i<list.size(); i++) {
|
||||
MyLocation o = list.get(i);
|
||||
if (o instanceof WayPointLocation) {
|
||||
traces.addPointObjectDog((WayPointLocation) o);
|
||||
} else if (o instanceof TraceLocation) {
|
||||
traces.addPointDog(o);
|
||||
}
|
||||
}
|
||||
} catch (XmlPullParserException e) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item
|
||||
android:id="@+id/action_import_gpx"
|
||||
android:title="@string/action_import_gpx"
|
||||
android:id="@+id/action_import_trail_gpx"
|
||||
android:title="@string/action_import_trail_gpx"
|
||||
android:icon="@drawable/ic_import" />
|
||||
<item
|
||||
android:id="@+id/action_import_dog_gpx"
|
||||
android:title="@string/action_import_dog_gpx"
|
||||
android:icon="@drawable/ic_import" />
|
||||
<item
|
||||
android:id="@+id/action_send_gpx_trail"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
<string name="dog_stop">Stop</string>
|
||||
<string name="dog_object">Objet trouvé</string>
|
||||
|
||||
<string name="action_import_gpx">Import GPX</string>
|
||||
<string name="action_import_trail_gpx">Import GPX traceur</string>
|
||||
<string name="action_import_dog_gpx">Import GPX chien</string>
|
||||
<string name="action_send_gpx_trail">Envoyer trace du traceur</string>
|
||||
<string name="action_send_to">Envoyer par</string>
|
||||
<string name="action_clear_trail">Supprimer données traceur</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue