From a2649bcaf6ca662a0316d08e304088e517c461f0 Mon Sep 17 00:00:00 2001 From: Reinka <0xre1nk0@gmail.com> Date: Thu, 27 Jul 2023 20:12:48 +0300 Subject: [PATCH 1/5] Fir write heading --- .../plus/plugins/monitoring/SavingTrackHelper.java | 9 ++++++--- .../bottomsheets/BooleanRadioButtonsBottomSheet.java | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java index eb9d548958d..32697ce4f29 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java @@ -387,8 +387,11 @@ private void collectDBTracks(@NonNull SQLiteDatabase db, @NonNull Map extensions = getPluginsExtensions(query.getString(7)); pt.getExtensionsToWrite().putAll(extensions); @@ -764,7 +767,7 @@ private void executeInsertTrackQuery(double lat, double lon, double alt, double rowsMap.put(TRACK_COL_SPEED, speed); rowsMap.put(TRACK_COL_HDOP, hdop); rowsMap.put(TRACK_COL_DATE, time); - rowsMap.put(TRACK_COL_HEADING, heading); + rowsMap.put(TRACK_COL_HEADING, Float.isNaN(heading) ? null : heading); rowsMap.put(TRACK_COL_PLUGINS_INFO, pluginsInfo); execWithClose(AndroidUtils.createDbInsertQuery(TRACK_NAME, rowsMap.keySet()), rowsMap.values().toArray()); } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java index 77ae4d42e66..6c6ef650496 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java @@ -117,6 +117,7 @@ private void onRadioButtonClick(@NonNull View view, @NonNull SwitchPreferenceEx } } } + dismiss(); } private void updatePreferenceButtons(boolean checked) { From 0317ad02c1a306a15293e58e3a95397978515777 Mon Sep 17 00:00:00 2001 From: Reinka <0xre1nk0@gmail.com> Date: Thu, 27 Jul 2023 20:20:33 +0300 Subject: [PATCH 2/5] Text size fix --- .../settings/bottomsheets/BooleanRadioButtonsBottomSheet.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java index 6c6ef650496..d586a08f1c0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanRadioButtonsBottomSheet.java @@ -3,6 +3,7 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import android.os.Bundle; +import android.util.TypedValue; import android.view.Gravity; import android.view.View; import android.widget.LinearLayout; @@ -82,6 +83,7 @@ public View getCustomRadioButtonView(@NonNull SwitchPreferenceEx preference, boo TextView textView = view.findViewById(R.id.text); textView.setText(getSummary(preference, enabled)); + textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.default_list_text_size)); int margin = getResources().getDimensionPixelSize(R.dimen.content_padding_small); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); From 39f2751132f6507bc5e1bab92d6b5213af28852d Mon Sep 17 00:00:00 2001 From: chumva Date: Fri, 28 Jul 2023 18:50:07 +0300 Subject: [PATCH 3/5] Code cleanup --- .../osmand/plus/plugins/monitoring/SavingTrackHelper.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java index 32697ce4f29..c38287aa1f5 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java @@ -386,12 +386,7 @@ private void collectDBTracks(@NonNull SQLiteDatabase db, @NonNull Map extensions = getPluginsExtensions(query.getString(7)); pt.getExtensionsToWrite().putAll(extensions); From df9f02bc87e99dbb3849bb723c847c63aaa45740 Mon Sep 17 00:00:00 2001 From: chumva Date: Mon, 31 Jul 2023 11:20:14 +0300 Subject: [PATCH 4/5] Remove unnecessary NO_HEADING constant --- .../plus/plugins/monitoring/SavingTrackHelper.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java index c38287aa1f5..9f0b5e40bec 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java @@ -81,9 +81,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { private static final String POINT_COL_ICON = "icon"; private static final String POINT_COL_BACKGROUND = "background"; - private static final float NO_HEADING = -1.0f; - - public static final NumberFormat DECIMAL_FORMAT = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.US)); + private static final NumberFormat DECIMAL_FORMAT = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.US)); private final OsmandApplication app; @@ -478,7 +476,7 @@ private void dropEmptyTracks(@NonNull Map dataTracks) { public void startNewSegment() { lastTimeUpdated = 0; lastPoint = null; - executeInsertTrackQuery(0, 0, 0, 0, 0, System.currentTimeMillis(), NO_HEADING, null); + executeInsertTrackQuery(0, 0, 0, 0, 0, System.currentTimeMillis(), Float.NaN, null); addTrackPoint(null, true, System.currentTimeMillis()); } @@ -488,7 +486,7 @@ public void updateLocation(net.osmand.Location location, Float heading) { OsmandDevelopmentPlugin plugin = PluginsHelper.getEnabledPlugin(OsmandDevelopmentPlugin.class); boolean writeHeading = plugin != null && plugin.SAVE_HEADING_TO_GPX.get(); - heading = heading != null && writeHeading ? MapUtils.normalizeDegrees360(heading) : NO_HEADING; + heading = heading != null && writeHeading ? MapUtils.normalizeDegrees360(heading) : Float.NaN; if (app.getRoutingHelper().isFollowingMode()) { lastRoutingApplicationMode = settings.getApplicationMode(); @@ -531,7 +529,6 @@ record = false; } } String pluginsInfo = json.length() > 0 ? json.toString() : null; - heading = heading == NO_HEADING ? Float.NaN : heading; WptPt wptPt = new WptPt(location.getLatitude(), location.getLongitude(), locationTime, location.getAltitude(), location.getSpeed(), location.getAccuracy(), heading); From a1484875e55ee7771f1e57f0c80317d42d6be51e Mon Sep 17 00:00:00 2001 From: chumva Date: Mon, 31 Jul 2023 11:26:19 +0300 Subject: [PATCH 5/5] Simple code cleanup --- .../plugins/monitoring/SavingTrackHelper.java | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java index 9f0b5e40bec..51536755fe5 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/plugins/monitoring/SavingTrackHelper.java @@ -9,6 +9,7 @@ import androidx.annotation.Nullable; import net.osmand.IndexConstants; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.gpx.GPXFile; @@ -480,19 +481,32 @@ public void startNewSegment() { addTrackPoint(null, true, System.currentTimeMillis()); } - public void updateLocation(net.osmand.Location location, Float heading) { + public void updateLocation(@Nullable Location location, @Nullable Float heading) { // use because there is a bug on some devices with location.getTime() long locationTime = System.currentTimeMillis(); - OsmandDevelopmentPlugin plugin = PluginsHelper.getEnabledPlugin(OsmandDevelopmentPlugin.class); - boolean writeHeading = plugin != null && plugin.SAVE_HEADING_TO_GPX.get(); - heading = heading != null && writeHeading ? MapUtils.normalizeDegrees360(heading) : Float.NaN; - if (app.getRoutingHelper().isFollowingMode()) { lastRoutingApplicationMode = settings.getApplicationMode(); } else if (settings.getApplicationMode() == settings.DEFAULT_APPLICATION_MODE.get()) { lastRoutingApplicationMode = null; } + boolean record = shouldRecordLocation(location, locationTime); + if (record) { + heading = getAdjustedHeading(heading); + + WptPt wptPt = new WptPt(location.getLatitude(), location.getLongitude(), locationTime, + location.getAltitude(), location.getSpeed(), location.getAccuracy(), heading); + + String pluginsInfo = getPluginsInfo(location); + Map extensions = getPluginsExtensions(pluginsInfo); + wptPt.getExtensionsToWrite().putAll(extensions); + + insertData(wptPt, pluginsInfo); + app.getNotificationHelper().refreshNotification(NotificationType.GPX); + } + } + + private boolean shouldRecordLocation(@Nullable Location location, long locationTime) { boolean record = false; if (location != null && SimulationProvider.isNotSimulatedLocation(location) && PluginsHelper.isActive(OsmandMonitoringPlugin.class)) { @@ -503,8 +517,8 @@ record = true; record = true; } float minDistance = settings.SAVE_TRACK_MIN_DISTANCE.get(); - if (minDistance > 0 && lastPoint != null && MapUtils.getDistance(lastPoint, location.getLatitude(), location.getLongitude()) < - minDistance) { + if (minDistance > 0 && lastPoint != null + && MapUtils.getDistance(lastPoint, location.getLatitude(), location.getLongitude()) < minDistance) { record = false; } float precision = settings.SAVE_TRACK_PRECISION.get(); @@ -516,29 +530,30 @@ record = false; record = false; } } - if (record) { - JSONObject json = new JSONObject(); - PluginsHelper.attachAdditionalInfoToRecordedTrack(location, json); - - boolean writeBearing = plugin != null && plugin.SAVE_BEARING_TO_GPX.get(); - if (writeBearing && location.hasBearing()) { - try { - json.put(TRACK_COL_BEARING, DECIMAL_FORMAT.format(location.getBearing())); - } catch (JSONException e) { - log.error(e.getMessage(), e); - } - } - String pluginsInfo = json.length() > 0 ? json.toString() : null; + return record; + } - WptPt wptPt = new WptPt(location.getLatitude(), location.getLongitude(), locationTime, - location.getAltitude(), location.getSpeed(), location.getAccuracy(), heading); + private float getAdjustedHeading(@Nullable Float heading) { + OsmandDevelopmentPlugin plugin = PluginsHelper.getEnabledPlugin(OsmandDevelopmentPlugin.class); + boolean writeHeading = plugin != null && plugin.SAVE_HEADING_TO_GPX.get(); + return heading != null && writeHeading ? MapUtils.normalizeDegrees360(heading) : Float.NaN; + } - Map extensions = getPluginsExtensions(pluginsInfo); - wptPt.getExtensionsToWrite().putAll(extensions); + @Nullable + private String getPluginsInfo(@NonNull net.osmand.Location location) { + JSONObject json = new JSONObject(); + PluginsHelper.attachAdditionalInfoToRecordedTrack(location, json); - insertData(wptPt, pluginsInfo); - app.getNotificationHelper().refreshNotification(NotificationType.GPX); + OsmandDevelopmentPlugin plugin = PluginsHelper.getEnabledPlugin(OsmandDevelopmentPlugin.class); + boolean writeBearing = plugin != null && plugin.SAVE_BEARING_TO_GPX.get(); + if (writeBearing && location.hasBearing()) { + try { + json.put(TRACK_COL_BEARING, DECIMAL_FORMAT.format(location.getBearing())); + } catch (JSONException e) { + log.error(e.getMessage(), e); + } } + return json.length() > 0 ? json.toString() : null; } private void insertData(@NonNull WptPt wptPt, @Nullable String pluginsInfo) {