Make transport rect clickable
This commit is contained in:
parent
d567797a5f
commit
24a75dc2bd
3 changed files with 38 additions and 2 deletions
|
@ -7,6 +7,7 @@
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:foreground="?attr/selectableItemBackground"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
osmand:typeface="@string/font_roboto_medium"
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
android:textColor="@color/color_white"
|
android:textColor="@color/color_white"
|
||||||
|
|
|
@ -33,6 +33,7 @@ import android.widget.TextView;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.QuadPoint;
|
import net.osmand.data.QuadPoint;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -49,6 +50,7 @@ import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.Transp
|
||||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||||
import net.osmand.plus.views.AnimateDraggingMapThread;
|
import net.osmand.plus.views.AnimateDraggingMapThread;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
|
import net.osmand.plus.views.TransportStopsLayer;
|
||||||
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
|
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
|
||||||
import net.osmand.plus.views.controls.SingleTapConfirm;
|
import net.osmand.plus.views.controls.SingleTapConfirm;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
@ -387,7 +389,22 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
||||||
GridView transportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_routes_grid);
|
GridView transportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_routes_grid);
|
||||||
List<TransportStopRoute> transportStopRoutes = menu.getTransportStopRoutes();
|
List<TransportStopRoute> transportStopRoutes = menu.getTransportStopRoutes();
|
||||||
if (transportStopRoutes != null && transportStopRoutes.size() > 0) {
|
if (transportStopRoutes != null && transportStopRoutes.size() > 0) {
|
||||||
TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getContext(), transportStopRoutes, nightMode);
|
final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getContext(), transportStopRoutes, nightMode);
|
||||||
|
adapter.setListener(new TransportStopRouteAdapter.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(int position) {
|
||||||
|
TransportStopRoute route = adapter.getItem(position);
|
||||||
|
if (route != null) {
|
||||||
|
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE,
|
||||||
|
route.getDescription(getMapActivity().getMyApplication(), false));
|
||||||
|
menu.show(menu.getLatLon(), pd, route);
|
||||||
|
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||||
|
stopsLayer.setRoute(route.route);
|
||||||
|
int cz = route.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||||
|
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
transportStopRoutesGrid.setAdapter(adapter);
|
transportStopRoutesGrid.setAdapter(adapter);
|
||||||
transportStopRoutesGrid.setVisibility(View.VISIBLE);
|
transportStopRoutesGrid.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,15 +19,20 @@ import java.util.List;
|
||||||
public class TransportStopRouteAdapter extends ArrayAdapter<TransportStopRoute> {
|
public class TransportStopRouteAdapter extends ArrayAdapter<TransportStopRoute> {
|
||||||
|
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
|
private OnClickListener listener;
|
||||||
|
|
||||||
public TransportStopRouteAdapter(@NonNull Context context, @NonNull List<TransportStopRoute> objects, boolean nightMode) {
|
public TransportStopRouteAdapter(@NonNull Context context, @NonNull List<TransportStopRoute> objects, boolean nightMode) {
|
||||||
super(context, 0, objects);
|
super(context, 0, objects);
|
||||||
this.nightMode = nightMode;
|
this.nightMode = nightMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setListener(OnClickListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.transport_stop_route_item, parent, false);
|
convertView = LayoutInflater.from(getContext()).inflate(R.layout.transport_stop_route_item, parent, false);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +45,15 @@ public class TransportStopRouteAdapter extends ArrayAdapter<TransportStopRoute>
|
||||||
gradientDrawableBg.setColor(ContextCompat.getColor(getContext(), getColor(transportStopRoute)));
|
gradientDrawableBg.setColor(ContextCompat.getColor(getContext(), getColor(transportStopRoute)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onClick(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,4 +90,8 @@ public class TransportStopRouteAdapter extends ArrayAdapter<TransportStopRoute>
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnClickListener {
|
||||||
|
void onClick(int position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue