Merge branch 'r3.3'
This commit is contained in:
commit
a8dc66f9f5
8 changed files with 68 additions and 39 deletions
|
@ -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) {
|
||||
|
|
|
@ -98,11 +98,15 @@
|
|||
android:layout_height="1dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
|
||||
|
||||
<net.osmand.plus.widgets.ButtonEx
|
||||
android:id="@+id/copy_maps"
|
||||
android:id="@+id/cancel"
|
||||
style="@style/DashboardGeneralButton"
|
||||
android:gravity="center"
|
||||
android:text="@string/move_maps"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/shared_string_cancel"
|
||||
osmand:textAllCapsCompat="true"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
|
@ -115,12 +119,10 @@
|
|||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<net.osmand.plus.widgets.ButtonEx
|
||||
android:id="@+id/cancel"
|
||||
android:id="@+id/copy_maps"
|
||||
style="@style/DashboardGeneralButton"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/shared_string_cancel"
|
||||
android:text="@string/move_maps"
|
||||
osmand:textAllCapsCompat="true"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1393,14 +1393,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;
|
||||
|
@ -1434,7 +1436,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;
|
||||
|
@ -1443,6 +1446,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);
|
||||
|
@ -1451,9 +1455,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;
|
||||
|
@ -1464,12 +1467,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) {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue