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/7] 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/7] 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/7] 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 8f7e85320008fbe4f3e85d729edba6cdf552043d Mon Sep 17 00:00:00 2001 From: chumva Date: Sun, 30 Jul 2023 16:27:31 +0300 Subject: [PATCH 4/7] Fix #17672 --- .../plus/myplaces/MyPlacesActivity.java | 22 ----------- .../dialogs/FavoritesTreeFragment.java | 38 +++++++++++++------ 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/MyPlacesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/MyPlacesActivity.java index 897bb5a9d2d..785d34cdb6b 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/MyPlacesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/MyPlacesActivity.java @@ -1,6 +1,5 @@ package net.osmand.plus.myplaces; -import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.MenuItem; @@ -12,14 +11,12 @@ import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager.SimpleOnPageChangeListener; -import net.osmand.PlatformUtil; import net.osmand.data.PointDescription; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.backup.ui.BackupAuthorizationFragment; -import net.osmand.plus.importfiles.ImportHelper; import net.osmand.plus.myplaces.favorites.dialogs.FavoritesTreeFragment; import net.osmand.plus.myplaces.favorites.dialogs.FragmentStateHolder; import net.osmand.plus.myplaces.tracks.dialogs.AvailableTracksFragment; @@ -27,8 +24,6 @@ import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.controls.PagerSlidingTabStrip; -import org.apache.commons.logging.Log; - import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -38,10 +33,6 @@ */ public class MyPlacesActivity extends TabActivity { - private static final Log LOG = PlatformUtil.getLog(MyPlacesActivity.class); - - public static final int OPEN_GPX_DOCUMENT_REQUEST = 1006; - public static final int IMPORT_FAVOURITES_REQUEST = 1007; public static final String TAB_ID = "selected_tab_id"; @@ -49,7 +40,6 @@ public class MyPlacesActivity extends TabActivity { public static final int FAV_TAB = R.string.shared_string_my_favorites; private OsmandSettings settings; - private ImportHelper importHelper; private ViewPager viewPager; private List> fragmentsStateList = new ArrayList<>(); @@ -61,7 +51,6 @@ public class MyPlacesActivity extends TabActivity { public void onCreate(@Nullable Bundle savedInstanceState) { OsmandApplication app = getMyApplication(); settings = app.getSettings(); - importHelper = new ImportHelper(this); app.applyTheme(this); super.onCreate(savedInstanceState); @@ -95,17 +84,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == IMPORT_FAVOURITES_REQUEST && resultCode == Activity.RESULT_OK) { - if (data != null && data.getData() != null) { - importHelper.handleFavouritesImport(data.getData()); - } - } else { - super.onActivityResult(requestCode, resultCode, data); - } - } - private void setTabs(@NonNull List tabItems) { PagerSlidingTabStrip mSlidingTabLayout = findViewById(R.id.sliding_tabs); Integer tabId = settings.FAVORITES_TAB.get(); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/favorites/dialogs/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/favorites/dialogs/FavoritesTreeFragment.java index b511798b3f2..ea31a511c7c 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/favorites/dialogs/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/favorites/dialogs/FavoritesTreeFragment.java @@ -4,10 +4,9 @@ import static net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import static net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import static net.osmand.plus.myplaces.MyPlacesActivity.FAV_TAB; -import static net.osmand.plus.myplaces.MyPlacesActivity.IMPORT_FAVOURITES_REQUEST; import static net.osmand.plus.myplaces.MyPlacesActivity.TAB_ID; -import static net.osmand.plus.widgets.dialogbutton.DialogButtonType.SECONDARY; +import android.app.Activity; import android.content.Intent; import android.graphics.PorterDuff; import android.graphics.Typeface; @@ -81,17 +80,19 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implements FragmentStateHolder, OsmAndCompassListener, OsmAndLocationListener, ShareFavoritesListener { - public static final int SEARCH_ID = -1; - public static final int DELETE_ID = 2; - public static final int DELETE_ACTION_ID = 3; - public static final int SHARE_ID = 4; - public static final int SELECT_MAP_MARKERS_ID = 5; - public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6; - public static final int IMPORT_FAVOURITES_ID = 7; - public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded"; + private static final int IMPORT_FAVOURITES_REQUEST = 1007; + private static final int SEARCH_ID = -1; + private static final int DELETE_ID = 2; + private static final int DELETE_ACTION_ID = 3; + private static final int SHARE_ID = 4; + private static final int SELECT_MAP_MARKERS_ID = 5; + private static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6; + private static final int IMPORT_FAVOURITES_ID = 7; + private static final String GROUP_EXPANDED_POSTFIX = "_group_expanded"; private FavouritesHelper helper; private FavouritesAdapter favouritesAdapter; + private ImportHelper importHelper; private boolean selectionMode; private final LinkedHashMap> favoritesSelected = new LinkedHashMap<>(); @@ -119,6 +120,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); favouritesAdapter = new FavouritesAdapter(); + importHelper = new ImportHelper(requireActivity()); helper = app.getFavoritesHelper(); if (helper.isFavoritesLoaded()) { @@ -179,10 +181,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, boolean nightMode = !app.getSettings().isLightContent(); View searchView = inflater.inflate(R.layout.search_fav_list_item, listView, false); searchView.setBackgroundResource(ColorUtilities.getListBgColorId(nightMode)); + TextView title = searchView.findViewById(R.id.title); - Drawable searchIcon = app.getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark); + Drawable searchIcon = getContentIcon(R.drawable.ic_action_search_dark); AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(title, searchIcon, null, null, null); - searchView.setOnClickListener(v -> FavoritesSearchFragment.showInstance(getActivity(), "")); + searchView.setOnClickListener(v -> FavoritesSearchFragment.showInstance(requireActivity(), "")); listView.addHeaderView(searchView); View dividerView = inflater.inflate(R.layout.list_item_divider, null, false); boolean proAvailable = InAppPurchaseHelper.isOsmAndProAvailable(app); @@ -594,6 +597,17 @@ private void importFavourites() { AndroidUtils.startActivityForResultIfSafe(this, intent, IMPORT_FAVOURITES_REQUEST); } + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + if (requestCode == IMPORT_FAVOURITES_REQUEST && resultCode == Activity.RESULT_OK) { + if (data != null && data.getData() != null) { + importHelper.handleFavouritesImport(data.getData()); + } + } else { + super.onActivityResult(requestCode, resultCode, data); + } + } + public void shareFavorites(@Nullable FavoriteGroup group) { ShareFavoritesAsyncTask shareFavoritesTask = new ShareFavoritesAsyncTask(app, group, this); shareFavoritesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); From 2875e87f372e38b8c2d623c3b1d55412bd4195ff Mon Sep 17 00:00:00 2001 From: chumva Date: Mon, 31 Jul 2023 11:01:43 +0300 Subject: [PATCH 5/7] Fix nautical item visibility --- .../plus/plugins/openseamaps/NauticalMapsPlugin.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/plugins/openseamaps/NauticalMapsPlugin.java b/OsmAnd/src/net/osmand/plus/plugins/openseamaps/NauticalMapsPlugin.java index a2c17128bc3..307fd68de39 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/openseamaps/NauticalMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/plugins/openseamaps/NauticalMapsPlugin.java @@ -17,6 +17,8 @@ import net.osmand.plus.download.LocalIndexHelper; import net.osmand.plus.download.LocalIndexInfo; import net.osmand.plus.plugins.OsmandPlugin; +import net.osmand.plus.plugins.PluginsHelper; +import net.osmand.plus.plugins.srtm.SRTMPlugin; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; @@ -111,6 +113,15 @@ public void createAdapterItem(@NonNull ContextMenuAdapter adapter, } } + @Override + public void registerLayerContextMenuActions(@NonNull ContextMenuAdapter menuAdapter, + @NonNull MapActivity mapActivity, + @NonNull List customRules) { + if (!PluginsHelper.isEnabled(SRTMPlugin.class)) { + createAdapterItem(menuAdapter, mapActivity, customRules); + } + } + private boolean hasDepthMaps() { boolean readFiles = !app.getResourceManager().isIndexesLoadedOnStart(); LocalIndexHelper helper = new LocalIndexHelper(app); From df9f02bc87e99dbb3849bb723c847c63aaa45740 Mon Sep 17 00:00:00 2001 From: chumva Date: Mon, 31 Jul 2023 11:20:14 +0300 Subject: [PATCH 6/7] 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 7/7] 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) {