add route info layer
git-svn-id: https://osmand.googlecode.com/svn/trunk@384 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
ee2de0c5cb
commit
58e3dc675e
4 changed files with 250 additions and 8 deletions
|
@ -10,5 +10,10 @@
|
|||
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|left" android:id="@+id/BackToMenu" android:background="@drawable/back_menu"></ImageButton>
|
||||
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:id="@+id/BackToLocation" android:background="@drawable/back_location"></ImageButton>
|
||||
|
||||
<LinearLayout android:layout_width="wrap_content" android:id="@+id/RouteLayout" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:layout_marginBottom="12dp" >
|
||||
<Button android:layout_width="wrap_content" android:id="@+id/PreviousButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_media_previous"/>
|
||||
<Button android:layout_width="wrap_content" android:id="@+id/InfoButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_dialog_info" android:layout_marginLeft="8dp"/>
|
||||
<Button android:layout_width="wrap_content" android:id="@+id/NextButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_media_next" android:layout_marginLeft="8dp" android:layout_marginRight="15dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -53,6 +53,7 @@ import android.view.View.OnClickListener;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
import android.widget.ZoomControls;
|
||||
|
@ -90,6 +91,7 @@ import com.osmand.views.OsmandMapTileView;
|
|||
import com.osmand.views.POIMapLayer;
|
||||
import com.osmand.views.PointLocationLayer;
|
||||
import com.osmand.views.PointNavigationLayer;
|
||||
import com.osmand.views.RouteInfoLayer;
|
||||
import com.osmand.views.RouteLayer;
|
||||
import com.osmand.views.TransportStopsLayer;
|
||||
|
||||
|
@ -122,6 +124,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
private PointLocationLayer locationLayer;
|
||||
private PointNavigationLayer navigationLayer;
|
||||
private MapInfoLayer mapInfoLayer;
|
||||
private RouteInfoLayer routeInfoLayer;
|
||||
|
||||
private SavingTrackHelper savingTrackHelper;
|
||||
private RoutingHelper routingHelper;
|
||||
|
@ -138,6 +141,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
|
||||
|
||||
|
||||
private boolean isMapLinkedToLocation(){
|
||||
return OsmandSettings.isMapSyncToGpsLocation(this);
|
||||
}
|
||||
|
@ -194,6 +198,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
mapView.setMapLocationListener(this);
|
||||
routingHelper = RoutingHelper.getInstance(this);
|
||||
|
||||
// 1. route layer
|
||||
routeLayer = new RouteLayer(routingHelper);
|
||||
mapView.addLayer(routeLayer, 1);
|
||||
|
@ -214,6 +219,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
// 8. map info layer
|
||||
mapInfoLayer = new MapInfoLayer(this, routeLayer);
|
||||
mapView.addLayer(mapInfoLayer, 8);
|
||||
// 9. route info layer
|
||||
routeInfoLayer = new RouteInfoLayer(routingHelper, (LinearLayout) findViewById(R.id.RouteLayout));
|
||||
mapView.addLayer(routeInfoLayer, 9);
|
||||
|
||||
|
||||
savingTrackHelper = new SavingTrackHelper(this);
|
||||
|
@ -1084,10 +1092,12 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
layersList.add(getString(R.string.layer_transport));
|
||||
layersList.add(getString(R.string.layer_osm_bugs));
|
||||
layersList.add(getString(R.string.layer_favorites));
|
||||
if(routingHelper != null && routingHelper.isRouteCalculated()){
|
||||
final int routeInfoInd = routeInfoLayer.couldBeVisible() ? layersList.size() : -1;
|
||||
if(routeInfoLayer.couldBeVisible()){
|
||||
layersList.add(getString(R.string.layer_route));
|
||||
}
|
||||
if(!TransportRouteHelper.getInstance().getRoute().isEmpty()){
|
||||
final int transportRouteInfoInd = TransportRouteHelper.getInstance().getRoute().isEmpty() ? - 1 : layersList.size();
|
||||
if(transportRouteInfoInd > -1){
|
||||
layersList.add(getString(R.string.layer_transport_route));
|
||||
}
|
||||
final boolean[] selected = new boolean[layersList.size()];
|
||||
|
@ -1096,6 +1106,14 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
selected[2] = OsmandSettings.isShowingTransportOverMap(this);
|
||||
selected[3] = OsmandSettings.isShowingOsmBugs(this);
|
||||
selected[4] = OsmandSettings.isShowingFavorites(this);
|
||||
if(routeInfoInd != -1){
|
||||
selected[routeInfoInd] = routeInfoLayer.isUserDefinedVisible();
|
||||
}
|
||||
if(transportRouteInfoInd != -1){
|
||||
// TODO
|
||||
selected[transportRouteInfoInd] = true;
|
||||
}
|
||||
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMultiChoiceItems(layersList.toArray(new String[layersList.size()]), selected, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
|
||||
|
@ -1115,8 +1133,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
OsmandSettings.setShowingOsmBugs(MapActivity.this, isChecked);
|
||||
} else if(item == 4){
|
||||
OsmandSettings.setShowingFavorites(MapActivity.this, isChecked);
|
||||
} else if(item == routeInfoInd){
|
||||
routeInfoLayer.setVisible(isChecked);
|
||||
} else if(item == transportRouteInfoInd){
|
||||
// TODO
|
||||
}
|
||||
// TODO others
|
||||
updateLayers();
|
||||
mapView.refreshMap();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.List;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.util.FloatMath;
|
||||
import android.widget.Toast;
|
||||
|
@ -24,6 +23,16 @@ public class RoutingHelper {
|
|||
|
||||
private static final org.apache.commons.logging.Log log = LogUtil.getLog(RoutingHelper.class);
|
||||
|
||||
public static interface IRouteInformationListener {
|
||||
|
||||
public void newRouteIsCalculated();
|
||||
|
||||
public void routeWasCancelled();
|
||||
}
|
||||
|
||||
|
||||
private List<IRouteInformationListener> listeners = new ArrayList<IRouteInformationListener>();
|
||||
|
||||
// activity to show messages & refresh map when route is calculated
|
||||
private Context context;
|
||||
|
||||
|
@ -95,8 +104,12 @@ public class RoutingHelper {
|
|||
listDistance = null;
|
||||
directionInfo = null;
|
||||
evalWaitInterval = 3000;
|
||||
for(IRouteInformationListener l : listeners){
|
||||
l.routeWasCancelled();
|
||||
}
|
||||
// to update route
|
||||
setCurrentLocation(currentLocation);
|
||||
|
||||
}
|
||||
|
||||
public void setFinalLocation(LatLon finalLocation){
|
||||
|
@ -162,6 +175,14 @@ public class RoutingHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void addListener(IRouteInformationListener l){
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public boolean removeListener(IRouteInformationListener l){
|
||||
return listeners.remove(l);
|
||||
}
|
||||
|
||||
|
||||
public void setCurrentLocation(Location currentLocation) {
|
||||
if(finalLocation == null || currentLocation == null){
|
||||
|
@ -318,10 +339,9 @@ public class RoutingHelper {
|
|||
currentRoute = 0;
|
||||
if(isFollowingMode){
|
||||
voiceRouter.newRouteIsCalculated();
|
||||
} else {
|
||||
Intent intent = new Intent(context, ShowRouteInfoActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
for(IRouteInformationListener l : listeners){
|
||||
l.newRouteIsCalculated();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
196
OsmAnd/src/com/osmand/views/RouteInfoLayer.java
Normal file
196
OsmAnd/src/com/osmand/views/RouteInfoLayer.java
Normal file
|
@ -0,0 +1,196 @@
|
|||
package com.osmand.views;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.location.Location;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.osmand.activities.RoutingHelper;
|
||||
import com.osmand.activities.ShowRouteInfoActivity;
|
||||
import com.osmand.activities.RoutingHelper.IRouteInformationListener;
|
||||
import com.osmand.activities.RoutingHelper.RouteDirectionInfo;
|
||||
|
||||
public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener {
|
||||
|
||||
|
||||
private OsmandMapTileView view;
|
||||
private final RoutingHelper routingHelper;
|
||||
private Button next;
|
||||
private Button prev;
|
||||
private Button info;
|
||||
private Handler uiHandler;
|
||||
private boolean visible = true;
|
||||
private RectF border;
|
||||
private Paint paintBorder;
|
||||
private Paint paintBlack;
|
||||
private final LinearLayout layout;
|
||||
private int directionInfo = -1;
|
||||
|
||||
public RouteInfoLayer(RoutingHelper routingHelper, LinearLayout layout){
|
||||
this.routingHelper = routingHelper;
|
||||
this.layout = layout;
|
||||
prev = (Button) layout.findViewById(com.osmand.R.id.PreviousButton);
|
||||
next = (Button) layout.findViewById(com.osmand.R.id.NextButton);
|
||||
info = (Button) layout.findViewById(com.osmand.R.id.InfoButton);
|
||||
routingHelper.addListener(this);
|
||||
attachListeners();
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
private void attachListeners() {
|
||||
prev.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(routingHelper.getRouteDirections() != null && directionInfo > 0){
|
||||
directionInfo--;
|
||||
if(routingHelper.getRouteDirections().size() > directionInfo){
|
||||
Location l = routingHelper.getLocationFromRouteDirection(routingHelper.getRouteDirections().get(directionInfo));
|
||||
view.getAnimatedDraggingThread().startMoving(view.getLatitude(), view.getLongitude(),
|
||||
l.getLatitude(), l.getLongitude(),
|
||||
view.getZoom(), view.getZoom(), view.getSourceTileSize(), view.getRotate(), true);
|
||||
}
|
||||
|
||||
}
|
||||
view.refreshMap();
|
||||
}
|
||||
|
||||
});
|
||||
next.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(routingHelper.getRouteDirections() != null && directionInfo < routingHelper.getRouteDirections().size() - 1){
|
||||
directionInfo++;
|
||||
Location l = routingHelper.getLocationFromRouteDirection(routingHelper.getRouteDirections().get(directionInfo));
|
||||
view.getAnimatedDraggingThread().startMoving(view.getLatitude(), view.getLongitude(),
|
||||
l.getLatitude(), l.getLongitude(),
|
||||
view.getZoom(), view.getZoom(), view.getSourceTileSize(), view.getRotate(), true);
|
||||
}
|
||||
view.refreshMap();
|
||||
}
|
||||
|
||||
});
|
||||
info.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(view.getContext(), ShowRouteInfoActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
view.getContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean isVisible(){
|
||||
return visible && routingHelper.isRouteCalculated() && !routingHelper.isFollowingMode();
|
||||
}
|
||||
public boolean couldBeVisible(){
|
||||
return routingHelper.isRouteCalculated() && !routingHelper.isFollowingMode();
|
||||
}
|
||||
private void updateVisibility(){
|
||||
int vis = isVisible() ? View.VISIBLE : View.INVISIBLE;
|
||||
prev.setVisibility(vis);
|
||||
next.setVisibility(vis);
|
||||
info.setVisibility(vis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
uiHandler = new Handler();
|
||||
border = new RectF();
|
||||
paintBorder = new Paint();
|
||||
paintBorder.setARGB(220, 160, 160, 160);
|
||||
paintBorder.setStyle(Style.FILL);
|
||||
paintBlack = new Paint();
|
||||
paintBlack.setARGB(255, 0, 0, 0);
|
||||
paintBlack.setStyle(Style.STROKE);
|
||||
paintBlack.setAntiAlias(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
if(isVisible()){
|
||||
border.set(layout.getLeft() - 10, layout.getTop() - 3, layout.getRight() - 8, layout.getBottom() + 3);
|
||||
canvas.drawRoundRect(border, 5, 5, paintBorder);
|
||||
canvas.drawRoundRect(border, 5, 5, paintBlack);
|
||||
List<RouteDirectionInfo> dir = routingHelper.getRouteDirections();
|
||||
if(dir != null && directionInfo < dir.size() && directionInfo >= 0){
|
||||
canvas.rotate(view.getRotate(), view.getCenterPointX(), view.getCenterPointY());
|
||||
RouteDirectionInfo info = dir.get(directionInfo);
|
||||
Location loc = routingHelper.getLocationFromRouteDirection(info);
|
||||
int x = view.getRotatedMapXForPoint(loc.getLatitude(), loc.getLongitude());
|
||||
int y = view.getRotatedMapYForPoint(loc.getLatitude(), loc.getLongitude());
|
||||
canvas.drawCircle(x, y, 5, paintBorder);
|
||||
canvas.drawCircle(x, y, 5, paintBlack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drawInScreenPixels() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongPressEvent(PointF point) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(PointF point) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newRouteIsCalculated() {
|
||||
uiHandler.post(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
directionInfo = -1;
|
||||
if(!routingHelper.isFollowingMode()){
|
||||
visible = true;
|
||||
}
|
||||
updateVisibility();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public boolean isUserDefinedVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
updateVisibility();
|
||||
}
|
||||
@Override
|
||||
public void routeWasCancelled() {
|
||||
uiHandler.post(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
directionInfo = -1;
|
||||
updateVisibility();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue