Merge pull request #6859 from osmandapp/Fix_6853

Fix_6853
This commit is contained in:
vshcherb 2019-04-23 14:43:08 +02:00 committed by GitHub
commit 7a28768c50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 23 deletions

View file

@ -1,5 +1,10 @@
package net.osmand.data;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -7,11 +12,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
public class TransportRoute extends MapObject {
private List<TransportStop> forwardStops = new ArrayList<TransportStop>();
private String ref;
@ -221,17 +221,19 @@ public class TransportRoute extends MapObject {
return d;
}
public String getAdjustedRouteRef() {
if (ref != null) {
int charPos = ref.lastIndexOf(':');
public String getAdjustedRouteRef(boolean small) {
String adjustedRef = getRef();
if (adjustedRef != null) {
int charPos = adjustedRef.lastIndexOf(':');
if (charPos != -1) {
ref = ref.substring(0, charPos);
adjustedRef = adjustedRef.substring(0, charPos);
}
if (ref.length() > 4) {
ref = ref.substring(0, 4);
int maxRefLength = small ? 5 : 8;
if (adjustedRef.length() > maxRefLength) {
adjustedRef = adjustedRef.substring(0, maxRefLength - 1) + "";
}
}
return ref;
return adjustedRef;
}
public boolean compareRoute(TransportRoute thatObj) {

View file

@ -14,6 +14,7 @@
android:textSize="@dimen/default_sub_text_size_small"
tools:text="3"
android:gravity="center"
android:maxLines="1"
android:id="@+id/transport_stop_route_text"
android:background="@drawable/transport_stop_route_bg"
android:layout_width="match_parent"

View file

@ -1339,14 +1339,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
if (!transportBadgesCreated) {
List<TransportStopRoute> localTransportStopRoutes = menu.getLocalTransportStopRoutes();
List<TransportStopRoute> nearbyTransportStopRoutes = menu.getNearbyTransportStopRoutes();
int localColumnsPerRow = getRoutesBadgesColumnsPerRow(null);
int maxLocalRows = 0;
if (localTransportStopRoutes != null) {
if (localTransportStopRoutes != null && !localTransportStopRoutes.isEmpty()) {
List<TransportStopRoute> localFilteredTransportStopRoutes = filterTransportRoutes(localTransportStopRoutes);
int minBadgeWidth = getMinBadgeWidth(localFilteredTransportStopRoutes);
int localColumnsPerRow = getRoutesBadgesColumnsPerRow(null, minBadgeWidth);
maxLocalRows = (int) Math.round(Math.ceil((double) localFilteredTransportStopRoutes.size() / localColumnsPerRow));
localTransportStopRoutesGrid.setColumnWidth(minBadgeWidth);
updateLocalRoutesBadges(localFilteredTransportStopRoutes, localColumnsPerRow);
}
if (nearbyTransportStopRoutes != null) {
if (nearbyTransportStopRoutes != null && !nearbyTransportStopRoutes.isEmpty()) {
updateNearbyRoutesBadges(maxLocalRows, filterNearbyTransportRoutes(nearbyTransportStopRoutes, localTransportStopRoutes));
}
transportBadgesCreated = true;
@ -1380,7 +1382,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
String nearInDistance = getString(R.string.transport_nearby_routes) + " "
+ OsmAndFormatter.getFormattedDistance(TransportStopController.SHOW_STOPS_RADIUS_METERS, getMyApplication()) + ":";
nearbyRoutesWithinTv.setText(nearInDistance);
int nearbyColumnsPerRow = getRoutesBadgesColumnsPerRow(nearInDistance);
int minBadgeWidth = getMinBadgeWidth(nearbyTransportStopRoutes);
int nearbyColumnsPerRow = getRoutesBadgesColumnsPerRow(nearInDistance, minBadgeWidth);
int maxNearbyRows = Math.min(3, 6 - maxLocalRows);
int nearbyMaxItems = maxNearbyRows * nearbyColumnsPerRow - 1;
TransportStopRouteAdapter adapter;
@ -1389,6 +1392,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} else {
adapter = createTransportStopRouteAdapter(nearbyTransportStopRoutes, false);
}
nearbyTransportStopRoutesGrid.setColumnWidth(minBadgeWidth);
nearbyTransportStopRoutesGrid.setAdapter(adapter);
nearbyTransportStopRoutesGrid.setVisibility(View.VISIBLE);
nearbyRoutesLayout.setVisibility(View.VISIBLE);
@ -1397,9 +1401,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
}
private int getRoutesBadgesColumnsPerRow(@Nullable String nearInDistance) {
private int getRoutesBadgesColumnsPerRow(@Nullable String nearInDistance, int minBadgeWidth) {
try {
double badgeWidth = getResources().getDimension(R.dimen.context_menu_transport_grid_item_width);
double gridSpacing = getResources().getDimension(R.dimen.context_menu_transport_grid_spacing);
double gridPadding = getResources().getDimension(R.dimen.context_menu_padding_margin_default);
int availableSpace;
@ -1410,12 +1413,32 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
double paddingTv = getResources().getDimension(R.dimen.context_menu_padding_margin_small);
availableSpace = (int) (routesBadgesContainer.getWidth() - gridPadding * 2 - paddingTv - textWidth);
}
return (int) ((availableSpace + gridSpacing) / (badgeWidth + gridSpacing));
return (int) ((availableSpace + gridSpacing) / (minBadgeWidth + gridSpacing));
} catch (Resources.NotFoundException e) {
return -1;
}
}
private int getMinBadgeWidth(List<TransportStopRoute> transportStopRoutes) {
try {
int minBadgeWidth = getResources().getDimensionPixelSize(R.dimen.context_menu_transport_grid_item_width);
int textPadding = getResources().getDimensionPixelSize(R.dimen.context_menu_subtitle_margin);
float textSizeSmall = getResources().getDimensionPixelSize(R.dimen.default_sub_text_size_small);
for (TransportStopRoute transportStopRoute : transportStopRoutes) {
String routeRef = transportStopRoute.route.getAdjustedRouteRef(false);
int textWidth = AndroidUtils.getTextWidth(textSizeSmall, routeRef) + textPadding * 2;
if (textWidth > minBadgeWidth) {
minBadgeWidth = textWidth;
}
}
return minBadgeWidth;
} catch (Resources.NotFoundException e) {
return dpToPx(32);
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void runLayoutListener() {
if (view != null) {

View file

@ -796,6 +796,7 @@ public class MenuBuilder {
transportRect.setTypeface(FontCache.getRobotoMedium(view.getContext()));
transportRect.setTextColor(Color.WHITE);
transportRect.setTextSize(10);
transportRect.setMaxLines(1);
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
@ -805,7 +806,7 @@ public class MenuBuilder {
transportRect.setTextColor(UiUtilities.getContrastColor(app, bgColor, true));
transportRect.setBackgroundDrawable(shape);
transportRect.setText(route.route.getAdjustedRouteRef());
transportRect.setText(route.route.getAdjustedRouteRef(true));
baseView.addView(transportRect);
LinearLayout infoView = new LinearLayout(view.getContext());

View file

@ -45,7 +45,7 @@ public class TransportStopRouteAdapter extends ArrayAdapter<Object> {
int bgColor = 0;
if (object instanceof TransportStopRoute) {
TransportStopRoute transportStopRoute = (TransportStopRoute) object;
routeRef = transportStopRoute.route.getAdjustedRouteRef();
routeRef = transportStopRoute.route.getAdjustedRouteRef(false);
bgColor = transportStopRoute.getColor(app, nightMode);
} else if (object instanceof String) {
routeRef = (String) object;

View file

@ -1453,7 +1453,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
OsmandApplication app = mapActivity.getMyApplication();
LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
if (transportStopRoute != null) {
String routeRef = transportStopRoute.route.getAdjustedRouteRef();
String routeRef = transportStopRoute.route.getAdjustedRouteRef(true);
int bgColor = transportStopRoute.getColor(app, isNightMode());
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text);

View file

@ -272,7 +272,7 @@ public class PublicTransportCard extends BaseCard {
TransportRoute transportRoute = segment.route;
TransportStopRoute transportStopRoute = TransportStopRoute.getTransportStopRoute(transportRoute, segment.getStart());
String routeRef = segment.route.getAdjustedRouteRef();
String routeRef = segment.route.getAdjustedRouteRef(true);
int bgColor = transportStopRoute.getColor(app, nightMode);
TextView transportStopRouteTextView = (TextView) bageView.findViewById(R.id.transport_stop_route_text);