Display routes in bottom view

This commit is contained in:
PavelRatushny 2017-12-15 10:19:16 +02:00
parent ebf26c79aa
commit bb62e054e8
6 changed files with 135 additions and 23 deletions

View file

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal"
android:paddingBottom="12dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
<TextView
android:id="@+id/route_ref"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:background="@drawable/transport_stop_route_bg"
android:gravity="center"
android:textColor="@color/color_white"
android:textSize="@dimen/default_desc_text_size"
tools:text="3"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:orientation="vertical">
<TextView
android:textSize="16sp"
android:id="@+id/route_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="№5: Льва Толстого площа - Белицкая улица (25м)"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="8dp">
<ImageView
android:id="@+id/route_type_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:src="@drawable/ic_action_polygom_dark"/>
<TextView
android:id="@+id/route_type_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Метро "/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -2099,6 +2099,7 @@
<string name="poi_route_monorail_ref">Monorail</string> <string name="poi_route_monorail_ref">Monorail</string>
<string name="poi_route_funicular_ref">Funicular</string> <string name="poi_route_funicular_ref">Funicular</string>
<string name="poi_route_ferry_ref">Ferry</string> <string name="poi_route_ferry_ref">Ferry</string>
<string name="poi_route_subway_ref">Subway</string>
<string name="poi_route_railway_ref">Route of a railroad</string> <string name="poi_route_railway_ref">Route of a railroad</string>

View file

@ -17,12 +17,14 @@ import android.text.TextUtils;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
@ -463,7 +465,6 @@ public class MenuBuilder {
baseView.addView(ll); baseView.addView(ll);
// Icon // Icon
boolean showIcon = false;
if (icon != null) { if (icon != null) {
LinearLayout llIcon = new LinearLayout(view.getContext()); LinearLayout llIcon = new LinearLayout(view.getContext());
llIcon.setOrientation(LinearLayout.HORIZONTAL); llIcon.setOrientation(LinearLayout.HORIZONTAL);
@ -479,7 +480,6 @@ public class MenuBuilder {
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
@ -489,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(showIcon ? 0 : dpToPx(16f), dpToPx(8f), 0, dpToPx(8f)); llTextParams.setMargins(icon != null ? 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);
@ -687,6 +687,65 @@ public class MenuBuilder {
); );
} }
private void buildTransportRouteRow(ViewGroup parent, TransportStopRoute r, OnClickListener listener) {
if (!isFirstRow()) {
buildRowDivider(parent, false);
}
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ctx_menu_transport_route_layout, parent, false);
TextView routeDesc = (TextView) view.findViewById(R.id.route_desc);
routeDesc.setText(r.getDescription(getMapActivity().getMyApplication(), true));
routeDesc.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
int drawableResId = r.type == null ? R.drawable.ic_action_polygom_dark : r.type.getResourceId();
((ImageView) view.findViewById(R.id.route_type_icon)).setImageDrawable(getRowIcon(drawableResId));
((TextView) view.findViewById(R.id.route_ref)).setText(r.route.getRef());
view.setOnClickListener(listener);
int typeResId;
switch (r.type) {
case BUS:
typeResId = R.string.poi_route_bus_ref;
break;
case TRAM:
typeResId = R.string.poi_route_tram_ref;
break;
case FERRY:
typeResId = R.string.poi_route_ferry_ref;
break;
case TRAIN:
typeResId = R.string.poi_route_train_ref;
break;
case SHARE_TAXI:
typeResId = R.string.poi_route_share_taxi_ref;
break;
case FUNICULAR:
typeResId = R.string.poi_route_funicular_ref;
break;
case LIGHT_RAIL:
typeResId = R.string.poi_route_light_rail_ref;
break;
case MONORAIL:
typeResId = R.string.poi_route_monorail_ref;
break;
case TROLLEYBUS:
typeResId = R.string.poi_route_trolleybus_ref;
break;
case RAILWAY:
typeResId = R.string.poi_route_railway_ref;
break;
case SUBWAY:
typeResId = R.string.poi_route_subway_ref;
break;
default:
typeResId = R.string.poi_filter_public_transport;
break;
}
((TextView) view.findViewById(R.id.route_type_text)).setText(typeResId);
parent.addView(view);
rowBuilt();
}
private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed) { private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed) {
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false); LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false);
@ -704,8 +763,7 @@ public class MenuBuilder {
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom()); getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
} }
}; };
int drawableResId = r.type == null ? R.drawable.ic_action_polygom_dark : r.type.getResourceId(); buildTransportRouteRow(view, r, listener);
buildRow(view, drawableResId, r.getDescription(getMapActivity().getMyApplication(), true), 0, false, null, false, 0, false, listener);
} }
return new CollapsableView(view, collapsed); return new CollapsableView(view, collapsed);

