diff --git a/OsmAnd/res/layout/popup_menu_item.xml b/OsmAnd/res/layout/popup_menu_item.xml
index 66509ffa4d..9e160fcc14 100644
--- a/OsmAnd/res/layout/popup_menu_item.xml
+++ b/OsmAnd/res/layout/popup_menu_item.xml
@@ -22,7 +22,9 @@
android:textColor="?android:textColorPrimary"
android:layout_gravity="center_vertical"
android:paddingLeft="@dimen/content_padding"
+ android:paddingStart="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
+ android:paddingEnd="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size"
diff --git a/OsmAnd/res/menu/track_sort_menu_item.xml b/OsmAnd/res/menu/track_sort_menu_item.xml
new file mode 100644
index 0000000000..8344782092
--- /dev/null
+++ b/OsmAnd/res/menu/track_sort_menu_item.xml
@@ -0,0 +1,9 @@
+
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java b/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java
index 4619e6a3e9..a646b7a416 100644
--- a/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java
@@ -12,6 +12,8 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import net.osmand.AndroidUtils;
+
import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem;
import java.util.List;
@@ -50,6 +52,10 @@ public class SimplePopUpMenuItemAdapter
} else {
ivIcon.setVisibility(View.GONE);
}
+ if (item.selected) {
+ convertView.setBackgroundColor(UiUtilities.getColorWithAlpha(
+ AndroidUtils.getColorFromAttr(getContext(), R.attr.active_color_basic), 0.1f));
+ }
}
return convertView;
}
@@ -64,6 +70,7 @@ public class SimplePopUpMenuItemAdapter
private CharSequence title;
private Drawable icon;
private View.OnClickListener onClickListener;
+ boolean selected;
public SimplePopUpMenuItem(CharSequence title, Drawable icon) {
this.title = title;
@@ -75,6 +82,12 @@ public class SimplePopUpMenuItemAdapter
this.onClickListener = onClickListener;
}
+ public SimplePopUpMenuItem(CharSequence title, Drawable icon, View.OnClickListener onClickListener,
+ boolean selected) {
+ this(title, icon, onClickListener);
+ this.selected = selected;
+ }
+
public CharSequence getTitle() {
return title;
}
diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java
index 5af06d9f23..f818716730 100644
--- a/OsmAnd/src/net/osmand/plus/UiUtilities.java
+++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java
@@ -784,7 +784,7 @@ public class UiUtilities {
titles.add(String.valueOf(item.getTitle()));
hasIcon = hasIcon || item.getIcon() != null;
}
- float itemWidth = AndroidUtils.getTextMaxWidth(defaultListTextSize, titles) + contentPadding;
+ float itemWidth = AndroidUtils.getTextMaxWidth(defaultListTextSize, titles) + contentPadding * 2;
float iconPartWidth = hasIcon ? standardIconSize + contentPaddingHalf : 0;
int totalWidth = (int) (Math.max(itemWidth, minWidth) + iconPartWidth);
@@ -808,4 +808,19 @@ public class UiUtilities {
});
return listPopupWindow;
}
+
+ public static void showPopUpMenu(View v, final List items) {
+ UiUtilities.createListPopupWindow(
+ v.getContext(), v, v.getWidth(), items, new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ if (position < items.size()) {
+ View.OnClickListener listener = items.get(position).getOnClickListener();
+ if (listener != null) {
+ listener.onClick(view);
+ }
+ }
+ }
+ }).show();
+ }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java
index cd84845584..d808f8f5e6 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;
@@ -19,6 +17,7 @@ import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
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 +25,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,6 +34,7 @@ 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;
@@ -73,7 +72,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;
@@ -105,30 +104,29 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
? 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.setImageResource(sortByMode.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;
+ final List items = new ArrayList<>();
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;
- }
- });
+ 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);
+ sortFileList();
+ adapter.notifyDataSetChanged();
+ }
+ }, sortByMode == mode
+ ));
}
- popup.show();
+ UiUtilities.showPopUpMenu(v, items);
}
});
}
@@ -202,25 +200,12 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
}
private void updateDescription(TextView descriptionView) {
- String string = getString(tracksSortBy.getNameId());
+ 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)));
}
- 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);
- }
- return menuItem;
- }
-
private void updateFileList(HorizontalSelectionAdapter folderAdapter) {
sortFileList();
adapter.setShowFolderName(showFoldersName());
@@ -238,9 +223,9 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
Collections.sort(gpxInfoList, new Comparator() {
@Override
public int compare(GPXInfo i1, GPXInfo i2) {
- if (tracksSortBy == TracksSortByMode.BY_NAME_ASCENDING) {
+ if (sortByMode == TracksSortByMode.BY_NAME_ASCENDING) {
return i1.getFileName().toLowerCase().compareTo(i2.getFileName().toLowerCase());
- } else if (tracksSortBy == TracksSortByMode.BY_NAME_DESCENDING) {
+ } else if (sortByMode == TracksSortByMode.BY_NAME_DESCENDING) {
return -i1.getFileName().toLowerCase().compareTo(i2.getFileName().toLowerCase());
} else {
long time1 = i1.getLastModified();
diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java
index ef184307e6..9596bafb89 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;
@@ -70,7 +69,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;
@@ -475,25 +474,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 +564,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 +573,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);
}
@@ -1492,10 +1501,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 +1518,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 +1531,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 +1542,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 +1560,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 +1578,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 +1590,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/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