" + track.getNumberOfLocations() + " " + gpsApp.getApplicationContext().getString(R.string.trackpoints) + "" ;
+
+ kmlBW.write(" " + newLine);
+ kmlBW.write(" " + gpsApp.getApplicationContext().getString(R.string.tab_track) + " " + track.getName() + "" + newLine);
+ kmlBW.write(" " + newLine);
+ kmlBW.write(" #TrackStyle" + newLine);
+ kmlBW.write(" " + newLine);
+ kmlBW.write(" 0" + newLine);
+ kmlBW.write(" 0" + newLine);
+ kmlBW.write(" " + (getPrefKMLAltitudeMode == 1 ? "clampToGround" : "absolute") + "" + newLine);
+ kmlBW.write(" " + newLine);
}
- if (ExportGPX) {
- GPXbw.write("" + newLine);
- GPXbw.write(" " + GPSApp.getApplicationContext().getString(R.string.tab_track) + " " + track.getName() + "" + newLine);
- GPXbw.write(" " + newLine);
+ if (exportGPX) {
+ gpxBW.write("" + newLine);
+ gpxBW.write(" " + gpsApp.getApplicationContext().getString(R.string.tab_track) + " " + track.getName() + "" + newLine);
+ gpxBW.write(" " + newLine);
}
LocationExtended loc;
for (int i = 0; i < track.getNumberOfLocations(); i++) {
- loc = ArrayGeopoints.take();
+ loc = arrayGeopoints.take();
// Create formatted strings
formattedLatitude = String.format(Locale.US, "%.8f", loc.getLocation().getLatitude());
formattedLongitude = String.format(Locale.US, "%.8f", loc.getLocation().getLongitude());
- if (loc.getLocation().hasAltitude()) formattedAltitude = String.format(Locale.US, "%.3f", loc.getLocation().getAltitude() + AltitudeManualCorrection - (((loc.getAltitudeEGM96Correction() == NOT_AVAILABLE) || (!EGMAltitudeCorrection)) ? 0 : loc.getAltitudeEGM96Correction()));
- if(ExportGPX || ExportTXT) {
+ if (loc.getLocation().hasAltitude()) formattedAltitude = String.format(Locale.US, "%.3f", loc.getLocation().getAltitude() + altitudeManualCorrection - (((loc.getAltitudeEGM96Correction() == NOT_AVAILABLE) || (!egmAltitudeCorrection)) ? 0 : loc.getAltitudeEGM96Correction()));
+ if(exportGPX || exportTXT) {
if (loc.getLocation().hasSpeed())
formattedSpeed = String.format(Locale.US, "%.3f", loc.getLocation().getSpeed());
}
// KML
- if (ExportKML) {
- if (loc.getLocation().hasAltitude()) KMLbw.write(" " + formattedLongitude + "," + formattedLatitude + "," + formattedAltitude + newLine);
- else KMLbw.write(" " + formattedLongitude + "," + formattedLatitude + ",0" + newLine);
+ if (exportKML) {
+ if (loc.getLocation().hasAltitude()) kmlBW.write(" " + formattedLongitude + "," + formattedLatitude + "," + formattedAltitude + newLine);
+ else kmlBW.write(" " + formattedLongitude + "," + formattedLatitude + ",0" + newLine);
}
// GPX
- if (ExportGPX) {
- GPXbw.write(" ");
+ if (exportGPX) {
+ gpxBW.write(" ");
if (loc.getLocation().hasAltitude()) {
- GPXbw.write(""); // Elevation
- GPXbw.write(formattedAltitude);
- GPXbw.write("");
+ gpxBW.write(""); // Elevation
+ gpxBW.write(formattedAltitude);
+ gpxBW.write("");
}
- GPXbw.write(""); // Time
- //GPXbw.write(dfdtGPX.format(loc.getLocation().getTime()));
- GPXbw.write(((loc.getLocation().getTime() % 1000L) == 0L) ?
+ gpxBW.write(""); // Time
+ //gpxBW.write(dfdtGPX.format(loc.getLocation().getTime()));
+ gpxBW.write(((loc.getLocation().getTime() % 1000L) == 0L) ?
dfdtGPX_NoMillis.format(loc.getLocation().getTime()) :
dfdtGPX.format(loc.getLocation().getTime()));
- GPXbw.write("");
+ gpxBW.write("");
if (getPrefGPXVersion == GPX1_0) {
if (loc.getLocation().hasSpeed()) {
- GPXbw.write(""); // Speed
- GPXbw.write(formattedSpeed);
- GPXbw.write("");
+ gpxBW.write(""); // Speed
+ gpxBW.write(formattedSpeed);
+ gpxBW.write("");
}
}
if (loc.getNumberOfSatellitesUsedInFix() > 0) { // GPX standards requires sats used for FIX.
- GPXbw.write(""); // and NOT the number of satellites in view!!!
- GPXbw.write(String.valueOf(loc.getNumberOfSatellitesUsedInFix()));
- GPXbw.write("");
+ gpxBW.write(""); // and NOT the number of satellites in view!!!
+ gpxBW.write(String.valueOf(loc.getNumberOfSatellitesUsedInFix()));
+ gpxBW.write("");
}
/*
if (getPrefGPXVersion == GPX1_1) { // GPX 1.1 doesn't support speed tags. Let's switch to Garmin extensions :(
if (loc.getLocation().hasSpeed()) {
- GPXbw.write(""); // Speed (as Garmin extension)
- GPXbw.write(formattedSpeed);
- GPXbw.write("");
+ gpxBW.write(""); // Speed (as Garmin extension)
+ gpxBW.write(formattedSpeed);
+ gpxBW.write("");
}
} */
- GPXbw.write("" + newLine);
+ gpxBW.write("" + newLine);
}
// TXT
- if (ExportTXT) {
+ if (exportTXT) {
//type,time,latitude,longitude,altitude (m),geoid_height (m),speed (m/s),sat_used,sat_inview,name,desc
- //TXTbw.write("T," + dfdtTXT.format(loc.getLocation().getTime()) + "," + formattedLatitude + "," + formattedLongitude + ",");
- TXTbw.write("T," + (((loc.getLocation().getTime() % 1000L) == 0L) ?
+ //txtBW.write("T," + dfdtTXT.format(loc.getLocation().getTime()) + "," + formattedLatitude + "," + formattedLongitude + ",");
+ txtBW.write("T," + (((loc.getLocation().getTime() % 1000L) == 0L) ?
dfdtTXT_NoMillis.format(loc.getLocation().getTime()) :
dfdtTXT.format(loc.getLocation().getTime()))
+ "," + formattedLatitude + "," + formattedLongitude + ",");
if (loc.getLocation().hasAccuracy())
- TXTbw.write(String.format(Locale.US, "%.0f", loc.getLocation().getAccuracy()));
- TXTbw.write(",");
+ txtBW.write(String.format(Locale.US, "%.0f", loc.getLocation().getAccuracy()));
+ txtBW.write(",");
if (loc.getLocation().hasAltitude())
- TXTbw.write(formattedAltitude);
- TXTbw.write(",");
- if ((loc.getAltitudeEGM96Correction() != NOT_AVAILABLE) && (EGMAltitudeCorrection))
- TXTbw.write(String.format(Locale.US, "%.3f",loc.getAltitudeEGM96Correction()));
- TXTbw.write(",");
+ txtBW.write(formattedAltitude);
+ txtBW.write(",");
+ if ((loc.getAltitudeEGM96Correction() != NOT_AVAILABLE) && (egmAltitudeCorrection))
+ txtBW.write(String.format(Locale.US, "%.3f",loc.getAltitudeEGM96Correction()));
+ txtBW.write(",");
if (loc.getLocation().hasSpeed())
- TXTbw.write(formattedSpeed);
- TXTbw.write(",");
+ txtBW.write(formattedSpeed);
+ txtBW.write(",");
if (loc.getLocation().hasBearing())
- TXTbw.write(String.format(Locale.US, "%.0f", loc.getLocation().getBearing()));
- TXTbw.write(",");
+ txtBW.write(String.format(Locale.US, "%.0f", loc.getLocation().getBearing()));
+ txtBW.write(",");
if (loc.getNumberOfSatellitesUsedInFix() > 0)
- TXTbw.write(String.valueOf(loc.getNumberOfSatellitesUsedInFix()));
- TXTbw.write(",");
+ txtBW.write(String.valueOf(loc.getNumberOfSatellitesUsedInFix()));
+ txtBW.write(",");
if (loc.getNumberOfSatellites() > 0)
- TXTbw.write(String.valueOf(loc.getNumberOfSatellites()));
- TXTbw.write(",");
- if (TXTFirstTrackpointFlag) { // First trackpoint of the track: add the description
- TXTbw.write(track.getName() + ",GPS Logger: " + track.getName());
- TXTFirstTrackpointFlag = false;
- } else TXTbw.write(",");
- TXTbw.write(newLine);
+ txtBW.write(String.valueOf(loc.getNumberOfSatellites()));
+ txtBW.write(",");
+ if (txtFirstTrackpointFlag) { // First trackpoint of the track: add the description
+ if (track.getDescription().isEmpty()) txtBW.write(track.getName() + ",GPS Logger: " + track.getName());
+ else txtBW.write(track.getName() + ",GPS Logger: " + track.getName() + " - " + track.getDescription().replace(",", "_"));
+ txtFirstTrackpointFlag = false;
+ } else txtBW.write(",");
+ txtBW.write(newLine);
}
exportingTask.setNumberOfPoints_Processed(exportingTask.getNumberOfPoints_Processed() + 1);
}
exportingTask.setNumberOfPoints_Processed(track.getNumberOfPlacemarks() + track.getNumberOfLocations());
- ArrayGeopoints.clear();
+ arrayGeopoints.clear();
- if (ExportKML) {
- KMLbw.write(" " + newLine);
- KMLbw.write(" " + newLine);
- KMLbw.write(" " + newLine + newLine);
+ if (exportKML) {
+ kmlBW.write(" " + newLine);
+ kmlBW.write(" " + newLine);
+ kmlBW.write(" " + newLine + newLine);
}
- if (ExportGPX) {
- GPXbw.write(" " + newLine);
- GPXbw.write("" + newLine + newLine);
+ if (exportGPX) {
+ gpxBW.write(" " + newLine);
+ gpxBW.write("" + newLine + newLine);
}
}
@@ -649,29 +705,29 @@ public void run() {
// ------------------------------------------------------------ Writing tails and close
Log.w("myApp", "[#] Exporter.java - Writing Tails and close files");
- if (ExportKML) {
- KMLbw.write(" " + newLine);
- KMLbw.write("" + newLine + " ");
- KMLbw.flush();
- KMLbw.close();
- KMLfw.flush();
- KMLfw.close();
+ if (exportKML) {
+ kmlBW.write(" " + newLine);
+ kmlBW.write("" + newLine + " ");
+ kmlBW.flush();
+ kmlBW.close();
+ kmlFW.flush();
+ kmlFW.close();
}
- if (ExportGPX) {
- GPXbw.write("" + newLine + " ");
- GPXbw.flush();
- GPXbw.close();
- GPXfw.flush();
- GPXfw.close();
+ if (exportGPX) {
+ gpxBW.write("" + newLine + " ");
+ gpxBW.flush();
+ gpxBW.close();
+ gpxFW.flush();
+ gpxFW.close();
}
- if (ExportTXT) {
- TXTbw.flush();
- TXTbw.close();
- TXTfw.flush();
- TXTfw.close();
+ if (exportTXT) {
+ txtBW.flush();
+ txtBW.close();
+ txtFW.flush();
+ txtFW.close();
}
- Log.w("myApp", "[#] Exporter.java - Track "+ track.getId() +" exported in " + (System.currentTimeMillis() - start_Time) + " ms (" + elements_total + " pts @ " + ((1000L * elements_total) / (System.currentTimeMillis() - start_Time)) + " pts/s)");
+ Log.w("myApp", "[#] Exporter.java - Track "+ track.getId() +" exported in " + (System.currentTimeMillis() - startTime) + " ms (" + elements_total + " pts @ " + ((1000L * elements_total) / (System.currentTimeMillis() - startTime)) + " pts/s)");
//EventBus.getDefault().post(new EventBusMSGNormal(EventBusMSG.TRACK_EXPORTED, track.getId()));
exportingTask.setStatus(ExportingTask.STATUS_ENDED_SUCCESS);
} catch (IOException e) {
@@ -686,7 +742,15 @@ public void run() {
}
}
-
+ /**
+ * This Thread feeds the arrayGeopoints list with the GeoPoints, by querying
+ * small blocks of points from the DB and keeping the list as full as possible.
+ * The thread is started as soon as the Exported is started in order to fill the
+ * list meanwhile the Exporter is initializing the files and is writing the file headers.
+ *
+ * The Database reading and the file writing are decoupled into two separate Threads
+ * in order to optimise the Exporter's performance.
+ */
private class AsyncGeopointsLoader extends Thread {
public AsyncGeopointsLoader() {
@@ -695,15 +759,15 @@ public AsyncGeopointsLoader() {
public void run() {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
- List lList = new ArrayList<>(GroupOfLocations);
+ List lList = new ArrayList<>(groupOfLocations);
- for (int i = 0; i <= track.getNumberOfLocations(); i += GroupOfLocations) {
+ for (int i = 0; i <= track.getNumberOfLocations(); i += groupOfLocations) {
//Log.w("myApp", "[#] Exporter.java - " + (i + GroupOfLocations));
- lList.addAll(GPSApplication.getInstance().GPSDataBase.getLocationsList(track.getId(), i, i + GroupOfLocations - 1));
+ lList.addAll(GPSApplication.getInstance().gpsDataBase.getLocationsList(track.getId(), i, i + groupOfLocations - 1));
if (!lList.isEmpty()) {
for (LocationExtended loc : lList) {
try {
- ArrayGeopoints.put(loc);
+ arrayGeopoints.put(loc);
//Log.w("myApp", "[#] Exporter.java - " + ArrayGeopoints.size());
} catch (InterruptedException e) {
Log.w("myApp", "[#] Exporter.java - Interrupted: " + e);
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExportingTask.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExportingTask.java
index 6e3e7c05..075463ff 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExportingTask.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExportingTask.java
@@ -1,6 +1,9 @@
-/**
+/*
* ExportingTask - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 15/6/2019
+ * Created by G.Capelli on 15/6/2019
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,6 +21,11 @@
package eu.basicairdata.graziano.gpslogger;
+/**
+ * The data structure that stores all the information needed to export a Track.
+ * It stores the properties, the amount of work,
+ * and the status of the exportation.
+ */
public class ExportingTask {
static final short STATUS_PENDING = 0; // Task not yet started
@@ -26,11 +34,10 @@ public class ExportingTask {
static final short STATUS_ENDED_FAILED = 3; // Task failed to export
private long id = 0;
- private long NumberOfPoints_Total = 0;
- private long NumberOfPoints_Processed = 0;
- private short Status = STATUS_PENDING;
- private String Name = "";
-
+ private long numberOfPoints_Total = 0;
+ private long numberOfPoints_Processed = 0;
+ private short status = STATUS_PENDING;
+ private String name = "";
public long getId() {
return id;
@@ -41,35 +48,35 @@ public void setId(long id) {
}
public long getNumberOfPoints_Total() {
- return NumberOfPoints_Total;
+ return numberOfPoints_Total;
}
public void setNumberOfPoints_Total(long numberOfPoints_Total) {
- NumberOfPoints_Total = numberOfPoints_Total;
+ this.numberOfPoints_Total = numberOfPoints_Total;
}
public long getNumberOfPoints_Processed() {
- return NumberOfPoints_Processed;
+ return numberOfPoints_Processed;
}
public void setNumberOfPoints_Processed(long numberOfPoints_Processed) {
- NumberOfPoints_Processed = numberOfPoints_Processed;
+ this.numberOfPoints_Processed = numberOfPoints_Processed;
}
public short getStatus() {
- return Status;
+ return status;
}
public void setStatus(short status) {
- Status = status;
+ this.status = status;
}
public String getName() {
- return Name;
+ return name;
}
public void setName(String name) {
- Name = name;
+ this.name = name;
}
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewer.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewer.java
new file mode 100644
index 00000000..27b65cb5
--- /dev/null
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewer.java
@@ -0,0 +1,36 @@
+/*
+ * ExternalViewer - Java Class for Android
+ * Created by G.Capelli on 23/9/2020
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package eu.basicairdata.graziano.gpslogger;
+
+import android.graphics.drawable.Drawable;
+
+/**
+ * The data structure that describes a Track Viewer.
+ */
+public class ExternalViewer {
+ String label = ""; // The name of the app
+ String packageName = ""; // The full package name
+ String mimeType = ""; // The mimetype to use with the ACTION_VIEW intent (for example "application/gpx+xml")
+ String fileType = ""; // "GPX" or "KML"
+ boolean requiresFileProvider = true; // True if the app requires the FileProvider method to open the track
+ Drawable icon = null; // The app's icon
+}
\ No newline at end of file
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/AppDialogList.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerAdapter.java
similarity index 64%
rename from app/src/main/java/eu/basicairdata/graziano/gpslogger/AppDialogList.java
rename to app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerAdapter.java
index 7de6a67a..f35599f2 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/AppDialogList.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerAdapter.java
@@ -1,6 +1,9 @@
-/**
- * AppDialogList - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 23/9/2020
+/*
+ * ExternalViewerAdapter - Java Class for Android
+ * Created by G.Capelli on 23/9/2020
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,14 +34,20 @@
import static eu.basicairdata.graziano.gpslogger.GPSApplication.FILETYPE_KML;
import static eu.basicairdata.graziano.gpslogger.GPSApplication.FILETYPE_GPX;
-
-public class AppDialogList extends BaseAdapter {
-
- private ArrayList listData;
-
- private LayoutInflater layoutInflater;
-
- public AppDialogList(Context context, ArrayList listData) {
+/**
+ * The Adapter for the menu that lists the Track Viewers.
+ */
+public class ExternalViewerAdapter extends BaseAdapter {
+ private final ArrayList listData;
+ private final LayoutInflater layoutInflater;
+
+ /**
+ * Creates a new ExternalViewerAdapter using the specified ArrayList of ExternalViewer.
+ *
+ * @param context the base context
+ * @param listData the ArrayList of ExternalViewer to be used as adapter data.
+ */
+ public ExternalViewerAdapter(Context context, ArrayList listData) {
this.listData = listData;
this.layoutInflater = LayoutInflater.from(context);
}
@@ -58,30 +67,37 @@ public long getItemId(int position) {
return position;
}
+ /**
+ * Returns the View of the given position.
+ *
+ * @param position the position of the view
+ * @param convertView the view
+ * @param parent the parent ViewGroup
+ */
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.appdialog_list_row, null);
holder = new ViewHolder();
- holder.icon = (ImageView) convertView.findViewById(R.id.id_appdialog_row_imageView_icon);
- holder.description = (TextView) convertView.findViewById(R.id.id_appdialog_row_textView_description);
- holder.format = (TextView) convertView.findViewById(R.id.id_appdialog_row_textView_format);
+ holder.icon = convertView.findViewById(R.id.id_appdialog_row_imageView_icon);
+ holder.description = convertView.findViewById(R.id.id_appdialog_row_textView_description);
+ holder.format = convertView.findViewById(R.id.id_appdialog_row_textView_format);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
-
holder.icon.setImageDrawable(listData.get(position).icon);
holder.description.setText(listData.get(position).label);
holder.format.setText(listData.get(position).fileType.equals(FILETYPE_GPX) ? "GPX" : listData.get(position).fileType.equals(FILETYPE_KML) ? "KML" : "");
-
return convertView;
}
+ /**
+ * The class used into the ExternalViewerAdapter Class.
+ */
static class ViewHolder {
ImageView icon;
TextView description;
TextView format;
}
-
}
\ No newline at end of file
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerChecker.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerChecker.java
index 7a0f36ac..1cd13722 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerChecker.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerChecker.java
@@ -1,6 +1,9 @@
-/**
+/*
* ExternalViewerChecker - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 12/7/2020
+ * Created by G.Capelli on 12/7/2020
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,70 +26,97 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.net.Uri;
+
+import androidx.core.content.FileProvider;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import static eu.basicairdata.graziano.gpslogger.GPSApplication.FILE_EMPTY_GPX;
+import static eu.basicairdata.graziano.gpslogger.GPSApplication.FILE_EMPTY_KML;
import static eu.basicairdata.graziano.gpslogger.GPSApplication.FILETYPE_KML;
import static eu.basicairdata.graziano.gpslogger.GPSApplication.FILETYPE_GPX;
-
+/**
+ * A class that makes and stores the list of External Viewers available on the device.
+ * The list is made of ExternalViewer items.
+ */
public class ExternalViewerChecker {
private final Context context;
+ private ArrayList externalViewerList = new ArrayList<>(); // The list of Viewers available
+ private final CustomComparator comparator = new CustomComparator(); // The comparator for the ExternalViewer list sorting
- private ArrayList appInfoList = new ArrayList<>();
-
- static private class CustomComparator implements Comparator {
+ /**
+ * The comparator used to orders the ExternalViewer items alphabetically by label (app name)
+ */
+ static private class CustomComparator implements Comparator {
@Override
- public int compare(AppInfo o1, AppInfo o2) {
+ public int compare(ExternalViewer o1, ExternalViewer o2) {
return o1.label.compareTo(o2.label);
}
}
- private class FileType {
- FileType (ArrayList _packages, String _mimeType, String _fileType) {
- this.packages = _packages;
- this.fileType = _fileType;
- this.mimeType = _mimeType;
+ /**
+ * The class that defines a filtered research.
+ */
+ static private class FileType {
+
+ /**
+ * Creates a new filtered research.
+ *
+ * @param packages the ArrayList of string that contains the packages to research.
+ * A package, for example, could be "com.vecturagames.android.app.gpxviewer".
+ * Pass null to search all packages (no package filter).
+ * @param mimeType The Mime Type of the research (for example "application/gpx+xml").
+ * A Mime Type must be specified.
+ * @param fileType The type of file that will be associated to the apps found by the research.
+ * The valid values are GPSApplication.FILETYPE_KML (the viewer supports KML)
+ * and GPSApplication.FILETYPE_GPX (the viewer supports GPX.
+ */
+ FileType (ArrayList packages, String mimeType, String fileType) {
+ this.packages = packages;
+ this.fileType = fileType;
+ this.mimeType = mimeType;
}
+
ArrayList packages;
String mimeType;
String fileType;
}
- private ArrayList fileTypeList = new ArrayList<>();
-
- public ArrayList getAppInfoList() {
- return appInfoList;
+ public ArrayList getExternalViewersList() {
+ return externalViewerList;
}
- private final CustomComparator Comparator = new CustomComparator();
-
-
public ExternalViewerChecker(Context context) {
this.context = context;
}
-
public int size() {
- return appInfoList.size();
+ return externalViewerList.size();
}
-
public boolean isEmpty() {
- return (appInfoList.isEmpty());
+ return (externalViewerList.isEmpty());
}
-
- public void makeAppInfoList() {
+ /**
+ * Creates the ExternalViewer list basing on the research criteria.
+ * The criteria are defined into this method.
+ * The list of ExternalViewer are stored here into this ExternalViewerChecker class,
+ * and can be obtained from outside using the getExternalViewersList() method.
+ */
+ public void makeExternalViewersList() {
final PackageManager pm = context.getPackageManager();
- appInfoList = new ArrayList<>();
+ externalViewerList = new ArrayList<>();
+ ArrayList fileTypeList = new ArrayList<>();
- fileTypeList = new ArrayList<>();
fileTypeList.add(new FileType(null, "application/gpx+xml", FILETYPE_GPX)); // The preferred format first
fileTypeList.add(new FileType(null, "application/vnd.google-earth.kml+xml", FILETYPE_KML));
@@ -100,16 +130,24 @@ public void makeAppInfoList() {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
for (FileType ft : fileTypeList) {
- intent.setType(ft.mimeType);
+ //intent.setType(ft.mimeType);
+
+ File file = new File(ft.mimeType.equals(FILETYPE_GPX) ? FILE_EMPTY_GPX : FILE_EMPTY_KML);
+ Uri uri = FileProvider.getUriForFile(GPSApplication.getInstance(), "eu.basicairdata.graziano.gpslogger.fileprovider", file);
+ intent.setDataAndType(uri, ft.mimeType);
+
+// File file = new File(ft.mimeType.equals(FILETYPE_GPX) ? EMPTY_GPX : EMPTY_KML);
+// intent.setDataAndType(Uri.fromFile(file), ft.mimeType);
+
//Log.w("myApp", "[#] ExternalViewerChecker.java - " + ft.mimeType);
//Log.w("myApp", "[#] GPSApplication.java - Open with: " + ri.activityInfo.applicationInfo.loadLabel(getContext().getPackageManager()));
- List KMLlri = pm.queryIntentActivities(intent, 0);
- //Log.w("myApp", "[#] ExternalViewerChecker.java - Found " + KMLlri.size() + " viewers:");
- for (ResolveInfo tmpri : KMLlri) {
+ List kmlLRI = pm.queryIntentActivities(intent, 0);
+ //Log.w("myApp", "[#] ExternalViewerChecker.java - Found " + kmlLRI.size() + " viewers:");
+ for (ResolveInfo tmpRI : kmlLRI) {
boolean isPackageInList = false;
if (ft.packages != null) {
for (String s : ft.packages) {
- if (s.equals(tmpri.activityInfo.applicationInfo.packageName)) {
+ if (s.equals(tmpRI.activityInfo.applicationInfo.packageName)) {
isPackageInList = true;
break;
}
@@ -117,44 +155,48 @@ public void makeAppInfoList() {
} else isPackageInList = true;
if (isPackageInList) {
- AppInfo ainfo = new AppInfo();
- ainfo.packageName = tmpri.activityInfo.applicationInfo.packageName;
- ainfo.label = tmpri.activityInfo.applicationInfo.loadLabel(pm).toString();
+ ExternalViewer aInfo = new ExternalViewer();
+ aInfo.packageName = tmpRI.activityInfo.applicationInfo.packageName;
+ aInfo.label = tmpRI.activityInfo.applicationInfo.loadLabel(pm).toString();
boolean found = false;
- for (AppInfo a : appInfoList) {
- if (a.label.equals(ainfo.label) && a.packageName.equals(ainfo.packageName)) {
+ for (ExternalViewer a : externalViewerList) {
+ if (a.label.equals(aInfo.label) && a.packageName.equals(aInfo.packageName)) {
found = true;
- //Log.w("myApp", "[#] ExternalViewerChecker.java - " + tmpri.activityInfo.applicationInfo.packageName);
+ //Log.w("myApp", "[#] ExternalViewerChecker.java - " + tmpRI.activityInfo.applicationInfo.packageName);
break;
}
}
if (!found) {
- ainfo.mimeType = ft.mimeType;
- ainfo.fileType = ft.fileType;
- ainfo.icon = tmpri.activityInfo.applicationInfo.loadIcon(pm);
- appInfoList.add(ainfo);
- //Log.w("myApp", "[#] ExternalViewerChecker.java - + " + tmpri.activityInfo.applicationInfo.packageName);
+ aInfo.mimeType = ft.mimeType;
+ aInfo.fileType = ft.fileType;
+ aInfo.icon = tmpRI.activityInfo.applicationInfo.loadIcon(pm);
+ externalViewerList.add(aInfo);
+ //Log.w("myApp", "[#] ExternalViewerChecker.java - + " + tmpRI.activityInfo.applicationInfo.packageName);
}
}
}
}
// Sort List by Package Name
- Collections.sort(appInfoList, Comparator);
+ Collections.sort(externalViewerList, comparator);
// Apply Exceptions
- for (AppInfo a : appInfoList) {
+ for (ExternalViewer a : externalViewerList) {
if (a.packageName.equals("at.xylem.mapin")) {
// MAPinr is not opening GPX correctly!
a.fileType = FILETYPE_KML;
a.mimeType = "application/vnd.google-earth.kml+xml";
}
- if (a.packageName.equals("com.google.earth")) {
- // Google Earth opens file with fileProvider only
- a.requiresFileProvider = true;
+ if (a.packageName.equals("com.vecturagames.android.app.gpxviewer")) {
+ // GPX Viewer saves a copy of the file if passed via FileProvider
+ a.requiresFileProvider = false;
}
+// if (a.packageName.equals("com.google.earth")) {
+// // Google Earth opens file with fileProvider only
+// a.requiresFileProvider = true;
+// }
}
}
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentAboutDialog.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentAboutDialog.java
index cd755503..8b394f3b 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentAboutDialog.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentAboutDialog.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentAboutDialog - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 26/7/2016
+ * Created by G.Capelli on 26/7/2016
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,33 +34,35 @@
import android.widget.TextView;
import android.widget.Toast;
+/**
+ * The About Dialog Fragment
+ */
public class FragmentAboutDialog extends DialogFragment {
- TextView TVVersion;
- TextView TVDescription;
-
//@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
+ TextView tvVersion;
+ TextView tvDescription;
AlertDialog.Builder createAboutAlert = new AlertDialog.Builder(getActivity(), R.style.MyMaterialThemeAbout);
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.fragment_about_dialog, null);
- final GPSApplication app = GPSApplication.getInstance();
+ final GPSApplication gpsApp = GPSApplication.getInstance();
- TVVersion = (TextView) view.findViewById(R.id.id_about_textView_Version);
+ tvVersion = view.findViewById(R.id.id_about_textView_Version);
String versionName = BuildConfig.VERSION_NAME;
- TVVersion.setText(getString(R.string.about_version) + " " + versionName);
+ tvVersion.setText(getString(R.string.about_version) + " " + versionName);
- TVDescription = (TextView) view.findViewById(R.id.id_about_textView_description);
- switch (app.getAppOrigin()) {
+ tvDescription = view.findViewById(R.id.id_about_textView_description);
+ switch (gpsApp.getAppOrigin()) {
case GPSApplication.APP_ORIGIN_NOT_SPECIFIED:
- TVDescription.setText(getString(R.string.about_description));
+ tvDescription.setText(getString(R.string.about_description));
break;
case GPSApplication.APP_ORIGIN_GOOGLE_PLAY_STORE:
- TVDescription.setText(getString(R.string.about_description_googleplaystore));
+ tvDescription.setText(getString(R.string.about_description) + "\n\n" + getString(R.string.about_description_googleplaystore));
break;
}
@@ -66,16 +71,16 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
public void onClick(DialogInterface dialog, int id) {}
});
- if (app.getAppOrigin() != GPSApplication.APP_ORIGIN_NOT_SPECIFIED) {
+ if (gpsApp.getAppOrigin() != GPSApplication.APP_ORIGIN_NOT_SPECIFIED) {
createAboutAlert.setView(view).setNegativeButton(R.string.about_rate_this_app, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
- if (app.getAppOrigin() == GPSApplication.APP_ORIGIN_GOOGLE_PLAY_STORE) {
+ if (gpsApp.getAppOrigin() == GPSApplication.APP_ORIGIN_GOOGLE_PLAY_STORE) {
boolean marketfailed = false;
try {
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID)));
} catch (Exception e) {
- // Unable to start the Google Play app for rating
+ // Unable to start the Google Play gpsApp for rating
marketfailed = true;
}
if (marketfailed) {
@@ -90,7 +95,6 @@ public void onClick(DialogInterface dialog, int id) {
}
});
}
-
return createAboutAlert.create();
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentGPSFix.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentGPSFix.java
index 652f5898..e18bec56 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentGPSFix.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentGPSFix.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentGPSFix - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 10/5/2016
+ * Created by G.Capelli on 10/5/2016
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -33,6 +36,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TableLayout;
@@ -52,45 +56,44 @@
import static eu.basicairdata.graziano.gpslogger.GPSApplication.GPS_STABILIZING;
import static eu.basicairdata.graziano.gpslogger.GPSApplication.GPS_OK;
-
+/**
+ * The Fragment that displays the information of the Fix
+ * on the first tab (GPS FIX) of the main Activity (GPSActivity).
+ */
public class FragmentGPSFix extends Fragment {
- private PhysicalDataFormatter phdformatter = new PhysicalDataFormatter();
-
+ private final PhysicalDataFormatter phdformatter = new PhysicalDataFormatter();
+ private final GPSApplication gpsApp = GPSApplication.getInstance();
private boolean isAWarningClicked = false;
- private FrameLayout FLGPSFix;
-
- private TextView TVLatitude;
- private TextView TVLongitude;
- private TextView TVLatitudeUM;
- private TextView TVLongitudeUM;
- private TextView TVAltitude;
- private TextView TVAltitudeUM;
- private TextView TVSpeed;
- private TextView TVSpeedUM;
- private TextView TVBearing;
- private TextView TVAccuracy;
- private TextView TVAccuracyUM;
- private TextView TVGPSFixStatus;
- private TextView TVDirectionUM;
- private TextView TVTime;
- private TextView TVTimeLabel;
- private TextView TVSatellites;
-
- private CardView CVWarningLocationDenied;
- private CardView CVWarningGPSDisabled;
- private CardView CVWarningBackgroundRestricted;
-
- private TableLayout TLCoordinates;
- private TableLayout TLAltitude;
- private TableLayout TLSpeed;
- private TableLayout TLBearing;
- private TableLayout TLAccuracy;
- private TableLayout TLTime;
- private TableLayout TLSatellites;
-
- private LinearLayout LLTimeSatellites;
+ private FrameLayout flGPSFix;
+ private TextView tvLatitude;
+ private TextView tvLongitude;
+ private TextView tvLatitudeUM;
+ private TextView tvLongitudeUM;
+ private TextView tvAltitude;
+ private TextView tvAltitudeUM;
+ private TextView tvSpeed;
+ private TextView tvSpeedUM;
+ private TextView tvBearing;
+ private TextView tvAccuracy;
+ private TextView tvAccuracyUM;
+ private TextView tvGPSFixStatus;
+ private TextView tvDirectionUM;
+ private TextView tvTime;
+ private TextView tvTimeLabel;
+ private TextView tvSatellites;
+ private TableLayout tlCoordinates;
+ private TableLayout tlAltitude;
+ private TableLayout tlSpeed;
+ private TableLayout tlBearing;
+ private TableLayout tlAccuracy;
+ private TableLayout tlTime;
+ private TableLayout tlSatellites;
+ private CardView cvWarningLocationDenied;
+ private CardView cvWarningGPSDisabled;
+ private CardView cvWarningBackgroundRestricted;
+ private LinearLayout llTimeSatellites;
private PhysicalData phdLatitude;
private PhysicalData phdLongitude;
@@ -100,19 +103,53 @@ public class FragmentGPSFix extends Fragment {
private PhysicalData phdAccuracy;
private PhysicalData phdTime;
- final GPSApplication gpsApplication = GPSApplication.getInstance();
+ private LocationExtended location;
+ private double AltitudeManualCorrection;
+ private int prefDirections;
+ private int GPSStatus = GPS_DISABLED;
+ private boolean EGMAltitudeCorrection;
+ private boolean isValidAltitude;
+ private boolean isBackgroundActivityRestricted;
+
+ /**
+ * The Observer that calculate the new available height when the layout is changed.
+ * If the height is enough, it set the setSpaceForExtraTilesAvailable flag
+ * that enable the visualization of the extra tiles:
+ *
+ *
Time and Satellites for FragmentGPSFix
+ *
Trackpoints ane Annotation for FragmentTrack
+ * *
+ */
+ ViewTreeObserver.OnGlobalLayoutListener viewTreeObserverOnGLL = new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+ flGPSFix.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ } else {
+ flGPSFix.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ }
+ //int width = flGPSFix.getMeasuredWidth();
+ //int height = flGPSFix.getMeasuredHeight();
+ //Log.w("myApp", "[#] FragmentGPSFix MEASURED: " + width + " x " + height);
+ int viewHeight = tlSpeed.getMeasuredHeight() + (int)(6*getResources().getDisplayMetrics().density);
+ int layoutHeight = flGPSFix.getHeight() - (int)(6*getResources().getDisplayMetrics().density);
+ boolean isTimeAndSatellitesVisible;
+ if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
+ isTimeAndSatellitesVisible = layoutHeight >= 6*viewHeight;
+ //Log.w("myApp", "[#] FragmentGPSFix MEASURED: " + layoutHeight + " / " + 6*viewHeight + " -> " + isTimeAndSatellitesVisible);
+ } else {
+ isTimeAndSatellitesVisible = layoutHeight >= 3.9*viewHeight;
+ //Log.w("myApp", "[#] FragmentGPSFix MEASURED: " + layoutHeight + " / " + 3.9*viewHeight + " -> " + isTimeAndSatellitesVisible);
+ }
+ GPSApplication.getInstance().setSpaceForExtraTilesAvailable(isTimeAndSatellitesVisible);
+ update();
+ }
+ };
public FragmentGPSFix() {
// Required empty public constructor
}
- @Subscribe (threadMode = ThreadMode.MAIN)
- public void onEvent(Short msg) {
- if (msg == EventBusMSG.UPDATE_FIX) {
- Update();
- }
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -125,43 +162,43 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
View view = inflater.inflate(R.layout.fragment_gpsfix, container, false);
// FrameLayouts
- FLGPSFix = view.findViewById(R.id.id_fragmentgpsfixFrameLayout);
+ flGPSFix = view.findViewById(R.id.id_fragmentgpsfixFrameLayout);
// TextViews
- TVLatitude = view.findViewById(R.id.id_textView_Latitude);
- TVLongitude = view.findViewById(R.id.id_textView_Longitude);
- TVLatitudeUM = view.findViewById(R.id.id_textView_LatitudeUM);
- TVLongitudeUM = view.findViewById(R.id.id_textView_LongitudeUM);
- TVAltitude = view.findViewById(R.id.id_textView_Altitude);
- TVAltitudeUM = view.findViewById(R.id.id_textView_AltitudeUM);
- TVSpeed = view.findViewById(R.id.id_textView_Speed);
- TVSpeedUM = view.findViewById(R.id.id_textView_SpeedUM);
- TVBearing = view.findViewById(R.id.id_textView_Bearing);
- TVAccuracy = view.findViewById(R.id.id_textView_Accuracy);
- TVAccuracyUM = view.findViewById(R.id.id_textView_AccuracyUM);
- TVGPSFixStatus = view.findViewById(R.id.id_textView_GPSFixStatus);
- TVDirectionUM = view.findViewById(R.id.id_textView_BearingUM);
- TVTime = view.findViewById(R.id.id_textView_Time);
- TVTimeLabel = view.findViewById(R.id.id_textView_TimeLabel);
- TVSatellites = view.findViewById(R.id.id_textView_Satellites);
-
- CVWarningLocationDenied = view.findViewById(R.id.card_view_warning_location_denied);
- CVWarningGPSDisabled = view.findViewById(R.id.card_view_warning_enable_location_service);
- CVWarningBackgroundRestricted = view.findViewById(R.id.card_view_warning_background_restricted);
+ tvLatitude = view.findViewById(R.id.id_textView_Latitude);
+ tvLongitude = view.findViewById(R.id.id_textView_Longitude);
+ tvLatitudeUM = view.findViewById(R.id.id_textView_LatitudeUM);
+ tvLongitudeUM = view.findViewById(R.id.id_textView_LongitudeUM);
+ tvAltitude = view.findViewById(R.id.id_textView_Altitude);
+ tvAltitudeUM = view.findViewById(R.id.id_textView_AltitudeUM);
+ tvSpeed = view.findViewById(R.id.id_textView_Speed);
+ tvSpeedUM = view.findViewById(R.id.id_textView_SpeedUM);
+ tvBearing = view.findViewById(R.id.id_textView_Bearing);
+ tvAccuracy = view.findViewById(R.id.id_textView_Accuracy);
+ tvAccuracyUM = view.findViewById(R.id.id_textView_AccuracyUM);
+ tvGPSFixStatus = view.findViewById(R.id.id_textView_GPSFixStatus);
+ tvDirectionUM = view.findViewById(R.id.id_textView_BearingUM);
+ tvTime = view.findViewById(R.id.id_textView_Time);
+ tvTimeLabel = view.findViewById(R.id.id_textView_TimeLabel);
+ tvSatellites = view.findViewById(R.id.id_textView_Satellites);
+
+ cvWarningLocationDenied = view.findViewById(R.id.card_view_warning_location_denied);
+ cvWarningGPSDisabled = view.findViewById(R.id.card_view_warning_enable_location_service);
+ cvWarningBackgroundRestricted = view.findViewById(R.id.card_view_warning_background_restricted);
// TableLayouts
- TLCoordinates = view.findViewById(R.id.id_TableLayout_Coordinates) ;
- TLAltitude = view.findViewById(R.id.id_TableLayout_Altitude);
- TLSpeed = view.findViewById(R.id.id_TableLayout_Speed);
- TLBearing = view.findViewById(R.id.id_TableLayout_Bearing);
- TLAccuracy = view.findViewById(R.id.id_TableLayout_Accuracy);
- TLTime = view.findViewById(R.id.id_TableLayout_Time);
- TLSatellites = view.findViewById(R.id.id_TableLayout_Satellites);
+ tlCoordinates = view.findViewById(R.id.id_TableLayout_Coordinates) ;
+ tlAltitude = view.findViewById(R.id.id_TableLayout_Altitude);
+ tlSpeed = view.findViewById(R.id.id_TableLayout_Speed);
+ tlBearing = view.findViewById(R.id.id_TableLayout_Bearing);
+ tlAccuracy = view.findViewById(R.id.id_TableLayout_Accuracy);
+ tlTime = view.findViewById(R.id.id_TableLayout_Time);
+ tlSatellites = view.findViewById(R.id.id_TableLayout_Satellites);
// LinearLayouts
- LLTimeSatellites = view.findViewById(R.id.id_linearLayout_Time_Satellites);
+ llTimeSatellites = view.findViewById(R.id.id_linearLayout_Time_Satellites);
- CVWarningGPSDisabled.setOnClickListener(new View.OnClickListener() {
+ cvWarningGPSDisabled.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!isAWarningClicked && (GPSStatus == GPS_DISABLED)) {
@@ -178,7 +215,7 @@ public void onClick(View v) {
}
});
- CVWarningBackgroundRestricted.setOnClickListener(new View.OnClickListener() {
+ cvWarningBackgroundRestricted.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!isAWarningClicked && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)) {
@@ -198,13 +235,13 @@ public void onClick(View v) {
}
});
- CVWarningLocationDenied.setOnClickListener(new View.OnClickListener() {
+ cvWarningLocationDenied.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!isAWarningClicked) {
//isAWarningClicked = true;
GPSActivity gpsActivity = (GPSActivity) getActivity();
- gpsActivity.CheckLocationPermission();
+ gpsActivity.checkLocationPermission();
}
}
});
@@ -226,32 +263,47 @@ public void onResume() {
}
EventBus.getDefault().register(this);
- Update();
+
+ ViewTreeObserver vto = flGPSFix.getViewTreeObserver();
+ vto.addOnGlobalLayoutListener(viewTreeObserverOnGLL);
+
+ update();
}
@Override
public void onPause() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+ flGPSFix.getViewTreeObserver().removeGlobalOnLayoutListener(viewTreeObserverOnGLL);
+ } else {
+ flGPSFix.getViewTreeObserver().removeOnGlobalLayoutListener(viewTreeObserverOnGLL);
+ }
+
EventBus.getDefault().unregister(this);
super.onPause();
}
+ /**
+ * The EventBus receiver for Short Messages.
+ */
+ @Subscribe (threadMode = ThreadMode.MAIN)
+ public void onEvent(Short msg) {
+ if (msg == EventBusMSG.UPDATE_FIX) {
+ update();
+ }
+ }
- private LocationExtended location;
- private double AltitudeManualCorrection;
- private int prefDirections;
- private int GPSStatus = GPS_DISABLED;
- private boolean EGMAltitudeCorrection;
- private boolean isValidAltitude;
- private boolean isBackgroundActivityRestricted;
-
- public void Update() {
- //Log.w("myApp", "[#] FragmentGPSFix.java - Update(Location location)");
- location = gpsApplication.getCurrentLocationExtended();
- AltitudeManualCorrection = gpsApplication.getPrefAltitudeCorrection();
- prefDirections = gpsApplication.getPrefShowDirections();
- GPSStatus = gpsApplication.getGPSStatus();
- EGMAltitudeCorrection = gpsApplication.getPrefEGM96AltitudeCorrection();
- isBackgroundActivityRestricted = gpsApplication.isBackgroundActivityRestricted();
+ /**
+ * Updates the user interface of the fragment.
+ * It takes care of visibility and value of each tile, messages, and GPS Status widgets.
+ */
+ public void update() {
+ //Log.w("myApp", "[#] FragmentGPSFix.java - Update");
+ location = gpsApp.getCurrentLocationExtended();
+ AltitudeManualCorrection = gpsApp.getPrefAltitudeCorrection();
+ prefDirections = gpsApp.getPrefShowDirections();
+ GPSStatus = gpsApp.getGPSStatus();
+ EGMAltitudeCorrection = gpsApp.getPrefEGM96AltitudeCorrection();
+ isBackgroundActivityRestricted = gpsApp.isBackgroundActivityRestricted();
if (isAdded()) {
if ((location != null) && (GPSStatus == GPS_OK)) {
@@ -263,111 +315,90 @@ public void Update() {
phdAccuracy = phdformatter.format(location.getAccuracy(), PhysicalDataFormatter.FORMAT_ACCURACY);
phdTime = phdformatter.format(location.getTime(), PhysicalDataFormatter.FORMAT_TIME);
- TVLatitude.setText(phdLatitude.Value);
- TVLongitude.setText(phdLongitude.Value);
- TVLatitudeUM.setText(phdLatitude.UM);
- TVLongitudeUM.setText(phdLongitude.UM);
- TVAltitude.setText(phdAltitude.Value);
- TVAltitudeUM.setText(phdAltitude.UM);
- TVSpeed.setText(phdSpeed.Value);
- TVSpeedUM.setText(phdSpeed.UM);
- TVBearing.setText(phdBearing.Value);
- TVAccuracy.setText(phdAccuracy.Value);
- TVAccuracyUM.setText(phdAccuracy.UM);
- TVTime.setText(phdTime.Value);
- TVTimeLabel.setText(phdTime.UM.isEmpty() ? getString(R.string.time) : String.format(Locale.getDefault(), "%s (%s)", getString(R.string.time), phdTime.UM));
- TVSatellites.setText(location.getNumberOfSatellitesUsedInFix() != NOT_AVAILABLE ? location.getNumberOfSatellitesUsedInFix() + "/" + location.getNumberOfSatellites() : "");
+ tvLatitude.setText(phdLatitude.value);
+ tvLongitude.setText(phdLongitude.value);
+ tvLatitudeUM.setText(phdLatitude.um);
+ tvLongitudeUM.setText(phdLongitude.um);
+ tvAltitude.setText(phdAltitude.value);
+ tvAltitudeUM.setText(phdAltitude.um);
+ tvSpeed.setText(phdSpeed.value);
+ tvSpeedUM.setText(phdSpeed.um);
+ tvBearing.setText(phdBearing.value);
+ tvAccuracy.setText(phdAccuracy.value);
+ tvAccuracyUM.setText(phdAccuracy.um);
+ tvTime.setText(phdTime.value);
+ tvTimeLabel.setText(phdTime.um.isEmpty() ? getString(R.string.time) : String.format(Locale.getDefault(), "%s (%s)", getString(R.string.time), phdTime.um));
+ tvSatellites.setText(location.getNumberOfSatellitesUsedInFix() != NOT_AVAILABLE ? location.getNumberOfSatellitesUsedInFix() + "/" + location.getNumberOfSatellites() : "");
// Colorize the Altitude textview depending on the altitude EGM Correction
isValidAltitude = EGMAltitudeCorrection && (location.getAltitudeEGM96Correction() != NOT_AVAILABLE);
- TVAltitude.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
- TVAltitudeUM.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
-
- TVGPSFixStatus.setVisibility(View.GONE);
-
- TVDirectionUM.setVisibility(prefDirections == 0 ? View.GONE : View.VISIBLE);
-
- TLCoordinates.setVisibility(phdLatitude.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLAltitude.setVisibility(phdAltitude.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLSpeed.setVisibility(phdSpeed.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLBearing.setVisibility(phdBearing.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLAccuracy.setVisibility(phdAccuracy.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLTime.setVisibility(View.VISIBLE);
- TLSatellites.setVisibility(location.getNumberOfSatellitesUsedInFix() == NOT_AVAILABLE ? View.INVISIBLE : View.VISIBLE);
-
- FLGPSFix.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
- @Override
- public void onLayoutChange(View v, int left, int top, int right, int bottom,
- int oldLeft, int oldTop, int oldRight, int oldBottom) {
- FLGPSFix.removeOnLayoutChangeListener(this);
-
- int ViewHeight = TLTime.getMeasuredHeight() + (int)(6*getResources().getDisplayMetrics().density);
- int LayoutHeight = FLGPSFix.getHeight() - (int)(6*getResources().getDisplayMetrics().density);
- //Log.w("myApp", "[#]");
- //Log.w("myApp", "[#] -----------------------------------");
- boolean isTimeAndSatellitesVisible;
- if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
- isTimeAndSatellitesVisible = LayoutHeight >= 6*ViewHeight;
- //Log.w("myApp", "[#] " + LayoutHeight + " / " + 6*ViewHeight + " -> " + isTimeAndSatellitesVisible);
- } else {
- isTimeAndSatellitesVisible = LayoutHeight >= 4*ViewHeight;
- //Log.w("myApp", "[#] " + LayoutHeight + " / " + 4*ViewHeight + " -> " + isTimeAndSatellitesVisible);
- }
- LLTimeSatellites.setVisibility(isTimeAndSatellitesVisible ? View.VISIBLE : View.GONE);
-
- //Log.w("myApp", "[#] -----------------------------------");
- //Log.w("myApp", "[#] Available Height = " + LayoutHeight + " px");
- //Log.w("myApp", "[#] Density = " + getResources().getDisplayMetrics().density);
- //Log.w("myApp", "[#] Tile Height = " + ViewHeight + " px");
- }
- });
- TVGPSFixStatus.setVisibility(View.INVISIBLE);
- CVWarningBackgroundRestricted.setVisibility(View.GONE);
- CVWarningGPSDisabled.setVisibility(View.GONE);
- CVWarningLocationDenied.setVisibility(View.GONE);
+ tvAltitude.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
+ tvAltitudeUM.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
+
+ tvGPSFixStatus.setVisibility(View.GONE);
+
+ tvDirectionUM.setVisibility(prefDirections == 0 ? View.GONE : View.VISIBLE);
+
+ tlCoordinates.setVisibility(phdLatitude.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlAltitude.setVisibility(phdAltitude.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlSpeed.setVisibility(phdSpeed.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlBearing.setVisibility(phdBearing.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlAccuracy.setVisibility(phdAccuracy.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlTime.setVisibility(View.VISIBLE);
+ tlSatellites.setVisibility(location.getNumberOfSatellitesUsedInFix() == NOT_AVAILABLE ? View.INVISIBLE : View.VISIBLE);
+
+ llTimeSatellites.setVisibility(gpsApp.isSpaceForExtraTilesAvailable() ? View.VISIBLE : View.GONE);
+
+ tvGPSFixStatus.setVisibility(View.INVISIBLE);
+ cvWarningBackgroundRestricted.setVisibility(View.GONE);
+ cvWarningGPSDisabled.setVisibility(View.GONE);
+ cvWarningLocationDenied.setVisibility(View.GONE);
} else {
- TLCoordinates.setVisibility(View.INVISIBLE);
- TLAltitude.setVisibility(View.INVISIBLE);
- TLSpeed.setVisibility(View.INVISIBLE);
- TLBearing.setVisibility(View.INVISIBLE);
- TLAccuracy.setVisibility(View.INVISIBLE);
- TLTime.setVisibility(View.INVISIBLE);
- TLSatellites.setVisibility(View.INVISIBLE);
-
- TVGPSFixStatus.setVisibility(View.VISIBLE);
+ tlCoordinates.setVisibility(View.INVISIBLE);
+ tlAltitude.setVisibility(View.INVISIBLE);
+ tlSpeed.setVisibility(View.INVISIBLE);
+ tlBearing.setVisibility(View.INVISIBLE);
+ tlAccuracy.setVisibility(View.INVISIBLE);
+ tlTime.setVisibility(View.INVISIBLE);
+ tlSatellites.setVisibility(View.INVISIBLE);
+
+ String ssat = "";
+ if (((GPSStatus == GPS_SEARCHING) || (GPSStatus == GPS_STABILIZING) || (GPSStatus == GPS_TEMPORARYUNAVAILABLE)) && (gpsApp.getNumberOfSatellitesUsedInFix() != NOT_AVAILABLE)) {
+ ssat = "\n\n" + gpsApp.getNumberOfSatellitesUsedInFix() + "/" + gpsApp.getNumberOfSatellitesTotal() + " " + getString(R.string.satellites);
+ }
+
+ tvGPSFixStatus.setVisibility(View.VISIBLE);
switch (GPSStatus) {
case GPS_DISABLED:
- TVGPSFixStatus.setText(R.string.gps_disabled);
- CVWarningGPSDisabled.setVisibility(View.VISIBLE);
+ tvGPSFixStatus.setText(R.string.gps_disabled);
+ cvWarningGPSDisabled.setVisibility(View.VISIBLE);
break;
case GPS_OUTOFSERVICE:
- TVGPSFixStatus.setText(R.string.gps_out_of_service);
- CVWarningGPSDisabled.setVisibility(View.GONE);
+ tvGPSFixStatus.setText(R.string.gps_out_of_service);
+ cvWarningGPSDisabled.setVisibility(View.GONE);
break;
case GPS_TEMPORARYUNAVAILABLE:
- //TVGPSFixStatus.setText(R.string.gps_temporary_unavailable);
- //break;
case GPS_SEARCHING:
- TVGPSFixStatus.setText(R.string.gps_searching);
- CVWarningGPSDisabled.setVisibility(View.GONE);
+ tvGPSFixStatus.setText(getString(R.string.gps_searching) + ssat);
+ cvWarningGPSDisabled.setVisibility(View.GONE);
break;
case GPS_STABILIZING:
- TVGPSFixStatus.setText(R.string.gps_stabilizing);
- CVWarningGPSDisabled.setVisibility(View.GONE);
+ tvGPSFixStatus.setText(getString(R.string.gps_stabilizing) + ssat);
+ cvWarningGPSDisabled.setVisibility(View.GONE);
break;
}
if (isBackgroundActivityRestricted) {
- CVWarningBackgroundRestricted.setVisibility(View.VISIBLE);
+ cvWarningBackgroundRestricted.setVisibility(View.VISIBLE);
} else {
- CVWarningBackgroundRestricted.setVisibility(View.GONE);
+ cvWarningBackgroundRestricted.setVisibility(View.GONE);
}
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- TVGPSFixStatus.setText(R.string.gps_not_accessible);
- CVWarningLocationDenied.setVisibility(View.VISIBLE);
+ tvGPSFixStatus.setText(R.string.gps_not_accessible);
+ cvWarningLocationDenied.setVisibility(View.VISIBLE);
} else {
- CVWarningLocationDenied.setVisibility(View.GONE);
+ cvWarningLocationDenied.setVisibility(View.GONE);
}
}
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentJobProgress.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentJobProgress.java
index 8a8474e2..52d47e71 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentJobProgress.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentJobProgress.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentJobProgress - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 6/1/2019
+ * Created by G.Capelli on 6/1/2019
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,22 +32,24 @@
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
+/**
+ * The Fragment that displays the bar that shows the progress of a ExportingTask
+ * on the third tab (Tracklist) of the main Activity (GPSActivity).
+ */
public class FragmentJobProgress extends Fragment {
ProgressBar progressBar;
-
public FragmentJobProgress() {
// Required empty public constructor
}
-
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_job_progress, container, false);
- progressBar = (ProgressBar) view.findViewById(R.id.id_jobProgressBar);
+ progressBar = view.findViewById(R.id.id_jobProgressBar);
progressBar.setProgress(GPSApplication.getInstance().getJobProgress());
return view;
}
@@ -70,6 +75,9 @@ public void onPause() {
super.onPause();
}
+ /**
+ * The EventBus receiver for Short Messages.
+ */
@Subscribe (threadMode = ThreadMode.MAIN)
public void onEvent(Short msg) {
if (msg == EventBusMSG.UPDATE_JOB_PROGRESS) {
@@ -77,6 +85,9 @@ public void onEvent(Short msg) {
}
}
+ /**
+ * Updates the status of the Progressbar.
+ */
public void Update() {
if (isAdded()) {
progressBar.setProgress((GPSApplication.getInstance().getJobProgress() == 1000) || (GPSApplication.getInstance().getJobsPending() == 0 ) ? 0 : GPSApplication.getInstance().getJobProgress());
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentPlacemarkDialog.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentPlacemarkDialog.java
index 843d4aaa..44f696ad 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentPlacemarkDialog.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentPlacemarkDialog.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentPlacemarkDialog - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 9/7/2016
+ * Created by G.Capelli on 9/7/2016
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,7 +28,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
@@ -36,30 +38,33 @@
import org.greenrobot.eventbus.EventBus;
+/**
+ * The dialog that appears when the user adds a new Annotation (Placemark).
+ */
public class FragmentPlacemarkDialog extends DialogFragment {
- EditText DescEditText;
+ EditText etDescription;
//@SuppressLint("InflateParams")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder createPlacemarkAlert = new AlertDialog.Builder(getActivity());
- createPlacemarkAlert.setTitle(R.string.dlg_add_placemark);
- createPlacemarkAlert.setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_add_location_24dp, getActivity().getTheme()));
+ createPlacemarkAlert.setTitle(R.string.dlg_add_annotation);
+ //createPlacemarkAlert.setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_add_location_24dp, getActivity().getTheme()));
LayoutInflater inflater = getActivity().getLayoutInflater();
- final View view = (View) inflater.inflate(R.layout.fragment_placemark_dialog, null);
+ final View view = inflater.inflate(R.layout.fragment_placemark_dialog, null);
- DescEditText = (EditText) view.findViewById(R.id.placemark_description);
- DescEditText.postDelayed(new Runnable()
+ etDescription = view.findViewById(R.id.placemark_description);
+ etDescription.postDelayed(new Runnable()
{
public void run()
{
if (isAdded()) {
- DescEditText.requestFocus();
- InputMethodManager mgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
- mgr.showSoftInput(DescEditText, InputMethodManager.SHOW_IMPLICIT);
+ etDescription.requestFocus();
+ InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ inputMethodManager.showSoftInput(etDescription, InputMethodManager.SHOW_IMPLICIT);
}
}
}, 200);
@@ -70,15 +75,15 @@ public void run()
@Override
public void onClick(DialogInterface dialog, int id) {
if (isAdded()) {
- String PlacemarkDescription = DescEditText.getText().toString();
- final GPSApplication GlobalVariables = (GPSApplication) getActivity().getApplicationContext();
- GlobalVariables.setPlacemarkDescription(PlacemarkDescription.trim());
+ String placemarkDescription = etDescription.getText().toString();
+ final GPSApplication gpsApp = GPSApplication.getInstance();
+ gpsApp.setPlacemarkDescription(placemarkDescription.trim());
EventBus.getDefault().post(EventBusMSG.ADD_PLACEMARK);
- //Log.w("myApp", "[#] FragmentPlacemarkDialog.java - posted ADD_PLACEMARK: " + PlacemarkDescription);
+ //Log.w("myApp", "[#] FragmentPlacemarkDialog.java - posted ADD_PLACEMARK: " + placemarkDescription);
}
}
})
- .setNegativeButton(R.string.dlg_button_cancel, new DialogInterface.OnClickListener() {
+ .setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentRecordingControls.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentRecordingControls.java
index 66a5268b..0935a313 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentRecordingControls.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentRecordingControls.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentRecordingControls - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 20/5/2016
+ * Created by G.Capelli on 20/5/2016
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,37 +22,46 @@
package eu.basicairdata.graziano.gpslogger;
-
import android.graphics.Color;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
+
+import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.TableLayout;
import android.widget.TextView;
+import android.widget.Toast;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
-public class FragmentRecordingControls extends Fragment{
+import static eu.basicairdata.graziano.gpslogger.GPSApplication.TOAST_VERTICAL_OFFSET;
+
+/**
+ * The Fragment that displays and manages the bottom bar.
+ */
+public class FragmentRecordingControls extends Fragment {
+
+ private TextView tvGeoPointsNumber;
+ private TextView tvPlacemarksNumber;
+ private TextView tvLockButton;
+ private TextView tvStopButton;
+ private TextView tvAnnotateButton;
+ private TextView tvRecordButton;
+ final GPSApplication gpsApp = GPSApplication.getInstance();
public FragmentRecordingControls() {
// Required empty public constructor
}
- TableLayout tableLayoutGeoPoints;
- TableLayout tableLayoutPlacemarks;
-
- private TextView TVGeoPoints;
- private TextView TVPlacemarks;
- private TextView TVGeoPointsLabel;
- private TextView TVPlacemarksLabel;
-
- final GPSApplication gpsApplication = GPSApplication.getInstance();
-
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -60,27 +72,36 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_recording_controls, container, false);
- tableLayoutGeoPoints = (TableLayout) view.findViewById(R.id.id_TableLayout_GeoPoints);
- tableLayoutGeoPoints.setOnClickListener(new View.OnClickListener() {
+ tvLockButton = view.findViewById(R.id.id_lock);
+ tvLockButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- ontoggleRecordGeoPoint(v);
+ onToggleLock();
}
});
-
- tableLayoutPlacemarks = (TableLayout) view.findViewById(R.id.id_TableLayout_Placemarks);
- tableLayoutPlacemarks.setOnClickListener(new View.OnClickListener() {
+ tvStopButton = view.findViewById(R.id.id_stop);
+ tvStopButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- onPlacemarkRequest(v);
+ onRequestStop();
}
});
-
- TVGeoPoints = (TextView) view.findViewById(R.id.id_textView_GeoPoints);
- TVPlacemarks = (TextView) view.findViewById(R.id.id_textView_Placemarks);
- TVGeoPointsLabel = (TextView) view.findViewById(R.id.id_textView_GeoPointsLabel);
- TVPlacemarksLabel = (TextView) view.findViewById(R.id.id_textView_PlacemarksLabel);
-
+ tvAnnotateButton = view.findViewById(R.id.id_annotate);
+ tvAnnotateButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onRequestAnnotation();
+ }
+ });
+ tvRecordButton = view.findViewById(R.id.id_record);
+ tvRecordButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onToggleRecord();
+ }
+ });
+ tvGeoPointsNumber = view.findViewById(R.id.id_textView_GeoPoints);
+ tvPlacemarksNumber = view.findViewById(R.id.id_textView_Placemarks);
return view;
}
@@ -94,7 +115,6 @@ public void onResume() {
//Log.w("myApp", "[#] FragmentRecordingControls - EventBus: FragmentRecordingControls already registered");
EventBus.getDefault().unregister(this);
}
-
EventBus.getDefault().register(this);
Update();
}
@@ -105,51 +125,222 @@ public void onPause() {
super.onPause();
}
- public void ontoggleRecordGeoPoint(View view) {
+ /**
+ * The EventBus receiver for Short Messages.
+ */
+ @Subscribe (threadMode = ThreadMode.MAIN)
+ public void onEvent(Short msg) {
+ if (msg == EventBusMSG.UPDATE_TRACK) {
+ Update();
+ }
+ }
+
+ /**
+ * Toggles the status of the recording, by managing the button behaviour and
+ * the status of the recording process.
+ * It also displays some toasts to inform the user about some conditions.
+ */
+ public void onToggleRecord() {
if (isAdded()) {
- final Boolean grs = gpsApplication.getRecording();
- boolean newRecordingState = !grs;
- gpsApplication.setRecording(newRecordingState);
- EventBus.getDefault().post(EventBusMSG.UPDATE_TRACK);
- tableLayoutGeoPoints.setBackgroundColor(newRecordingState ? getResources().getColor(R.color.colorPrimary) : Color.TRANSPARENT);
- TVGeoPoints.setTextColor(getResources().getColor(newRecordingState ? R.color.textColorRecControlPrimary_Active : R.color.textColorRecControlPrimary));
- TVGeoPointsLabel.setTextColor(getResources().getColor(newRecordingState ? R.color.textColorRecControlSecondary_Active : R.color.textColorRecControlSecondary));
+ if (!gpsApp.isBottomBarLocked()) {
+ if (!gpsApp.isStopButtonFlag()) {
+ gpsApp.setRecording(!gpsApp.isRecording());
+ if (!gpsApp.isFirstFixFound() && (gpsApp.isRecording())) {
+ Toast toast = Toast.makeText(gpsApp.getApplicationContext(), R.string.toast_recording_when_gps_found, Toast.LENGTH_LONG);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ }
+ Update();
+ }
+ } else {
+ Toast toast = Toast.makeText(gpsApp.getApplicationContext(), R.string.toast_bottom_bar_locked, Toast.LENGTH_SHORT);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ }
}
}
- public void onPlacemarkRequest(View view) {
+ /**
+ * Toggles the status of the placemark request, by managing the button behaviour and
+ * the status of the request.
+ * It also displays some toasts to inform the user about some conditions.
+ */
+ public void onRequestAnnotation() {
if (isAdded()) {
- final Boolean pr = gpsApplication.getPlacemarkRequest();
- boolean newPlacemarkRequestState = !pr;
- gpsApplication.setPlacemarkRequest(newPlacemarkRequestState);
- tableLayoutPlacemarks.setBackgroundColor(newPlacemarkRequestState ? getResources().getColor(R.color.colorPrimary) : Color.TRANSPARENT);
- TVPlacemarks.setTextColor(getResources().getColor(newPlacemarkRequestState ? R.color.textColorRecControlPrimary_Active : R.color.textColorRecControlPrimary));
- TVPlacemarksLabel.setTextColor(getResources().getColor(newPlacemarkRequestState ? R.color.textColorRecControlSecondary_Active : R.color.textColorRecControlSecondary));
+ if (!gpsApp.isBottomBarLocked()) {
+ if (!gpsApp.isStopButtonFlag()) {
+ gpsApp.setPlacemarkRequested(!gpsApp.isPlacemarkRequested());
+ if (!gpsApp.isFirstFixFound() && (gpsApp.isPlacemarkRequested())) {
+ Toast toast = Toast.makeText(gpsApp.getApplicationContext(), R.string.toast_annotate_when_gps_found, Toast.LENGTH_LONG);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ }
+ Update();
+ }
+ } else {
+ Toast toast = Toast.makeText(gpsApp.getApplicationContext(), R.string.toast_bottom_bar_locked, Toast.LENGTH_SHORT);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ }
+ }
+ }
+ /**
+ * Manages the Stop button behaviour.
+ * It also displays some toasts to inform the user about some conditions.
+ */
+ public void onRequestStop() {
+ if (isAdded()) {
+ if (!gpsApp.isBottomBarLocked()) {
+ if (!gpsApp.isStopButtonFlag()) {
+ gpsApp.setStopButtonFlag(true, gpsApp.getCurrentTrack().getNumberOfLocations() + gpsApp.getCurrentTrack().getNumberOfPlacemarks() > 0 ? 1000 : 300);
+ gpsApp.setRecording(false);
+ gpsApp.setPlacemarkRequested(false);
+ Update();
+ if (gpsApp.getCurrentTrack().getNumberOfLocations() + gpsApp.getCurrentTrack().getNumberOfPlacemarks() > 0) {
+ FragmentManager fm = getActivity().getSupportFragmentManager();
+ FragmentTrackPropertiesDialog tpDialog = new FragmentTrackPropertiesDialog();
+ gpsApp.setTrackToEdit(gpsApp.getCurrentTrack());
+ tpDialog.setTitleResource(R.string.finalize_track);
+ tpDialog.setFinalizeTrackWithOk(true);
+ tpDialog.show(fm, "");
+ } else {
+ Toast toast = Toast.makeText(gpsApp.getApplicationContext(), R.string.toast_nothing_to_save, Toast.LENGTH_SHORT);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ }
+ }
+ } else {
+ Toast toast = Toast.makeText(gpsApp.getApplicationContext(), R.string.toast_bottom_bar_locked, Toast.LENGTH_SHORT);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ }
}
}
- @Subscribe (threadMode = ThreadMode.MAIN)
- public void onEvent(Short msg) {
- if (msg == EventBusMSG.UPDATE_TRACK) {
+ /**
+ * Manages the Lock button behaviour.
+ */
+ public void onToggleLock() {
+ if (isAdded()) {
+ gpsApp.setBottomBarLocked(!gpsApp.isBottomBarLocked());
+ if (gpsApp.isBottomBarLocked()) {
+ Toast toast = Toast.makeText(gpsApp.getApplicationContext(), R.string.toast_bottom_bar_locked, Toast.LENGTH_SHORT);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ }
Update();
}
}
+ /**
+ * Sets the color of a drawable.
+ *
+ * @param drawable The Drawable
+ * @param color The new Color to set
+ */
+ private void setTextViewDrawableColor(Drawable drawable, int color) {
+ if (drawable != null) {
+ drawable.clearColorFilter();
+ drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
+ }
+ }
+
+// private void setButtonToClickedState(@NonNull TextView button, int imageId, int stringId) {
+// ColorDrawable[] colorDrawables = {new ColorDrawable(getResources().getColor(R.color.colorPrimaryLight)),
+// new ColorDrawable(getResources().getColor(R.color.colorPrimary))};
+// TransitionDrawable transitionDrawable = new TransitionDrawable(colorDrawables);
+//
+// button.setBackgroundDrawable(transitionDrawable);
+// if (imageId != 0) button.setCompoundDrawablesWithIntrinsicBounds(0, imageId, 0, 0);
+// button.setTextColor(getResources().getColor(R.color.textColorRecControlSecondary_Active));
+// if (stringId != 0) button.setText(getString(stringId));
+// setTextViewDrawableColor(button.getCompoundDrawables()[1], getResources().getColor(R.color.textColorRecControlPrimary_Active));
+// transitionDrawable.startTransition(500);
+// }
+
+ /**
+ * Sets the appearance of a button (TextView + upper compound Drawable) as "Clicked",
+ * by setting the specified Drawable and Text and applying the right colours.
+ *
+ * @param button The TextView button
+ * @param imageId The resource of the drawable
+ * @param stringId The resource of the string
+ */
+ private void setButtonToClickedState(@NonNull TextView button, int imageId, int stringId) {
+ button.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
+ if (imageId != 0) button.setCompoundDrawablesWithIntrinsicBounds(0, imageId, 0, 0);
+ button.setTextColor(getResources().getColor(R.color.textColorRecControlSecondary_Active));
+ if (stringId != 0) button.setText(getString(stringId));
+ setTextViewDrawableColor(button.getCompoundDrawables()[1], getResources().getColor(R.color.textColorRecControlPrimary_Active));
+ }
+
+ /**
+ * Sets the appearance of a button (TextView + upper compound Drawable) as "Normal",
+ * by setting the specified Drawable and Text and applying the right colours.
+ *
+ * @param button The TextView button
+ * @param imageId The resource of the drawable
+ * @param stringId The resource of the string
+ */
+ private void setButtonToNormalState(@NonNull TextView button, int imageId, int stringId) {
+ button.setBackgroundColor(Color.TRANSPARENT);
+ if (imageId != 0) button.setCompoundDrawablesWithIntrinsicBounds(0, imageId, 0, 0);
+ button.setTextColor(getResources().getColor(R.color.textColorRecControlSecondary));
+ if (stringId != 0) button.setText(getString(stringId));
+ setTextViewDrawableColor(button.getCompoundDrawables()[1], getResources().getColor(R.color.textColorRecControlPrimary));
+ }
+
+ /**
+ * Sets the appearance of a button (TextView + upper compound Drawable) as "Disabled"
+ * by setting the specified Drawable and Text and applying the right colours.
+ *
+ * @param button The TextView button
+ * @param imageId The resource of the drawable
+ * @param stringId The resource of the string
+ */
+ private void setButtonToDisabledState(@NonNull TextView button, int imageId, int stringId) {
+ button.setBackgroundColor(Color.TRANSPARENT);
+ if (imageId != 0) button.setCompoundDrawablesWithIntrinsicBounds(0, imageId, 0, 0);
+ button.setTextColor(getResources().getColor(R.color.textColorRecControlDisabled));
+ if (stringId != 0) button.setText(getString(stringId));
+ setTextViewDrawableColor(button.getCompoundDrawables()[1], getResources().getColor(R.color.textColorRecControlDisabled));
+ }
+
+ /**
+ * Updates the user interface of the fragment.
+ * It takes care of the state of each button.
+ */
public void Update() {
if (isAdded()) {
- final Track track = gpsApplication.getCurrentTrack();
- final Boolean grs = gpsApplication.getRecording();
- final Boolean pr = gpsApplication.getPlacemarkRequest();
+ final Track track = gpsApp.getCurrentTrack();
+ final boolean isRec = gpsApp.isRecording();
+ final boolean isAnnot = gpsApp.isPlacemarkRequested();
+ final boolean isLck = gpsApp.isBottomBarLocked();
if (track != null) {
- if (TVGeoPoints != null) TVGeoPoints.setText(String.valueOf(track.getNumberOfLocations()));
- if (TVPlacemarks != null) TVPlacemarks.setText(String.valueOf(track.getNumberOfPlacemarks()));
- if (tableLayoutGeoPoints != null) tableLayoutGeoPoints.setBackgroundColor(grs ? getResources().getColor(R.color.colorPrimary) : Color.TRANSPARENT);
- if (tableLayoutPlacemarks != null) tableLayoutPlacemarks.setBackgroundColor(pr ? getResources().getColor(R.color.colorPrimary) : Color.TRANSPARENT);
- if (TVPlacemarks != null) TVPlacemarks.setTextColor(getResources().getColor(pr ? R.color.textColorRecControlPrimary_Active : R.color.textColorRecControlPrimary));
- if (TVPlacemarksLabel != null) TVPlacemarksLabel.setTextColor(getResources().getColor(pr ? R.color.textColorRecControlSecondary_Active : R.color.textColorRecControlSecondary));
- if (TVGeoPoints != null) TVGeoPoints.setTextColor(getResources().getColor(grs ? R.color.textColorRecControlPrimary_Active : R.color.textColorRecControlPrimary));
- if (TVGeoPointsLabel != null) TVGeoPointsLabel.setTextColor(getResources().getColor(grs ? R.color.textColorRecControlSecondary_Active : R.color.textColorRecControlSecondary));
+ if (tvGeoPointsNumber != null) tvGeoPointsNumber.setText(track.getNumberOfLocations() == 0 ? "" : String.valueOf(track.getNumberOfLocations()));
+ if (tvPlacemarksNumber != null) tvPlacemarksNumber.setText(String.valueOf(track.getNumberOfPlacemarks() == 0 ? "" : track.getNumberOfPlacemarks()));
+ if (tvRecordButton != null) {
+ if (isRec) setButtonToClickedState(tvRecordButton, R.drawable.ic_pause_24, R.string.pause);
+ else setButtonToNormalState(tvRecordButton, R.drawable.ic_record_24, R.string.record);
+ }
+ if (tvAnnotateButton != null) {
+ if (isAnnot) setButtonToClickedState(tvAnnotateButton, 0, 0);
+ else setButtonToNormalState(tvAnnotateButton, 0, 0);
+ }
+ if (tvLockButton != null) {
+ if (isLck) setButtonToClickedState(tvLockButton, R.drawable.ic_unlock_24, R.string.unlock);
+ else setButtonToNormalState(tvLockButton, R.drawable.ic_lock_24, R.string.lock);
+ }
+ if (tvStopButton != null) {
+ tvStopButton.setClickable(isRec || isAnnot || (track.getNumberOfLocations() + track.getNumberOfPlacemarks() > 0));
+ if (isRec || isAnnot || (track.getNumberOfLocations() + track.getNumberOfPlacemarks() > 0) || gpsApp.isStopButtonFlag()) {
+ if (gpsApp.isStopButtonFlag()) setButtonToClickedState(tvStopButton, 0, 0);
+ else setButtonToNormalState(tvStopButton, 0, 0);
+ } else {
+ setButtonToDisabledState(tvStopButton, 0, 0);
+ }
+ }
}
}
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentSettings.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentSettings.java
index d9e21070..cedac3dc 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentSettings.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentSettings.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentSettings - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 23/7/2016
+ * Created by G.Capelli on 23/7/2016
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,7 +30,6 @@
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.os.Environment;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.res.ResourcesCompat;
import androidx.preference.EditTextPreference;
@@ -55,23 +57,20 @@
import java.net.URL;
import java.util.ArrayList;
-
import static eu.basicairdata.graziano.gpslogger.GPSApplication.FILETYPE_GPX;
-
+/**
+ * The Fragment that manages the Settings on the SettingsActivity
+ */
public class FragmentSettings extends PreferenceFragmentCompat {
private static final float M_TO_FT = 3.280839895f;
-
SharedPreferences.OnSharedPreferenceChangeListener prefListener;
-
private SharedPreferences prefs;
public double altcor; // manual offset
- public double altcorm; // Manual offset in m
-
- private ProgressDialog mProgressDialog;
- public boolean Downloaded = false;
-
+ public double altcorm; // Manual offset in m
+ private ProgressDialog progressDialog;
+ public boolean isDownloaded = false;
@Override
public void onCreate(final Bundle savedInstanceState) {
@@ -79,39 +78,34 @@ public void onCreate(final Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.app_preferences);
- File tsd = new File(Environment.getExternalStorageDirectory() + "/GPSLogger");
- boolean isGPSLoggerFolder = true;
- if (!tsd.exists()) {
- isGPSLoggerFolder = tsd.mkdir();
- }
- tsd = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData");
- if (!tsd.exists()) {
- isGPSLoggerFolder = tsd.mkdir();
- }
- Log.w("myApp", "[#] FragmentSettings.java - " + (isGPSLoggerFolder ? "Folder /GPSLogger/AppData OK" : "Unable to create folder /GPSLogger/AppData"));
+ File tsd = new File(GPSApplication.DIRECTORY_EXPORT);
+ if (!tsd.exists()) tsd.mkdir();
+ tsd = new File(GPSApplication.DIRECTORY_TEMP);
+ if (!tsd.exists()) tsd.mkdir();
+ //Log.w("myApp", "[#] FragmentSettings.java - " + (isGPSLoggerFolder ? "Folder /GPSLogger/AppData OK" : "Unable to create folder /GPSLogger/AppData"));
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
- // Chech if EGM96 file is downloaded and complete;
+ // Check if EGM96 file is downloaded and the size of the file is correct;
File sd = new File(getActivity().getApplicationContext().getFilesDir() + "/WW15MGH.DAC");
- File sd_old = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/WW15MGH.DAC");
+ File sd_old = new File(GPSApplication.DIRECTORY_TEMP + "/WW15MGH.DAC");
if ((sd.exists() && (sd.length() == 2076480)) || (sd_old.exists() && (sd_old.length() == 2076480))) {
- Downloaded = true;
+ isDownloaded = true;
} else {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor1 = settings.edit();
editor1.putBoolean("prefEGM96AltitudeCorrection", false);
editor1.commit();
- SwitchPreferenceCompat EGM96 = (SwitchPreferenceCompat) super.findPreference("prefEGM96AltitudeCorrection");
- EGM96.setChecked(false);
+ SwitchPreferenceCompat egm96 = super.findPreference("prefEGM96AltitudeCorrection");
+ egm96.setChecked(false);
}
// Instantiate Progress dialog
- mProgressDialog = new ProgressDialog(getActivity());
- mProgressDialog.setIndeterminate(true);
- mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mProgressDialog.setCancelable(true);
- mProgressDialog.setMessage(getString(R.string.pref_EGM96AltitudeCorrection_download_progress));
+ progressDialog = new ProgressDialog(getActivity());
+ progressDialog.setIndeterminate(true);
+ progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ progressDialog.setCancelable(true);
+ progressDialog.setMessage(getString(R.string.pref_EGM96AltitudeCorrection_download_progress));
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
@@ -122,31 +116,27 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
SharedPreferences.Editor editor = prefs.edit();
editor.putString("prefAltitudeCorrectionRaw", String.valueOf(altcor));
editor.commit();
- EditTextPreference pAltitudeCorrection = (EditTextPreference) findPreference("prefAltitudeCorrectionRaw");
- pAltitudeCorrection.setText(prefs.getString("prefAltitudeCorrectionRaw", "0"));
+ EditTextPreference etpAltitudeCorrection = findPreference("prefAltitudeCorrectionRaw");
+ etpAltitudeCorrection.setText(prefs.getString("prefAltitudeCorrectionRaw", "0"));
}
-
if (key.equals("prefAltitudeCorrectionRaw")) {
try {
- double d = Double.parseDouble(sharedPreferences.getString("prefAltitudeCorrectionRaw", "0"));
- altcor = d;
+ altcor = Double.parseDouble(sharedPreferences.getString("prefAltitudeCorrectionRaw", "0"));
}
catch(NumberFormatException nfe)
{
altcor = 0;
- EditTextPreference Alt = (EditTextPreference) findPreference("prefAltitudeCorrectionRaw");
- Alt.setText("0");
+ EditTextPreference etpAltitudeCorrection = findPreference("prefAltitudeCorrectionRaw");
+ etpAltitudeCorrection.setText("0");
}
-
altcorm = prefs.getString("prefUM", "0").equals("0") ? altcor : altcor / M_TO_FT;
SharedPreferences.Editor editor = prefs.edit();
editor.putString("prefAltitudeCorrection", String.valueOf(altcorm));
editor.commit();
}
-
if (key.equals("prefEGM96AltitudeCorrection")) {
if (sharedPreferences.getBoolean(key, false)) {
- if (!Downloaded) {
+ if (!isDownloaded) {
// execute this when the downloader must be fired
final DownloadTask downloadTask = new DownloadTask(getActivity());
// Original Link not available anymore
@@ -155,7 +145,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
// The connection is not secured with HTTPS for now, we chosen to use it anyway.
downloadTask.execute("http://download.osgeo.org/proj/vdatum/egm96_15/outdated/WW15MGH.DAC");
- mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
downloadTask.cancel(true);
@@ -166,7 +156,6 @@ public void onCancel(DialogInterface dialog) {
}
}
}
-
if (key.equals("prefColorTheme")) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor1 = settings.edit();
@@ -177,7 +166,6 @@ public void onCancel(DialogInterface dialog) {
AppCompatDelegate.setDefaultNightMode(Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("prefColorTheme", "2")));
//getActivity().recreate();
}
-
SetupPreferences();
}
};
@@ -189,10 +177,9 @@ public void onResume() {
// Remove dividers between preferences
setDivider(new ColorDrawable(Color.TRANSPARENT));
setDividerHeight(0);
-
prefs.registerOnSharedPreferenceChangeListener(prefListener);
//Log.w("myApp", "[#] FragmentSettings.java - onResume");
- GPSApplication.getInstance().getExternalViewerChecker().makeAppInfoList();
+ GPSApplication.getInstance().getExternalViewerChecker().makeExternalViewersList();
SetupPreferences();
}
@@ -204,33 +191,30 @@ public void onPause() {
super.onPause();
}
-
@Override
public void onCreatePreferences(Bundle bundle, String s) {
Log.w("myApp", "[#] FragmentSettings.java - onCreatePreferences");
}
public void SetupPreferences() {
-
- ListPreference pUM = (ListPreference) findPreference("prefUM");
- ListPreference pUMSpeed = (ListPreference) findPreference("prefUMSpeed");
- ListPreference pGPSDistance = (ListPreference) findPreference("prefGPSdistance");
- ListPreference pGPSUpdateFrequency = (ListPreference) findPreference("prefGPSupdatefrequency");
- ListPreference pKMLAltitudeMode = (ListPreference) findPreference("prefKMLAltitudeMode");
- ListPreference pGPXVersion = (ListPreference) findPreference("prefGPXVersion");
- ListPreference pShowTrackStatsType = (ListPreference) findPreference("prefShowTrackStatsType");
- ListPreference pShowDirections = (ListPreference) findPreference("prefShowDirections");
- ListPreference pColorTheme = (ListPreference) findPreference("prefColorTheme");
- EditTextPreference pAltitudeCorrection = (EditTextPreference) findPreference("prefAltitudeCorrectionRaw");
- Preference pTracksViewer = (Preference) findPreference("prefTracksViewer");
+ ListPreference pUM = findPreference("prefUM");
+ ListPreference pUMSpeed = findPreference("prefUMSpeed");
+ ListPreference pGPSDistance = findPreference("prefGPSdistance");
+ ListPreference pGPSUpdateFrequency = findPreference("prefGPSupdatefrequency");
+ ListPreference pKMLAltitudeMode = findPreference("prefKMLAltitudeMode");
+ ListPreference pGPXVersion = findPreference("prefGPXVersion");
+ ListPreference pShowTrackStatsType = findPreference("prefShowTrackStatsType");
+ ListPreference pShowDirections = findPreference("prefShowDirections");
+ ListPreference pColorTheme = findPreference("prefColorTheme");
+ EditTextPreference pAltitudeCorrection = findPreference("prefAltitudeCorrectionRaw");
+ Preference pTracksViewer = findPreference("prefTracksViewer");
// Keep Screen On Flag
if (prefs.getBoolean("prefKeepScreenOn", true)) getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Track Viewer
-
- final ArrayList ail = new ArrayList<>(GPSApplication.getInstance().getExternalViewerChecker().getAppInfoList());
+ final ArrayList evList = new ArrayList<>(GPSApplication.getInstance().getExternalViewerChecker().getExternalViewersList());
switch (GPSApplication.getInstance().getExternalViewerChecker().size()) {
case 0:
pTracksViewer.setEnabled(false); // No viewers installed
@@ -254,17 +238,17 @@ public boolean onPreferenceClick(Preference preference) {
View view = getLayoutInflater().inflate(R.layout.appdialog_list, null);
ListView lv = (ListView) view.findViewById(R.id.id_appdialog_list);
- final ArrayList aild = new ArrayList<>();
+ final ArrayList aild = new ArrayList<>();
// Add "Select every Time" menu item
- AppInfo askai = new AppInfo();
+ ExternalViewer askai = new ExternalViewer();
askai.label = getString(R.string.pref_track_viewer_select_every_time);
askai.icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_visibility_24dp, getActivity().getTheme());
aild.add(askai);
- aild.addAll(ail);
+ aild.addAll(evList);
- AppDialogList clad = new AppDialogList(getActivity(), aild);
+ ExternalViewerAdapter clad = new ExternalViewerAdapter(getActivity(), aild);
lv.setAdapter(clad);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@@ -287,24 +271,22 @@ public void onItemClick(AdapterView> parent, View view, int position, long id)
});
}
// ------------
-
- if (ail.isEmpty())
+ if (evList.isEmpty())
pTracksViewer.setSummary(R.string.pref_track_viewer_not_installed); // no Viewers installed
- else if (ail.size() == 1)
- pTracksViewer.setSummary(ail.get(0).label + (ail.get(0).fileType.equals(FILETYPE_GPX) ? " (GPX)" : " (KML)")); // 1 Viewer installed
+ else if (evList.size() == 1)
+ pTracksViewer.setSummary(evList.get(0).label + (evList.get(0).fileType.equals(FILETYPE_GPX) ? " (GPX)" : " (KML)")); // 1 Viewer installed
else {
pTracksViewer.setSummary(R.string.pref_track_viewer_select_every_time); // ask every time
String pn = prefs.getString("prefTracksViewer", "");
Log.w("myApp", "[#] FragmentSettings.java - prefTracksViewer = " + pn);
- for (AppInfo ai : ail) {
- if (ai.packageName.equals(pn)) {
- //Log.w("myApp", "[#] FragmentSettings.java - Found " + ai.Label);
- pTracksViewer.setSummary(ai.label + (ai.fileType.equals(FILETYPE_GPX) ? " (GPX)" : " (KML)")); // Default Viewer available!
+ for (ExternalViewer ev : evList) {
+ if (ev.packageName.equals(pn)) {
+ //Log.w("myApp", "[#] FragmentSettings.java - Found " + ev.Label);
+ pTracksViewer.setSummary(ev.label + (ev.fileType.equals(FILETYPE_GPX) ? " (GPX)" : " (KML)")); // Default Viewer available!
}
}
}
-
altcorm = Double.valueOf(prefs.getString("prefAltitudeCorrection", "0"));
altcor = prefs.getString("prefUM", "0").equals("0") ? altcorm : altcorm * M_TO_FT;
@@ -341,7 +323,9 @@ else if (ail.size() == 1)
//pViewTracksWith.setSummary(pViewTracksWith.getEntry());
}
-
+ /**
+ * Sets the PrefEGM96 to false
+ */
public void PrefEGM96SetToFalse() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor1 = settings.edit();
@@ -351,6 +335,9 @@ public void PrefEGM96SetToFalse() {
EGM96.setChecked(false);
}
+ /**
+ * Sets the PrefEGM96 to true
+ */
public void PrefEGM96SetToTrue() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor1 = settings.edit();
@@ -360,13 +347,17 @@ public void PrefEGM96SetToTrue() {
EGM96.setChecked(true);
}
+ // ------------------------------------------------------------- Download of the EGM96 grid file
- // ----------------------------------------------------------------.----- EGM96 - Download file
-
-
- // usually, subclasses of AsyncTask are declared inside the activity class.
- // that way, you can easily modify the UI thread from here
+ /**
+ * The Class that manages the download of the EGM96 grid file.
+ * The WW15MGH.DAC file is downloaded into the getFilesDir() folder.
+ * It displays and keeps updated a progress dialog
+ * that shows the progress of the download
+ */
private class DownloadTask extends AsyncTask {
+ // usually, subclasses of AsyncTask are declared inside the activity class.
+ // that way, you can easily modify the UI thread from here
private Context context;
//private PowerManager.WakeLock mWakeLock;
@@ -441,61 +432,32 @@ protected void onPreExecute() {
//mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
// getClass().getName());
//mWakeLock.acquire();
- mProgressDialog.show();
+ progressDialog.show();
}
@Override
protected void onProgressUpdate(Integer... progress) {
super.onProgressUpdate(progress);
// if we get here, length is known, now set indeterminate to false
- mProgressDialog.setIndeterminate(false);
- mProgressDialog.setMax(2028);
- mProgressDialog.setProgress(progress[0]);
+ progressDialog.setIndeterminate(false);
+ progressDialog.setMax(2028);
+ progressDialog.setProgress(progress[0]);
}
@Override
protected void onPostExecute(String result) {
if (getActivity() != null) {
//mWakeLock.release();
- mProgressDialog.dismiss();
+ progressDialog.dismiss();
if (result != null)
Toast.makeText(context, getString(R.string.toast_download_error) + ": " + result, Toast.LENGTH_LONG).show();
else {
File sd = new File(getActivity().getApplicationContext().getFilesDir() + "/WW15MGH.DAC");
- File sd_old = new File(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/WW15MGH.DAC");
+ File sd_old = new File(GPSApplication.DIRECTORY_TEMP + "/WW15MGH.DAC");
if ((sd.exists() && (sd.length() == 2076480)) || (sd_old.exists() && (sd_old.length() == 2076480))) {
- Downloaded = true;
+ isDownloaded = true;
Toast.makeText(context, getString(R.string.toast_download_completed), Toast.LENGTH_SHORT).show();
PrefEGM96SetToTrue();
-
- // Ask to switch to Absolute Altitude Mode if not already active.
- /*
- ListPreference pKMLAltitudeMode = (ListPreference) findPreference("prefKMLAltitudeMode");
- if (!(pKMLAltitudeMode.getValue().equals("0"))) {
- AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getContext(), R.style.StyledDialog));
- builder.setMessage(getResources().getString(R.string.pref_message_switch_to_absolute_altitude_mode));
- builder.setIcon(android.R.drawable.ic_menu_info_details);
- builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
- SharedPreferences.Editor editor1 = settings.edit();
- editor1.putString("prefKMLAltitudeMode", "0");
- editor1.commit();
- ListPreference pKMLAltitudeMode = (ListPreference) findPreference("prefKMLAltitudeMode");
- pKMLAltitudeMode.setValue("0");
- pKMLAltitudeMode.setSummary(R.string.pref_KML_altitude_mode_absolute);
- }
- });
- builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.dismiss();
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
- */
-
} else {
Toast.makeText(context, getString(R.string.toast_download_failed), Toast.LENGTH_SHORT).show();
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTrack.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTrack.java
index cb64e6ba..5bdc03ac 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTrack.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTrack.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentTrack - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 4/6/2016
+ * Created by G.Capelli on 4/6/2016
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,11 +21,17 @@
package eu.basicairdata.graziano.gpslogger;
+import android.content.res.Configuration;
+import android.os.Build;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
+
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TextView;
@@ -30,32 +39,44 @@
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
+/**
+ * The Fragment that displays the information of the current Track
+ * on the second tab (Track) of the main Activity (GPSActivity).
+ */
public class FragmentTrack extends Fragment {
private PhysicalDataFormatter phdformatter = new PhysicalDataFormatter();
-
- private TextView TVDuration;
- private TextView TVTrackName;
- private TextView TVTrackID;
- private TextView TVDistance;
- private TextView TVDistanceUM;
- private TextView TVMaxSpeed;
- private TextView TVMaxSpeedUM;
- private TextView TVAverageSpeed;
- private TextView TVAverageSpeedUM;
- private TextView TVAltitudeGap;
- private TextView TVAltitudeGapUM;
- private TextView TVOverallDirection;
- private TextView TVTrackStatus;
- private TextView TVDirectionUM;
-
- private TableLayout TLTrack;
- private TableLayout TLDuration;
- private TableLayout TLSpeedMax;
- private TableLayout TLSpeedAvg;
- private TableLayout TLDistance;
- private TableLayout TLAltitudeGap;
- private TableLayout TLOverallDirection;
+ final GPSApplication gpsApp = GPSApplication.getInstance();
+
+ private FrameLayout flTrack;
+
+ private TextView tvDuration;
+ private TextView tvTrackName;
+ private TextView tvTrackID;
+ private TextView tvDistance;
+ private TextView tvDistanceUM;
+ private TextView tvAnnotations;
+ private TextView tvTrackpoints;
+ private TextView tvMaxSpeed;
+ private TextView tvMaxSpeedUM;
+ private TextView tvAverageSpeed;
+ private TextView tvAverageSpeedUM;
+ private TextView tvAltitudeGap;
+ private TextView tvAltitudeGapUM;
+ private TextView tvOverallDirection;
+ private TextView tvTrackStatus;
+ private TextView tvDirectionUM;
+ private TableLayout tlTrack;
+ private TableLayout tlTrackpoints;
+ private TableLayout tlAnnotations;
+ private TableLayout tlDuration;
+ private TableLayout tlSpeedMax;
+ private TableLayout tlSpeedAvg;
+ private TableLayout tlDistance;
+ private TableLayout tlAltitudeGap;
+ private TableLayout tlOverallDirection;
+
+ private LinearLayout llTrackpointsAnnotations;
private PhysicalData phdDuration;
private PhysicalData phdSpeedMax;
@@ -64,54 +85,94 @@ public class FragmentTrack extends Fragment {
private PhysicalData phdAltitudeGap;
private PhysicalData phdOverallDirection;
- private String FTrackID = "";
- private String FTrackName = "";
-
- final GPSApplication gpsApplication = GPSApplication.getInstance();
+ private String fTrackID = "";
+ private String fTrackName = "";
+ private Track track;
+ private int prefDirections;
+ private boolean EGMAltitudeCorrection;
+ private boolean isValidAltitude;
+ /**
+ * The Observer that calculate the new available height when the layout is changed.
+ * If the height is enough, it set the setSpaceForExtraTilesAvailable flag
+ * that enable the visualization of the extra tiles:
+ *
+ *
Time and Satellites for FragmentGPSFix
+ *
Trackpoints ane Annotation for FragmentTrack
+ * *
+ */
+ ViewTreeObserver.OnGlobalLayoutListener viewTreeObserverOnGLL = new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+ flTrack.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ } else {
+ flTrack.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ }
+ //int width = flTrack.getMeasuredWidth();
+ //int height = flTrack.getMeasuredHeight();
+ //Log.w("myApp", "[#] FragmentTrack MEASURED: " + width + " x " + height);
+ int viewHeight = tlDistance.getMeasuredHeight() + (int)(6*getResources().getDisplayMetrics().density);
+ int layoutHeight = flTrack.getHeight() - (int)(6*getResources().getDisplayMetrics().density);
+ boolean isTimeAndSatellitesVisible;
+ if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
+ isTimeAndSatellitesVisible = layoutHeight >= 6*viewHeight;
+ //Log.w("myApp", "[#] FragmentTrack MEASURED: " + layoutHeight + " / " + 6*viewHeight + " -> " + isTimeAndSatellitesVisible);
+ } else {
+ isTimeAndSatellitesVisible = layoutHeight >= 3.9*viewHeight;
+ //Log.w("myApp", "[#] FragmentTrack MEASURED: " + layoutHeight + " / " + 3.9*viewHeight + " -> " + isTimeAndSatellitesVisible);
+ }
+ GPSApplication.getInstance().setSpaceForExtraTilesAvailable(isTimeAndSatellitesVisible);
+ update();
+ }
+ };
public FragmentTrack() {
// Required empty public constructor
}
- @Subscribe (threadMode = ThreadMode.MAIN)
- public void onEvent(Short msg) {
- if (msg == EventBusMSG.UPDATE_TRACK) {
- Update();
- }
- }
-
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_track, container, false);
+ // FrameLayouts
+ flTrack = view.findViewById(R.id.id_fragmenttrackFrameLayout);
+
// TextViews
- TVDuration = view.findViewById(R.id.id_textView_Duration);
- TVTrackID = view.findViewById(R.id.id_textView_TrackIDLabel);
- TVTrackName = view.findViewById(R.id.id_textView_TrackName);
- TVDistance = view.findViewById(R.id.id_textView_Distance);
- TVMaxSpeed = view.findViewById(R.id.id_textView_SpeedMax);
- TVAverageSpeed = view.findViewById(R.id.id_textView_SpeedAvg);
- TVAltitudeGap = view.findViewById(R.id.id_textView_AltitudeGap);
- TVOverallDirection = view.findViewById(R.id.id_textView_OverallDirection);
- TVTrackStatus = view.findViewById(R.id.id_textView_TrackStatus);
- TVDirectionUM = view.findViewById(R.id.id_textView_OverallDirectionUM);
- TVDistanceUM = view.findViewById(R.id.id_textView_DistanceUM);
- TVMaxSpeedUM = view.findViewById(R.id.id_textView_SpeedMaxUM);
- TVAverageSpeedUM = view.findViewById(R.id.id_textView_SpeedAvgUM);
- TVAltitudeGapUM = view.findViewById(R.id.id_textView_AltitudeGapUM);
+ tvDuration = view.findViewById(R.id.id_textView_Duration);
+ tvTrackID = view.findViewById(R.id.id_textView_TrackIDLabel);
+ tvTrackName = view.findViewById(R.id.id_textView_TrackName);
+ tvTrackpoints = view.findViewById(R.id.id_textView_Trackpoints);
+ tvAnnotations = view.findViewById(R.id.id_textView_Annotations);
+ tvDistance = view.findViewById(R.id.id_textView_Distance);
+ tvMaxSpeed = view.findViewById(R.id.id_textView_SpeedMax);
+ tvAverageSpeed = view.findViewById(R.id.id_textView_SpeedAvg);
+ tvAltitudeGap = view.findViewById(R.id.id_textView_AltitudeGap);
+ tvOverallDirection = view.findViewById(R.id.id_textView_OverallDirection);
+ tvTrackStatus = view.findViewById(R.id.id_textView_TrackStatus);
+ tvDirectionUM = view.findViewById(R.id.id_textView_OverallDirectionUM);
+ tvDistanceUM = view.findViewById(R.id.id_textView_DistanceUM);
+ tvMaxSpeedUM = view.findViewById(R.id.id_textView_SpeedMaxUM);
+ tvAverageSpeedUM = view.findViewById(R.id.id_textView_SpeedAvgUM);
+ tvAltitudeGapUM = view.findViewById(R.id.id_textView_AltitudeGapUM);
// TableLayouts
- TLTrack = view.findViewById(R.id.id_tableLayout_TrackName) ;
- TLDuration = view.findViewById(R.id.id_tableLayout_Duration) ;
- TLSpeedMax = view.findViewById(R.id.id_tableLayout_SpeedMax) ;
- TLDistance = view.findViewById(R.id.id_tableLayout_Distance) ;
- TLSpeedAvg = view.findViewById(R.id.id_tableLayout_SpeedAvg) ;
- TLAltitudeGap = view.findViewById(R.id.id_tableLayout_AltitudeGap) ;
- TLOverallDirection = view.findViewById(R.id.id_tableLayout_OverallDirection) ;
-
+ tlTrack = view.findViewById(R.id.id_tableLayout_TrackName) ;
+ tlTrackpoints = view.findViewById(R.id.id_TableLayout_Trackpoints) ;
+ tlAnnotations = view.findViewById(R.id.id_TableLayout_Annotations) ;
+ tlDuration = view.findViewById(R.id.id_tableLayout_Duration) ;
+ tlSpeedMax = view.findViewById(R.id.id_tableLayout_SpeedMax) ;
+ tlDistance = view.findViewById(R.id.id_tableLayout_Distance) ;
+ tlSpeedAvg = view.findViewById(R.id.id_tableLayout_SpeedAvg) ;
+ tlAltitudeGap = view.findViewById(R.id.id_tableLayout_AltitudeGap) ;
+ tlOverallDirection = view.findViewById(R.id.id_tableLayout_OverallDirection) ;
+
+ // LinearLayouts
+ llTrackpointsAnnotations = view.findViewById(R.id.id_linearLayout_Annotation_Trackpoints);
+
+ tvTrackStatus.setText(getString(R.string.track_empty) + "\n\n" + getString(R.string.track_start_with_button_below));
return view;
}
@@ -127,31 +188,51 @@ public void onResume() {
}
EventBus.getDefault().register(this);
- Update();
+
+ ViewTreeObserver vto = flTrack.getViewTreeObserver();
+ vto.addOnGlobalLayoutListener(viewTreeObserverOnGLL);
+
+ update();
}
@Override
public void onPause() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+ flTrack.getViewTreeObserver().removeGlobalOnLayoutListener(viewTreeObserverOnGLL);
+ } else {
+ flTrack.getViewTreeObserver().removeOnGlobalLayoutListener(viewTreeObserverOnGLL);
+ }
EventBus.getDefault().unregister(this);
super.onPause();
}
+ /**
+ * The EventBus receiver for Short Messages.
+ */
+ @Subscribe (threadMode = ThreadMode.MAIN)
+ public void onEvent(Short msg) {
+ if (msg == EventBusMSG.UPDATE_TRACK) {
+ update();
+ }
+ }
- private Track track;
- private int prefDirections;
- private boolean EGMAltitudeCorrection;
- private boolean isValidAltitude;
-
- public void Update() {
- track = gpsApplication.getCurrentTrack();
- prefDirections = gpsApplication.getPrefShowDirections();
- EGMAltitudeCorrection = gpsApplication.getPrefEGM96AltitudeCorrection();
+ /**
+ * Updates the user interface of the fragment.
+ * It takes care of visibility and value of each tile, and Track Status widgets.
+ */
+ public void update() {
+ //Log.w("myApp", "[#] FragmentTrack.java - Update");
+ track = gpsApp.getCurrentTrack();
+ prefDirections = gpsApp.getPrefShowDirections();
+ EGMAltitudeCorrection = gpsApp.getPrefEGM96AltitudeCorrection();
if (isAdded()) {
if ((track != null) && (track.getNumberOfLocations() + track.getNumberOfPlacemarks() > 0)) {
- FTrackID = getString(R.string.track_id) + " " + String.valueOf(track.getId());
- FTrackName = track.getName();
+ fTrackID = (track.getDescription().isEmpty() ?
+ getString(R.string.track_id) + " " + String.valueOf(track.getId()) :
+ track.getDescription());
+ fTrackName = track.getName();
phdDuration = phdformatter.format(track.getPrefTime(),PhysicalDataFormatter.FORMAT_DURATION);
phdSpeedMax = phdformatter.format(track.getSpeedMax(),PhysicalDataFormatter.FORMAT_SPEED);
phdSpeedAvg = phdformatter.format(track.getPrefSpeedAverage(),PhysicalDataFormatter.FORMAT_SPEED_AVG);
@@ -159,47 +240,54 @@ public void Update() {
phdAltitudeGap = phdformatter.format(track.getEstimatedAltitudeGap(EGMAltitudeCorrection),PhysicalDataFormatter.FORMAT_ALTITUDE);
phdOverallDirection = phdformatter.format(track.getBearing(),PhysicalDataFormatter.FORMAT_BEARING);
- TVTrackID.setText(FTrackID);
- TVTrackName.setText(FTrackName);
- TVDuration.setText(phdDuration.Value);
- TVMaxSpeed.setText(phdSpeedMax.Value);
- TVAverageSpeed.setText(phdSpeedAvg.Value);
- TVDistance.setText(phdDistance.Value);
- TVAltitudeGap.setText(phdAltitudeGap.Value);
- TVOverallDirection.setText(phdOverallDirection.Value);
-
- TVMaxSpeedUM.setText(phdSpeedMax.UM);
- TVAverageSpeedUM.setText(phdSpeedAvg.UM);
- TVDistanceUM.setText(phdDistance.UM);
- TVAltitudeGapUM.setText(phdAltitudeGap.UM);
+ tvTrackID.setText(fTrackID);
+ tvTrackName.setText(fTrackName);
+ tvDuration.setText(phdDuration.value);
+ tvMaxSpeed.setText(phdSpeedMax.value);
+ tvAverageSpeed.setText(phdSpeedAvg.value);
+ tvDistance.setText(phdDistance.value);
+ tvAltitudeGap.setText(phdAltitudeGap.value);
+ tvOverallDirection.setText(phdOverallDirection.value);
- // Colorize the Altitude Gap textview depending on the altitude filter
- isValidAltitude = track.isValidAltitude();
- TVAltitudeGap.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
- TVAltitudeGapUM.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
-
- TVTrackStatus.setVisibility(View.INVISIBLE);
+ tvMaxSpeedUM.setText(phdSpeedMax.um);
+ tvAverageSpeedUM.setText(phdSpeedAvg.um);
+ tvDistanceUM.setText(phdDistance.um);
+ tvAltitudeGapUM.setText(phdAltitudeGap.um);
- TVDirectionUM.setVisibility(prefDirections == 0 ? View.GONE : View.VISIBLE);
+ llTrackpointsAnnotations.setVisibility(gpsApp.isSpaceForExtraTilesAvailable() ? View.VISIBLE : View.GONE);
- TLTrack.setVisibility(FTrackName.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLDuration.setVisibility(phdDuration.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLSpeedMax.setVisibility(phdSpeedMax.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLSpeedAvg.setVisibility(phdSpeedAvg.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLDistance.setVisibility(phdDistance.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLOverallDirection.setVisibility(phdOverallDirection.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
- TLAltitudeGap.setVisibility(phdAltitudeGap.Value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tvAnnotations.setText(String.valueOf(track.getNumberOfPlacemarks()));
+ tvTrackpoints.setText(String.valueOf(track.getNumberOfLocations()));
+ // Colorize the Altitude Gap textview depending on the altitude filter
+ isValidAltitude = track.isValidAltitude();
+ tvAltitudeGap.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
+ tvAltitudeGapUM.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
+
+ tvTrackStatus.setVisibility(View.INVISIBLE);
+ tvDirectionUM.setVisibility(prefDirections == 0 ? View.GONE : View.VISIBLE);
+
+ tlTrack.setVisibility(fTrackName.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlDuration.setVisibility(phdDuration.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlSpeedMax.setVisibility(phdSpeedMax.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlSpeedAvg.setVisibility(phdSpeedAvg.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlDistance.setVisibility(phdDistance.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlOverallDirection.setVisibility(phdOverallDirection.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlAltitudeGap.setVisibility(phdAltitudeGap.value.equals("") ? View.INVISIBLE : View.VISIBLE);
+ tlTrackpoints.setVisibility(track.getNumberOfLocations() > 0 ? View.VISIBLE : View.INVISIBLE);
+ tlAnnotations.setVisibility(track.getNumberOfPlacemarks() + track.getNumberOfLocations() > 0 ? View.VISIBLE : View.INVISIBLE);
} else {
- TVTrackStatus.setVisibility(View.VISIBLE);
-
- TLTrack.setVisibility(View.INVISIBLE);
- TLDuration.setVisibility(View.INVISIBLE);
- TLSpeedMax.setVisibility(View.INVISIBLE);
- TLSpeedAvg.setVisibility(View.INVISIBLE);
- TLDistance.setVisibility(View.INVISIBLE);
- TLOverallDirection.setVisibility(View.INVISIBLE);
- TLAltitudeGap.setVisibility(View.INVISIBLE);
+ tvTrackStatus.setVisibility(View.VISIBLE);
+
+ tlTrack.setVisibility(View.INVISIBLE);
+ tlDuration.setVisibility(View.INVISIBLE);
+ tlSpeedMax.setVisibility(View.INVISIBLE);
+ tlSpeedAvg.setVisibility(View.INVISIBLE);
+ tlDistance.setVisibility(View.INVISIBLE);
+ tlOverallDirection.setVisibility(View.INVISIBLE);
+ tlAltitudeGap.setVisibility(View.INVISIBLE);
+ tlTrackpoints.setVisibility(View.INVISIBLE);
+ tlAnnotations.setVisibility(View.INVISIBLE);
}
}
}
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTrackPropertiesDialog.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTrackPropertiesDialog.java
new file mode 100644
index 00000000..8ff1a7ed
--- /dev/null
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTrackPropertiesDialog.java
@@ -0,0 +1,199 @@
+/*
+ * FragmentTrackPropertiesDialog - Java Class for Android
+ * Created by G.Capelli on 18/4/2021
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package eu.basicairdata.graziano.gpslogger;
+
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.graphics.PorterDuff;
+import android.os.Bundle;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import androidx.fragment.app.DialogFragment;
+import androidx.appcompat.app.AlertDialog;
+
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.Toast;
+
+import org.greenrobot.eventbus.EventBus;
+
+import static eu.basicairdata.graziano.gpslogger.GPSApplication.NOT_AVAILABLE;
+import static eu.basicairdata.graziano.gpslogger.GPSApplication.TOAST_VERTICAL_OFFSET;
+
+/**
+ * The Dialog that shows the properties of a Track.
+ * The user can use it to edit the description and the activity type.
+ * As extra feature of this dialog, The OK Button can finalize the Track.
+ */
+public class FragmentTrackPropertiesDialog extends DialogFragment {
+
+ private EditText etDescription;
+ private final ImageView[] tracktypeImageView = new ImageView[7];
+
+ private int selectedTrackType = NOT_AVAILABLE; // The track type selected by the user
+ private Track trackToEdit = null; // The track to edit
+ private int title = 0; // The resource id for the title
+ private boolean finalizeTrackWithOk = false; // True if the "OK" button finalizes the track and creates a new one
+
+ private static final String KEY_SELTRACKTYPE = "selectedTrackType";
+ private static final String KEY_TITLE = "_title";
+ private static final String KEY_ISFINALIZATION = "_isFinalization";
+
+ @Override
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ outState.putInt(KEY_SELTRACKTYPE, selectedTrackType);
+ outState.putInt(KEY_TITLE, title);
+ outState.putBoolean(KEY_ISFINALIZATION, finalizeTrackWithOk);
+ }
+
+ //@SuppressLint("InflateParams")
+ @NonNull
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ AlertDialog.Builder createPlacemarkAlert = new AlertDialog.Builder(getActivity());
+ trackToEdit = GPSApplication.getInstance().getTrackToEdit();
+
+ if (savedInstanceState != null) {
+ title = savedInstanceState.getInt(KEY_TITLE, 0);
+ selectedTrackType = savedInstanceState.getInt(KEY_SELTRACKTYPE, NOT_AVAILABLE);
+ finalizeTrackWithOk = savedInstanceState.getBoolean(KEY_ISFINALIZATION, false);
+ } else {
+ selectedTrackType = trackToEdit.getType();
+ }
+
+ if (title != 0) createPlacemarkAlert.setTitle(title);
+ //createPlacemarkAlert.setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_stop_24, getActivity().getTheme()));
+
+ LayoutInflater inflater = getActivity().getLayoutInflater();
+ final View view = inflater.inflate(R.layout.fragment_track_properties_dialog, null);
+
+ etDescription = view.findViewById(R.id.track_description);
+ if (!trackToEdit.getDescription().isEmpty()) {
+ etDescription.setText(trackToEdit.getDescription());
+ }
+ etDescription.setHint(GPSApplication.getInstance().getString(R.string.track_id) + " " + trackToEdit.getId());
+
+// DescEditText.postDelayed(new Runnable()
+// {
+// public void run()
+// {
+// if (isAdded()) {
+// DescEditText.requestFocus();
+// InputMethodManager mgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+// mgr.showSoftInput(DescEditText, InputMethodManager.SHOW_IMPLICIT);
+// }
+// }
+// }, 200);
+
+ tracktypeImageView[Track.TRACK_TYPE_STEADY ] = view.findViewById(R.id.tracktype_steady);
+ tracktypeImageView[Track.TRACK_TYPE_MOUNTAIN ] = view.findViewById(R.id.tracktype_mountain);
+ tracktypeImageView[Track.TRACK_TYPE_WALK ] = view.findViewById(R.id.tracktype_walk);
+ tracktypeImageView[Track.TRACK_TYPE_RUN ] = view.findViewById(R.id.tracktype_run);
+ tracktypeImageView[Track.TRACK_TYPE_BICYCLE ] = view.findViewById(R.id.tracktype_bicycle);
+ tracktypeImageView[Track.TRACK_TYPE_CAR ] = view.findViewById(R.id.tracktype_car);
+ tracktypeImageView[Track.TRACK_TYPE_FLIGHT ] = view.findViewById(R.id.tracktype_flight);
+
+ // Disable all images
+ for (int i = 0; i< tracktypeImageView.length; i++) {
+ tracktypeImageView[i].setColorFilter(getResources().getColor(R.color.colorIconDisabledOnDialog), PorterDuff.Mode.SRC_IN);
+ tracktypeImageView[i].setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ for (int i = 0; i < tracktypeImageView.length; i++) {
+ if (view == tracktypeImageView[i]) {
+ tracktypeImageView[i].setColorFilter(getResources().getColor(R.color.textColorRecControlPrimary), PorterDuff.Mode.SRC_IN);
+ selectedTrackType = i;
+ } else
+ tracktypeImageView[i].setColorFilter(getResources().getColor(R.color.colorIconDisabledOnDialog), PorterDuff.Mode.SRC_IN);
+ }
+ }
+ });
+ }
+ // Activate the right image
+ if (selectedTrackType != NOT_AVAILABLE)
+ tracktypeImageView[selectedTrackType].setColorFilter(getResources().getColor(R.color.textColorRecControlPrimary), PorterDuff.Mode.SRC_IN);
+ else if (trackToEdit.getEstimatedTrackType() != Track.TRACK_TYPE_ND)
+ tracktypeImageView[trackToEdit.getEstimatedTrackType()].setColorFilter(getResources().getColor(R.color.textColorRecControlSecondary), PorterDuff.Mode.SRC_IN);
+
+ createPlacemarkAlert.setView(view)
+ .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ if (isAdded()) {
+ String trackDescription = etDescription.getText().toString();
+ trackToEdit.setDescription (trackDescription.trim());
+ if (selectedTrackType != NOT_AVAILABLE) trackToEdit.setType(selectedTrackType); // the user selected a track type!
+ GPSApplication.getInstance().gpsDataBase.updateTrack(trackToEdit);
+ if (finalizeTrackWithOk) {
+ // a request to finalize a track
+ EventBus.getDefault().post(EventBusMSG.NEW_TRACK);
+ Toast toast = Toast.makeText(GPSApplication.getInstance().getApplicationContext(), R.string.toast_track_saved_into_tracklist, Toast.LENGTH_SHORT);
+ toast.setGravity(Gravity.BOTTOM, 0, TOAST_VERTICAL_OFFSET);
+ toast.show();
+ } else {
+ GPSApplication.getInstance().UpdateTrackList();
+ EventBus.getDefault().post(EventBusMSG.UPDATE_TRACK);
+ }
+ }
+ }
+ })
+ .setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ }
+ });
+ return createPlacemarkAlert.create();
+ }
+
+ @Override
+ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ }
+
+ /**
+ * Sets the title of the Dialog.
+ *
+ * @param titleResource The Resource String of the title
+ */
+ public void setTitleResource(int titleResource) {
+ title = titleResource;
+ }
+
+ /**
+ * If true, the dialog finalizes the track when the user press the OK Button.
+ *
+ * @param finalize true if the dialog should finalize the track
+ */
+ public void setFinalizeTrackWithOk(boolean finalize) {
+ finalizeTrackWithOk = finalize;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTracklist.java b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTracklist.java
index 5cdbf011..c0496703 100644
--- a/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTracklist.java
+++ b/app/src/main/java/eu/basicairdata/graziano/gpslogger/FragmentTracklist.java
@@ -1,6 +1,9 @@
-/**
+/*
* FragmentTracklist - Java Class for Android
- * Created by G.Capelli (BasicAirData) on 19/6/2016
+ * Created by G.Capelli on 19/6/2016
+ * This file is part of BasicAirData GPS Logger
+ *
+ * Copyright (C) 2011 BasicAirData
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,13 +30,13 @@
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Environment;
import android.preference.PreferenceManager;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -56,28 +59,23 @@
import static eu.basicairdata.graziano.gpslogger.GPSApplication.NOT_AVAILABLE;
-
+/**
+ * The Fragment that displays and manages the list of the archived Tracks
+ * on the third tab (Tracklist) of the main Activity (GPSActivity).
+ */
public class FragmentTracklist extends Fragment {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
-
private TrackAdapter adapter;
private final List