diff --git a/.gitignore b/.gitignore
index 53fa990..6899b72 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
*.iml
.gradle
-/local.properties
+local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
diff --git a/README.md b/README.md
index 0a62514..84506e2 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,13 @@ Here you can find some ways for contribution. If you are insterested in, please
* Include new features to the app.
* Port the project to other languages and platforms.
+## Setup
+### Setup Fabric
+Inside app/ create a file called fabric.properties with apiKey=here_the_api_key and below apiSecret=here_api_secret.
+
+### Setup Google Maps
+Inside app/ create a file called gradle.properties and add MAPS_KEY="the_key_here".
+
## Special Thanks to
* Ian Forster-Lewis for his IGC File Format Reference
* Mauro Gianzone for contributing to app design.
diff --git a/app/build.gradle b/app/build.gradle
index 8686eb2..90fb935 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -22,8 +22,8 @@ android {
applicationId "com.shollmann.igcparser"
minSdkVersion 16
targetSdkVersion 24
- versionCode 10702
- versionName "1.7.2"
+ versionCode 10800
+ versionName "1.8.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
diff --git a/app/src/main/java/com/shollmann/igcparser/IGCViewerApplication.java b/app/src/main/java/com/shollmann/igcparser/IGCViewerApplication.java
index 5bd601a..5a84541 100644
--- a/app/src/main/java/com/shollmann/igcparser/IGCViewerApplication.java
+++ b/app/src/main/java/com/shollmann/igcparser/IGCViewerApplication.java
@@ -36,22 +36,21 @@
import io.fabric.sdk.android.Fabric;
public class IGCViewerApplication extends Application {
- private static Context instance;
private static IGCFile currentIGCFile;
@Override
public void onCreate() {
super.onCreate();
- instance = this;
setupCrashlytics();
setupTaskConfig();
}
private void setupTaskConfig() {
- TaskConfig.setAreaWidth(PreferencesHelper.getAreaWidth());
- TaskConfig.setStartLength(PreferencesHelper.getStartLength());
- TaskConfig.setFinishLength(PreferencesHelper.getFinishLength());
+ PreferencesHelper preferencesHelper = new PreferencesHelper(this);
+ TaskConfig.setAreaWidth(preferencesHelper.getAreaWidth());
+ TaskConfig.setStartLength(preferencesHelper.getStartLength());
+ TaskConfig.setFinishLength(preferencesHelper.getFinishLength());
}
private void setupCrashlytics() {
@@ -62,8 +61,8 @@ private void setupCrashlytics() {
Fabric.with(this, crashlyticsKit);
}
- public static Context getApplication() {
- return instance;
+ public Context getApplication() {
+ return this;
}
public static IGCFile getCurrentIGCFile() {
diff --git a/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightInformationActivity.java b/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightInformationActivity.java
index f06b88c..f50e1df 100644
--- a/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightInformationActivity.java
+++ b/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightInformationActivity.java
@@ -165,7 +165,7 @@ private void setupGraphic(LineChart chart, List entries, float axisMinimu
LineDataSet dataSet = new LineDataSet(entries, Constants.EMPTY_STRING);
dataSet.setDrawCircles(false);
dataSet.setDrawCircleHole(false);
- dataSet.setLineWidth(ResourcesHelper.getDimensionPixelSize(R.dimen.half_dp));
+ dataSet.setLineWidth(ResourcesHelper.getDimensionPixelSize(this, R.dimen.half_dp));
dataSet.setFillColor(getResources().getColor(R.color.colorPrimary));
dataSet.setDrawFilled(true);
dataSet.setFillAlpha(Constants.Chart.ALPHA_FILL);
@@ -296,7 +296,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onDestroy() {
- super.onStop();
+ super.onDestroy();
IGCViewerApplication.setCurrentIGCFile(null);
}
}
diff --git a/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightPreviewActivity.java b/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightPreviewActivity.java
index 3247b95..8033ff1 100644
--- a/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightPreviewActivity.java
+++ b/app/src/main/java/com/shollmann/igcparser/ui/activity/FlightPreviewActivity.java
@@ -91,6 +91,7 @@
public class FlightPreviewActivity extends AppCompatActivity implements OnMapReadyCallback, View.OnClickListener {
+ private final Object lock = new Object();
private boolean isFinishReplay = true;
private int duration;
private int replaySpeed = Constants.Map.DEFAULT_REPLAY_SPEED;
@@ -122,12 +123,41 @@ public class FlightPreviewActivity extends AppCompatActivity implements OnMapRea
private ImageView btnSpeedDown;
private View viewAltitudeReferenceBar;
private Toast toast;
- private Object lock = new Object();
+ private PreferencesHelper preferencesHelper;
+
+ public PaintDrawable getColorScala() {
+ ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
+ @Override
+ public Shader resize(int width, int height) {
+ LinearGradient linearGradient = new LinearGradient(width, height, 0, 0,
+ new int[]{
+ getResources().getColor(R.color.altitude_0_100),
+ getResources().getColor(R.color.altitude_100_300),
+ getResources().getColor(R.color.altitude_300_500),
+ getResources().getColor(R.color.altitude_500_1000),
+ getResources().getColor(R.color.altitude_1000_1500),
+ getResources().getColor(R.color.altitude_1500_2000),
+ getResources().getColor(R.color.altitude_2000_2500),
+ getResources().getColor(R.color.altitude_more_than_2500)},
+ new float[]{
+ 0, 0.07f, 0.14f, 0.28f, 0.42f, 0.56f, 0.7f, 0.84f},
+ Shader.TileMode.REPEAT);
+ return linearGradient;
+ }
+ };
+
+ PaintDrawable paint = new PaintDrawable();
+ paint.setShape(new RectShape());
+ paint.setShaderFactory(shaderFactory);
+
+ return paint;
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
findViews();
+ preferencesHelper = new PreferencesHelper(getApplicationContext());
setClickListeners();
initMap(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -247,31 +277,31 @@ private PolylineOptions getAltitudeTrackPolyline(AltitudeTrackSegment trackSegme
PolylineOptions polyline;
switch (trackSegment1.getSegmentType()) {
case ALTITUDE_0_100:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_0_100)).zIndex(0);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this, R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_0_100)).zIndex(0);
break;
case ALTITUDE_100_300:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_100_300)).zIndex(1);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this, R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_100_300)).zIndex(1);
break;
case ALTITUDE_300_500:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_300_500)).zIndex(2);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this, R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_300_500)).zIndex(2);
break;
case ALTITUDE_500_1000:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_500_1000)).zIndex(3);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this,R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_500_1000)).zIndex(3);
break;
case ALTITUDE_1000_1500:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_1000_1500)).zIndex(4);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this,R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_1000_1500)).zIndex(4);
break;
case ALTITUDE_1500_2000:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_1500_2000)).zIndex(5);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this,R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_1500_2000)).zIndex(5);
break;
case ALTITUDE_2000_2500:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_2000_2500)).zIndex(6);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this, R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_2000_2500)).zIndex(6);
break;
case ALTITUDE_MORE_THAN_2500:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_more_than_2500)).zIndex(7);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this, R.dimen.track_line_width)).color(getResources().getColor(R.color.altitude_more_than_2500)).zIndex(7);
break;
default:
- polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.track_line_width)).color(Color.BLACK).zIndex(-1);
+ polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this,R.dimen.track_line_width)).color(Color.BLACK).zIndex(-1);
}
@@ -290,14 +320,14 @@ private void displayWayPoints() {
private void displayFinishStartLines(List waypoints) {
try {//TODO Move the logic to determine takeoff, start, etc points to WaypointsHelper
if (((CRecordWayPoint) waypoints.get(0)).getType() == CRecordType.START) {
- googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(waypoints.get(0), waypoints.get(1), TaskConfig.getStartLength()));
+ googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(getApplicationContext(), waypoints.get(0), waypoints.get(1), TaskConfig.getStartLength()));
} else {
- googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(waypoints.get(1), waypoints.get(2), TaskConfig.getStartLength()));
+ googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(this, waypoints.get(1), waypoints.get(2), TaskConfig.getStartLength()));
}
if (((CRecordWayPoint) waypoints.get(waypoints.size() - 1)).getType() == CRecordType.FINISH) {
- googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(waypoints.get(waypoints.size() - 1), waypoints.get(waypoints.size() - 2), TaskConfig.getFinishLength()));
+ googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(getApplicationContext(), waypoints.get(waypoints.size() - 1), waypoints.get(waypoints.size() - 2), TaskConfig.getFinishLength()));
} else {
- googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(waypoints.get(waypoints.size() - 2), waypoints.get(waypoints.size() - 3), TaskConfig.getFinishLength()));
+ googleMap.addPolyline(MapUtilities.getPerpendicularPolyline(getApplicationContext(), waypoints.get(waypoints.size() - 2), waypoints.get(waypoints.size() - 3), TaskConfig.getFinishLength()));
}
} catch (Throwable t) {
Logger.logError("Error trying to draw task lines: " + t.getMessage());
@@ -322,7 +352,7 @@ private void displayMarkers(List waypoints) {
private void displayLinesAndAreas(List waypoints) {
try {
- PolylineOptions polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(R.dimen.task_line_width)).color(getResources().getColor(R.color.task_line));
+ PolylineOptions polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this, R.dimen.task_line_width)).color(getResources().getColor(R.color.task_line));
for (int i = 0; i < waypoints.size(); i++) {
CRecordWayPoint cRecordWayPoint = (CRecordWayPoint) waypoints.get(i);
@@ -342,7 +372,6 @@ private void displayLinesAndAreas(List waypoints) {
}
}
-
@Override
public void onResume() {
super.onResume();
@@ -398,28 +427,6 @@ public void onClick(View view) {
}
}
- private class ParseIGCFileAsyncTask extends AsyncTask {
- private WeakReference activity;
-
- public ParseIGCFileAsyncTask(FlightPreviewActivity activity) {
- this.activity = new WeakReference<>(activity);
- }
-
- protected Void doInBackground(Void... something) {
- igcFile = Parser.parse(Uri.parse(fileToLoadPath));
- return null;
- }
-
- protected void onProgressUpdate(Void... something) {
- }
-
- protected void onPostExecute(Void result) {
- if (activity.get() != null) {
- handleIGCFileLoaded();
- }
- }
- }
-
private void handleIGCFileLoaded() {
listLatLngPoints = Utilities.getLatLngPoints(igcFile.getTrackPoints());
displayWayPoints();
@@ -430,7 +437,7 @@ private void handleIGCFileLoaded() {
viewAltitudeReferenceBar.setBackground(getColorScala());
mapView.setVisibility(View.VISIBLE);
cardviewInformation.setVisibility(View.VISIBLE);
- PreferencesHelper.setViewedFlightsForRate();
+ preferencesHelper.setViewedFlightsForRate();
loading.setVisibility(View.GONE);
}
@@ -585,32 +592,46 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
- public static PaintDrawable getColorScala() {
- ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
- @Override
- public Shader resize(int width, int height) {
- LinearGradient linearGradient = new LinearGradient(width, height, 0, 0,
- new int[]{
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_0_100),
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_100_300),
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_300_500),
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_500_1000),
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_1000_1500),
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_1500_2000),
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_2000_2500),
- IGCViewerApplication.getApplication().getResources().getColor(R.color.altitude_more_than_2500)},
- new float[]{
- 0, 0.07f, 0.14f, 0.28f, 0.42f, 0.56f, 0.7f, 0.84f},
- Shader.TileMode.REPEAT);
- return linearGradient;
- }
- };
+ private void launchShareFile(String tempIgcFilePath) {
+ try {
+ TrackerHelper.trackShareFlight();
+ Intent intentEmail = new Intent(Intent.ACTION_SEND);
+ intentEmail.setType(Constants.App.TEXT_HTML);
+ intentEmail.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(FlightPreviewActivity.this, Constants.App.FILE_PROVIDER, new File(tempIgcFilePath)));
+ intentEmail.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.share_email_subject), Uri.parse(tempIgcFilePath).getLastPathSegment()));
+ startActivity(Intent.createChooser(intentEmail, getString(R.string.share)));
+ } catch (Throwable t) {
+ Toast.makeText(this, R.string.sorry_error_happen, Toast.LENGTH_SHORT).show();
+ }
+ }
- PaintDrawable paint = new PaintDrawable();
- paint.setShape(new RectShape());
- paint.setShaderFactory(shaderFactory);
+ @Override
+ public boolean onCreateOptionsMenu(final Menu menu) {
+ getMenuInflater().inflate(R.menu.flight_preview_menu, menu);
- return paint;
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ private class ParseIGCFileAsyncTask extends AsyncTask {
+ private WeakReference activity;
+
+ public ParseIGCFileAsyncTask(FlightPreviewActivity activity) {
+ this.activity = new WeakReference<>(activity);
+ }
+
+ protected Void doInBackground(Void... something) {
+ igcFile = Parser.parse(Uri.parse(fileToLoadPath));
+ return null;
+ }
+
+ protected void onProgressUpdate(Void... something) {
+ }
+
+ protected void onPostExecute(Void result) {
+ if (activity.get() != null) {
+ handleIGCFileLoaded();
+ }
+ }
}
private class GetGmailAttachmentAsyncTask extends AsyncTask {
@@ -656,24 +677,4 @@ protected void onPostExecute(String tempIgcFilePath) {
}
}
-
- private void launchShareFile(String tempIgcFilePath) {
- try {
- TrackerHelper.trackShareFlight();
- Intent intentEmail = new Intent(Intent.ACTION_SEND);
- intentEmail.setType(Constants.App.TEXT_HTML);
- intentEmail.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(FlightPreviewActivity.this, Constants.App.FILE_PROVIDER, new File(tempIgcFilePath)));
- intentEmail.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.share_email_subject), Uri.parse(tempIgcFilePath).getLastPathSegment()));
- startActivity(Intent.createChooser(intentEmail, getString(R.string.share)));
- } catch (Throwable t) {
- Toast.makeText(this, R.string.sorry_error_happen, Toast.LENGTH_SHORT).show();
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(final Menu menu) {
- getMenuInflater().inflate(R.menu.flight_preview_menu, menu);
-
- return super.onCreateOptionsMenu(menu);
- }
}
diff --git a/app/src/main/java/com/shollmann/igcparser/ui/activity/IGCFilesActivity.java b/app/src/main/java/com/shollmann/igcparser/ui/activity/IGCFilesActivity.java
index 540e56a..8d1ea9a 100644
--- a/app/src/main/java/com/shollmann/igcparser/ui/activity/IGCFilesActivity.java
+++ b/app/src/main/java/com/shollmann/igcparser/ui/activity/IGCFilesActivity.java
@@ -30,6 +30,7 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
@@ -85,10 +86,10 @@ public class IGCFilesActivity extends AppCompatActivity implements MenuItem.OnMe
private TextView txtLoading;
private ProgressBar progress;
private FilesAdapter adapter;
- private LinearLayoutManager layoutManager;
private List listFiles = new ArrayList<>();
private File lastSearchedPath;
private boolean isSearching = true;
+ private PreferencesHelper preferencesHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -96,12 +97,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_igc_files);
findViews();
+ preferencesHelper = new PreferencesHelper(getApplicationContext());
setupFilesList();
- checkForStoragePemrission();
+ checkForStoragePermission();
}
private void setupRateUsView() {
- if (!PreferencesHelper.isRated() && PreferencesHelper.getViewedFlightCountForRate() >= PreferencesHelper.getMinFlightsViewedToRate()) {
+ if (!preferencesHelper.isRated() && preferencesHelper.getViewedFlightCountForRate() >= preferencesHelper.getMinFlightsViewedToRate()) {
viewRateUs.setVisibility(View.VISIBLE);
} else {
viewRateUs.setVisibility(View.GONE);
@@ -110,7 +112,7 @@ private void setupRateUsView() {
private void setupFilesList() {
recyclerView.setHasFixedSize(true);
- layoutManager = new LinearLayoutManager(this);
+ LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
adapter = new FilesAdapter(listFiles);
recyclerView.setAdapter(adapter);
@@ -279,53 +281,7 @@ private void sortBy(Comparator comparator) {
}
}
- private class FindIGCFilesAsyncTask extends AsyncTask {
- WeakReference activity;
-
- public FindIGCFilesAsyncTask(IGCFilesActivity activity) {
- this.activity = new WeakReference<>(activity);
- }
-
- protected Boolean doInBackground(File... file) {
- isSearching = true;
- lastSearchedPath = file[0];
- listFiles = getListIGCFiles(file[0]);
- return file[0].getAbsolutePath().equals(Utilities.getSdCardFolder().getAbsolutePath());
- }
-
- protected void onProgressUpdate(Void... something) {
- }
-
- protected void onPostExecute(Boolean isEntireFolder) {
- if (activity.get() != null) {
- handleFinishFilesLoad(isEntireFolder);
- }
- }
-
- private void handleFinishFilesLoad(Boolean isEntireFolder) {
- if (!listFiles.isEmpty()) {
- layoutLoading.setVisibility(RecyclerView.GONE);
- adapter.setDataset(listFiles);
- adapter.notifyDataSetChanged();
- } else {
- if (!isEntireFolder) {
- final String message = "No IGC files found on XCSoar folder. Searching on other folders";
- Logger.log(message);
- Crashlytics.log(message);
- txtLoading.setText(getString(R.string.searching_igc_files));
- new FindIGCFilesAsyncTask(activity.get()).execute(Utilities.getSdCardFolder());
- } else {
- viewRateUs.setVisibility(View.GONE);
- layoutLoading.setVisibility(View.GONE);
- layoutEmpty.setVisibility(View.VISIBLE);
- TrackerHelper.trackNoFilesFound();
- }
- }
- isSearching = false;
- }
- }
-
- private void checkForStoragePemrission() {
+ private void checkForStoragePermission() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
@@ -341,7 +297,7 @@ private void checkForStoragePemrission() {
@Override
public void onRequestPermissionsResult(int requestCode,
- String permissions[], int[] grantResults) {
+ @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case EXTERNAL_STORAGE_PERMISSION_REQUEST: {
if (grantResults.length > 0
@@ -355,11 +311,10 @@ public void onRequestPermissionsResult(int requestCode,
txtLoading.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- checkForStoragePemrission();
+ checkForStoragePermission();
}
});
}
- return;
}
}
}
@@ -381,4 +336,50 @@ protected void onResume() {
super.onResume();
setupRateUsView();
}
+
+ private class FindIGCFilesAsyncTask extends AsyncTask {
+ WeakReference activity;
+
+ FindIGCFilesAsyncTask(IGCFilesActivity activity) {
+ this.activity = new WeakReference<>(activity);
+ }
+
+ protected Boolean doInBackground(File... file) {
+ isSearching = true;
+ lastSearchedPath = file[0];
+ listFiles = getListIGCFiles(file[0]);
+ return file[0].getAbsolutePath().equals(Utilities.getSdCardFolder().getAbsolutePath());
+ }
+
+ protected void onProgressUpdate(Void... something) {
+ }
+
+ protected void onPostExecute(Boolean isEntireFolder) {
+ if (activity.get() != null) {
+ handleFinishFilesLoad(isEntireFolder);
+ }
+ }
+
+ private void handleFinishFilesLoad(Boolean isEntireFolder) {
+ if (!listFiles.isEmpty()) {
+ layoutLoading.setVisibility(RecyclerView.GONE);
+ adapter.setDataset(listFiles);
+ adapter.notifyDataSetChanged();
+ } else {
+ if (!isEntireFolder) {
+ final String message = "No IGC files found on XCSoar folder. Searching on other folders";
+ Logger.log(message);
+ Crashlytics.log(message);
+ txtLoading.setText(getString(R.string.searching_igc_files));
+ new FindIGCFilesAsyncTask(activity.get()).execute(Utilities.getSdCardFolder());
+ } else {
+ viewRateUs.setVisibility(View.GONE);
+ layoutLoading.setVisibility(View.GONE);
+ layoutEmpty.setVisibility(View.VISIBLE);
+ TrackerHelper.trackNoFilesFound();
+ }
+ }
+ isSearching = false;
+ }
+ }
}
diff --git a/app/src/main/java/com/shollmann/igcparser/ui/view/RateUsView.java b/app/src/main/java/com/shollmann/igcparser/ui/view/RateUsView.java
index 21687d8..d05b5a4 100644
--- a/app/src/main/java/com/shollmann/igcparser/ui/view/RateUsView.java
+++ b/app/src/main/java/com/shollmann/igcparser/ui/view/RateUsView.java
@@ -42,6 +42,7 @@
import org.greenrobot.eventbus.EventBus;
public class RateUsView extends LinearLayout implements View.OnClickListener {
+ private final PreferencesHelper preferencesHelper;
private TextView btnOk;
private TextView btnCancel;
private TextView txtMessage;
@@ -56,6 +57,7 @@ public RateUsView(Context context, AttributeSet attrs) {
public RateUsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
+ preferencesHelper = new PreferencesHelper(getContext());
init();
}
@@ -80,12 +82,12 @@ public void onClick(View view) {
switch (view.getId()) {
case R.id.rate_us_yes:
TrackerHelper.trackRateUsYes();
- PreferencesHelper.setIsRated();
+ preferencesHelper.setIsRated();
openPlayStore();
break;
case R.id.rate_us_no:
- PreferencesHelper.resetViewedFlightsForRate();
- PreferencesHelper.setMinFlightsViewedToRate();
+ preferencesHelper.resetViewedFlightsForRate();
+ preferencesHelper.setMinFlightsViewedToRate();
TrackerHelper.trackRateUsNo();
break;
}
diff --git a/app/src/main/java/com/shollmann/igcparser/ui/view/SettingsSeekBarView.java b/app/src/main/java/com/shollmann/igcparser/ui/view/SettingsSeekBarView.java
index 53b1007..774143b 100644
--- a/app/src/main/java/com/shollmann/igcparser/ui/view/SettingsSeekBarView.java
+++ b/app/src/main/java/com/shollmann/igcparser/ui/view/SettingsSeekBarView.java
@@ -37,6 +37,7 @@
import com.shollmann.igcparser.util.PreferencesHelper;
public class SettingsSeekBarView extends RelativeLayout {
+ private final PreferencesHelper preferencesHelper;
private TextView txtValue;
private TextView txtTitle;
private ImageView imgIcon;
@@ -54,6 +55,7 @@ public SettingsSeekBarView(Context context, AttributeSet attrs) {
public SettingsSeekBarView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
findViews();
+ preferencesHelper = new PreferencesHelper(getContext());
}
public void init(SeekbarType type) {
@@ -101,9 +103,9 @@ private void setTextValue(int value) {
float realValue;
if (value == 0) {
realValue = 0.5f;
- txtValue.setText(String.valueOf(realValue) + "km");
+ txtValue.setText(String.format("%skm", String.valueOf(realValue)));
} else {
- txtValue.setText(String.valueOf(value) + "km");
+ txtValue.setText(String.format("%skm", String.valueOf(value)));
}
}
@@ -111,13 +113,13 @@ private void setInitialValue() {
int value;
switch (type) {
case AREA:
- value = PreferencesHelper.getAreaWidth();
+ value = preferencesHelper.getAreaWidth();
break;
case START:
- value = PreferencesHelper.getStartLength();
+ value = preferencesHelper.getStartLength();
break;
case FINISH:
- value = PreferencesHelper.getFinishLength();
+ value = preferencesHelper.getFinishLength();
break;
default:
value = 0;
@@ -134,15 +136,15 @@ private void saveValue(int value) {
switch (type) {
case AREA:
TaskConfig.setAreaWidth(value);
- PreferencesHelper.setAreaWidth(value);
+ preferencesHelper.setAreaWidth(value);
break;
case START:
TaskConfig.setStartLength(value);
- PreferencesHelper.setStartLength(value);
+ preferencesHelper.setStartLength(value);
break;
case FINISH:
TaskConfig.setFinishLength(value);
- PreferencesHelper.setFinishLength(value);
+ preferencesHelper.setFinishLength(value);
break;
}
}
diff --git a/app/src/main/java/com/shollmann/igcparser/util/Constants.java b/app/src/main/java/com/shollmann/igcparser/util/Constants.java
index f530569..3ba8a12 100644
--- a/app/src/main/java/com/shollmann/igcparser/util/Constants.java
+++ b/app/src/main/java/com/shollmann/igcparser/util/Constants.java
@@ -36,7 +36,8 @@ public static class App {
public static final String TEMP_TRACK_NAME = "tmp_record.igc";
public static final String TEXT_HTML = "text/html";
public static final String FILE_PROVIDER = "com.shollmann.fileprovider";
- public static final int MIN_FLIGHTS_TO_RATE_APP = 10;
+ public static final int MIN_FLIGHTS_TO_RATE_APP = 12;
+ public static final int MIN_FLIGHTS_TO_RATE_APP_MULTIPLIER = 2;
}
public class Map {
diff --git a/app/src/main/java/com/shollmann/igcparser/util/MapUtilities.java b/app/src/main/java/com/shollmann/igcparser/util/MapUtilities.java
index 3bea5bd..c6934bb 100644
--- a/app/src/main/java/com/shollmann/igcparser/util/MapUtilities.java
+++ b/app/src/main/java/com/shollmann/igcparser/util/MapUtilities.java
@@ -24,16 +24,14 @@
package com.shollmann.igcparser.util;
+import android.content.Context;
import android.support.annotation.NonNull;
-import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.PolylineOptions;
import com.shollmann.android.igcparser.model.BRecord;
import com.shollmann.android.igcparser.model.IGCFile;
import com.shollmann.android.igcparser.model.ILatLonRecord;
-import com.shollmann.android.igcparser.util.Utilities;
import com.shollmann.android.igcparser.util.WaypointUtilities;
-import com.shollmann.igcparser.IGCViewerApplication;
import com.shollmann.igcparser.R;
import com.shollmann.igcparser.model.AltitudeSegment;
import com.shollmann.igcparser.model.AltitudeTrackSegment;
@@ -100,11 +98,11 @@ private static boolean between(int value, int min, int max) {
return min < value && value <= max;
}
- public static PolylineOptions getPerpendicularPolyline(ILatLonRecord point1, ILatLonRecord point2, int lineRadius) {
+ public static PolylineOptions getPerpendicularPolyline(Context context, ILatLonRecord point1, ILatLonRecord point2, int lineRadius) {
WaypointUtilities.PerpendicularLineCoordinates perpendicularLine = getPerpendicularLine(point1, point2, lineRadius);
PolylineOptions polyline = new PolylineOptions()
- .color(IGCViewerApplication.getApplication().getResources().getColor(R.color.start_finish_color))
- .width(ResourcesHelper.getDimensionPixelSize(R.dimen.task_start_finish_line_width))
+ .color(context.getResources().getColor(R.color.start_finish_color))
+ .width(ResourcesHelper.getDimensionPixelSize(context, R.dimen.task_start_finish_line_width))
.add(perpendicularLine.start)
.add(perpendicularLine.end);
diff --git a/app/src/main/java/com/shollmann/igcparser/util/PreferencesHelper.java b/app/src/main/java/com/shollmann/igcparser/util/PreferencesHelper.java
index 5733cf5..1f7e189 100644
--- a/app/src/main/java/com/shollmann/igcparser/util/PreferencesHelper.java
+++ b/app/src/main/java/com/shollmann/igcparser/util/PreferencesHelper.java
@@ -24,131 +24,124 @@
package com.shollmann.igcparser.util;
+import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
-import com.shollmann.igcparser.IGCViewerApplication;
-
public class PreferencesHelper {
- private static final String IS_RATED = "is_rated";
- private static final String FLIGHT_VIEWED = "flight_viewed";
- private static final String MIN_FLIGHTS_TO_RATE = "min_flights_to_rate";
- private static final String AREA_WIDTH = "area_width";
- private static final String START_LENGTH = "start_length";
- private static final String FINISH_LENGTH = "finish_length";
-
- static {
- prefs = PreferenceManager.getDefaultSharedPreferences(IGCViewerApplication.getApplication());
- }
-
-
- private static SharedPreferences prefs;
+ private final String IS_RATED = "is_rated";
+ private final String FLIGHT_VIEWED = "flight_viewed";
+ private final String MIN_FLIGHTS_TO_RATE = "min_flights_to_rate";
+ private final String AREA_WIDTH = "area_width";
+ private final String START_LENGTH = "start_length";
+ private final String FINISH_LENGTH = "finish_length";
+ private SharedPreferences prefs;
- public static void clear() {
- prefs.edit().clear().commit();
+ public PreferencesHelper(Context appContext) {
+ prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
}
- public static int get(String key, int _default) {
+ public int get(String key, int _default) {
return prefs.getInt(key, _default);
}
- public static String get(String key, String _default) {
+ public String get(String key, String _default) {
return prefs.getString(key, _default);
}
- public static float get(String key, float _default) {
+ public float get(String key, float _default) {
return prefs.getFloat(key, _default);
}
- public static boolean get(String key, boolean _default) {
+ public boolean get(String key, boolean _default) {
return prefs.getBoolean(key, _default);
}
- public static long get(String key, long _default) {
+ public long get(String key, long _default) {
return prefs.getLong(key, _default);
}
- public static void set(String key, long value) {
+ public void set(String key, long value) {
prefs.edit().putLong(key, value).commit();
}
- public static void set(String key, int value) {
+ public void set(String key, int value) {
prefs.edit().putInt(key, value).commit();
}
- public static void set(String key, String value) {
+ public void set(String key, String value) {
prefs.edit().putString(key, value).commit();
}
- public static void set(String key, float value) {
+ public void set(String key, float value) {
prefs.edit().putFloat(key, value).commit();
}
- public static void set(String key, boolean value) {
+ public void set(String key, boolean value) {
prefs.edit().putBoolean(key, value).commit();
}
- public static void remove(String key) {
+ public void remove(String key) {
prefs.edit().remove(key).commit();
}
- public static void setIsRated() {
+ public void setIsRated() {
set(IS_RATED, true);
}
- public static boolean isRated() {
+ public boolean isRated() {
return get(IS_RATED, false);
}
- public static void resetViewedFlightsForRate() {
+ public void resetViewedFlightsForRate() {
set(FLIGHT_VIEWED, 0);
}
- public static void setViewedFlightsForRate() {
+ public void setViewedFlightsForRate() {
int flightViewed = getViewedFlightCountForRate();
flightViewed++;
set(FLIGHT_VIEWED, flightViewed);
}
- public static int getViewedFlightCountForRate() {
+ public int getViewedFlightCountForRate() {
return get(FLIGHT_VIEWED, 0);
}
- public static int getMinFlightsViewedToRate() {
+ public int getMinFlightsViewedToRate() {
return get(MIN_FLIGHTS_TO_RATE, Constants.App.MIN_FLIGHTS_TO_RATE_APP);
}
- public static void setMinFlightsViewedToRate() {
+ public void setMinFlightsViewedToRate() {
int flightViewed = getMinFlightsViewedToRate();
- flightViewed = (int) (flightViewed * 1.7);
+ flightViewed = (int) (flightViewed * Constants.App.MIN_FLIGHTS_TO_RATE_APP_MULTIPLIER);
set(MIN_FLIGHTS_TO_RATE, flightViewed);
}
- public static int getAreaWidth() {
+ public int getAreaWidth() {
return get(AREA_WIDTH, Constants.Task.AREA_WIDTH_IN_METERS);
}
- public static void setAreaWidth(int value) {
+ public void setAreaWidth(int value) {
set(AREA_WIDTH, value);
}
- public static int getStartLength() {
+ public int getStartLength() {
return get(START_LENGTH, Constants.Task.START_IN_METERS);
}
- public static void setStartLength(int value) {
+ public void setStartLength(int value) {
set(START_LENGTH, value);
}
- public static int getFinishLength() {
+ public int getFinishLength() {
return get(FINISH_LENGTH, Constants.Task.FINISH_IN_METERS);
}
- public static void setFinishLength(int value) {
+ public void setFinishLength(int value) {
set(FINISH_LENGTH, value);
}
}
diff --git a/app/src/main/java/com/shollmann/igcparser/util/ResourcesHelper.java b/app/src/main/java/com/shollmann/igcparser/util/ResourcesHelper.java
index 64dbf8b..3bbece5 100644
--- a/app/src/main/java/com/shollmann/igcparser/util/ResourcesHelper.java
+++ b/app/src/main/java/com/shollmann/igcparser/util/ResourcesHelper.java
@@ -27,20 +27,17 @@
import android.content.Context;
import android.util.TypedValue;
-import com.shollmann.igcparser.IGCViewerApplication;
-
public class ResourcesHelper {
- public static int getDimensionPixelSize(int resource) {
- Context app = IGCViewerApplication.getApplication();
+ public static int getDimensionPixelSize(Context context, int resource) {
TypedValue rawValue = new TypedValue();
- app.getResources().getValue(resource, rawValue, true);
+ context.getResources().getValue(resource, rawValue, true);
if (rawValue.type == TypedValue.TYPE_FIRST_INT) {
//This is the case in which a dimen references an int like this: @integer/custom_match_parent
- return app.getResources().getInteger(resource);
+ return context.getResources().getInteger(resource);
} else {
//This is the standard case of reading a dimen as a dimen like this: 400dp
- return app.getResources().getDimensionPixelSize(resource);
+ return context.getResources().getDimensionPixelSize(resource);
}
}
}
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 4f09422..aab8e3e 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -15,12 +15,12 @@
#ff0000
- #ff8800
- #ffdd00
- #99dd00
- #40bb00
- #00ccdd
- #0088cc
+ #ff6600
+ #ffee00
+ #88dd00
+ #40dd00
+ #00ddff
+ #0088ff
#0000cc
diff --git a/build.gradle b/build.gradle
index d9b961b..f1bed3e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.2.3'
+ classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 13372ae..c97a8bd 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 04e285f..0400566 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Dec 28 10:00:20 PST 2015
+#Tue Jan 10 19:41:21 PST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
diff --git a/gradlew b/gradlew
index 9d82f78..91a7e26 100755
--- a/gradlew
+++ b/gradlew
@@ -42,6 +42,11 @@ case "`uname`" in
;;
esac
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@@ -56,9 +61,9 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
+cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
+cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@@ -109,7 +114,6 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
- JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
diff --git a/igcParser/src/main/java/com/shollmann/android/igcparser/Parser.java b/igcParser/src/main/java/com/shollmann/android/igcparser/Parser.java
index 29e3b41..0da9a1b 100644
--- a/igcParser/src/main/java/com/shollmann/android/igcparser/Parser.java
+++ b/igcParser/src/main/java/com/shollmann/android/igcparser/Parser.java
@@ -33,7 +33,6 @@
import com.shollmann.android.igcparser.model.BRecord;
import com.shollmann.android.igcparser.model.CRecordWayPoint;
import com.shollmann.android.igcparser.model.IGCFile;
-import com.shollmann.android.igcparser.model.TaskConfig;
import com.shollmann.android.igcparser.util.Constants;
import com.shollmann.android.igcparser.util.CoordinatesUtilities;
import com.shollmann.android.igcparser.util.Logger;
@@ -65,7 +64,7 @@ public static IGCFile parse(Uri filePath) {
String line;
while ((line = reader.readLine()) != null) {
if (isBRecord(line)) {
- if (firstBRecord == null) { // Classify waypoints to determine reached ares later
+ if (firstBRecord == null) { // Classify waypoints to later determine reached areas
WaypointUtilities.classifyWayPoints(igcFile.getWaypoints());
}
diff --git a/igcParser/src/main/java/com/shollmann/android/igcparser/model/CRecordWayPoint.java b/igcParser/src/main/java/com/shollmann/android/igcparser/model/CRecordWayPoint.java
index 573d6c2..c6fdff2 100644
--- a/igcParser/src/main/java/com/shollmann/android/igcparser/model/CRecordWayPoint.java
+++ b/igcParser/src/main/java/com/shollmann/android/igcparser/model/CRecordWayPoint.java
@@ -97,6 +97,6 @@ public void setType(CRecordType type) {
@Override
public String toString() {
- return lat + lon;
+ return lat + lon + type;
}
}
diff --git a/igcParser/src/main/java/com/shollmann/android/igcparser/model/IGCFile.java b/igcParser/src/main/java/com/shollmann/android/igcparser/model/IGCFile.java
index 03da2e8..2e58b7c 100644
--- a/igcParser/src/main/java/com/shollmann/android/igcparser/model/IGCFile.java
+++ b/igcParser/src/main/java/com/shollmann/android/igcparser/model/IGCFile.java
@@ -136,18 +136,10 @@ public String getFlightTime() {
return Utilities.getFlightTime(takeOffTime, landingTime);
}
- public String getGliderType() {
- return gliderType;
- }
-
public void setGliderType(String gliderType) {
this.gliderType = gliderType;
}
- public String getGliderId() {
- return gliderId;
- }
-
public void setGliderId(String gliderId) {
this.gliderId = gliderId;
}
@@ -172,18 +164,10 @@ public String getFileName() {
return fileName;
}
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-
public String getFilePath() {
return filePath;
}
- public void setFilePath(String filePath) {
- this.filePath = filePath;
- }
-
public String getGliderTypeAndId() {
if (TextUtils.isEmpty(gliderId) && TextUtils.isEmpty(gliderType)) {
return Constants.EMPTY_STRING;
diff --git a/igcParser/src/main/java/com/shollmann/android/igcparser/util/Constants.java b/igcParser/src/main/java/com/shollmann/android/igcparser/util/Constants.java
index 5d9cd14..0b9466d 100644
--- a/igcParser/src/main/java/com/shollmann/android/igcparser/util/Constants.java
+++ b/igcParser/src/main/java/com/shollmann/android/igcparser/util/Constants.java
@@ -87,6 +87,6 @@ public class Task {
public static final int AREA_WIDTH_IN_METERS = 10000;
public static final int START_IN_METERS = 5000;
public static final int FINISH_IN_METERS = 1000;
- public static final int MIN_TOLERANCE_IN_METERS = 200;
+ public static final int MIN_TOLERANCE_IN_METERS = 400;
}
}
diff --git a/igcParser/src/main/java/com/shollmann/android/igcparser/util/CoordinatesUtilities.java b/igcParser/src/main/java/com/shollmann/android/igcparser/util/CoordinatesUtilities.java
index 1bbed44..4c6c211 100644
--- a/igcParser/src/main/java/com/shollmann/android/igcparser/util/CoordinatesUtilities.java
+++ b/igcParser/src/main/java/com/shollmann/android/igcparser/util/CoordinatesUtilities.java
@@ -29,6 +29,7 @@
public class CoordinatesUtilities {
public static boolean isZeroCoordinate(ILatLonRecord wayPoint) {
return wayPoint == null
+ || wayPoint.getLatLon() == null
|| (Utilities.isZero(wayPoint.getLatLon().getLat()) && Utilities.isZero(wayPoint.getLatLon().getLon()));
}
diff --git a/igcParser/src/main/java/com/shollmann/android/igcparser/util/Utilities.java b/igcParser/src/main/java/com/shollmann/android/igcparser/util/Utilities.java
index 1e2e215..508ca3c 100644
--- a/igcParser/src/main/java/com/shollmann/android/igcparser/util/Utilities.java
+++ b/igcParser/src/main/java/com/shollmann/android/igcparser/util/Utilities.java
@@ -87,6 +87,16 @@ public static List getLatLngPoints(List listRecord) {
return listLatLng;
}
+ public static LatLng getLatLng(ILatLonRecord record) {
+ LatLng latLng = new LatLng(0, 0);
+ if (record != null && record.getLatLon() != null) {
+ final double lat = record.getLatLon().getLat();
+ final double lon = record.getLatLon().getLon();
+ latLng = new LatLng(lat, lon);
+ }
+ return latLng;
+ }
+
public static String generateTime(String igcTime) {
try {
final String hoursString = igcTime.substring(0, 2);
diff --git a/igcParser/src/main/java/com/shollmann/android/igcparser/util/WaypointUtilities.java b/igcParser/src/main/java/com/shollmann/android/igcparser/util/WaypointUtilities.java
index 078fe93..66a7152 100644
--- a/igcParser/src/main/java/com/shollmann/android/igcparser/util/WaypointUtilities.java
+++ b/igcParser/src/main/java/com/shollmann/android/igcparser/util/WaypointUtilities.java
@@ -45,6 +45,7 @@ public static void calculateReachedAreas(int positionBRecord, BRecord bRecord, I
List waypoints = igcFile.getWaypoints();
boolean isPointToAdd = false;
float[] distance = new float[2];
+
for (int i = 0; i < waypoints.size(); i++) {
final CRecordWayPoint waypoint = (CRecordWayPoint) waypoints.get(i);
if (waypoint.getType() == CRecordType.TURN) {
@@ -66,15 +67,9 @@ public static void calculateReachedAreas(int positionBRecord, BRecord bRecord, I
if (isPointToAdd) {
String waypointKey = waypoint.toString();
- if (waypoint.getType() == CRecordType.TURN) {
- if (mapAreaReached.get(waypointKey) == null) {
- //We kept only the first point of the reached area
- mapAreaReached.put(waypointKey, positionBRecord);
- }
- } else {
- //We overwrite the last start and finish points
+ if (mapAreaReached.get(waypointKey) == null) {
+ //We kept only the first point of the reached area
mapAreaReached.put(waypointKey, positionBRecord);
-
}
}
@@ -132,7 +127,9 @@ public static void classifyWayPoints(List waypoints) {
CRecordWayPoint aCRecord = (CRecordWayPoint) waypoints.get(i);
int oppositePosition = waypoints.size() - 1 - i;
CRecordWayPoint otherCRecord = (CRecordWayPoint) waypoints.get(oppositePosition);
- if (!includesTakeOffOrLanding(aCRecord) && (!aCRecord.getDescription().equalsIgnoreCase(otherCRecord.getDescription()) || oppositePosition == i)) {
+ if (!includesTakeOffOrLanding(aCRecord)
+ && (!aCRecord.getDescription().equalsIgnoreCase(otherCRecord.getDescription())
+ || oppositePosition == i)) {
aCRecord.setType(CRecordType.TURN);
} else {
if (i == 1) { //it has take off, start, finish and landing way points
@@ -148,8 +145,10 @@ public static void classifyWayPoints(List waypoints) {
}
}
- public static boolean includesTakeOffOrLanding(CRecordWayPoint aCRecord) {
- return aCRecord.getDescription().toUpperCase().contains("TAKE_OFF") || aCRecord.getDescription().toUpperCase().contains("TAKEOFF") || aCRecord.getDescription().toUpperCase().contains("LANDING");
+ private static boolean includesTakeOffOrLanding(CRecordWayPoint aCRecord) {
+ return aCRecord.getDescription().toUpperCase().contains("TAKE_OFF")
+ || aCRecord.getDescription().toUpperCase().contains("TAKEOFF")
+ || aCRecord.getDescription().toUpperCase().contains("LANDING");
}
public static double calculateTaskDistance(List waypoints) {
@@ -164,7 +163,7 @@ public static double calculateTaskDistance(List waypoints) {
}
- /**
+ /*
* Returns line through point1, at right angles to line between point1 and point2, length lineRadius in meters.
*
* @param point1
@@ -198,7 +197,7 @@ public static int getTaskAverageSpeed(IGCFile igcFile, HashMap
ArrayList listReachedAreas = getListReachedAreas(mapAreaReached);
String startTime = ((BRecord) igcFile.getTrackPoints().get(listReachedAreas.get(0))).getTime();
String finishTime = ((BRecord) igcFile.getTrackPoints().get(listReachedAreas.get(listReachedAreas.size() - 1))).getTime();
- return Utilities.calculateAverageSpeed(igcFile.getTaskDistance(), Utilities.getDiffTimeInSeconds(startTime, finishTime));
+ return Utilities.calculateAverageSpeed(igcFile.getTraveledTaskDistance(), Utilities.getDiffTimeInSeconds(startTime, finishTime));
} catch (Throwable t) {
return -1;
}
@@ -216,16 +215,16 @@ public static String getTaskDuration(IGCFile igcFile, HashMap m
}
public static double getTaskTraveledDistance(IGCFile igcFile, HashMap mapAreaReached) {
+ ArrayList list = new ArrayList<>();
if (!igcFile.isTaskCompleted()) {
return igcFile.getDistance();
}
- double totalDistance = 0;
+
ArrayList listReachedAreas = getListReachedAreas(mapAreaReached);
- for (int i = 0; i < listReachedAreas.size() - 1; i++) {
- int nextPosition = i + 1;
- totalDistance = totalDistance + SphericalUtil.computeLength(Utilities.getLatLngPoints(igcFile.getTrackPoints().subList(listReachedAreas.get(i), listReachedAreas.get(nextPosition))));
+ for (int i = 0; i < listReachedAreas.size(); i++) {
+ list.add(igcFile.getTrackPoints().get(listReachedAreas.get(i)));
}
- return totalDistance;
+ return SphericalUtil.computeLength(Utilities.getLatLngPoints(list));
}
private static ArrayList getListReachedAreas(HashMap mapAreaReached) {
@@ -237,9 +236,9 @@ private static ArrayList getListReachedAreas(HashMap m
public static class PerpendicularLineCoordinates {
public LatLng start;
public LatLng end;
- protected LatLng center;
+ LatLng center;
- public PerpendicularLineCoordinates(LatLng lineStart, LatLng lineEnd, ILatLonRecord point1) {
+ PerpendicularLineCoordinates(LatLng lineStart, LatLng lineEnd, ILatLonRecord point1) {
start = lineStart;
end = lineEnd;
center = new LatLng(point1.getLatLon().getLat(), point1.getLatLon().getLon());