Merge remote-tracking branch 'origin/r3.8'

This commit is contained in:
Victor Shcherb 2020-09-24 12:47:04 +02:00
commit 5118ddebbe
9 changed files with 122 additions and 85 deletions

View file

@ -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"

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_sort"
android:icon="@drawable/ic_action_time_start"
app:showAsAction="always"
android:title="@string/sort_last_modified" />
</menu>

View file

@ -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;
}

View file

@ -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<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> 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();
}
}

View file

@ -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<SimplePopUpMenuItem> 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<GPXInfo>() {
@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();

View file

@ -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<SimplePopUpMenuItem> 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<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items = new ArrayList<>();
final List<SimplePopUpMenuItem> 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() {

View file

@ -132,7 +132,7 @@ public class GpxGeometryWay extends GeometryWay<GpxGeometryWayContext, GeometryW
@Override
public double getPointStepPx(double zoomCoef) {
return getPointBitmap().getHeight() * DIRECTION_ARROW_DISTANCE_MULTIPLIER * zoomCoef;
return getPointBitmap().getHeight() + trackWidth * 1.5f;
}
}
}

View file

@ -15,6 +15,6 @@ public class GpxGeometryWayContext extends GeometryWayContext {
@Override
protected int getArrowBitmapResId() {
return R.drawable.mm_special_arrow_up;
return R.drawable.ic_action_direction_arrow;
}
}

View file

@ -1,19 +1,16 @@
package net.osmand.plus.views.layers.geometry;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.views.layers.geometry.GeometryWayDrawer.PathPoint;
import net.osmand.plus.views.layers.geometry.GpxGeometryWay.GeometryArrowsStyle;
import java.util.ArrayList;
import java.util.List;
public class GpxGeometryWayDrawer extends GeometryWayDrawer<GpxGeometryWayContext> {
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<GpxGeometryWayContex
void draw(Canvas canvas, GeometryWayContext context) {
if (style instanceof GeometryArrowsStyle) {
GeometryArrowsStyle arrowsWayStyle = (GeometryArrowsStyle) style;
Bitmap bitmap = style.getPointBitmap();
float arrowWidth = style.getPointBitmap().getWidth();
if (arrowWidth > 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);
}
}
}