Create collapsable view for routes
This commit is contained in:
parent
61c3cda033
commit
ebf26c79aa
5 changed files with 67 additions and 42 deletions
|
@ -26,6 +26,7 @@ public class Amenity extends MapObject {
|
||||||
public static final String WEBSITE = "website";
|
public static final String WEBSITE = "website";
|
||||||
public static final String PHONE = "phone";
|
public static final String PHONE = "phone";
|
||||||
public static final String DESCRIPTION = "description";
|
public static final String DESCRIPTION = "description";
|
||||||
|
public static final String ROUTE = "route";
|
||||||
public static final String OPENING_HOURS = "opening_hours";
|
public static final String OPENING_HOURS = "opening_hours";
|
||||||
public static final String CONTENT = "content";
|
public static final String CONTENT = "content";
|
||||||
public static final String CUISINE = "cuisine";
|
public static final String CUISINE = "cuisine";
|
||||||
|
|
|
@ -46,8 +46,10 @@ import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
|
||||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
||||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
|
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
|
||||||
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
|
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
|
||||||
|
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||||
import net.osmand.plus.render.RenderingIcons;
|
import net.osmand.plus.render.RenderingIcons;
|
||||||
|
import net.osmand.plus.views.TransportStopsLayer;
|
||||||
import net.osmand.plus.widgets.TextViewEx;
|
import net.osmand.plus.widgets.TextViewEx;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
@ -81,6 +83,7 @@ public class MenuBuilder {
|
||||||
private boolean showOnlinePhotos = true;
|
private boolean showOnlinePhotos = true;
|
||||||
protected List<Amenity> nearestWiki = new ArrayList<>();
|
protected List<Amenity> nearestWiki = new ArrayList<>();
|
||||||
private List<OsmandPlugin> menuPlugins = new ArrayList<>();
|
private List<OsmandPlugin> menuPlugins = new ArrayList<>();
|
||||||
|
private List<TransportStopRoute> routes = new ArrayList<>();
|
||||||
private CardsRowBuilder onlinePhotoCardsRow;
|
private CardsRowBuilder onlinePhotoCardsRow;
|
||||||
private List<AbstractCard> onlinePhotoCards;
|
private List<AbstractCard> onlinePhotoCards;
|
||||||
|
|
||||||
|
@ -204,6 +207,10 @@ public class MenuBuilder {
|
||||||
transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
|
transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRoutes(List<TransportStopRoute> routes) {
|
||||||
|
this.routes = routes;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPreferredMapLang() {
|
public String getPreferredMapLang() {
|
||||||
return preferredMapLang;
|
return preferredMapLang;
|
||||||
}
|
}
|
||||||
|
@ -279,6 +286,10 @@ public class MenuBuilder {
|
||||||
if (needBuildPlainMenuItems()) {
|
if (needBuildPlainMenuItems()) {
|
||||||
buildPlainMenuItems(view);
|
buildPlainMenuItems(view);
|
||||||
}
|
}
|
||||||
|
if (routes.size() > 0) {
|
||||||
|
buildRow(view, 0, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), true),
|
||||||
|
false, 0, false, null);
|
||||||
|
}
|
||||||
buildInternal(view);
|
buildInternal(view);
|
||||||
if (showOnlinePhotos) {
|
if (showOnlinePhotos) {
|
||||||
buildNearestPhotosRow(view);
|
buildNearestPhotosRow(view);
|
||||||
|
@ -419,7 +430,7 @@ public class MenuBuilder {
|
||||||
public View buildRow(View view, int iconId, String text, int textColor,
|
public View buildRow(View view, int iconId, String text, int textColor,
|
||||||
boolean collapsable, final CollapsableView collapsableView,
|
boolean collapsable, final CollapsableView collapsableView,
|
||||||
boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener) {
|
boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener) {
|
||||||
return buildRow(view, getRowIcon(iconId), text, textColor, collapsable, collapsableView,
|
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), text, textColor, collapsable, collapsableView,
|
||||||
needLinks, textLinesLimit, isUrl, onClickListener);
|
needLinks, textLinesLimit, isUrl, onClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,20 +463,24 @@ public class MenuBuilder {
|
||||||
baseView.addView(ll);
|
baseView.addView(ll);
|
||||||
|
|
||||||
// Icon
|
// Icon
|
||||||
LinearLayout llIcon = new LinearLayout(view.getContext());
|
boolean showIcon = false;
|
||||||
llIcon.setOrientation(LinearLayout.HORIZONTAL);
|
if (icon != null) {
|
||||||
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(64f), dpToPx(48f)));
|
LinearLayout llIcon = new LinearLayout(view.getContext());
|
||||||
llIcon.setGravity(Gravity.CENTER_VERTICAL);
|
llIcon.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
ll.addView(llIcon);
|
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(64f), dpToPx(48f)));
|
||||||
|
llIcon.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
|
ll.addView(llIcon);
|
||||||
|
|
||||||
ImageView iconView = new ImageView(view.getContext());
|
ImageView iconView = new ImageView(view.getContext());
|
||||||
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f));
|
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f));
|
||||||
llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f));
|
llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(24f), dpToPx(12f));
|
||||||
llIconParams.gravity = Gravity.CENTER_VERTICAL;
|
llIconParams.gravity = Gravity.CENTER_VERTICAL;
|
||||||
iconView.setLayoutParams(llIconParams);
|
iconView.setLayoutParams(llIconParams);
|
||||||
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||||
iconView.setImageDrawable(icon);
|
iconView.setImageDrawable(icon);
|
||||||
llIcon.addView(iconView);
|
llIcon.addView(iconView);
|
||||||
|
showIcon = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
LinearLayout llText = new LinearLayout(view.getContext());
|
LinearLayout llText = new LinearLayout(view.getContext());
|
||||||
|
@ -474,7 +489,7 @@ public class MenuBuilder {
|
||||||
|
|
||||||
TextViewEx textView = new TextViewEx(view.getContext());
|
TextViewEx textView = new TextViewEx(view.getContext());
|
||||||
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
llTextParams.setMargins(0, dpToPx(8f), 0, dpToPx(8f));
|
llTextParams.setMargins(showIcon ? 0 : dpToPx(16f), dpToPx(8f), 0, dpToPx(8f));
|
||||||
textView.setLayoutParams(llTextParams);
|
textView.setLayoutParams(llTextParams);
|
||||||
textView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
|
textView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
|
||||||
textView.setTextSize(16);
|
textView.setTextSize(16);
|
||||||
|
@ -672,6 +687,30 @@ public class MenuBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed) {
|
||||||
|
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false);
|
||||||
|
|
||||||
|
for (final TransportStopRoute r : routes) {
|
||||||
|
View.OnClickListener listener = new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View arg0) {
|
||||||
|
MapContextMenu mm = getMapActivity().getContextMenu();
|
||||||
|
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE,
|
||||||
|
r.getDescription(getMapActivity().getMyApplication(), false));
|
||||||
|
mm.show(latLon, pd, r);
|
||||||
|
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||||
|
stopsLayer.setRoute(r.route);
|
||||||
|
int cz = r.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||||
|
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
int drawableResId = r.type == null ? R.drawable.ic_action_polygom_dark : r.type.getResourceId();
|
||||||
|
buildRow(view, drawableResId, r.getDescription(getMapActivity().getMyApplication(), true), 0, false, null, false, 0, false, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CollapsableView(view, collapsed);
|
||||||
|
}
|
||||||
|
|
||||||
protected CollapsableView getCollapsableTextView(Context context, boolean collapsed, String text) {
|
protected CollapsableView getCollapsableTextView(Context context, boolean collapsed, String text) {
|
||||||
final TextViewEx textView = new TextViewEx(context);
|
final TextViewEx textView = new TextViewEx(context);
|
||||||
textView.setVisibility(collapsed ? View.GONE : View.VISIBLE);
|
textView.setVisibility(collapsed ? View.GONE : View.VISIBLE);
|
||||||
|
@ -686,7 +725,7 @@ public class MenuBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CollapsableView getCollapsableFavouritesView(final Context context, boolean collapsed, @NonNull final FavoriteGroup group, FavouritePoint selectedPoint) {
|
protected CollapsableView getCollapsableFavouritesView(final Context context, boolean collapsed, @NonNull final FavoriteGroup group, FavouritePoint selectedPoint) {
|
||||||
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed);
|
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
|
||||||
|
|
||||||
List<FavouritePoint> points = group.points;
|
List<FavouritePoint> points = group.points;
|
||||||
for (int i = 0; i < points.size() && i < 10; i++) {
|
for (int i = 0; i < points.size() && i < 10; i++) {
|
||||||
|
@ -730,7 +769,7 @@ public class MenuBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) {
|
protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) {
|
||||||
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed);
|
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
|
||||||
|
|
||||||
for (final Amenity wiki : nearestWiki) {
|
for (final Amenity wiki : nearestWiki) {
|
||||||
TextViewEx button = buildButtonInCollapsableView(context, false);
|
TextViewEx button = buildButtonInCollapsableView(context, false);
|
||||||
|
@ -751,12 +790,14 @@ public class MenuBuilder {
|
||||||
return new CollapsableView(view, collapsed);
|
return new CollapsableView(view, collapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed) {
|
protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed, boolean needMargin) {
|
||||||
final LinearLayout view = new LinearLayout(context);
|
final LinearLayout view = new LinearLayout(context);
|
||||||
view.setOrientation(LinearLayout.VERTICAL);
|
view.setOrientation(LinearLayout.VERTICAL);
|
||||||
view.setVisibility(collapsed ? View.GONE : View.VISIBLE);
|
view.setVisibility(collapsed ? View.GONE : View.VISIBLE);
|
||||||
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
llParams.setMargins(dpToPx(64f), 0, dpToPx(12f), 0);
|
if (needMargin) {
|
||||||
|
llParams.setMargins(dpToPx(64f), 0, dpToPx(12f), 0);
|
||||||
|
}
|
||||||
view.setLayoutParams(llParams);
|
view.setLayoutParams(llParams);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
|
@ -378,6 +378,8 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
sb.append(poiTypes.getPoiTranslation("cuisine_" + c).toLowerCase());
|
sb.append(poiTypes.getPoiTranslation("cuisine_" + c).toLowerCase());
|
||||||
}
|
}
|
||||||
vl = sb.toString();
|
vl = sb.toString();
|
||||||
|
} else if (key.contains(Amenity.ROUTE)) {
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (key.contains(Amenity.DESCRIPTION)) {
|
if (key.contains(Amenity.DESCRIPTION)) {
|
||||||
iconId = R.drawable.ic_action_note_dark;
|
iconId = R.drawable.ic_action_note_dark;
|
||||||
|
|
|
@ -171,29 +171,6 @@ public class AmenityMenuController extends MenuController {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
|
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
|
||||||
addPlainMenuItems(amenity, typeStr, builder);
|
|
||||||
for (final TransportStopRoute r : routes) {
|
|
||||||
View.OnClickListener listener = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View arg0) {
|
|
||||||
MapContextMenu mm = getMapActivity().getContextMenu();
|
|
||||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE,
|
|
||||||
r.getDescription(getMapActivity().getMyApplication(), false));
|
|
||||||
mm.show(amenity.getLocation(), pd, r);
|
|
||||||
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
|
||||||
stopsLayer.setRoute(r.route);
|
|
||||||
int cz = r.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
|
||||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (r.type == null) {
|
|
||||||
builder.addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.getDescription(getMapActivity().getMyApplication(), true),
|
|
||||||
false, false, listener);
|
|
||||||
} else {
|
|
||||||
builder.addPlainMenuItem(r.type.getResourceId(), r.getDescription(getMapActivity().getMyApplication(), true),
|
|
||||||
false, false, listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addPlainMenuItems(Amenity amenity, String typeStr, MenuBuilder builder) {
|
public static void addPlainMenuItems(Amenity amenity, String typeStr, MenuBuilder builder) {
|
||||||
|
@ -242,6 +219,8 @@ public class AmenityMenuController extends MenuController {
|
||||||
return o1.desc.compareTo(o2.desc);
|
return o1.desc.compareTo(o2.desc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.setRoutes(routes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, int dist) {
|
private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, int dist) {
|
||||||
|
|
|
@ -198,6 +198,8 @@ public class TransportStopController extends MenuController {
|
||||||
return o1.desc.compareTo(o2.desc);
|
return o1.desc.compareTo(o2.desc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.setRoutes(routes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
|
private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
|
||||||
|
|
Loading…
Reference in a new issue