View file

@ -230,7 +230,7 @@ public class AmenityMenuController extends MenuController {
TransportStopController.TransportStopType type = TransportStopController.TransportStopType.findType(rs.getType()); TransportStopController.TransportStopType type = TransportStopController.TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute(); TransportStopRoute r = new TransportStopRoute();
r.type = type; r.type = type;
r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName()); r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs; r.route = rs;
r.stop = s; r.stop = s;
r.distance = dist; r.distance = dist;

View file

@ -36,6 +36,11 @@ public class FavouritePointMenuController extends MenuController {
leftTitleButtonController = markerMenuController.getLeftTitleButtonController(); leftTitleButtonController = markerMenuController.getLeftTitleButtonController();
rightTitleButtonController = markerMenuController.getRightTitleButtonController(); rightTitleButtonController = markerMenuController.getRightTitleButtonController();
} }
if (getObject() instanceof TransportStop) {
TransportStop stop = (TransportStop) getObject();
TransportStopController transportStopController = new TransportStopController(getMapActivity(), pointDescription, stop);
transportStopController.processTransportStop(builder);
}
} }
@Override @Override
@ -120,12 +125,6 @@ public class FavouritePointMenuController extends MenuController {
if (originObject instanceof Amenity) { if (originObject instanceof Amenity) {
Amenity amenity = (Amenity) originObject; Amenity amenity = (Amenity) originObject;
AmenityMenuController.addPlainMenuItems(amenity, AmenityMenuController.getTypeStr(amenity), builder); AmenityMenuController.addPlainMenuItems(amenity, AmenityMenuController.getTypeStr(amenity), builder);
} else if (originObject instanceof TransportStop) {
TransportStop stop = (TransportStop) originObject;
TransportStopController transportStopController =
new TransportStopController(getMapActivity(), pointDescription, stop);
transportStopController.addPlainMenuItems(builder, latLon);
addMyLocationToPlainItems(latLon);
} }
} else { } else {
addMyLocationToPlainItems(latLon); addMyLocationToPlainItems(latLon);

View file

@ -82,14 +82,14 @@ public class TransportStopController extends MenuController {
PointDescription pointDescription, TransportStop transportStop) { PointDescription pointDescription, TransportStop transportStop) {
super(new MenuBuilder(mapActivity), pointDescription, mapActivity); super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
this.transportStop = transportStop; this.transportStop = transportStop;
processTransportStop(); processTransportStop(builder);
} }
@Override @Override
protected void setObject(Object object) { protected void setObject(Object object) {
if (object instanceof TransportStop) { if (object instanceof TransportStop) {
this.transportStop = (TransportStop) object; this.transportStop = (TransportStop) object;
processTransportStop(); processTransportStop(builder);
} }
} }
@ -127,12 +127,6 @@ public class TransportStopController extends MenuController {
return getPointDescription().getTypeName(); return getPointDescription().getTypeName();
} }
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) {
addPlainMenuItems(builder, latLon);
super.addPlainMenuItems(typeStr, pointDescription, latLon);
}
public void addPlainMenuItems(MenuBuilder builder, final LatLon latLon) { public void addPlainMenuItems(MenuBuilder builder, final LatLon latLon) {
for (final TransportStopRoute r : routes) { for (final TransportStopRoute r : routes) {
OnClickListener listener = new OnClickListener() { OnClickListener listener = new OnClickListener() {
@ -158,7 +152,7 @@ public class TransportStopController extends MenuController {
} }
} }
private void processTransportStop() { public void processTransportStop(MenuBuilder builder) {
routes.clear(); routes.clear();
List<TransportIndexRepository> reps = getMapActivity().getMyApplication() List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(), .getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
@ -212,7 +206,7 @@ public class TransportStopController extends MenuController {
topType = type; topType = type;
} }
r.type = type; r.type = type;
r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName()); r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
r.route = rs; r.route = rs;
r.refStop = refStop; r.refStop = refStop;
r.stop = s; r.stop = s;