This commit is contained in:
crimean 2019-07-04 20:06:06 +03:00
commit 474154dadd
18 changed files with 558 additions and 342 deletions

View file

@ -317,6 +317,8 @@ public class GPXUtilities {
public static class Metadata extends GPXExtensions {
public String desc;
public String link;
public String getArticleTitle() {
return getExtensionsToRead().get("article_title");
}
@ -1404,6 +1406,7 @@ public class GPXUtilities {
writeNotNullText(serializer, "name", trackName);
if (file.metadata != null) {
writeNotNullText(serializer, "desc", file.metadata.desc);
writeNotNullTextWithAttribute(serializer, "link", "href", file.metadata.link);
writeExtensions(serializer, file.metadata);
}
serializer.endTag(null, "metadata");
@ -1472,6 +1475,14 @@ public class GPXUtilities {
return path;
}
private static void writeNotNullTextWithAttribute(XmlSerializer serializer, String tag, String attribute, String value) throws IOException {
if (value != null) {
serializer.startTag(null, tag);
serializer.attribute(null, attribute, value);
serializer.endTag(null, tag);
}
}
private static void writeNotNullText(XmlSerializer serializer, String tag, String value) throws IOException {
if (value != null) {
serializer.startTag(null, tag);
@ -1502,11 +1513,7 @@ public class GPXUtilities {
}
writeNotNullText(serializer, "name", p.name);
writeNotNullText(serializer, "desc", p.desc);
if (p.link != null) {
serializer.startTag(null, "link");
serializer.attribute(null, "href", p.link);
serializer.endTag(null, "link");
}
writeNotNullTextWithAttribute(serializer, "link", "href", p.link);
writeNotNullText(serializer, "type", p.category);
if (p.comment != null) {
writeNotNullText(serializer, "cmt", p.comment);
@ -1697,6 +1704,9 @@ public class GPXUtilities {
if (tag.equals("desc")) {
((Metadata) parse).desc = readText(parser, "desc");
}
if (tag.equals("link")) {
((Metadata) parse).link = parser.getAttributeValue("", "href");
}
} else if (parse instanceof Route) {
if (tag.equals("name")) {
((Route) parse).name = readText(parser, "name");

View file

@ -11,7 +11,7 @@ public class TransportStop extends MapObject {
private static final int DELETED_STOP = -1;
private int[] referencesToRoutes = null;
private Amenity amenity;
private TransportStopAggregated transportStopAggregated;
public int distance;
public int x31;
public int y31;
@ -37,11 +37,53 @@ public class TransportStop extends MapObject {
}
public Amenity getAmenity() {
return amenity;
if (transportStopAggregated != null) {
return transportStopAggregated.getAmenity();
}
return null;
}
public void setAmenity(Amenity amenity) {
this.amenity = amenity;
if (transportStopAggregated == null) {
transportStopAggregated = new TransportStopAggregated();
}
transportStopAggregated.setAmenity(amenity);
}
public List<TransportStop> getLocalTransportStops() {
if (transportStopAggregated != null) {
return transportStopAggregated.getLocalTransportStops();
}
return Collections.emptyList();
}
public void addLocalTransportStop(TransportStop stop) {
if (transportStopAggregated == null) {
transportStopAggregated = new TransportStopAggregated();
}
transportStopAggregated.addLocalTransportStop(stop);
}
public List<TransportStop> getNearbyTransportStops() {
if (transportStopAggregated != null) {
return transportStopAggregated.getNearbyTransportStops();
}
return Collections.emptyList();
}
public void addNearbyTransportStop(TransportStop stop) {
if (transportStopAggregated == null) {
transportStopAggregated = new TransportStopAggregated();
}
transportStopAggregated.addNearbyTransportStop(stop);
}
public TransportStopAggregated getTransportStopAggregated() {
return transportStopAggregated;
}
public void setTransportStopAggregated(TransportStopAggregated stopAggregated) {
transportStopAggregated = stopAggregated;
}
@Override

View file

@ -0,0 +1,65 @@
package net.osmand.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TransportStopAggregated {
private Amenity amenity;
private List<TransportStop> localTransportStops;
private List<TransportStop> nearbyTransportStops;
public TransportStopAggregated() {
}
public Amenity getAmenity() {
return amenity;
}
public void setAmenity(Amenity amenity) {
this.amenity = amenity;
}
public List<TransportStop> getLocalTransportStops() {
if (localTransportStops == null) {
return Collections.emptyList();
}
return this.localTransportStops;
}
public void addLocalTransportStop(TransportStop stop) {
if (localTransportStops == null) {
localTransportStops = new ArrayList<>();
}
localTransportStops.add(stop);
}
public void addLocalTransportStops(List<TransportStop> stops) {
if (localTransportStops == null) {
localTransportStops = new ArrayList<>();
}
localTransportStops.addAll(stops);
}
public List<TransportStop> getNearbyTransportStops() {
if (nearbyTransportStops == null) {
return Collections.emptyList();
}
return this.nearbyTransportStops;
}
public void addNearbyTransportStop(TransportStop stop) {
if (nearbyTransportStops == null) {
nearbyTransportStops = new ArrayList<>();
}
nearbyTransportStops.add(stop);
}
public void addNearbyTransportStops(List<TransportStop> stops) {
if (nearbyTransportStops == null) {
nearbyTransportStops = new ArrayList<>();
}
nearbyTransportStops.addAll(stops);
}
}

View file

@ -404,7 +404,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit_profile_configure_map"
android:text="@string/configure_map"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
@ -452,7 +452,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit_profile_configure_screen_title"
android:text="@string/map_widget_config"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
@ -502,7 +502,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit_profile_nav_settings_title"
android:text="@string/routing_settings_2"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>

View file

@ -108,10 +108,11 @@
android:layout_height="match_parent" >
<ImageView
android:id="@+id/selector_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/bg_shadow_list_bottom"/>
android:layout_height="@dimen/abp__shadow_height"
android:src="@drawable/preference_activity_action_bar_shadow"
android:visibility="invisible"/>
<ListView
android:id="@android:id/list"

View file

@ -1465,8 +1465,7 @@
<string name="waypoint_visit_before">Відвідати, перш ніж</string>
<string name="simulate_your_location">Моделювання вашого місця розташування</string>
<string name="drawer">Суцільним списком</string>
<string name="short_location_on_map">Шир %1$s↵
Дов %2$s</string>
<string name="short_location_on_map">Шир %1$s\nДов %2$s</string>
<string name="tips_and_tricks_descr">Запитання та відповіді, останні зміни та інше.</string>
<string name="routing_settings_2">Налаштування навігації</string>
<string name="general_settings_2">Загальні параметри</string>

View file

@ -14,11 +14,8 @@
<string name="app_mode_offroad">Offroad</string>
<string name="edit_profile_setup_title">Setup Profile</string>
<string name="edit_profile_setup_subtitle">Profile keeps its own settings</string>
<string name="edit_profile_configure_map">Configure map</string>
<string name="edit_profile_setup_map_subtitle">Select default map options for profile</string>
<string name="edit_profile_configure_screen_title">Configure screen</string>
<string name="edit_profile_screen_options_subtitle">Select default screen options for profile</string>
<string name="edit_profile_nav_settings_title">Navigation settings</string>
<string name="edit_profile_nav_settings_subtitle">Select default navigation settings for profile</string>
<string name="routing_attr_max_num_changes_description">Specify max number of changes</string>
<string name="routing_attr_max_num_changes_name">Number of changes</string>

View file

@ -46,11 +46,14 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
private static final Log LOG = PlatformUtil.getLog(SettingsBaseActivity.class);
public static final String INTENT_APP_MODE = "INTENT_APP_MODE";
private static final String PREV_MODE_KEY = "previous_mode";
private static final String SELECTED_MODE_KEY = "selected_mode";
protected OsmandSettings settings;
protected final boolean profileSettings;
protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>();
private ApplicationMode previousAppMode;
protected ApplicationMode selectedAppMode;
private Map<String, Preference> screenPreferences = new LinkedHashMap<String, Preference>();
private Map<String, OsmandPreference<Boolean>> booleanPreferences = new LinkedHashMap<String, OsmandPreference<Boolean>>();
@ -333,6 +336,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
if (profileSettings) {
modes.clear();
findViewById(R.id.selector_shadow).setVisibility(View.VISIBLE);
for (ApplicationMode a : ApplicationMode.values(app)) {
if (a != ApplicationMode.DEFAULT) {
modes.add(a);
@ -358,7 +362,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
final List<ProfileDataObject> activeModes = new ArrayList<>();
for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
boolean isSelected = false;
if (previousAppMode != null && previousAppMode == am) {
if (am == selectedAppMode) {
isSelected = true;
}
if (am != ApplicationMode.DEFAULT) {
@ -411,8 +415,8 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
getModeTitleTV().setText(title);
getModeSubTitleTV().setText(getAppModeDescription(mode));
settings.APPLICATION_MODE.set(mode);
previousAppMode = mode;
getModeIconIV().setImageDrawable(app.getUIUtilities().getIcon(mode.getIconRes(),
selectedAppMode = mode;
getModeIconIV().setImageDrawable(getMyApplication().getUIUtilities().getIcon(mode.getIconRes(),
mode.getIconColorInfo().getColor(nightMode)));
getDropDownArrow().setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, !nightMode));
isModeSelected = true;
@ -438,33 +442,28 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
protected void onResume() {
super.onResume();
if (profileSettings) {
previousAppMode = settings.getApplicationMode();
boolean found;
if (previousAppMode == null) {
previousAppMode = settings.getApplicationMode();
}
if (getIntent() != null && getIntent().hasExtra(INTENT_APP_MODE)) {
String modeStr = getIntent().getStringExtra(INTENT_APP_MODE);
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeStr, previousAppMode);
found = setSelectedAppMode(mode);
setSelectedAppMode(mode);
} else {
found = setSelectedAppMode(previousAppMode);
}
if (!found) {
getSpinner().setSelection(0);
setSelectedAppMode(selectedAppMode);
}
} else {
updateAllSettings();
}
}
protected boolean setSelectedAppMode(ApplicationMode am) {
boolean found = false;
protected void setSelectedAppMode(ApplicationMode am) {
for (ApplicationMode a : modes) {
if (am == a) {
if (am != null && am == a) {
updateModeButton(a);
found = true;
break;
}
}
return found;
}
@Override
@ -474,7 +473,36 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
settings.APPLICATION_MODE.set(previousAppMode);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (profileSettings) {
if (previousAppMode != null) {
outState.putString(PREV_MODE_KEY, previousAppMode.getStringKey());
}
if (selectedAppMode != null) {
outState.putString(SELECTED_MODE_KEY, selectedAppMode.getStringKey());
}
}
}
@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
if (state != null) {
if (profileSettings && state.containsKey(SELECTED_MODE_KEY) && state.containsKey(PREV_MODE_KEY)) {
for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
if (am.getStringKey() == state.get(SELECTED_MODE_KEY)) {
setSelectedAppMode(am);
}
if (am.getStringKey() == state.get(PREV_MODE_KEY)) {
previousAppMode = am;
}
}
}
}
}
public void updateAllSettings() {
for (OsmandPreference<Boolean> b : booleanPreferences.values()) {

View file

@ -85,6 +85,16 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
createUI();
}
@Override
protected void onResume() {
super.onResume();
if(getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
setSelectedAppMode(settings.getApplicationMode());
} else if (selectedAppMode == null) {
selectAppModeDialog().show();
}
}
private void createUI() {
addPreferencesFromResource(R.xml.navigation_settings);
PreferenceScreen screen = getPreferenceScreen();
@ -181,11 +191,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
// registerListPreference(settings.DELAY_TO_START_NAVIGATION, screen, delayIntervalNames, delayIntervals);
if(getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
setSelectedAppMode(settings.getApplicationMode());
} else {
selectAppModeDialog().show();
}
addVoicePrefs((PreferenceGroup) screen.findPreference("voice"));
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.activities.actions;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.LayoutRes;
@ -8,11 +9,14 @@ import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -21,9 +25,12 @@ import net.osmand.plus.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
public class AppModeDialog {
private static final Log LOG = PlatformUtil.getLog(AppModeDialog.class);
public static View prepareAppModeView(Activity a, final Set<ApplicationMode> selected, boolean showDefault,
ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener) {
OsmandApplication app = (OsmandApplication) a.getApplication();
@ -58,7 +65,7 @@ public class AppModeDialog {
public static View prepareAppModeView(Activity a, final List<ApplicationMode> values, final Set<ApplicationMode> selected,
ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener, boolean nightMode) {
View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
final View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
if (useListBg) {
AndroidUtils.setListItemBackground(a, ll, nightMode);
} else {
@ -73,6 +80,23 @@ public class AppModeDialog {
updateButtonState((OsmandApplication) a.getApplication(), values, selected, onClickListener, buttons, i,
singleSelection, useMapTheme, nightMode);
}
ApplicationMode activeMode = ((OsmandApplication) a.getApplication()).getSettings().getApplicationMode();
final int idx = values.indexOf(activeMode);
OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
HorizontalScrollView scrollView = ll.findViewById(R.id.app_modes_scroll_container);
LinearLayout container = ll.findViewById(R.id.app_modes_content);
int s = container.getChildAt(idx) != null ? container.getChildAt(idx).getRight() : 0;
scrollView.scrollTo(s - scrollView.getWidth() > 0 ? s - scrollView.getWidth() : 0, 0);
ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
};
ll.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
return ll;
}
@ -84,11 +108,13 @@ public class AppModeDialog {
View tb = buttons[i];
final ApplicationMode mode = visible.get(i);
final boolean checked = selected.contains(mode);
final View selection = tb.findViewById(R.id.selection);
ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon);
if (checked) {
iv.setImageDrawable(ctx.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode)));
iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_checked)));
tb.findViewById(R.id.selection).setVisibility(View.VISIBLE);
selection.setBackgroundResource(mode.getIconColorInfo().getColor(nightMode));
selection.setVisibility(View.VISIBLE);
} else {
if (useMapTheme) {
iv.setImageDrawable(ctx.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode)));
@ -97,7 +123,7 @@ public class AppModeDialog {
iv.setImageDrawable(ctx.getUIUtilities().getThemedIcon(mode.getIconRes()));
}
iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_unchecked)));
tb.findViewById(R.id.selection).setVisibility(View.INVISIBLE);
selection.setVisibility(View.INVISIBLE);
}
iv.setOnClickListener(new View.OnClickListener() {

View file

@ -4,7 +4,6 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
@ -39,12 +38,12 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
@ -53,8 +52,8 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms;
@ -67,8 +66,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.*;
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
public class MenuBuilder {
@ -91,7 +89,6 @@ public class MenuBuilder {
private boolean showOnlinePhotos = true;
protected List<Amenity> nearestWiki = new ArrayList<>();
private List<OsmandPlugin> menuPlugins = new ArrayList<>();
private List<TransportStopRoute> routes = new ArrayList<>();
@Nullable
private CardsRowBuilder onlinePhotoCardsRow;
private List<AbstractCard> onlinePhotoCards;
@ -235,10 +232,6 @@ public class MenuBuilder {
this.collapseExpandListener = collapseExpandListener;
}
public void setRoutes(List<TransportStopRoute> routes) {
this.routes = routes;
}
public String getPreferredMapLang() {
return preferredMapLang;
}
@ -324,7 +317,7 @@ public class MenuBuilder {
}
private boolean showTransportRoutes() {
return routes.size() > 0;
return showLocalTransportRoutes() || showNearbyTransportRoutes();
}
private boolean showLocalTransportRoutes() {
@ -460,17 +453,15 @@ public class MenuBuilder {
}
protected void buildTopInternal(View view) {
if (showTransportRoutes()) {
if (showLocalTransportRoutes()) {
buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false),
false, 0, false, null, true);
}
if (showNearbyTransportRoutes()) {
CollapsableView collapsableView = getCollapsableTransportStopRoutesView(view.getContext(), false, true);
String routesWithingDistance = app.getString(R.string.transport_nearby_routes_within) + " " + OsmAndFormatter.getFormattedDistance(TransportStopController.SHOW_STOPS_RADIUS_METERS, app);
buildRow(view, 0, null, routesWithingDistance, 0, true, collapsableView,
false, 0, false, null, true);
}
if (showLocalTransportRoutes()) {
buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false),
false, 0, false, null, true);
}
if (showNearbyTransportRoutes()) {
CollapsableView collapsableView = getCollapsableTransportStopRoutesView(view.getContext(), false, true);
String routesWithingDistance = app.getString(R.string.transport_nearby_routes_within) + " " + OsmAndFormatter.getFormattedDistance(TransportStopController.SHOW_STOPS_RADIUS_METERS, app);
buildRow(view, 0, null, routesWithingDistance, 0, true, collapsableView,
false, 0, false, null, true);
}
}

View file

@ -7,45 +7,32 @@ import android.text.TextUtils;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiFilter;
import net.osmand.osm.PoiType;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.resources.TransportIndexRepository;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.transport.TransportStopType;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import net.osmand.util.OpeningHoursParser;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import gnu.trove.list.array.TLongArrayList;
import gnu.trove.map.hash.TLongObjectHashMap;
public class AmenityMenuController extends MenuController {
private Amenity amenity;
private List<TransportStopRoute> routes = new ArrayList<>();
private MapMarker marker;
private TransportStopController transportStopController;
public AmenityMenuController(@NonNull MapActivity mapActivity,
@NonNull PointDescription pointDescription,
@NonNull final Amenity amenity) {
@ -63,7 +50,11 @@ public class AmenityMenuController extends MenuController {
}
}
if (showTransportStops) {
processTransportStop();
TransportStop transportStop = TransportStopController.findBestTransportStopForAmenity(mapActivity.getMyApplication(), amenity);
if (transportStop != null) {
transportStopController = new TransportStopController(mapActivity, pointDescription, transportStop);
transportStopController.processRoutes();
}
}
}
@ -213,23 +204,16 @@ public class AmenityMenuController extends MenuController {
@Override
public List<TransportStopRoute> getTransportStopRoutes() {
return routes;
if (transportStopController != null) {
return transportStopController.getTransportStopRoutes();
}
return null;
}
@Override
protected List<TransportStopRoute> getSubTransportStopRoutes(boolean nearby) {
List<TransportStopRoute> allRoutes = getTransportStopRoutes();
if (allRoutes != null) {
List<TransportStopRoute> res = new ArrayList<>();
for (TransportStopRoute route : allRoutes) {
boolean isCurrentRouteLocal = route.refStop != null && route.refStop.getName().equals(route.stop.getName());
if (!nearby && isCurrentRouteLocal) {
res.add(route);
} else if (nearby && route.refStop == null) {
res.add(route);
}
}
return res;
if (transportStopController != null) {
return transportStopController.getSubTransportStopRoutes(nearby);
}
return null;
}
@ -264,77 +248,4 @@ public class AmenityMenuController extends MenuController {
}
return null;
}
private void processTransportStop() {
routes = new ArrayList<>();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
List<TransportIndexRepository> reps = app
.getResourceManager().searchTransportRepositories(amenity.getLocation().getLatitude(),
amenity.getLocation().getLongitude());
boolean useEnglishNames = app.getSettings().usingEnglishNames();
boolean isSubwayEntrance = amenity.getSubType().equals("subway_entrance");
TLongArrayList addedTransportStops = new TLongArrayList();
for (TransportIndexRepository t : reps) {
ArrayList<TransportStop> ls = new ArrayList<>();
QuadRect ll = MapUtils.calculateLatLonBbox(amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(),
isSubwayEntrance ? 400 : 150);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
for (TransportStop tstop : ls) {
if (!addedTransportStops.contains(tstop.getId())) {
addedTransportStops.add(tstop.getId());
if (!tstop.isDeleted()) {
addRoutes(useEnglishNames, t, tstop,
(int) MapUtils.getDistance(tstop.getLocation(), amenity.getLocation()), isSubwayEntrance);
}
}
}
}
Collections.sort(routes, new Comparator<TransportStopRoute>() {
@Override
public int compare(TransportStopRoute o1, TransportStopRoute o2) {
// int radEqual = 50;
// int dist1 = o1.distance / radEqual;
// int dist2 = o2.distance / radEqual;
// if (dist1 != dist2) {
// return Algorithms.compare(dist1, dist2);
// }
int i1 = Algorithms.extractFirstIntegerNumber(o1.route.getRef());
int i2 = Algorithms.extractFirstIntegerNumber(o2.route.getRef());
if (i1 != i2) {
return Algorithms.compare(i1, i2);
}
return o1.desc.compareTo(o2.desc);
}
});
builder.setRoutes(routes);
}
}
private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, int dist, boolean isSubwayEntrance) {
Collection<TransportRoute> rts = t.getRouteForStop(s);
if (rts != null) {
for (TransportRoute rs : rts) {
TransportStopType type = TransportStopType.findType(rs.getType());
if (isSubwayEntrance && type != TransportStopType.SUBWAY && dist > 150) {
continue;
}
TransportStopRoute r = new TransportStopRoute();
r.type = type;
r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs;
r.stop = s;
if (amenity.getLocation().equals(s.getLocation()) || (isSubwayEntrance && type == TransportStopType.SUBWAY)) {
r.refStop = s;
}
r.distance = dist;
this.routes.add(r);
}
}
}
}
}

View file

@ -21,14 +21,13 @@ import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.util.OpeningHoursParser;
import java.util.ArrayList;
import java.util.List;
public class FavouritePointMenuController extends MenuController {
private FavouritePoint fav;
private MapMarker mapMarker;
private List<TransportStopRoute> routes = new ArrayList<>();
private TransportStopController transportStopController;
public FavouritePointMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, final @NonNull FavouritePoint fav) {
@ -49,8 +48,7 @@ public class FavouritePointMenuController extends MenuController {
if (getObject() instanceof TransportStop) {
TransportStop stop = (TransportStop) getObject();
transportStopController = new TransportStopController(mapActivity, pointDescription, stop);
routes = transportStopController.processTransportStop();
builder.setRoutes(routes);
transportStopController.processRoutes();
}
Object originObject = getBuilder().getOriginObject();
@ -73,7 +71,10 @@ public class FavouritePointMenuController extends MenuController {
@Override
public List<TransportStopRoute> getTransportStopRoutes() {
return routes;
if (transportStopController != null) {
return transportStopController.getTransportStopRoutes();
}
return null;
}
@Override

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
@ -8,6 +9,9 @@ import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.data.TransportStopAggregated;
import net.osmand.data.TransportStopExit;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuController;
@ -29,9 +33,11 @@ import gnu.trove.list.array.TLongArrayList;
public class TransportStopController extends MenuController {
public static final int SHOW_STOPS_RADIUS_METERS = 150;
public static final int SHOW_SUBWAY_STOPS_FROM_ENTRANCES_RADIUS_METERS = 400;
private TransportStop transportStop;
private List<TransportStopRoute> routes = new ArrayList<>();
private List<TransportStopRoute> routesNearby = new ArrayList<>();
private List<TransportStopRoute> routesOnTheSameExit = new ArrayList<>();
private TransportStopType topType;
public TransportStopController(@NonNull MapActivity mapActivity,
@ -50,9 +56,10 @@ public class TransportStopController extends MenuController {
}
}
private void processRoutes() {
routes = processTransportStop();
builder.setRoutes(routes);
public void processRoutes() {
routesOnTheSameExit.clear();
routesNearby.clear();
processTransportStop(routesOnTheSameExit, routesNearby);
}
@Override
@ -71,23 +78,14 @@ public class TransportStopController extends MenuController {
@Override
public List<TransportStopRoute> getTransportStopRoutes() {
List<TransportStopRoute> routes = new ArrayList<>(routesOnTheSameExit);
routes.addAll(routesNearby);
return routes;
}
@Override
protected List<TransportStopRoute> getSubTransportStopRoutes(boolean nearby) {
List<TransportStopRoute> allRoutes = getTransportStopRoutes();
if (allRoutes != null) {
List<TransportStopRoute> res = new ArrayList<>();
for (TransportStopRoute route : allRoutes) {
boolean isCurrentRouteNearby = route.stop != null && !route.stop.equals(transportStop);
if ((nearby && isCurrentRouteNearby) || (!nearby && !isCurrentRouteNearby)) {
res.add(route);
}
}
return res;
}
return null;
return nearby ? routesNearby : routesOnTheSameExit;
}
@Override
@ -112,8 +110,17 @@ public class TransportStopController extends MenuController {
return getPointDescription().getTypeName();
}
public List<TransportStopRoute> processTransportStop() {
ArrayList<TransportStopRoute> routes = new ArrayList<>();
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
Amenity amenity = transportStop.getAmenity();
if (amenity != null) {
AmenityMenuController.addTypeMenuItem(amenity, builder);
} else {
super.addPlainMenuItems(typeStr, pointDescription, latLon);
}
}
private void processTransportStop(List<TransportStopRoute> routesOnTheSameExit, List<TransportStopRoute> routesNearby) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
List<TransportIndexRepository> reps = mapActivity.getMyApplication()
@ -122,53 +129,57 @@ public class TransportStopController extends MenuController {
boolean useEnglishNames = mapActivity.getMyApplication().getSettings().usingEnglishNames();
TLongArrayList addedTransportStops = new TLongArrayList();
for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) {
boolean empty = transportStop.getReferencesToRoutes() == null || transportStop.getReferencesToRoutes().length == 0;
if (!empty) {
addRoutes(routes, useEnglishNames, t, transportStop, transportStop, 0);
}
ArrayList<TransportStop> ls = new ArrayList<>();
QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), SHOW_STOPS_RADIUS_METERS);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
for (TransportStop tstop : ls) {
if (!addedTransportStops.contains(tstop.getId())) {
addedTransportStops.add(tstop.getId());
if (!tstop.isDeleted() && (tstop.getId().longValue() != transportStop.getId().longValue() || empty)) {
addRoutes(routes, useEnglishNames, t, tstop, transportStop,
(int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
}
}
}
ArrayList<TransportStop> transportStopsSameExit = new ArrayList<TransportStop>(transportStop.getLocalTransportStops());
ArrayList<TransportStop> nearbyTransportStops = new ArrayList<TransportStop>(transportStop.getNearbyTransportStops());
addTransportStopRoutes(transportStopsSameExit, routesOnTheSameExit, useEnglishNames, t);
addTransportStopRoutes(nearbyTransportStops, routesNearby, useEnglishNames, t);
}
}
Collections.sort(routes, new Comparator<TransportStopRoute>() {
sortTransportStopRoutes(routesOnTheSameExit);
sortTransportStopRoutes(routesNearby);
}
}
@Override
public int compare(TransportStopRoute o1, TransportStopRoute o2) {
private void sortTransportStopRoutes(List<TransportStopRoute> routes) {
Collections.sort(routes, new Comparator<TransportStopRoute>() {
@Override
public int compare(TransportStopRoute o1, TransportStopRoute o2) {
// int radEqual = 50;
// int dist1 = o1.distance / radEqual;
// int dist2 = o2.distance / radEqual;
// if (dist1 != dist2) {
// return Algorithms.compare(dist1, dist2);
// }
int i1 = Algorithms.extractFirstIntegerNumber(o1.route.getRef());
int i2 = Algorithms.extractFirstIntegerNumber(o2.route.getRef());
if (i1 != i2) {
return Algorithms.compare(i1, i2);
}
return o1.desc.compareTo(o2.desc);
int i1 = Algorithms.extractFirstIntegerNumber(o1.route.getRef());
int i2 = Algorithms.extractFirstIntegerNumber(o2.route.getRef());
if (i1 != i2) {
return Algorithms.compare(i1, i2);
}
});
return o1.desc.compareTo(o2.desc);
}
});
}
private void addTransportStopRoutes(List<TransportStop> stops, List<TransportStopRoute> routes, boolean useEnglishNames, TransportIndexRepository t) {
for (TransportStop tstop : stops) {
if (!tstop.isDeleted()) {
addRoutes(routes, useEnglishNames, t, tstop, transportStop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
}
}
return routes;
}
private void addRoutes(List<TransportStopRoute> routes, boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
Collection<TransportRoute> rts = t.getRouteForStop(s);
if (rts != null) {
for (TransportRoute rs : rts) {
boolean routeAlreadyAdded = checkSameRoute(routes, rs);
if (routeAlreadyAdded) {
continue;
}
TransportStopType type = TransportStopType.findType(rs.getType());
if (topType == null && type != null && type.isTopType()) {
topType = type;
@ -185,13 +196,112 @@ public class TransportStopController extends MenuController {
}
}
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
Amenity amenity = transportStop.getAmenity();
if (amenity != null) {
AmenityMenuController.addTypeMenuItem(amenity, builder);
} else {
super.addPlainMenuItems(typeStr, pointDescription, latLon);
public static void sortTransportStops(@NonNull LatLon latLon, List<TransportStop> transportStops) {
for (TransportStop transportStop : transportStops) {
transportStop.distance = (int) MapUtils.getDistance(latLon, transportStop.getLocation());
}
Collections.sort(transportStops, new Comparator<TransportStop>() {
@Override
public int compare(TransportStop s1, TransportStop s2) {
return Algorithms.compare(s1.distance, s2.distance);
}
});
}
}
@NonNull
public static List<TransportStop> findTransportStopsAt(OsmandApplication app, double latitude, double longitude, int radiusMeters) {
ArrayList<TransportStop> transportStops = new ArrayList<>();
List<TransportIndexRepository> reps = app.getResourceManager().searchTransportRepositories(latitude, longitude);
TLongArrayList addedTransportStops = new TLongArrayList();
for (TransportIndexRepository t : reps) {
ArrayList<TransportStop> stops = new ArrayList<>();
QuadRect ll = MapUtils.calculateLatLonBbox(latitude, longitude, radiusMeters);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, stops, null);
for (TransportStop transportStop : stops) {
if (!addedTransportStops.contains(transportStop.getId())) {
addedTransportStops.add(transportStop.getId());
if (!transportStop.isDeleted()) {
transportStops.add(transportStop);
}
}
}
}
return transportStops;
}
@Nullable
public static TransportStop findBestTransportStopForAmenity(OsmandApplication app, Amenity amenity) {
TransportStopAggregated stopAggregated;
boolean isSubwayEntrance = amenity.getSubType().equals("subway_entrance");
LatLon loc = amenity.getLocation();
int radiusMeters = isSubwayEntrance ? SHOW_SUBWAY_STOPS_FROM_ENTRANCES_RADIUS_METERS : SHOW_STOPS_RADIUS_METERS;
List<TransportStop> transportStops = findTransportStopsAt(app, loc.getLatitude(), loc.getLongitude(), radiusMeters);
sortTransportStops(loc, transportStops);
if (isSubwayEntrance) {
stopAggregated = processTransportStopsForAmenity(transportStops, amenity);
} else {
stopAggregated = new TransportStopAggregated();
stopAggregated.setAmenity(amenity);
TransportStop nearestStop = null;
for (TransportStop stop : transportStops) {
stop.setTransportStopAggregated(stopAggregated);
if ((stop.getName().startsWith(amenity.getName())
&& (nearestStop == null
|| nearestStop.getLocation().equals(stop.getLocation())))
|| stop.getLocation().equals(loc)) {
stopAggregated.addLocalTransportStop(stop);
if (nearestStop == null) {
nearestStop = stop;
}
} else {
stopAggregated.addNearbyTransportStop(stop);
}
}
}
List<TransportStop> localStops = stopAggregated.getLocalTransportStops();
List<TransportStop> nearbyStops = stopAggregated.getNearbyTransportStops();
if (!localStops.isEmpty()) {
return localStops.get(0);
} else if (!nearbyStops.isEmpty()) {
return nearbyStops.get(0);
}
return null;
}
public static TransportStopAggregated processTransportStopsForAmenity(List<TransportStop> transportStops, Amenity amenity) {
TransportStopAggregated stopAggregated = new TransportStopAggregated();
stopAggregated.setAmenity(amenity);
for (TransportStop stop : transportStops) {
stop.setTransportStopAggregated(stopAggregated);
List<TransportStopExit> stopExits = stop.getExits();
boolean stopOnSameExitAdded = false;
for (TransportStopExit exit : stopExits) {
if (exit.getLocation().equals(amenity.getLocation())) {
stopOnSameExitAdded = true;
stopAggregated.addLocalTransportStop(stop);
break;
}
}
if (!stopOnSameExitAdded && MapUtils.getDistance(stop.getLocation(), amenity.getLocation()) <= SHOW_STOPS_RADIUS_METERS) {
stopAggregated.addNearbyTransportStop(stop);
}
}
return stopAggregated;
}
public static boolean checkSameRoute(List<TransportStopRoute> stopRoutes, TransportRoute route) {
for (TransportStopRoute stopRoute : stopRoutes) {
if (stopRoute.route.compareRoute(route)) {
return true;
}
}
return false;
}
}

View file

@ -32,15 +32,15 @@ import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.PicassoUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
@ -64,6 +64,7 @@ import net.osmand.render.RenderingRulesStorage;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import gnu.trove.list.array.TIntArrayList;
@ -459,13 +460,60 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
return createTravelArticleCard(context, article);
}
if (!TextUtils.isEmpty(gpx.metadata.desc)) {
return createDescriptionCard(context, gpx.metadata.desc);
final String description = getMetadataDescription(gpx.metadata);
if (!TextUtils.isEmpty(description)) {
String link = getMetadataImageLink(gpx.metadata);
if (!TextUtils.isEmpty(link)) {
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
openGpxDescriptionDialog(description);
}
};
return createArticleCard(context, null, description, null, link, onClickListener);
} else {
return createDescriptionCard(context, description);
}
}
return null;
}
@Nullable
private String getMetadataDescription(@NonNull GPXUtilities.Metadata metadata) {
String descHtml = metadata.desc;
if (TextUtils.isEmpty(descHtml)) {
Map<String, String> extensions = metadata.getExtensionsToRead();
if (!extensions.isEmpty() && extensions.containsKey("desc")) {
descHtml = extensions.get("desc");
}
}
if (descHtml != null) {
String content = WikiArticleHelper.getPartialContent(descHtml);
if (!TextUtils.isEmpty(content)) {
return content;
}
}
return descHtml;
}
@Nullable
private String getMetadataImageLink(@NonNull GPXUtilities.Metadata metadata) {
String link = metadata.link;
if (!TextUtils.isEmpty(link)) {
String lowerCaseLink = link.toLowerCase();
if (lowerCaseLink.contains(".jpg")
|| lowerCaseLink.contains(".jpeg")
|| lowerCaseLink.contains(".png")
|| lowerCaseLink.contains(".bmp")
|| lowerCaseLink.contains(".webp")) {
return link;
}
}
return null;
}
@Nullable
private TravelArticle getTravelArticle(@NonNull GPXUtilities.Metadata metadata) {
String title = metadata.getArticleTitle();
@ -482,34 +530,11 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
}
private View createTravelArticleCard(final Context context, @NonNull final TravelArticle article) {
View card = LayoutInflater.from(context).inflate(R.layout.wikivoyage_article_card, null);
card.findViewById(R.id.background_view).setBackgroundColor(ContextCompat.getColor(context,
app.getSettings().isLightContent() ? R.color.list_background_color_light : R.color.list_background_color_dark));
((TextView) card.findViewById(R.id.title)).setText(article.getTitle());
((TextView) card.findViewById(R.id.content)).setText(WikiArticleHelper.getPartialContent(article.getContent()));
((TextView) card.findViewById(R.id.part_of)).setText(article.getGeoDescription());
final ImageView icon = (ImageView) card.findViewById(R.id.icon);
final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
final PicassoUtils picassoUtils = PicassoUtils.getPicasso(app);
RequestCreator rc = Picasso.get().load(url);
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.transform(new CropCircleTransformation())
.into(icon, new Callback() {
@Override
public void onSuccess() {
icon.setVisibility(View.VISIBLE);
picassoUtils.setResultLoaded(url, true);
}
@Override
public void onError(Exception e) {
picassoUtils.setResultLoaded(url, false);
}
});
TextView readBtn = (TextView) card.findViewById(R.id.left_button);
readBtn.setText(app.getString(R.string.shared_string_read));
readBtn.setCompoundDrawablesWithIntrinsicBounds(getReadIcon(), null, null, null);
readBtn.setOnClickListener(new View.OnClickListener() {
String title = article.getTitle();
String content = WikiArticleHelper.getPartialContent(article.getContent());
String geoDescription = article.getGeoDescription();
String imageUrl = TravelArticle.getImageUrl(article.getImageTitle(), false);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
@ -518,7 +543,44 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
activity.getSupportFragmentManager(), article.getTripId(), article.getLang());
}
}
});
};
return createArticleCard(context, title, content, geoDescription, imageUrl, onClickListener);
}
private View createArticleCard(final Context context, String title, String content, String geoDescription, final String imageUrl, View.OnClickListener readBtnClickListener) {
View card = LayoutInflater.from(context).inflate(R.layout.wikivoyage_article_card, null);
card.findViewById(R.id.background_view).setBackgroundColor(ContextCompat.getColor(context,
app.getSettings().isLightContent() ? R.color.list_background_color_light : R.color.list_background_color_dark));
if (!TextUtils.isEmpty(title)) {
((TextView) card.findViewById(R.id.title)).setText(title);
} else {
card.findViewById(R.id.title).setVisibility(View.GONE);
}
((TextView) card.findViewById(R.id.content)).setText(content);
((TextView) card.findViewById(R.id.part_of)).setText(geoDescription);
final ImageView icon = (ImageView) card.findViewById(R.id.icon);
final PicassoUtils picassoUtils = PicassoUtils.getPicasso(app);
RequestCreator rc = Picasso.get().load(imageUrl);
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.transform(new CropCircleTransformation())
.into(icon, new Callback() {
@Override
public void onSuccess() {
icon.setVisibility(View.VISIBLE);
picassoUtils.setResultLoaded(imageUrl, true);
}
@Override
public void onError(Exception e) {
picassoUtils.setResultLoaded(imageUrl, false);
}
});
TextView readBtn = (TextView) card.findViewById(R.id.left_button);
readBtn.setText(app.getString(R.string.shared_string_read));
readBtn.setCompoundDrawablesWithIntrinsicBounds(getReadIcon(), null, null, null);
readBtn.setOnClickListener(readBtnClickListener);
card.findViewById(R.id.right_button).setVisibility(View.GONE);
card.findViewById(R.id.divider).setVisibility(View.GONE);
card.findViewById(R.id.list_item_divider).setVisibility(View.VISIBLE);
@ -537,14 +599,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
readBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null) {
Bundle args = new Bundle();
args.putString(GpxDescriptionDialogFragment.CONTENT_KEY, descHtml);
GpxDescriptionDialogFragment fragment = new GpxDescriptionDialogFragment();
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), GpxDescriptionDialogFragment.TAG);
}
openGpxDescriptionDialog(descHtml);
}
});
return card;
@ -552,6 +607,17 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
return null;
}
private void openGpxDescriptionDialog(@NonNull final String descHtml) {
TrackActivity activity = getTrackActivity();
if (activity != null) {
Bundle args = new Bundle();
args.putString(GpxDescriptionDialogFragment.CONTENT_KEY, descHtml);
GpxDescriptionDialogFragment fragment = new GpxDescriptionDialogFragment();
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), GpxDescriptionDialogFragment.TAG);
}
}
public boolean isGpxFileSelected(GPXFile gpxFile) {
return gpxFile != null &&
((gpxFile.showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) ||

View file

@ -1113,9 +1113,11 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
private TrkSegment getTrkSegment() {
for (Track t : gpxItem.group.getGpx().tracks) {
for (TrkSegment s : t.segments) {
if (s.points.size() > 0 && s.points.get(0).equals(gpxItem.analysis.locationStart)) {
return s;
if (!t.generalTrack) {
for (TrkSegment s : t.segments) {
if (s.points.size() > 0 && s.points.get(0).equals(gpxItem.analysis.locationStart)) {
return s;
}
}
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.routepreparationmenu;
import android.content.Context;
import android.content.DialogInterface.OnDismissListener;
import android.content.res.Configuration;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Build;
@ -21,6 +22,7 @@ import android.support.v7.widget.AppCompatImageView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
@ -30,6 +32,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder;
import net.osmand.binary.RouteDataObject;
@ -103,9 +106,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.commons.logging.Log;
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener {
private static final Log LOG = PlatformUtil.getLog(MapRouteInfoMenu.class);
private static final int BUTTON_ANIMATION_DELAY = 2000;
public static final int DEFAULT_MENU_STATE = 0;
private static final int MAX_PEDESTRIAN_ROUTE_DURATION = 30 * 60;
@ -804,15 +810,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
updateApplicationMode(am, next);
}
View ll = mapActivity.getLayoutInflater().inflate(R.layout.mode_toggles, vg);
final View ll = mapActivity.getLayoutInflater().inflate(R.layout.mode_toggles, vg);
ll.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.card_and_list_background_dark : R.color.card_and_list_background_light));
HorizontalScrollView scrollView = ll.findViewById(R.id.app_modes_scroll_container);
final HorizontalScrollView scrollView = ll.findViewById(R.id.app_modes_scroll_container);
scrollView.setVerticalScrollBarEnabled(false);
scrollView.setHorizontalScrollBarEnabled(false);
int leftTogglePadding = AndroidUtils.dpToPx(mapActivity, 8f);
int rightTogglePadding = mapActivity.getResources().getDimensionPixelSize(R.dimen.content_padding);
final int rightTogglePadding = mapActivity.getResources().getDimensionPixelSize(R.dimen.content_padding);
final View[] buttons = new View[values.size()];
int k = 0;
Iterator<ApplicationMode> iterator = values.iterator();
@ -837,6 +843,21 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
for (int i = 0; i < buttons.length; i++) {
AppModeDialog.updateButtonStateForRoute((OsmandApplication) mapActivity.getApplication(), values, selected, listener, buttons, i, true, true, nightMode);
}
final ApplicationMode activeMode = app.getSettings().getApplicationMode();
final int idx = values.indexOf(activeMode);
OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LinearLayout container = ll.findViewById(R.id.app_modes_content);
int s = container.getChildAt(idx) != null ? container.getChildAt(idx).getRight() + rightTogglePadding : 0;
scrollView.scrollTo(s - scrollView.getWidth() > 0 ? s - scrollView.getWidth() : 0, 0);
ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
};
ll.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
}
private void updateOptionsButtons() {

View file

@ -43,7 +43,6 @@ import net.osmand.core.jni.Utilities;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop;
import net.osmand.osm.PoiCategory;
@ -56,10 +55,10 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.resources.TransportIndexRepository;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.corenative.NativeCoreContext;
@ -67,8 +66,6 @@ import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -76,10 +73,8 @@ import java.util.Map.Entry;
import java.util.Set;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.list.array.TLongArrayList;
import static net.osmand.plus.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CHANGE_MARKER_POSITION;
import static net.osmand.plus.mapcontextmenu.controllers.TransportStopController.SHOW_STOPS_RADIUS_METERS;
public class ContextMenuLayer extends OsmandMapLayer {
//private static final Log LOG = PlatformUtil.getLog(ContextMenuLayer.class);
@ -864,31 +859,12 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
}
if (transportStopAmenities.size() > 0) {
List<TransportStop> transportStops = findTransportStopsAt(latLon.getLatitude(), latLon.getLongitude());
List<TransportStop> transportStopsReplacement = new ArrayList<>();
for (Amenity amenity : transportStopAmenities) {
List<TransportStop> amenityTransportStops = new ArrayList<>();
for (TransportStop transportStop : transportStops) {
if (transportStop.getName().startsWith(amenity.getName())) {
amenityTransportStops.add(transportStop);
transportStop.setAmenity(amenity);
}
}
if (amenityTransportStops.size() > 0) {
selectedObjects.remove(amenity);
if (amenityTransportStops.size() > 1) {
sortTransportStops(amenity.getLocation(), amenityTransportStops);
}
TransportStop amenityTransportStop = amenityTransportStops.get(0);
if (!transportStopsReplacement.contains(amenityTransportStop)) {
transportStopsReplacement.add(amenityTransportStop);
}
}
}
if (transportStopsReplacement.size() > 0) {
TransportStopsLayer transportStopsLayer = activity.getMapLayers().getTransportStopsLayer();
if (transportStopsLayer != null) {
for (TransportStop transportStop : transportStopsReplacement) {
TransportStop transportStop = TransportStopController.findBestTransportStopForAmenity(activity.getMyApplication(), amenity);
if (transportStop != null) {
TransportStopsLayer transportStopsLayer = activity.getMapLayers().getTransportStopsLayer();
if (transportStopsLayer != null) {
selectedObjects.remove(amenity);
selectedObjects.put(transportStop, transportStopsLayer);
}
}
@ -897,42 +873,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
}
private void sortTransportStops(@NonNull LatLon latLon, List<TransportStop> transportStops) {
for (TransportStop transportStop : transportStops) {
transportStop.distance = (int) MapUtils.getDistance(latLon, transportStop.getLocation());
}
Collections.sort(transportStops, new Comparator<TransportStop>() {
@Override
public int compare(TransportStop s1, TransportStop s2) {
return Algorithms.compare(s1.distance, s2.distance);
}
});
}
@NonNull
private List<TransportStop> findTransportStopsAt(double latitude, double longitude) {
ArrayList<TransportStop> transportStops = new ArrayList<>();
List<TransportIndexRepository> reps =
activity.getMyApplication().getResourceManager().searchTransportRepositories(latitude, longitude);
TLongArrayList addedTransportStops = new TLongArrayList();
for (TransportIndexRepository t : reps) {
ArrayList<TransportStop> ls = new ArrayList<>();
QuadRect ll = MapUtils.calculateLatLonBbox(latitude, longitude, SHOW_STOPS_RADIUS_METERS);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
for (TransportStop tstop : ls) {
if (!addedTransportStops.contains(tstop.getId())) {
addedTransportStops.add(tstop.getId());
if (!tstop.isDeleted()) {
transportStops.add(tstop);
}
}
}
}
return transportStops;
}
@NonNull
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox,
PointF point, boolean acquireObjLatLon,