From a7cdc87553bf99c099614776a6455c7f7c8f6f88 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 29 Apr 2011 00:10:15 +0200 Subject: [PATCH] Issue 416 allow to user share location --- .../src/net/osmand/osm/MapUtils.java | 51 ++++++++++ OsmAnd/res/values-ru/strings.xml | 7 +- OsmAnd/res/values/strings.xml | 5 + .../plus/activities/MainMenuActivity.java | 1 - .../osmand/plus/activities/MapActivity.java | 92 ++++++++++++++----- 5 files changed, 132 insertions(+), 24 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/osm/MapUtils.java b/DataExtractionOSM/src/net/osmand/osm/MapUtils.java index 987a1f0e4a..a5e8649daa 100644 --- a/DataExtractionOSM/src/net/osmand/osm/MapUtils.java +++ b/DataExtractionOSM/src/net/osmand/osm/MapUtils.java @@ -18,6 +18,22 @@ import net.osmand.data.MapObject; * */ public class MapUtils { + + private static final String BASE_SHORT_OSM_URL = "http://osm.org/go/"; + + /** + * This array is a lookup table that translates 6-bit positive integer + * index values into their "Base64 Alphabet" equivalents as specified + * in Table 1 of RFC 2045. + */ + private static final char intToBase64[] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '@' + }; + public static double getDistance(Node e1, Node e2){ return getDistance(e1.getLatitude(), e1.getLongitude(), e2.getLatitude(), e2.getLongitude()); } @@ -294,5 +310,40 @@ public class MapUtils { }); } + // Examples +// System.out.println(buildShortOsmUrl(51.51829d, 0.07347d, 16)); // http://osm.org/go/0EEQsyfu +// System.out.println(buildShortOsmUrl(52.30103d, 4.862927d, 18)); // http://osm.org/go/0E4_JiVhs +// System.out.println(buildShortOsmUrl(40.59d, -115.213d, 9)); // http://osm.org/go/TelHTB-- + public static String buildShortOsmUrl(double latitude, double longitude, int zoom){ + long lat = (long) (((latitude + 90d)/180d)*(1l << 32)); + long lon = (long) (((longitude + 180d)/360d)*(1l << 32)); + long code = interleaveBits(lon, lat); + StringBuilder str = new StringBuilder(10); + str.append(BASE_SHORT_OSM_URL); + // add eight to the zoom level, which approximates an accuracy of one pixel in a tile. + for(int i=0; i< Math.ceil((zoom+8)/3d); i++){ + str.append(intToBase64[(int) ((code >> (58 - 6 * i)) & 0x3f)]); + } + // append characters onto the end of the string to represent + // partial zoom levels (characters themselves have a granularity of 3 zoom levels). + for(int j=0; j< (zoom + 8) % 3 ; j++){ + str.append('-'); + } + str.append("?m"); + return str.toString(); + } + + /** + * interleaves the bits of two 32-bit numbers. the result is known as a Morton code. + */ + private static long interleaveBits(long x, long y){ + long c = 0; + for(byte b = 31; b>=0; b--){ + c = (c << 1) | ((x >> b) & 1); + c = (c << 1) | ((y >> b) & 1); + } + return c; + } + } diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 5d3eb08aa5..93e22c529d 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,6 +1,11 @@ -Точка \'\'{0}\'\' была успешно добавлена + Поделиться используя + Я нахожусь : {0} , {1} + Чтобы увидить местоположение следуйте ссылке {0} или android ссылке {1} + Отправить местоположение + Поделиться + Точка \'\'{0}\'\' была успешно добавлена Добавить точку к записи GPX трека Добавить точку к треку Административное diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index e4647fe8fd..9eede4d469 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,10 @@ + Share location using + Mine location : {0} ; {1} + To see location follow the web browser link {0} or android intent link {1} + Send location + Share location Waypoint \'\'{0}\'\' was successfully added Add waypoint to recorded GPX track Add Gpx waypoint diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index 99d946802d..d603e56ff8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -21,7 +21,6 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Environment; import android.text.SpannableString; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 1f117beca7..420f2ee4c5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -96,6 +96,8 @@ import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.os.PowerManager.WakeLock; +import android.text.ClipboardManager; +import android.text.Html; import android.util.FloatMath; import android.util.Log; import android.view.KeyEvent; @@ -1592,22 +1594,28 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso public void contextMenuPoint(final double latitude, final double longitude, List additionalItems, final DialogInterface.OnClickListener additionalActions){ Builder builder = new AlertDialog.Builder(this); - Resources resources = this.getResources(); final int sizeAdditional = additionalActions == null || additionalItems == null ? 0 : additionalItems.size(); List actions = new ArrayList(); if(sizeAdditional > 0){ actions.addAll(additionalItems); } - actions.add(resources.getString(R.string.context_menu_item_navigate_point)); - actions.add(resources.getString(R.string.context_menu_item_search_poi)); - actions.add(resources.getString(R.string.context_menu_item_show_route)); - actions.add(resources.getString(R.string.context_menu_item_search_transport)); - actions.add(resources.getString(R.string.context_menu_item_add_favorite)); - actions.add(resources.getString(R.string.context_menu_item_create_poi)); - actions.add(resources.getString(R.string.context_menu_item_add_waypoint)); - actions.add(resources.getString(R.string.context_menu_item_open_bug)); - actions.add(resources.getString(R.string.context_menu_item_update_map)); - actions.add(resources.getString(R.string.context_menu_item_download_map)); + final int[] contextMenuStandardActions = new int[]{ + R.string.context_menu_item_navigate_point, + R.string.context_menu_item_search_poi, + R.string.context_menu_item_show_route, + R.string.context_menu_item_search_transport, + R.string.context_menu_item_add_favorite, + R.string.context_menu_item_share_location, + R.string.context_menu_item_create_poi, + R.string.context_menu_item_add_waypoint, + R.string.context_menu_item_open_bug, + R.string.context_menu_item_update_map, + R.string.context_menu_item_download_map + }; + for(int j = 0; jgeo link"; + + AlertDialog.Builder builder = new Builder(this); + builder.setTitle(R.string.send_location_way_choose_title); + builder.setItems(new String[]{ + "Email", "SMS", "Clipboard" + }, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String sms = MessageFormat.format(getString(R.string.send_location_sms_pattern), shortOsmUrl, simpleGeo); + String email = MessageFormat.format(getString(R.string.send_location_email_pattern), shortOsmUrl, simpleGeo ); + if(which == 0){ + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$ + intent.putExtra(Intent.EXTRA_SUBJECT, "Mine location"); //$NON-NLS-1$ + intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(email)); + intent.setType("text/html"); + startActivity(Intent.createChooser(intent, getString(R.string.send_location))); + } else if(which == 1){ + Intent sendIntent = new Intent(Intent.ACTION_VIEW); + sendIntent.putExtra("sms_body", sms); + sendIntent.setType("vnd.android-dir/mms-sms"); + startActivity(sendIntent); + } else if (which == 2){ + ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + clipboard.setText(sms); + } + + } + }); + + builder.show(); + } + private void openChangeLocationDialog() { NavigatePointActivity dlg = new NavigatePointActivity(this);