From 344c0b9b8e3639b62e4807438c1a5ff3b4aab0bb Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 9 Jun 2010 12:06:59 +0000 Subject: [PATCH] fix menu, fix context menu git-svn-id: https://osmand.googlecode.com/svn/trunk@146 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 15 ++-- .../com/osmand/osm/util/MinskTransReader.java | 11 --- OsmAnd/res/menu/map_menu.xml | 11 +-- OsmAnd/res/values/strings.xml | 4 +- OsmAnd/src/com/osmand/ResourceManager.java | 20 ++++- .../com/osmand/activities/MapActivity.java | 83 +++++++++++++++---- OsmAnd/src/com/osmand/views/MapInfoLayer.java | 3 + OsmAnd/src/com/osmand/views/OsmBugsLayer.java | 4 +- .../com/osmand/views/OsmandMapTileView.java | 31 ++++++- 9 files changed, 134 insertions(+), 48 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index e599a257e6..8a195662c3 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -46,24 +46,25 @@ public class ToDoConstants { // 34. Investigate routing (bicycle, car) // 36. Postcode search // 37. Get rid of exit button (!). Think about when notification should go & how clear resources if it is necessary -// 38. Add Button in search navigate to. +// 38. Add button in search "navigate to". // BUGS Android - // 1. Fix bug with navigation layout (less zoom controls) (fixed). - // 4. Fix layout problems with add comment (fixed) - // 3. Implement clear existing area with tiles (update map) + // 1. Fix bug with navigation layout (less zoom controls) [fixed]. + // 4. Fix layout problems with add comment [fixed] + // 7. Fix set location (clear sync with gps) [fixed] + // 3. Implement clear existing area with tiles (update map) [fixed] + // 6. Implement context menu for long press & trackball press [fixed - trackball todo] // 2. Include to amenity index : historic, sport, .... // 5. Implement caching files existing on FS, implement specific method in RM - // 7. Fix set location (clear sync with gps) - // Improvements - // 6. Implement context menu for long press & trackball press + // TODO swing // 2. Internal (Simplify MapPanel - introduce layers for it)ю // 3. Implement clear progress. + // 4. Fix issues with big files (such as netherlands) // 1. Download tiles without using dir tiles diff --git a/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java b/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java index c2562df14c..b518bc894f 100644 --- a/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java +++ b/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java @@ -1,9 +1,5 @@ package com.osmand.osm.util; -import java.awt.BorderLayout; -import java.awt.Container; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -21,11 +17,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.swing.JFrame; -import javax.swing.JMenuBar; -import javax.swing.UIManager; -import javax.xml.stream.XMLStreamException; - import org.xml.sax.SAXException; import com.osmand.data.DataTileManager; @@ -40,8 +31,6 @@ import com.osmand.osm.Way; import com.osmand.osm.OSMSettings.OSMTagKey; import com.osmand.osm.io.IOsmStorageFilter; import com.osmand.osm.io.OsmBaseStorage; -import com.osmand.osm.io.OsmStorageWriter; -import com.osmand.swing.DataExtractionSettings; import com.osmand.swing.MapPanel; public class MinskTransReader { diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml index 3f67971e87..a9da0836f1 100644 --- a/OsmAnd/res/menu/map_menu.xml +++ b/OsmAnd/res/menu/map_menu.xml @@ -1,11 +1,12 @@ - - - - - + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ffcb2e221d..ef1736f5f0 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,8 +1,10 @@ + Update map + Reload tile Input user name to communicate osm User name - Mark point + Target Show open street bugs on map Show open street bugs List of favourite points diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index f2c1564c76..349fe8ddbf 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -81,11 +81,11 @@ public class ResourceManager { ////////////////////////////////////////////// Working with tiles //////////////////////////////////////////////// - public Bitmap getTileImageForMapAsync(ITileSource map, int x, int y, int zoom, boolean loadFromInternetIfNeeded) { return getTileImageForMap(map, x, y, zoom, loadFromInternetIfNeeded, false, true); } + public Bitmap getTileImageFromCache(ITileSource map, int x, int y, int zoom){ return getTileImageForMap(map, x, y, zoom, false, false, false); } @@ -99,10 +99,18 @@ public class ResourceManager { return false; } + public void clearTileImageForMap(ITileSource map, int x, int y, int zoom){ + getTileImageForMap(map, x, y, zoom, true, false, false, true); + } + protected Bitmap getTileImageForMap(ITileSource map, int x, int y, int zoom, + boolean loadFromInternetIfNeeded, boolean sync, boolean loadFromFs) { + return getTileImageForMap(map, x, y, zoom, loadFromInternetIfNeeded, sync, loadFromFs, false); + } + // introduce cache in order save memory protected StringBuilder builder = new StringBuilder(40); protected synchronized Bitmap getTileImageForMap(ITileSource map, int x, int y, int zoom, - boolean loadFromInternetIfNeeded, boolean sync, boolean loadFromFs) { + boolean loadFromInternetIfNeeded, boolean sync, boolean loadFromFs, boolean deleteBefore) { if (map == null) { return null; } @@ -110,6 +118,14 @@ public class ResourceManager { builder.append(map.getName()).append('/').append(zoom). append('/').append(x). append('/').append(y).append(map.getTileFormat()).append(".tile"); String file = builder.toString(); + if(deleteBefore){ + cacheOfImages.remove(file); + File f = new File(dirWithTiles, file); + if(f.exists()){ + f.delete(); + } + } + if (loadFromFs && cacheOfImages.get(file) == null) { String url = loadFromInternetIfNeeded ? map.getUrlToLoad(x, y, zoom) : null; TileLoadDownloadRequest req = new TileLoadDownloadRequest(dirWithTiles, file, url, new File(dirWithTiles, file), diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 8335ce8de9..7024794eef 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -6,6 +6,7 @@ import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.PointF; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; @@ -67,6 +68,8 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat private WakeLock wakeLock; private boolean sensorRegistered = false; + private MenuItem navigateToPointMenu; + private boolean isMapLinkedToLocation(){ return OsmandSettings.isMapSyncToGpsLocation(this); } @@ -149,6 +152,22 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } }); + mapView.setOnLongClickListener(new OsmandMapTileView.OnLongClickListener(){ + + @Override + public boolean onLongPressEvent(PointF point) { + float dx = point.x - mapView.getCenterPointX(); + float dy = point.y - mapView.getCenterPointY(); + float fy = mapView.calcDiffTileY(dx, dy); + float fx = mapView.calcDiffTileX(dx, dy); + double latitude = MapUtils.getLatitudeFromTile(mapView.getZoom(), mapView.getYTile() + fy); + double longitude = MapUtils.getLongitudeFromTile(mapView.getZoom(), mapView.getXTile() + fx); + contextMenuPoint(latitude, longitude); + return true; + } + + }); + } @@ -172,6 +191,10 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat double lon = MapUtils.getLongitudeFromTile(mapView.getZoom(), x); setMapLocation(lat, lon); return true; + // that doesn't work for now +// } else if(event.getAction() == MotionEvent.ACTION_UP){ +// contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); +// return true; } return super.onTrackballEvent(event); } @@ -225,13 +248,13 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } public void navigateToPoint(LatLon point){ - if(point != null){ OsmandSettings.setPointToNavigate(this, point.getLatitude(), point.getLongitude()); } else { OsmandSettings.clearPointToNavigate(this); } navigationLayer.setPointToNavigate(point); + updateNavigateToPointMenu(); } public Location getLastKnownLocation(){ @@ -373,18 +396,21 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat locationLayer.setHeading(event.values[0]); } + private void updateNavigateToPointMenu(){ + if (navigateToPointMenu != null) { + if (OsmandSettings.getPointToNavigate(this) != null) { + navigateToPointMenu.setVisible(true); + } else { + navigateToPointMenu.setVisible(false); + } + } + } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.map_menu, menu); - MenuItem item = menu.findItem(R.id.map_navigate_to_point); - if (item != null) { - if (OsmandSettings.getPointToNavigate(this) != null) { - item.setTitle(R.string.stop_navigation); - } else { - item.setTitle(R.string.navigate_to_point); - } - } + navigateToPointMenu = menu.findItem(R.id.map_navigate_to_point); + updateNavigateToPointMenu(); return true; } @@ -395,7 +421,10 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat startActivity(settings); return true; } else if (item.getItemId() == R.id.map_mark_point) { - markPoint(); + contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); + return true; + } else if (item.getItemId() == R.id.map_reload_tile) { + reloadTile(mapView.getZoom(), mapView.getLatitude(), mapView.getLongitude()); return true; } else if (item.getItemId() == R.id.map_specify_point) { openChangeLocationDialog(); @@ -410,18 +439,36 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat return super.onOptionsItemSelected(item); } - protected void markPoint(){ + protected void reloadTile(final int zoom, final double latitude, final double longitude){ Builder builder = new AlertDialog.Builder(this); - builder.setItems(new String[]{"Navigate to point", "Add to favourites", "Open osm bug"}, new DialogInterface.OnClickListener(){ + builder.setMessage("Tile image will be removed from file system. Do you want to reload tile from internet?"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Yes", new DialogInterface.OnClickListener(){ + @Override + public void onClick(DialogInterface dialog, int which) { + int x = (int) MapUtils.getTileNumberX(zoom, longitude); + int y = (int) MapUtils.getTileNumberY(zoom, latitude); + ResourceManager.getResourceManager().clearTileImageForMap(mapView.getMap(), x, y, zoom); + mapView.refreshMap(); + } + }); + builder.create().show(); + } + + protected void contextMenuPoint(final double latitude, final double longitude){ + Builder builder = new AlertDialog.Builder(this); + builder.setItems(new String[]{"Navigate to point", "Add to favourites", "Update map", "Open osm bug"}, new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { if(which == 0){ - navigateToPoint(new LatLon(mapView.getLatitude(), mapView.getLongitude())); + navigateToPoint(new LatLon(latitude, longitude)); } else if(which == 1){ - addFavouritePoint(); + addFavouritePoint(latitude, longitude); } else if(which == 2){ - osmBugsLayer.openBug(MapActivity.this, getLayoutInflater(), mapView); + reloadTile(mapView.getZoom(), latitude, longitude); + } else if(which == 3){ + osmBugsLayer.openBug(MapActivity.this, getLayoutInflater(), mapView, latitude, longitude); } } }); @@ -429,10 +476,10 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } - protected void addFavouritePoint(){ + protected void addFavouritePoint(double latitude, double longitude){ final FavouritePoint p = new FavouritesActivity.FavouritePoint(); - p.setLatitude(mapView.getLatitude()); - p.setLongitude(mapView.getLongitude()); + p.setLatitude(latitude); + p.setLongitude(longitude); p.setName("Favourite"); Builder builder = new AlertDialog.Builder(this); diff --git a/OsmAnd/src/com/osmand/views/MapInfoLayer.java b/OsmAnd/src/com/osmand/views/MapInfoLayer.java index 1b2a01b169..b15fda466a 100644 --- a/OsmAnd/src/com/osmand/views/MapInfoLayer.java +++ b/OsmAnd/src/com/osmand/views/MapInfoLayer.java @@ -113,6 +113,9 @@ public class MapInfoLayer implements OsmandMapLayer { } } } + } else { + cachedMeters = 0; + cachedDistString = null; } if(view.getZoom() != cachedZoom){ cachedZoom = view.getZoom(); diff --git a/OsmAnd/src/com/osmand/views/OsmBugsLayer.java b/OsmAnd/src/com/osmand/views/OsmBugsLayer.java index 74b6e9df38..5ab9c3f7a1 100644 --- a/OsmAnd/src/com/osmand/views/OsmBugsLayer.java +++ b/OsmAnd/src/com/osmand/views/OsmBugsLayer.java @@ -338,7 +338,7 @@ public class OsmBugsLayer implements OsmandMapLayer { } - public void openBug(final Context ctx, LayoutInflater layoutInflater, final OsmandMapTileView mapView){ + public void openBug(final Context ctx, LayoutInflater layoutInflater, final OsmandMapTileView mapView, final double latitude, final double longitude){ Builder builder = new AlertDialog.Builder(ctx); builder.setTitle("Input text of bug"); final View view = layoutInflater.inflate(R.layout.open_bug, null); @@ -351,7 +351,7 @@ public class OsmBugsLayer implements OsmandMapLayer { String text = ((EditText)view.findViewById(R.id.BugMessage)).getText().toString(); String author = ((EditText)view.findViewById(R.id.AuthorName)).getText().toString(); OsmandSettings.setUserName(ctx, author); - boolean bug = createNewBug(mapView.getLatitude(), mapView.getLongitude(), + boolean bug = createNewBug(latitude, longitude, text, author); if (bug) { Toast.makeText(ctx, "Bug was successfully created", Toast.LENGTH_LONG).show(); diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index 810d69e8df..5b4dbd4454 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -45,6 +45,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall protected final int timeForDraggingAnimation = 300; protected final int minimumDistanceForDraggingAnimation = 40; + public interface OnLongClickListener { + public boolean onLongPressEvent(PointF point); + } + public interface OnClickListener { + public boolean onPressEvent(PointF point); + } + protected static final Log log = LogUtil.getLog(OsmandMapTileView.class); /** @@ -65,6 +72,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall private IMapLocationListener locationListener; + private OnLongClickListener onLongClickListener; + + private OnClickListener onClickListener; + private List layers = new ArrayList(); // UI Part @@ -120,8 +131,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall setClickable(true); setLongClickable(true); - setOnLongClickListener(this); - setOnClickListener(this); + super.setOnLongClickListener(this); + super.setOnClickListener(this); getHolder().addCallback(this); @@ -620,9 +631,21 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall return true; } } + if(onLongClickListener != null && onLongClickListener.onLongPressEvent(point)){ + return true; + } } + return false; } + + public void setOnLongClickListener(OnLongClickListener l) { + this.onLongClickListener = l; + } + + public void setOnClickListener(OnClickListener l) { + this.onClickListener = l; + } @Override public void onClick(View v) { @@ -637,9 +660,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall return; } } + if(onClickListener != null && onClickListener.onPressEvent(point)){ + return; + } } } +