getAmenities(QuadRect rect, PoiUIFilter wikiPoiFilter) {
+ return wikiPoiFilter.searchAmenities(rect.top, rect.left,
+ rect.bottom, rect.right, -1, null);
+ }
+
@SuppressWarnings("unchecked")
public static void execute(AsyncTask
task, P... requests) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
index 523ce5fef4..f676c5812e 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
@@ -25,8 +25,8 @@ public abstract class MenuTitleController {
private AddressLookupRequest addressLookupRequest;
- protected String searchAddressStr;
- protected String addressNotFoundStr;
+ protected String searchAddressStr = "";
+ protected String addressNotFoundStr = "";
@Nullable
public abstract MapActivity getMapActivity();
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java
index 231182be8b..5b4058f339 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java
@@ -105,7 +105,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
@Override
public void afterTextChanged(Editable s) {
- checkEmptyName(s.toString());
+ updateFileNameFromEditText(s.toString());
}
});
BaseBottomSheetItem editFileName = new BaseBottomSheetItem.Builder()
@@ -215,7 +215,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
folderName = item;
EditText editText = nameTextBox.getEditText();
if (editText != null) {
- checkEmptyName(editText.getText().toString());
+ updateFileNameFromEditText(editText.getText().toString());
}
}
};
@@ -307,7 +307,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
return rightButtonEnabled;
}
- private void checkEmptyName(String name) {
+ private void updateFileNameFromEditText(String name) {
rightButtonEnabled = false;
String text = name.trim();
if (text.isEmpty()) {
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java
index cd84845584..24d3ec8282 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java
@@ -3,8 +3,6 @@ package net.osmand.plus.measurementtool;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
@@ -16,9 +14,12 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
+import net.osmand.Collator;
import net.osmand.IndexConstants;
+import net.osmand.OsmAndCollator;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
+import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.BottomSheetBehaviourDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.helpers.GpxTrackAdapter;
@@ -26,7 +27,6 @@ import net.osmand.plus.helpers.GpxTrackAdapter.OnItemClickListener;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener;
-import net.osmand.plus.widgets.IconPopupMenu;
import java.io.File;
import java.util.ArrayList;
@@ -36,12 +36,17 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static net.osmand.plus.SimplePopUpMenuItemAdapter.*;
import static net.osmand.plus.helpers.GpxUiHelper.getSortedGPXFilesInfo;
import static net.osmand.plus.settings.backend.OsmandSettings.*;
import static net.osmand.util.Algorithms.collectDirs;
public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
+ private List folders;
+ private HorizontalSelectionAdapter folderAdapter;
+ private GPXInfo currentlyRecording;
+
enum Mode {
OPEN_TRACK(R.string.shared_string_gpx_tracks, R.string.sort_by),
ADD_TO_TRACK(R.string.add_to_a_track, R.string.route_between_points_add_track_desc);
@@ -73,7 +78,7 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
private Mode fragmentMode;
private String selectedFolder;
private String allFilesFolder;
- TracksSortByMode tracksSortBy = TracksSortByMode.BY_DATE;
+ TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
public void setFragmentMode(Mode fragmentMode) {
this.fragmentMode = fragmentMode;
@@ -99,56 +104,52 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
if (fragmentMode == Mode.OPEN_TRACK) {
titleView.setText(AndroidUtils.addColon(app, fragmentMode.title));
updateDescription(descriptionView);
- final ImageButton sortButton = mainView.findViewById(R.id.sort_button);
- Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark,
- nightMode
- ? R.color.inactive_buttons_and_links_bg_dark
- : R.color.inactive_buttons_and_links_bg_light);
- AndroidUtils.setBackground(sortButton, background);
- sortButton.setImageResource(tracksSortBy.getIconId());
- sortButton.setVisibility(View.VISIBLE);
- sortButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- IconPopupMenu popup = new IconPopupMenu(v.getContext(), v);
- final Menu menu = popup.getMenu();
- MenuItem mi;
- for (final TracksSortByMode mode : TracksSortByMode.values()) {
- mi = createMenuItem(app, menu, mode.getNameId(), mode.getNameId(), mode.getIconId(),
- MenuItem.SHOW_AS_ACTION_ALWAYS, false, R.color.icon_color_default_light);
- mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- tracksSortBy = mode;
- sortButton.setImageResource(mode.getIconId());
- updateDescription(descriptionView);
- sortFileList();
- adapter.notifyDataSetChanged();
- return false;
- }
- });
- }
- popup.show();
- }
- });
}
+ final ImageButton sortButton = mainView.findViewById(R.id.sort_button);
+ Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark,
+ nightMode
+ ? R.color.inactive_buttons_and_links_bg_dark
+ : R.color.inactive_buttons_and_links_bg_light);
+ AndroidUtils.setBackground(sortButton, background);
+ sortButton.setImageResource(sortByMode.getIconId());
+ sortButton.setVisibility(View.VISIBLE);
+ sortButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final List items = new ArrayList<>();
+ for (final TracksSortByMode mode : TracksSortByMode.values()) {
+ items.add(new SimplePopUpMenuItem(
+ getString(mode.getNameId()),
+ app.getUIUtilities().getThemedIcon(mode.getIconId()),
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ sortByMode = mode;
+ sortButton.setImageResource(mode.getIconId());
+ updateDescription(descriptionView);
+ sortFolderList();
+ folderAdapter.setItems(getFolderNames());
+ folderAdapter.notifyDataSetChanged();
+ sortFileList();
+ adapter.notifyDataSetChanged();
+ }
+ }, sortByMode == mode
+ ));
+ }
+ UiUtilities.showPopUpMenu(v, items);
+ }
+ });
- List dirs = new ArrayList<>();
final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
- collectDirs(gpxDir, dirs);
- List dirItems = new ArrayList<>();
+
allFilesFolder = context.getString(R.string.shared_string_all);
if (savedInstanceState == null) {
selectedFolder = allFilesFolder;
}
- dirItems.add(allFilesFolder);
- for (File dir : dirs) {
- dirItems.add(dir.getName());
- }
-
final List allGpxList = getSortedGPXFilesInfo(gpxDir, null, false);
+ currentlyRecording = new GPXInfo(getString(R.string.shared_string_currently_recording_track), 0, 0);
if (isShowCurrentGpx()) {
- allGpxList.add(0, new GPXInfo(getString(R.string.shared_string_currently_recording_track), 0, 0));
+ allGpxList.add(0, currentlyRecording);
}
gpxInfoMap = new HashMap<>();
gpxInfoMap.put(allFilesFolder, allGpxList);
@@ -186,8 +187,11 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
final RecyclerView foldersRecyclerView = mainView.findViewById(R.id.folder_list);
foldersRecyclerView.setLayoutManager(new LinearLayoutManager(context,
RecyclerView.HORIZONTAL, false));
- final HorizontalSelectionAdapter folderAdapter = new HorizontalSelectionAdapter(app, nightMode);
- folderAdapter.setItems(dirItems);
+ folderAdapter = new HorizontalSelectionAdapter(app, nightMode);
+ folders = new ArrayList<>();
+ collectDirs(gpxDir, folders);
+ sortFolderList();
+ folderAdapter.setItems(getFolderNames());
folderAdapter.setSelectedItem(selectedFolder);
foldersRecyclerView.setAdapter(folderAdapter);
folderAdapter.setListener(new HorizontalSelectionAdapterListener() {
@@ -201,24 +205,22 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
updateFileList(folderAdapter);
}
- private void updateDescription(TextView descriptionView) {
- String string = getString(tracksSortBy.getNameId());
- descriptionView.setText(String.format(getString(R.string.ltr_or_rtl_combine_via_space),
- getString(fragmentMode.description),
- Character.toLowerCase(string.charAt(0)) + string.substring(1)));
+ private List getFolderNames() {
+ List folderNames = new ArrayList<>();
+ folderNames.add(allFilesFolder);
+ for (File folder : folders) {
+ folderNames.add(folder.getName());
+ }
+ return folderNames;
}
- public MenuItem createMenuItem(OsmandApplication app, Menu m, int id, int titleRes, int iconId, int menuItemType,
- boolean flipIconForRtl, int iconColor) {
- Drawable d = iconId == 0 ? null : app.getUIUtilities().getIcon(iconId, iconColor);
- MenuItem menuItem = m.add(0, id, 0, titleRes);
- if (d != null) {
- if (flipIconForRtl) {
- d = AndroidUtils.getDrawableForDirection(app, d);
- }
- menuItem.setIcon(d);
+ private void updateDescription(TextView descriptionView) {
+ if (fragmentMode == Mode.OPEN_TRACK) {
+ String string = getString(sortByMode.getNameId());
+ descriptionView.setText(String.format(getString(R.string.ltr_or_rtl_combine_via_space),
+ getString(fragmentMode.description),
+ Character.toLowerCase(string.charAt(0)) + string.substring(1)));
}
- return menuItem;
}
private void updateFileList(HorizontalSelectionAdapter folderAdapter) {
@@ -228,25 +230,20 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
folderAdapter.notifyDataSetChanged();
}
- private void sortFileList() {
- List gpxInfoList = gpxInfoMap.get(selectedFolder);
- sortSelected(gpxInfoList);
- adapter.setGpxInfoList(gpxInfoList != null ? gpxInfoList : new ArrayList());
- }
-
- public void sortSelected(List gpxInfoList) {
- Collections.sort(gpxInfoList, new Comparator() {
+ private void sortFolderList() {
+ final Collator collator = OsmAndCollator.primaryCollator();
+ Collections.sort(folders, new Comparator() {
@Override
- public int compare(GPXInfo i1, GPXInfo i2) {
- if (tracksSortBy == TracksSortByMode.BY_NAME_ASCENDING) {
- return i1.getFileName().toLowerCase().compareTo(i2.getFileName().toLowerCase());
- } else if (tracksSortBy == TracksSortByMode.BY_NAME_DESCENDING) {
- return -i1.getFileName().toLowerCase().compareTo(i2.getFileName().toLowerCase());
+ public int compare(File i1, File i2) {
+ if (sortByMode == TracksSortByMode.BY_NAME_ASCENDING) {
+ return collator.compare(i1.getName(), i2.getName());
+ } else if (sortByMode == TracksSortByMode.BY_NAME_DESCENDING) {
+ return -collator.compare(i1.getName(), i2.getName());
} else {
- long time1 = i1.getLastModified();
- long time2 = i2.getLastModified();
+ long time1 = i1.lastModified();
+ long time2 = i2.lastModified();
if (time1 == time2) {
- return i1.getFileName().toLowerCase().compareTo(i2.getFileName().toLowerCase());
+ return collator.compare(i1.getName(), i2.getName());
}
return -((time1 < time2) ? -1 : ((time1 == time2) ? 0 : 1));
}
@@ -254,6 +251,39 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
});
}
+ private void sortFileList() {
+ List gpxInfoList = gpxInfoMap.get(selectedFolder);
+ if (gpxInfoList != null) {
+ sortSelected(gpxInfoList);
+ }
+ adapter.setGpxInfoList(gpxInfoList != null ? gpxInfoList : new ArrayList());
+ }
+
+ public void sortSelected(List gpxInfoList) {
+ boolean hasRecording = gpxInfoList.remove(currentlyRecording);
+ final Collator collator = OsmAndCollator.primaryCollator();
+ Collections.sort(gpxInfoList, new Comparator() {
+ @Override
+ public int compare(GPXInfo i1, GPXInfo i2) {
+ if (sortByMode == TracksSortByMode.BY_NAME_ASCENDING) {
+ return collator.compare(i1.getFileName(), i2.getFileName());
+ } else if (sortByMode == TracksSortByMode.BY_NAME_DESCENDING) {
+ return -collator.compare(i1.getFileName(), i2.getFileName());
+ } else {
+ long time1 = i1.getLastModified();
+ long time2 = i2.getLastModified();
+ if (time1 == time2) {
+ return collator.compare(i1.getFileName(), i2.getFileName());
+ }
+ return -((time1 < time2) ? -1 : ((time1 == time2) ? 0 : 1));
+ }
+ }
+ });
+ if (hasRecording) {
+ gpxInfoList.add(0, currentlyRecording);
+ }
+ }
+
private boolean showFoldersName() {
return allFilesFolder.equals(selectedFolder);
}
diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java
index ef184307e6..fae190ea01 100644
--- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java
+++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java
@@ -19,7 +19,6 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
-import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
@@ -46,6 +45,7 @@ import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
+import net.osmand.Collator;
import net.osmand.FileUtils;
import net.osmand.FileUtils.RenameCallback;
import net.osmand.GPXUtilities;
@@ -54,6 +54,7 @@ import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.Track;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.IndexConstants;
+import net.osmand.OsmAndCollator;
import net.osmand.data.PointDescription;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
@@ -70,7 +71,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
-import net.osmand.plus.SimplePopUpMenuItemAdapter;
+import net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
@@ -86,7 +87,6 @@ import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.TracksSortByMode;
import java.io.File;
-import java.text.Collator;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -166,8 +166,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
super.onAttach(activity);
this.app = (OsmandApplication) getActivity().getApplication();
sortByMode = app.getSettings().TRACKS_SORT_BY_MODE.get();
- final Collator collator = Collator.getInstance();
- collator.setStrength(Collator.SECONDARY);
currentRecording = new GpxInfo(app.getSavingTrackHelper().getCurrentGpx(), getString(R.string.shared_string_currently_recording_track));
currentRecording.currentlyRecordingTrack = true;
asyncLoader = new LoadGpxTask();
@@ -475,25 +473,12 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
});
- menu.addSubMenu(Menu.NONE, R.string.shared_string_sort, Menu.NONE, R.string.shared_string_sort);
- final SubMenu sortMenu = menu.findItem(R.string.shared_string_sort).getSubMenu();
- mi = sortMenu.getItem();
+ inflater.inflate(R.menu.track_sort_menu_item, menu);
+ mi = menu.findItem(R.id.action_sort);
mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
- final int iconColorId = isLightActionBar() ? R.color.active_buttons_and_links_text_light
+ int iconColorId = isLightActionBar() ? R.color.active_buttons_and_links_text_light
: R.color.active_buttons_and_links_text_dark;
mi.setIcon(getIcon(sortByMode.getIconId(), iconColorId));
- for (final TracksSortByMode mode : TracksSortByMode.values()) {
- mi = createMenuItem(sortMenu, mode.getNameId(), mode.getNameId(), mode.getIconId(),
- MenuItem.SHOW_AS_ACTION_ALWAYS, false, R.color.icon_color_default_light);
- mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- updateTracksSort(mode);
- sortMenu.setIcon(getIcon(mode.getIconId(), iconColorId));
- return false;
- }
- });
- }
if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
menu = ((FavoritesActivity) getActivity()).getClearToolbar(true).getMenu();
@@ -578,7 +563,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
+ public boolean onOptionsItemSelected(final MenuItem item) {
int itemId = item.getItemId();
for (int i = 0; i < optionsMenuAdapter.length(); i++) {
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i);
@@ -587,6 +572,29 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
return true;
}
}
+ if (itemId == R.id.action_sort) {
+ Activity activity = getActivity();
+ if (activity != null) {
+ View menuSortItemView = getActivity().findViewById(R.id.action_sort);
+ final List items = new ArrayList<>();
+ for (final TracksSortByMode mode : TracksSortByMode.values()) {
+ items.add(new SimplePopUpMenuItem(
+ getString(mode.getNameId()),
+ app.getUIUtilities().getThemedIcon(mode.getIconId()),
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ updateTracksSort(mode);
+ int iconColorId = isLightActionBar() ? R.color.active_buttons_and_links_text_light
+ : R.color.active_buttons_and_links_text_dark;
+ item.setIcon(getIcon(mode.getIconId(), iconColorId));
+ }
+ }, sortByMode == mode
+ ));
+ }
+ UiUtilities.showPopUpMenu(menuSortItemView, items);
+ }
+ }
return super.onOptionsItemSelected(item);
}
@@ -941,26 +949,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
for (GpxInfo v : values) {
allGpxAdapter.addLocalIndexInfo(v);
}
- // disable sort
- // allGpxAdapter.sort();
allGpxAdapter.notifyDataSetChanged();
}
- public void setResult(List result) {
- this.result = result;
- allGpxAdapter.clear();
- if (result != null) {
- for (GpxInfo v : result) {
- allGpxAdapter.addLocalIndexInfo(v);
- }
- // disable sort
- // allGpxAdapter.sort();
- allGpxAdapter.refreshSelected();
- allGpxAdapter.notifyDataSetChanged();
- onPostExecute(result);
- }
- }
-
@Override
protected void onPostExecute(List result) {
this.result = result;
@@ -980,17 +971,18 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
// This file could be sorted in different way for folders
// now folders are also sorted by last modified date
+ final Collator collator = OsmAndCollator.primaryCollator();
Arrays.sort(listFiles, new Comparator() {
@Override
public int compare(File f1, File f2) {
if (sortByMode == TracksSortByMode.BY_NAME_ASCENDING) {
- return f1.getName().compareTo(f2.getName());
+ return collator.compare(f1.getName(), (f2.getName()));
} else if (sortByMode == TracksSortByMode.BY_NAME_DESCENDING) {
- return -f1.getName().compareTo(f2.getName());
+ return -collator.compare(f1.getName(), (f2.getName()));
} else {
// here we could guess date from file name '2017-08-30 ...' - first part date
if (f1.lastModified() == f2.lastModified()) {
- return -f1.getName().compareTo(f2.getName());
+ return -collator.compare(f1.getName(), (f2.getName()));
}
return -((f1.lastModified() < f2.lastModified()) ? -1 : ((f1.lastModified() == f2.lastModified()) ? 0 : 1));
}
@@ -1087,21 +1079,22 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
public void refreshSelected() {
selected.clear();
selected.addAll(getSelectedGpx());
+ final Collator collator = OsmAndCollator.primaryCollator();
Collections.sort(selected, new Comparator() {
@Override
public int compare(GpxInfo i1, GpxInfo i2) {
if (sortByMode == TracksSortByMode.BY_NAME_ASCENDING) {
- return i1.getName().toLowerCase().compareTo(i2.getName().toLowerCase());
+ return collator.compare(i1.getName(), i2.getName());
} else if (sortByMode == TracksSortByMode.BY_NAME_DESCENDING) {
- return -i1.getName().toLowerCase().compareTo(i2.getName().toLowerCase());
+ return -collator.compare(i1.getName(), i2.getName());
} else {
if (i1.file == null || i2.file == null) {
- return i1.getName().toLowerCase().compareTo(i2.getName().toLowerCase());
+ return collator.compare(i1.getName(), i2.getName());
}
long time1 = i1.file.lastModified();
long time2 = i2.file.lastModified();
if (time1 == time2) {
- return i1.getName().toLowerCase().compareTo(i2.getName().toLowerCase());
+ return collator.compare(i1.getName(), i2.getName());
}
return -((time1 < time2) ? -1 : ((time1 == time2) ? 0 : 1));
}
@@ -1166,15 +1159,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
data.get(category.get(found)).add(info);
}
- public void sort() {
- Collections.sort(category, new Comparator() {
- @Override
- public int compare(String lhs, String rhs) {
- return lhs.toLowerCase().compareTo(rhs.toLowerCase());
- }
- });
- }
-
@Override
public GpxInfo getChild(int groupPosition, int childPosition) {
if (isSelectedGroup(groupPosition)) {
@@ -1492,10 +1476,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
- final List items = new ArrayList<>();
+ final List items = new ArrayList<>();
UiUtilities iconsCache = getMyApplication().getUIUtilities();
- items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
+ items.add(new SimplePopUpMenuItem(
getString(R.string.shared_string_show_on_map),
iconsCache.getThemedIcon(R.drawable.ic_show_on_map),
new View.OnClickListener() {
@@ -1509,7 +1493,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
GPXTrackAnalysis analysis;
if ((analysis = getGpxTrackAnalysis(gpxInfo, app, null)) != null) {
if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
- items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
+ items.add(new SimplePopUpMenuItem(
getString(R.string.analyze_on_map),
iconsCache.getThemedIcon(R.drawable.ic_action_info_dark),
new View.OnClickListener() {
@@ -1522,7 +1506,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
}
- items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
+ items.add(new SimplePopUpMenuItem(
getString(R.string.shared_string_move),
iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke),
new View.OnClickListener() {
@@ -1533,7 +1517,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
));
- items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
+ items.add(new SimplePopUpMenuItem(
getString(R.string.shared_string_rename),
iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark),
new View.OnClickListener() {
@@ -1551,7 +1535,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
));
Drawable shareIcon = iconsCache.getThemedIcon((R.drawable.ic_action_gshare_dark));
- items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
+ items.add(new SimplePopUpMenuItem(
getString(R.string.shared_string_share),
AndroidUtils.getDrawableForDirection(app, shareIcon),
new View.OnClickListener() {
@@ -1569,7 +1553,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
- items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
+ items.add(new SimplePopUpMenuItem(
getString(R.string.shared_string_export),
iconsCache.getThemedIcon(R.drawable.ic_action_export),
new View.OnClickListener() {
@@ -1581,7 +1565,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
));
}
- items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
+ items.add(new SimplePopUpMenuItem(
getString(R.string.shared_string_delete),
iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark),
new View.OnClickListener() {
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java
index 004f5c4d2b..407f65295f 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java
@@ -487,7 +487,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
fileName = FileUtils.createUniqueFileName(app, suggestedName, IndexConstants.GPX_INDEX_DIR, GPX_FILE_EXT);
} else {
- fileName = new File(paramsBuilder.getFile().path).getName();
+ fileName = AndroidUtils.trimExtension(new File(paramsBuilder.getFile().path).getName());
}
SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
ChooseRouteFragment.this, null, fileName,
diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
index e41c7d58df..efa7147e6c 100644
--- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
@@ -2214,6 +2214,8 @@ public class OsmandSettings {
}
}.makeProfile().cache();
+ public final OsmandPreference SHOW_START_FINISH_ICONS = new BooleanPreference("show_start_finish_icons", true).makeGlobal().cache();
+
public final OsmandPreference GPX_ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache();
// public final OsmandPreference GPX_CALCULATE_RTEPT = new BooleanPreference("gpx_routing_calculate_rtept", true).makeGlobal().cache();
public final OsmandPreference GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();
diff --git a/OsmAnd/src/net/osmand/plus/track/ShowStartFinishCard.java b/OsmAnd/src/net/osmand/plus/track/ShowStartFinishCard.java
new file mode 100644
index 0000000000..3941bdbb15
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/track/ShowStartFinishCard.java
@@ -0,0 +1,59 @@
+package net.osmand.plus.track;
+
+import android.view.View;
+import android.widget.CompoundButton;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.helpers.AndroidUiHelper;
+import net.osmand.plus.routepreparationmenu.cards.BaseCard;
+import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+
+class ShowStartFinishCard extends BaseCard {
+
+ private TrackDrawInfo trackDrawInfo;
+ private OsmandPreference showStartFinishPreference;
+
+ public ShowStartFinishCard(@NonNull MapActivity mapActivity, @NonNull TrackDrawInfo trackDrawInfo) {
+ super(mapActivity);
+ this.showStartFinishPreference = app.getSettings().SHOW_START_FINISH_ICONS;
+ this.trackDrawInfo = trackDrawInfo;
+ }
+
+ @Override
+ public int getCardLayoutId() {
+ return R.layout.bottom_sheet_item_with_switch;
+ }
+
+ @Override
+ protected void updateContent() {
+ AndroidUiHelper.updateVisibility(view.findViewById(R.id.icon), false);
+
+ TextView titleView = view.findViewById(R.id.title);
+ titleView.setText(R.string.track_show_start_finish_icons);
+
+ final CompoundButton compoundButton = view.findViewById(R.id.compound_button);
+ //compoundButton.setChecked(trackDrawInfo.isShowStartFinish());
+ compoundButton.setChecked(showStartFinishPreference.get());
+
+ view.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ boolean checked = !compoundButton.isChecked();
+ compoundButton.setChecked(checked);
+ //trackDrawInfo.setShowStartFinish(checked);
+ showStartFinishPreference.set(checked);
+ mapActivity.refreshMap();
+
+ CardListener listener = getListener();
+ if (listener != null) {
+ listener.onCardPressed(ShowStartFinishCard.this);
+ }
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java
index 4381dd61f6..81a43da20f 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java
@@ -62,9 +62,10 @@ import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM;
public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener {
public static final String TAG = TrackAppearanceFragment.class.getName();
-
private static final Log log = PlatformUtil.getLog(TrackAppearanceFragment.class);
+ private static final String SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY = "showStartFinishIconsInitialValueKey";
+
private OsmandApplication app;
@Nullable
@@ -79,6 +80,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
private TrackWidthCard trackWidthCard;
private SplitIntervalCard splitIntervalCard;
private TrackColoringCard trackColoringCard;
+ private boolean showStartFinishIconsInitialValue;
private ImageView trackIcon;
private View buttonsShadow;
@@ -134,9 +136,12 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
if (!selectedGpxFile.isShowCurrentTrack()) {
gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath()));
}
+ showStartFinishIconsInitialValue = savedInstanceState.getBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY,
+ app.getSettings().SHOW_START_FINISH_ICONS.get());
} else if (arguments != null) {
String gpxFilePath = arguments.getString(TRACK_FILE_NAME);
boolean currentRecording = arguments.getBoolean(CURRENT_RECORDING, false);
+ showStartFinishIconsInitialValue = app.getSettings().SHOW_START_FINISH_ICONS.get();
if (gpxFilePath == null && !currentRecording) {
log.error("Required extra '" + TRACK_FILE_NAME + "' is missing");
@@ -152,7 +157,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else {
gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFilePath));
- trackDrawInfo = new TrackDrawInfo(gpxDataItem, false);
+ trackDrawInfo = new TrackDrawInfo(app, gpxDataItem, false);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
}
updateTrackColor();
@@ -294,6 +299,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
trackDrawInfo.saveToBundle(outState);
+ outState.putBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY, showStartFinishIconsInitialValue);
}
@Override
@@ -455,6 +461,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
@Override
public void onClick(View v) {
discardSplitChanges();
+ discardShowStartFinishChanges();
FragmentActivity activity = getActivity();
if (activity != null) {
activity.onBackPressed();
@@ -520,7 +527,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval());
gpxFile.setShowArrows(trackDrawInfo.isShowArrows());
- gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish());
+ //gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish());
if (gpxFile.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor());
@@ -551,6 +558,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
}
+ private void discardShowStartFinishChanges() {
+ app.getSettings().SHOW_START_FINISH_ICONS.set(showStartFinishIconsInitialValue);
+ }
+
void applySplit(GpxSplitType splitType, int timeSplit, double distanceSplit) {
if (splitIntervalCard != null) {
splitIntervalCard.updateContent();
@@ -599,6 +610,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
directionArrowsCard.setListener(this);
cardsContainer.addView(directionArrowsCard.build(mapActivity));
+ ShowStartFinishCard showStartFinishCard = new ShowStartFinishCard(mapActivity, trackDrawInfo);
+ showStartFinishCard.setListener(this);
+ cardsContainer.addView(showStartFinishCard.build(mapActivity));
+
trackColoringCard = new TrackColoringCard(mapActivity, trackDrawInfo, this);
trackColoringCard.setListener(this);
cardsContainer.addView(trackColoringCard.build(mapActivity));
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java
index e8ab755507..99571dad6c 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java
@@ -29,6 +29,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType;
import net.osmand.plus.helpers.AndroidUiHelper;
@@ -41,8 +42,6 @@ import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
-import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems;
-
public class TrackColoringCard extends BaseCard implements ColorPickerListener {
private static final int MINIMUM_CONTRAST_RATIO = 3;
@@ -131,7 +130,7 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener {
selectColor.addView(createDividerView(selectColor));
List colors = new ArrayList<>();
- for (AppearanceListItem appearanceListItem : getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) {
+ for (AppearanceListItem appearanceListItem : GpxAppearanceAdapter.getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) {
if (!colors.contains(appearanceListItem.getColor())) {
colors.add(appearanceListItem.getColor());
}
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java
index 3dbacb7b56..18d1c30775 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java
@@ -5,6 +5,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import net.osmand.plus.GPXDatabase.GpxDataItem;
+import net.osmand.plus.OsmandApplication;
import net.osmand.util.Algorithms;
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
@@ -40,7 +41,7 @@ public class TrackDrawInfo {
readBundle(bundle);
}
- public TrackDrawInfo(GpxDataItem gpxDataItem, boolean currentRecording) {
+ public TrackDrawInfo(@NonNull OsmandApplication app, @NonNull GpxDataItem gpxDataItem, boolean currentRecording) {
filePath = gpxDataItem.getFile().getPath();
width = gpxDataItem.getWidth();
gradientScaleType = gpxDataItem.getGradientScaleType();
diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java
index 3bb49859be..641944ce21 100644
--- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java
@@ -453,7 +453,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
if (segment.points.size() >= 2) {
WptPt start = segment.points.get(0);
WptPt end = segment.points.get(segment.points.size() - 1);
- drawStartEndPoints(canvas, tileBox, start, end);
+ drawStartEndPoints(canvas, tileBox, start, selectedGpxFile.isShowCurrentTrack() ? null : end);
}
}
}
@@ -461,24 +461,28 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
}
- private void drawStartEndPoints(Canvas canvas, RotatedTileBox tileBox, WptPt start, WptPt end) {
- int startX = (int) tileBox.getPixXFromLatLon(start.lat, start.lon);
- int startY = (int) tileBox.getPixYFromLatLon(start.lat, start.lon);
- int endX = (int) tileBox.getPixXFromLatLon(end.lat, end.lon);
- int endY = (int) tileBox.getPixYFromLatLon(end.lat, end.lon);
+ private void drawStartEndPoints(@NonNull Canvas canvas, @NonNull RotatedTileBox tileBox, @Nullable WptPt start, @Nullable WptPt end) {
+ int startX = start != null ? (int) tileBox.getPixXFromLatLon(start.lat, start.lon) : 0;
+ int startY = start != null ? (int) tileBox.getPixYFromLatLon(start.lat, start.lon) : 0;
+ int endX = end != null ? (int) tileBox.getPixXFromLatLon(end.lat, end.lon) : 0;
+ int endY = end != null ? (int) tileBox.getPixYFromLatLon(end.lat, end.lon) : 0;
int iconSize = AndroidUtils.dpToPx(view.getContext(), 14);
QuadRect startRectWithoutShadow = calculateRect(startX, startY, iconSize, iconSize);
QuadRect endRectWithoutShadow = calculateRect(endX, endY, iconSize, iconSize);
- if (QuadRect.intersects(startRectWithoutShadow, endRectWithoutShadow)) {
+ if (start != null && end != null && QuadRect.intersects(startRectWithoutShadow, endRectWithoutShadow)) {
QuadRect startAndFinishRect = calculateRect(startX, startY, startAndFinishIcon.getIntrinsicWidth(), startAndFinishIcon.getIntrinsicHeight());
drawPoint(canvas, startAndFinishRect, startAndFinishIcon);
} else {
- QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight());
- QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight());
- drawPoint(canvas, startRect, startPointIcon);
- drawPoint(canvas, endRect, finishPointIcon);
+ if (start != null) {
+ QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight());
+ drawPoint(canvas, startRect, startPointIcon);
+ }
+ if (end != null) {
+ QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight());
+ drawPoint(canvas, endRect, finishPointIcon);
+ }
}
}
@@ -711,6 +715,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
private boolean isShowStartFinishForTrack(GPXFile gpxFile) {
+ return view.getApplication().getSettings().SHOW_START_FINISH_ICONS.get();
+ /*
if (hasTrackDrawInfoForTrack(gpxFile)) {
return trackDrawInfo.isShowStartFinish();
} else if (gpxFile.showCurrentTrack) {
@@ -718,6 +724,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} else {
return gpxFile.isShowStartFinish();
}
+ */
}
private boolean hasTrackDrawInfoForTrack(GPXFile gpxFile) {
diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java
index 76bee7cdf2..24d49df0b1 100644
--- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java
+++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java
@@ -132,7 +132,7 @@ public class GpxGeometryWay extends GeometryWay {
- private static final float DIRECTION_ARROW_CIRCLE_MULTIPLIER = 1.5f;
-
public GpxGeometryWayDrawer(GpxGeometryWayContext context) {
super(context);
}
@@ -33,16 +30,23 @@ public class GpxGeometryWayDrawer extends GeometryWayDrawer arrowsWayStyle.getTrackWidth()) {
- Paint paint = context.getPaintIcon();
- paint.setColor(arrowsWayStyle.getTrackColor());
- paint.setStrokeWidth(arrowWidth * DIRECTION_ARROW_CIRCLE_MULTIPLIER);
- canvas.drawPoint(x, y, paint);
- }
+ float newWidth = arrowsWayStyle.getTrackWidth() / 2f;
+ float paintH2 = bitmap.getHeight() / 2f;
+ float paintW2 = newWidth / 2f;
+
+ Matrix matrix = getMatrix();
+ matrix.reset();
+ matrix.postScale(newWidth / bitmap.getWidth(), 1);
+ matrix.postRotate((float) angle, paintW2, paintH2);
+ matrix.postTranslate(x - paintW2, y - paintH2);
+
+ Paint paint = context.getPaintIconCustom();
+ Integer pointColor = style.getPointColor();
+ paint.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.SRC_IN));
+ canvas.drawBitmap(bitmap, matrix, paint);
}
- super.draw(canvas, context);
}
}
-}
+}
\ No newline at end of file