Issue 416 allow to user share location
This commit is contained in:
parent
a7caa6caee
commit
a7cdc87553
5 changed files with 132 additions and 24 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="add_waypoint_dialog_added">Точка \'\'{0}\'\' была успешно добавлена</string>
|
||||
<string name="send_location_way_choose_title">Поделиться используя</string>
|
||||
<string name="send_location_sms_pattern">Я нахожусь : {0} , {1}</string>
|
||||
<string name="send_location_email_pattern">Чтобы увидить местоположение следуйте ссылке {0} или android ссылке {1}</string>
|
||||
<string name="send_location">Отправить местоположение</string>
|
||||
<string name="context_menu_item_share_location">Поделиться</string>
|
||||
<string name="add_waypoint_dialog_added">Точка \'\'{0}\'\' была успешно добавлена</string>
|
||||
<string name="add_waypoint_dialog_title">Добавить точку к записи GPX трека</string>
|
||||
<string name="context_menu_item_add_waypoint">Добавить точку к треку</string>
|
||||
<string name="amenity_type_administrative">Административное</string>
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="send_location_way_choose_title">Share location using</string>
|
||||
<string name="send_location_sms_pattern">Mine location : {0} ; {1}</string>
|
||||
<string name="send_location_email_pattern">To see location follow the web browser link {0} or android intent link {1}</string>
|
||||
<string name="send_location">Send location</string>
|
||||
<string name="context_menu_item_share_location">Share location</string>
|
||||
<string name="add_waypoint_dialog_added">Waypoint \'\'{0}\'\' was successfully added</string>
|
||||
<string name="add_waypoint_dialog_title">Add waypoint to recorded GPX track</string>
|
||||
<string name="context_menu_item_add_waypoint">Add Gpx waypoint</string>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String> 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<String> actions = new ArrayList<String>();
|
||||
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; j<contextMenuStandardActions.length; j++){
|
||||
actions.add(getResources().getString(contextMenuStandardActions[j]));
|
||||
}
|
||||
|
||||
builder.setItems(actions.toArray(new String[actions.size()]), new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override
|
||||
|
@ -1616,34 +1624,36 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
additionalActions.onClick(dialog, which);
|
||||
return;
|
||||
}
|
||||
which -= sizeAdditional;
|
||||
if(which == 0){
|
||||
int standardId = contextMenuStandardActions[which - sizeAdditional];
|
||||
if(standardId == R.string.context_menu_item_navigate_point){
|
||||
navigateToPoint(new LatLon(latitude, longitude));
|
||||
} else if(which == 1){
|
||||
} else if(standardId == R.string.context_menu_item_search_poi){
|
||||
Intent intent = new Intent(MapActivity.this, SearchPoiFilterActivity.class);
|
||||
intent.putExtra(SearchPoiFilterActivity.SEARCH_LAT, latitude);
|
||||
intent.putExtra(SearchPoiFilterActivity.SEARCH_LON, longitude);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
} else if(which == 2){
|
||||
} else if(standardId == R.string.context_menu_item_show_route){
|
||||
getDirections(latitude, longitude, false);
|
||||
} else if(which == 3){
|
||||
} else if(standardId == R.string.context_menu_item_search_transport){
|
||||
Intent intent = new Intent(MapActivity.this, SearchTransportActivity.class);
|
||||
intent.putExtra(SearchTransportActivity.LAT_KEY, latitude);
|
||||
intent.putExtra(SearchTransportActivity.LON_KEY, longitude);
|
||||
startActivity(intent);
|
||||
} else if(which == 4){
|
||||
} else if(standardId == R.string.context_menu_item_add_favorite){
|
||||
addFavouritePoint(latitude, longitude);
|
||||
} else if(which == 5){
|
||||
} else if(standardId == R.string.context_menu_item_share_location){
|
||||
shareLocation(latitude, longitude, mapView.getZoom());
|
||||
} else if(standardId == R.string.context_menu_item_search_poi){
|
||||
EditingPOIActivity activity = new EditingPOIActivity(MapActivity.this, (OsmandApplication) getApplication(), mapView);
|
||||
activity.showCreateDialog(latitude, longitude);
|
||||
} else if(which == 6){
|
||||
} else if(standardId == R.string.context_menu_item_add_waypoint){
|
||||
addWaypoint(latitude, longitude);
|
||||
} else if(which == 7){
|
||||
} else if(standardId == R.string.context_menu_item_open_bug){
|
||||
osmBugsLayer.openBug(MapActivity.this, getLayoutInflater(), mapView, latitude, longitude);
|
||||
} else if(which == 8){
|
||||
} else if(standardId == R.string.context_menu_item_update_map){
|
||||
reloadTile(mapView.getZoom(), latitude, longitude);
|
||||
} else if(which == 9){
|
||||
} else if(standardId == R.string.context_menu_item_download_map){
|
||||
DownloadTilesDialog dlg = new DownloadTilesDialog(MapActivity.this,
|
||||
(OsmandApplication) getApplication(), mapView);
|
||||
dlg.openDialog();
|
||||
|
@ -1731,6 +1741,44 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
builder.create().show();
|
||||
}
|
||||
|
||||
protected void shareLocation(final double latitude, final double longitude, int zoom){
|
||||
final String shortOsmUrl = MapUtils.buildShortOsmUrl(latitude, longitude, zoom);
|
||||
final String simpleGeo = "geo:"+((float) latitude)+","+((float)longitude) +"?z="+zoom;
|
||||
//final String geoIntent = "<a href=\""+simpleGeo+"\">geo link</a>";
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue