From 2ec706819777a0f5fcaf835487c81dafb7870503 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 28 May 2010 13:19:56 +0000 Subject: [PATCH] implement dialog go to point by location git-svn-id: https://osmand.googlecode.com/svn/trunk@93 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../data/preparation/MapTileDownloader.java | 4 +- OsmAnd/res/layout-land/navigate_point.xml | 31 +++++ OsmAnd/res/layout/navigate_point.xml | 32 +++++ OsmAnd/res/menu/map_menu.xml | 1 + OsmAnd/res/values/strings.xml | 2 + .../com/osmand/activities/MapActivity.java | 8 ++ .../activities/NavigatePointDialog.java | 129 ++++++++++++++++++ 7 files changed, 204 insertions(+), 3 deletions(-) create mode 100644 OsmAnd/res/layout-land/navigate_point.xml create mode 100644 OsmAnd/res/layout/navigate_point.xml create mode 100644 OsmAnd/src/com/osmand/activities/NavigatePointDialog.java diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java index 67b3129044..5aafb44b71 100644 --- a/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java @@ -131,9 +131,7 @@ public class MapTileDownloader { public void refuseAllPreviousRequests(){ - while(!threadPoolExecutor.getQueue().isEmpty()){ - threadPoolExecutor.getQueue().remove(); - } + threadPoolExecutor.getQueue().clear(); } public void requestToDownload(DownloadRequest request){ diff --git a/OsmAnd/res/layout-land/navigate_point.xml b/OsmAnd/res/layout-land/navigate_point.xml new file mode 100644 index 0000000000..3a82dc182b --- /dev/null +++ b/OsmAnd/res/layout-land/navigate_point.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/navigate_point.xml b/OsmAnd/res/layout/navigate_point.xml new file mode 100644 index 0000000000..ea47a8ad74 --- /dev/null +++ b/OsmAnd/res/layout/navigate_point.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml index 670992345e..f4ccf9ba99 100644 --- a/OsmAnd/res/menu/map_menu.xml +++ b/OsmAnd/res/menu/map_menu.xml @@ -4,5 +4,6 @@ + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 32680fdfbe..1e696bd29c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,6 @@ + Specify point Show aspect of vew based on compass Show aspect of view Unmark location @@ -29,4 +30,5 @@ #CFFACD search #FFFFFF +#FF0000 diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index c7c2c78b85..07ca01edc4 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -328,6 +328,9 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat final Intent settings = new Intent(MapActivity.this, SettingsActivity.class); startActivity(settings); return true; + } else if (item.getItemId() == R.id.map_specify_point) { + openChangeLocationDialog(); + return true; } else if (item.getItemId() == R.id.map_navigate_to_point) { if(navigationLayer.getPointToNavigate() != null){ item.setTitle(R.string.navigate_to_point); @@ -340,6 +343,11 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat return super.onOptionsItemSelected(item); } + private void openChangeLocationDialog() { + NavigatePointDialog dlg = new NavigatePointDialog(this, mapView); + dlg.showDialog(); + } + @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } diff --git a/OsmAnd/src/com/osmand/activities/NavigatePointDialog.java b/OsmAnd/src/com/osmand/activities/NavigatePointDialog.java new file mode 100644 index 0000000000..95dda2b814 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/NavigatePointDialog.java @@ -0,0 +1,129 @@ +package com.osmand.activities; + +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + +import android.app.Dialog; +import android.content.Context; +import android.location.Location; +import android.view.View; +import android.widget.Button; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; + +import com.osmand.OsmandSettings; +import com.osmand.R; +import com.osmand.views.OsmandMapTileView; + +public class NavigatePointDialog { + Dialog dlg; + OsmandMapTileView view; + int currentFormat = Location.FORMAT_DEGREES; + + public NavigatePointDialog(Context ctx, OsmandMapTileView view){ + this.view = view; + dlg = new Dialog(ctx); + initUI(view.getLatitude(), view.getLongitude()); + } + + public void initUI(double latitude, double longitude){ + dlg.setContentView(R.layout.navigate_point); + dlg.setTitle("Navigate to point"); + ((TextView)dlg.findViewById(R.id.LatitudeEdit)).setText(convert(latitude, Location.FORMAT_DEGREES)); + ((TextView)dlg.findViewById(R.id.LongitudeEdit)).setText(convert(longitude, Location.FORMAT_DEGREES)); + ((RadioButton)dlg.findViewById(R.id.Format1)).setChecked(true); + ((RadioGroup)dlg.findViewById(R.id.RadioGroup01)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + int newFormat = currentFormat; + if(checkedId == R.id.Format1){ + newFormat = Location.FORMAT_DEGREES; + } else if(checkedId == R.id.Format2){ + newFormat = Location.FORMAT_MINUTES; + } else if(checkedId == R.id.Format3){ + newFormat = Location.FORMAT_SECONDS; + } + try { + double lat = Location.convert(((TextView) dlg.findViewById(R.id.LatitudeEdit)).getText().toString()); + double lon = Location.convert(((TextView) dlg.findViewById(R.id.LongitudeEdit)).getText().toString()); + ((TextView)dlg.findViewById(R.id.LatitudeEdit)).setText(convert(lat, newFormat)); + ((TextView)dlg.findViewById(R.id.LongitudeEdit)).setText(convert(lon, newFormat)); + } catch (RuntimeException e) { + } + } + + }); + ((Button) dlg.findViewById(R.id.Cancel)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dlg.dismiss(); + } + }); + ((Button) dlg.findViewById(R.id.ShowOnMap)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + double lat = Location.convert(((TextView) dlg.findViewById(R.id.LatitudeEdit)).getText().toString()); + double lon = Location.convert(((TextView) dlg.findViewById(R.id.LongitudeEdit)).getText().toString()); + if(view != null) { + view.setLatLon(lat, lon); + } else { + OsmandSettings.setLastKnownMapLocation(dlg.getContext(), lat, lon); + } + dlg.dismiss(); + } catch (RuntimeException e) { + ((TextView) dlg.findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); + } + } + }); + } + + + // THIS code is copied from Location.convert() in order to change locale + public static final int FORMAT_DEGREES = 0; + public static final int FORMAT_MINUTES = 1; + public static final int FORMAT_SECONDS = 2; + + public static String convert(double coordinate, int outputType) { + if (coordinate < -180.0 || coordinate > 180.0 || Double.isNaN(coordinate)) { + throw new IllegalArgumentException("coordinate=" + coordinate); + } + if ((outputType != FORMAT_DEGREES) && (outputType != FORMAT_MINUTES) && (outputType != FORMAT_SECONDS)) { + throw new IllegalArgumentException("outputType=" + outputType); + } + + StringBuilder sb = new StringBuilder(); + + // Handle negative values + if (coordinate < 0) { + sb.append('-'); + coordinate = -coordinate; + } + + DecimalFormat df = new DecimalFormat("###.#####", new DecimalFormatSymbols(Locale.US)); + if (outputType == FORMAT_MINUTES || outputType == FORMAT_SECONDS) { + int degrees = (int) Math.floor(coordinate); + sb.append(degrees); + sb.append(':'); + coordinate -= degrees; + coordinate *= 60.0; + if (outputType == FORMAT_SECONDS) { + int minutes = (int) Math.floor(coordinate); + sb.append(minutes); + sb.append(':'); + coordinate -= minutes; + coordinate *= 60.0; + } + } + sb.append(df.format(coordinate)); + return sb.toString(); + } + + public void showDialog(){ + dlg.show(); + } + +}