/** * @return length and duration of the whole road, or of a leg of the road, * as a String, in a readable format. * @param leg leg index, starting from 0. -1 for the whole road */ public String getLengthDurationText(Context context, int leg) { double length = (leg == -1 ? mLength : mLegs.get(leg).mLength); double duration = (leg == -1 ? mDuration : mLegs.get(leg).mDuration); return getLengthDurationText(context, length, duration); }
@Override public View getView(int position, View convertView, ViewGroup viewGroup) { RoadNode entry = (RoadNode)getItem(position); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.item_layout, null); } TextView tvTitle = (TextView)convertView.findViewById(R.id.title); String instructions = (entry.mInstructions==null ? "" : entry.mInstructions); tvTitle.setText("" + (position+1) + ". " + instructions); TextView tvDetails = (TextView)convertView.findViewById(R.id.details); tvDetails.setText(Road.getLengthDurationText(mContext, entry.mLength, entry.mDuration)); int iconId = iconIds.getResourceId(entry.mManeuverType, R.drawable.ic_empty); Drawable icon = mContext.getResources().getDrawable(iconId); ImageView ivManeuver = (ImageView)convertView.findViewById(R.id.thumbnail); ivManeuver.setImageDrawable(icon); return convertView; }
void selectRoad(int roadIndex){ mSelectedRoad = roadIndex; putRoadNodes(mRoads[roadIndex]); //Set route info in the text view: TextView textView = (TextView)findViewById(R.id.routeInfo); textView.setText(mRoads[roadIndex].getLengthDurationText(this, -1)); for (int i=0; i<mRoadOverlays.length; i++){ Paint p = mRoadOverlays[i].getPaint(); if (i == roadIndex) p.setColor(0x800000FF); //blue else p.setColor(0x90666666); //grey } map.invalidate(); }
p.setPathEffect(new DashPathEffect(new float[]{10, 5}, 0)); String routeDesc = roads[i].getLengthDurationText(this, -1); roadPolyline.setTitle(getString(R.string.route) + " - " + routeDesc); roadPolyline.setInfoWindow(new BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map));
private void putRoadNodes(Road road){ mRoadNodeMarkers.getItems().clear(); Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.marker_node, null); int n = road.mNodes.size(); MarkerInfoWindow infoWindow = new MarkerInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map); TypedArray iconIds = getResources().obtainTypedArray(R.array.direction_icons); for (int i=0; i<n; i++){ RoadNode node = road.mNodes.get(i); String instructions = (node.mInstructions==null ? "" : node.mInstructions); Marker nodeMarker = new Marker(map); nodeMarker.setTitle(getString(R.string.step)+ " " + (i+1)); nodeMarker.setSnippet(instructions); nodeMarker.setSubDescription(Road.getLengthDurationText(this, node.mLength, node.mDuration)); nodeMarker.setPosition(node.mLocation); nodeMarker.setIcon(icon); nodeMarker.setInfoWindow(infoWindow); //use a shared infowindow. int iconId = iconIds.getResourceId(node.mManeuverType, R.drawable.ic_empty); if (iconId != R.drawable.ic_empty){ Drawable image = ResourcesCompat.getDrawable(getResources(), iconId, null); nodeMarker.setImage(image); } nodeMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER); mRoadNodeMarkers.add(nodeMarker); } iconIds.recycle(); }
nodeMarker.setSubDescription(Road.getLengthDurationText(this, node.mLength, node.mDuration)); Drawable iconContinue = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_continue, null); nodeMarker.setImage(iconContinue);