Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-09-04 11:29:12 +02:00
commit 8dd9cdced4
30 changed files with 1254 additions and 65 deletions

View file

@ -78,7 +78,8 @@
android:text="•" android:text="•"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size" android:textSize="@dimen/default_sub_text_size"
android:visibility="gone"/> android:visibility="gone"
tools:visibility="visible"/>
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:id="@+id/map_marker_description" android:id="@+id/map_marker_description"
@ -101,12 +102,12 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end" android:layout_gravity="center_vertical|end"
android:layout_marginBottom="16dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="16dp"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:paddingBottom="16dp"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingTop="16dp"
tools:src="@drawable/ic_overflow_menu_white"/> tools:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout> </LinearLayout>

View file

@ -41,6 +41,14 @@ import net.osmand.aidl.maplayer.AddMapLayerParams;
import net.osmand.aidl.maplayer.RemoveMapLayerParams; import net.osmand.aidl.maplayer.RemoveMapLayerParams;
import net.osmand.aidl.maplayer.UpdateMapLayerParams; import net.osmand.aidl.maplayer.UpdateMapLayerParams;
import net.osmand.aidl.navigation.NavigateParams;
import net.osmand.aidl.navigation.NavigateGpxParams;
import net.osmand.aidl.note.TakePhotoNoteParams;
import net.osmand.aidl.note.StartVideoRecordingParams;
import net.osmand.aidl.note.StartAudioRecordingParams;
import net.osmand.aidl.note.StopRecordingParams;
// NOTE: Add new methods at the end of file!!! // NOTE: Add new methods at the end of file!!!
interface IOsmAndAidlInterface { interface IOsmAndAidlInterface {
@ -82,4 +90,12 @@ interface IOsmAndAidlInterface {
boolean startGpxRecording(in StartGpxRecordingParams params); boolean startGpxRecording(in StartGpxRecordingParams params);
boolean stopGpxRecording(in StopGpxRecordingParams params); boolean stopGpxRecording(in StopGpxRecordingParams params);
boolean takePhotoNote(in TakePhotoNoteParams params);
boolean startVideoRecording(in StartVideoRecordingParams params);
boolean startAudioRecording(in StartAudioRecordingParams params);
boolean stopRecording(in StopRecordingParams params);
boolean navigate(in NavigateParams params);
boolean navigateGpx(in NavigateGpxParams params);
} }

View file

@ -2,11 +2,14 @@ package net.osmand.aidl;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -22,6 +25,7 @@ import net.osmand.aidl.mapwidget.AMapWidget;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
@ -32,10 +36,13 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.AidlMapLayer; import net.osmand.plus.views.AidlMapLayer;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
@ -49,6 +56,7 @@ import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -65,6 +73,17 @@ public class OsmandAidlApi {
private static final String AIDL_ZOOM = "aidl_zoom"; private static final String AIDL_ZOOM = "aidl_zoom";
private static final String AIDL_ANIMATED = "aidl_animated"; private static final String AIDL_ANIMATED = "aidl_animated";
private static final String AIDL_START_NAME = "aidl_start_name";
private static final String AIDL_START_LAT = "aidl_start_lat";
private static final String AIDL_START_LON = "aidl_start_lon";
private static final String AIDL_DEST_NAME = "aidl_dest_name";
private static final String AIDL_DEST_LAT = "aidl_dest_lat";
private static final String AIDL_DEST_LON = "aidl_dest_lon";
private static final String AIDL_PROFILE = "aidl_profile";
private static final String AIDL_DATA = "aidl_data";
private static final String AIDL_URI = "aidl_uri";
private static final String AIDL_FORCE = "aidl_force";
private static final String AIDL_OBJECT_ID = "aidl_object_id"; private static final String AIDL_OBJECT_ID = "aidl_object_id";
private static final String AIDL_ADD_MAP_WIDGET = "aidl_add_map_widget"; private static final String AIDL_ADD_MAP_WIDGET = "aidl_add_map_widget";
@ -73,6 +92,22 @@ public class OsmandAidlApi {
private static final String AIDL_ADD_MAP_LAYER = "aidl_add_map_layer"; private static final String AIDL_ADD_MAP_LAYER = "aidl_add_map_layer";
private static final String AIDL_REMOVE_MAP_LAYER = "aidl_remove_map_layer"; private static final String AIDL_REMOVE_MAP_LAYER = "aidl_remove_map_layer";
private static final String AIDL_TAKE_PHOTO_NOTE = "aidl_take_photo_note";
private static final String AIDL_START_VIDEO_RECORDING = "aidl_start_video_recording";
private static final String AIDL_START_AUDIO_RECORDING = "aidl_start_audio_recording";
private static final String AIDL_STOP_RECORDING = "aidl_stop_recording";
private static final String AIDL_NAVIGATE = "aidl_navigate";
private static final String AIDL_NAVIGATE_GPX = "aidl_navigate_gpx";
private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR;
private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{
ApplicationMode.CAR,
ApplicationMode.BICYCLE,
ApplicationMode.PEDESTRIAN
};
private OsmandApplication app; private OsmandApplication app;
private Map<String, AMapWidget> widgets = new ConcurrentHashMap<>(); private Map<String, AMapWidget> widgets = new ConcurrentHashMap<>();
private Map<String, TextInfoWidget> widgetControls = new ConcurrentHashMap<>(); private Map<String, TextInfoWidget> widgetControls = new ConcurrentHashMap<>();
@ -85,6 +120,12 @@ public class OsmandAidlApi {
private BroadcastReceiver removeMapWidgetReceiver; private BroadcastReceiver removeMapWidgetReceiver;
private BroadcastReceiver addMapLayerReceiver; private BroadcastReceiver addMapLayerReceiver;
private BroadcastReceiver removeMapLayerReceiver; private BroadcastReceiver removeMapLayerReceiver;
private BroadcastReceiver takePhotoNoteReceiver;
private BroadcastReceiver startVideoRecordingReceiver;
private BroadcastReceiver startAudioRecordingReceiver;
private BroadcastReceiver stopRecordingReceiver;
private BroadcastReceiver navigateReceiver;
private BroadcastReceiver navigateGpxReceiver;
public OsmandAidlApi(OsmandApplication app) { public OsmandAidlApi(OsmandApplication app) {
this.app = app; this.app = app;
@ -97,6 +138,12 @@ public class OsmandAidlApi {
registerRemoveMapWidgetReceiver(mapActivity); registerRemoveMapWidgetReceiver(mapActivity);
registerAddMapLayerReceiver(mapActivity); registerAddMapLayerReceiver(mapActivity);
registerRemoveMapLayerReceiver(mapActivity); registerRemoveMapLayerReceiver(mapActivity);
registerTakePhotoNoteReceiver(mapActivity);
registerStartVideoRecordingReceiver(mapActivity);
registerStartAudioRecordingReceiver(mapActivity);
registerStopRecordingReceiver(mapActivity);
registerNavigateReceiver(mapActivity);
registerNavigateGpxReceiver(mapActivity);
} }
public void onDestroyMapActivity(final MapActivity mapActivity) { public void onDestroyMapActivity(final MapActivity mapActivity) {
@ -151,6 +198,54 @@ public class OsmandAidlApi {
} }
removeMapLayerReceiver = null; removeMapLayerReceiver = null;
} }
if (takePhotoNoteReceiver != null) {
try {
mapActivity.unregisterReceiver(takePhotoNoteReceiver);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
takePhotoNoteReceiver = null;
}
if (startVideoRecordingReceiver != null) {
try {
mapActivity.unregisterReceiver(startVideoRecordingReceiver);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
startVideoRecordingReceiver = null;
}
if (startAudioRecordingReceiver != null) {
try {
mapActivity.unregisterReceiver(startAudioRecordingReceiver);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
startAudioRecordingReceiver = null;
}
if (stopRecordingReceiver != null) {
try {
mapActivity.unregisterReceiver(stopRecordingReceiver);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
stopRecordingReceiver = null;
}
if (navigateReceiver != null) {
try {
mapActivity.unregisterReceiver(navigateReceiver);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
navigateReceiver = null;
}
if (navigateGpxReceiver != null) {
try {
mapActivity.unregisterReceiver(navigateGpxReceiver);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
navigateGpxReceiver = null;
}
} }
private void registerRefreshMapReceiver(final MapActivity mapActivity) { private void registerRefreshMapReceiver(final MapActivity mapActivity) {
@ -303,6 +398,208 @@ public class OsmandAidlApi {
mapActivity.registerReceiver(removeMapLayerReceiver, new IntentFilter(AIDL_REMOVE_MAP_LAYER)); mapActivity.registerReceiver(removeMapLayerReceiver, new IntentFilter(AIDL_REMOVE_MAP_LAYER));
} }
private void registerTakePhotoNoteReceiver(final MapActivity mapActivity) {
takePhotoNoteReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
if (plugin != null) {
double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN);
double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
plugin.takePhoto(lat, lon, mapActivity, false, true);
}
}
};
mapActivity.registerReceiver(takePhotoNoteReceiver, new IntentFilter(AIDL_TAKE_PHOTO_NOTE));
}
private void registerStartVideoRecordingReceiver(final MapActivity mapActivity) {
startVideoRecordingReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
if (plugin != null) {
double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN);
double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
plugin.recordVideo(lat, lon, mapActivity, true);
}
}
};
mapActivity.registerReceiver(startVideoRecordingReceiver, new IntentFilter(AIDL_START_VIDEO_RECORDING));
}
private void registerStartAudioRecordingReceiver(final MapActivity mapActivity) {
startVideoRecordingReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
if (plugin != null) {
double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN);
double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
plugin.recordAudio(lat, lon, mapActivity);
}
}
};
mapActivity.registerReceiver(startVideoRecordingReceiver, new IntentFilter(AIDL_START_AUDIO_RECORDING));
}
private void registerStopRecordingReceiver(final MapActivity mapActivity) {
stopRecordingReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
if (plugin != null) {
plugin.stopRecording(mapActivity, false);
}
}
};
mapActivity.registerReceiver(stopRecordingReceiver, new IntentFilter(AIDL_STOP_RECORDING));
}
private void registerNavigateReceiver(final MapActivity mapActivity) {
navigateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String profileStr = intent.getStringExtra(AIDL_PROFILE);
final ApplicationMode profile = ApplicationMode.valueOfStringKey(profileStr, DEFAULT_PROFILE);
boolean validProfile = false;
for (ApplicationMode mode : VALID_PROFILES) {
if (mode == profile) {
validProfile = true;
break;
}
}
if (validProfile) {
String startName = intent.getStringExtra(AIDL_START_NAME);
if (Algorithms.isEmpty(startName)) {
startName = "";
}
String destName = intent.getStringExtra(AIDL_DEST_NAME);
if (Algorithms.isEmpty(destName)) {
destName = "";
}
final LatLon start;
final PointDescription startDesc;
double startLat = intent.getDoubleExtra(AIDL_START_LAT, 0);
double startLon = intent.getDoubleExtra(AIDL_START_LON, 0);
if (startLat != 0 && startLon != 0) {
start = new LatLon(startLat, startLon);
startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
} else {
start = null;
startDesc = null;
}
double destLat = intent.getDoubleExtra(AIDL_DEST_LAT, 0);
double destLon = intent.getDoubleExtra(AIDL_DEST_LON, 0);
final LatLon dest = new LatLon(destLat, destLon);
final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName);
final RoutingHelper routingHelper = app.getRoutingHelper();
boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
if (routingHelper.isFollowingMode() && !force) {
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (!routingHelper.isFollowingMode()) {
startNavigation(mapActivity, null, start, startDesc, dest, destDesc, profile);
}
}
});
} else {
startNavigation(mapActivity, null, start, startDesc, dest, destDesc, profile);
}
}
}
};
mapActivity.registerReceiver(navigateReceiver, new IntentFilter(AIDL_NAVIGATE));
}
private void registerNavigateGpxReceiver(final MapActivity mapActivity) {
navigateGpxReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
boolean force = intent.getBooleanExtra(AIDL_FORCE, false);
GPXFile gpx = null;
if (intent.getStringExtra(AIDL_DATA) != null) {
String gpxStr = intent.getStringExtra(AIDL_DATA);
if (!Algorithms.isEmpty(gpxStr)) {
gpx = GPXUtilities.loadGPXFile(mapActivity, new ByteArrayInputStream(gpxStr.getBytes()));
}
} else if (intent.getParcelableExtra(AIDL_URI) != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Uri gpxUri = intent.getParcelableExtra(AIDL_URI);
ParcelFileDescriptor gpxParcelDescriptor = null;
try {
gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (gpxParcelDescriptor != null) {
FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor();
gpx = GPXUtilities.loadGPXFile(mapActivity, new FileInputStream(fileDescriptor));
}
}
}
if (gpx != null) {
final RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() && !force) {
final GPXFile gpxFile = gpx;
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (!routingHelper.isFollowingMode()) {
startNavigation(mapActivity, gpxFile, null, null, null, null, null);
}
}
});
} else {
startNavigation(mapActivity, gpx, null, null, null, null, null);
}
}
}
};
mapActivity.registerReceiver(navigateGpxReceiver, new IntentFilter(AIDL_NAVIGATE_GPX));
}
private void startNavigation(MapActivity mapActivity,
GPXFile gpx,
LatLon from, PointDescription fromDesc,
LatLon to, PointDescription toDesc,
ApplicationMode mode) {
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if (gpx == null) {
app.getSettings().APPLICATION_MODE.set(mode);
final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
targets.removeAllWayPoints(false, true);
targets.navigateToPoint(to, true, -1, toDesc);
}
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpx, from, fromDesc, true, false);
if (!app.getTargetPointsHelper().checkPointToNavigateShort()) {
mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().show();
} else {
if (app.getSettings().APPLICATION_MODE.get() != routingHelper.getAppMode()) {
app.getSettings().APPLICATION_MODE.set(routingHelper.getAppMode());
}
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
app.getSettings().FOLLOW_THE_ROUTE.set(true);
routingHelper.setFollowingMode(true);
routingHelper.setRoutePlanningMode(false);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
app.getRoutingHelper().notifyIfRouteIsCalculated();
routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false);
}
}
public void registerMapLayers(MapActivity mapActivity) { public void registerMapLayers(MapActivity mapActivity) {
for (AMapLayer layer : layers.values()) { for (AMapLayer layer : layers.values()) {
OsmandMapLayer mapLayer = mapLayers.get(layer.getId()); OsmandMapLayer mapLayer = mapLayers.get(layer.getId());
@ -521,7 +818,7 @@ public class OsmandAidlApi {
if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
PointDescription pd = new PointDescription( PointDescription pd = new PointDescription(
PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : "");
MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.creationDate, m.index);
markersHelper.moveMapMarker(marker, latLonNew); markersHelper.moveMapMarker(marker, latLonNew);
refreshMap(); refreshMap();
return true; return true;
@ -865,4 +1162,63 @@ public class OsmandAidlApi {
} }
return false; return false;
} }
boolean takePhotoNote(double latitude, double longitude) {
Intent intent = new Intent();
intent.setAction(AIDL_TAKE_PHOTO_NOTE);
intent.putExtra(AIDL_LATITUDE, latitude);
intent.putExtra(AIDL_LONGITUDE, longitude);
app.sendBroadcast(intent);
return true;
}
boolean startVideoRecording(double latitude, double longitude) {
Intent intent = new Intent();
intent.setAction(AIDL_START_VIDEO_RECORDING);
intent.putExtra(AIDL_LATITUDE, latitude);
intent.putExtra(AIDL_LONGITUDE, longitude);
app.sendBroadcast(intent);
return true;
}
boolean startAudioRecording(double latitude, double longitude) {
Intent intent = new Intent();
intent.setAction(AIDL_START_AUDIO_RECORDING);
intent.putExtra(AIDL_LATITUDE, latitude);
intent.putExtra(AIDL_LONGITUDE, longitude);
app.sendBroadcast(intent);
return true;
}
boolean stopRecording() {
Intent intent = new Intent();
intent.setAction(AIDL_STOP_RECORDING);
app.sendBroadcast(intent);
return true;
}
boolean navigate(String startName, double startLat, double startLon, String destName, double destLat, double destLon, String profile, boolean force) {
Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE);
intent.putExtra(AIDL_START_NAME, startName);
intent.putExtra(AIDL_START_LAT, startLat);
intent.putExtra(AIDL_START_LON, startLon);
intent.putExtra(AIDL_DEST_NAME, destName);
intent.putExtra(AIDL_DEST_LAT, destLat);
intent.putExtra(AIDL_DEST_LON, destLon);
intent.putExtra(AIDL_PROFILE, profile);
intent.putExtra(AIDL_FORCE, force);
app.sendBroadcast(intent);
return true;
}
boolean navigateGpx(String data, Uri uri, boolean force) {
Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE_GPX);
intent.putExtra(AIDL_DATA, data);
intent.putExtra(AIDL_URI, uri);
intent.putExtra(AIDL_FORCE, force);
app.sendBroadcast(intent);
return true;
}
} }

View file

@ -31,6 +31,12 @@ import net.osmand.aidl.mapmarker.UpdateMapMarkerParams;
import net.osmand.aidl.mapwidget.AddMapWidgetParams; import net.osmand.aidl.mapwidget.AddMapWidgetParams;
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams; import net.osmand.aidl.mapwidget.RemoveMapWidgetParams;
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams; import net.osmand.aidl.mapwidget.UpdateMapWidgetParams;
import net.osmand.aidl.navigation.NavigateGpxParams;
import net.osmand.aidl.navigation.NavigateParams;
import net.osmand.aidl.note.StartAudioRecordingParams;
import net.osmand.aidl.note.StopRecordingParams;
import net.osmand.aidl.note.TakePhotoNoteParams;
import net.osmand.aidl.note.StartVideoRecordingParams;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -340,5 +346,59 @@ public class OsmandAidlService extends Service {
return false; return false;
} }
} }
@Override
public boolean takePhotoNote(TakePhotoNoteParams params) throws RemoteException {
try {
return params != null && getApi().takePhotoNote(params.getLatitude(), params.getLongitude());
} catch (Exception e) {
return false;
}
}
@Override
public boolean startVideoRecording(StartVideoRecordingParams params) throws RemoteException {
try {
return params != null && getApi().startVideoRecording(params.getLatitude(), params.getLongitude());
} catch (Exception e) {
return false;
}
}
@Override
public boolean startAudioRecording(StartAudioRecordingParams params) throws RemoteException {
try {
return params != null && getApi().startAudioRecording(params.getLatitude(), params.getLongitude());
} catch (Exception e) {
return false;
}
}
@Override
public boolean stopRecording(StopRecordingParams params) throws RemoteException {
try {
return getApi().stopRecording();
} catch (Exception e) {
return false;
}
}
@Override
public boolean navigate(NavigateParams params) throws RemoteException {
try {
return params != null && getApi().navigate(params.getStartName(), params.getStartLat(), params.getStartLon(), params.getDestName(), params.getDestLat(), params.getDestLon(), params.getProfile(), params.isForce());
} catch (Exception e) {
return false;
}
}
@Override
public boolean navigateGpx(NavigateGpxParams params) throws RemoteException {
try {
return params != null && getApi().navigateGpx(params.getData(), params.getUri(), params.isForce());
} catch (Exception e) {
return false;
}
}
}; };
} }

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.navigation;
parcelable NavigateGpxParams;

View file

@ -0,0 +1,69 @@
package net.osmand.aidl.navigation;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
public class NavigateGpxParams implements Parcelable {
private String data;
private Uri uri;
private boolean force;
public NavigateGpxParams(String data, boolean force) {
this.data = data;
this.force = force;
}
public NavigateGpxParams(Uri uri, boolean force) {
this.uri = uri;
this.force = force;
}
public NavigateGpxParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<NavigateGpxParams> CREATOR = new Creator<NavigateGpxParams>() {
@Override
public NavigateGpxParams createFromParcel(Parcel in) {
return new NavigateGpxParams(in);
}
@Override
public NavigateGpxParams[] newArray(int size) {
return new NavigateGpxParams[size];
}
};
public String getData() {
return data;
}
public Uri getUri() {
return uri;
}
public boolean isForce() {
return force;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(data);
out.writeParcelable(uri, flags);
out.writeByte((byte) (force ? 1 : 0));
}
private void readFromParcel(Parcel in) {
data = in.readString();
uri = in.readParcelable(Uri.class.getClassLoader());
force = in.readByte() != 0;
}
@Override
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.navigation;
parcelable NavigateParams;

View file

@ -0,0 +1,104 @@
package net.osmand.aidl.navigation;
import android.os.Parcel;
import android.os.Parcelable;
public class NavigateParams implements Parcelable {
private String startName;
private double startLat;
private double startLon;
private String destName;
private double destLat;
private double destLon;
private String profile;
private boolean force;
public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat, double destLon, String profile, boolean force) {
this.startName = startName;
this.startLat = startLat;
this.startLon = startLon;
this.destName = destName;
this.destLat = destLat;
this.destLon = destLon;
this.profile = profile;
this.force = force;
}
public NavigateParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<NavigateParams> CREATOR = new Creator<NavigateParams>() {
@Override
public NavigateParams createFromParcel(Parcel in) {
return new NavigateParams(in);
}
@Override
public NavigateParams[] newArray(int size) {
return new NavigateParams[size];
}
};
public String getStartName() {
return startName;
}
public double getStartLat() {
return startLat;
}
public double getStartLon() {
return startLon;
}
public String getDestName() {
return destName;
}
public double getDestLat() {
return destLat;
}
public double getDestLon() {
return destLon;
}
public String getProfile() {
return profile;
}
public boolean isForce() {
return force;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(startName);
out.writeDouble(startLat);
out.writeDouble(startLon);
out.writeString(destName);
out.writeDouble(destLat);
out.writeDouble(destLon);
out.writeString(profile);
out.writeByte((byte) (force ? 1 : 0));
}
private void readFromParcel(Parcel in) {
startName = in.readString();
startLat = in.readDouble();
startLon = in.readDouble();
destName = in.readString();
destLat = in.readDouble();
destLon = in.readDouble();
profile = in.readString();
force = in.readByte() != 0;
}
@Override
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable StartAudioRecordingParams;

View file

@ -0,0 +1,56 @@
package net.osmand.aidl.note;
import android.os.Parcel;
import android.os.Parcelable;
public class StartAudioRecordingParams implements Parcelable {
private double latitude;
private double longitude;
public StartAudioRecordingParams(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public StartAudioRecordingParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<StartAudioRecordingParams> CREATOR = new Creator<StartAudioRecordingParams>() {
@Override
public StartAudioRecordingParams createFromParcel(Parcel in) {
return new StartAudioRecordingParams(in);
}
@Override
public StartAudioRecordingParams[] newArray(int size) {
return new StartAudioRecordingParams[size];
}
};
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(latitude);
out.writeDouble(longitude);
}
private void readFromParcel(Parcel in) {
latitude = in.readDouble();
longitude = in.readDouble();
}
@Override
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable StartVideoRecordingParams;

View file

@ -0,0 +1,56 @@
package net.osmand.aidl.note;
import android.os.Parcel;
import android.os.Parcelable;
public class StartVideoRecordingParams implements Parcelable {
private double latitude;
private double longitude;
public StartVideoRecordingParams(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public StartVideoRecordingParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<StartVideoRecordingParams> CREATOR = new Creator<StartVideoRecordingParams>() {
@Override
public StartVideoRecordingParams createFromParcel(Parcel in) {
return new StartVideoRecordingParams(in);
}
@Override
public StartVideoRecordingParams[] newArray(int size) {
return new StartVideoRecordingParams[size];
}
};
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(latitude);
out.writeDouble(longitude);
}
private void readFromParcel(Parcel in) {
latitude = in.readDouble();
longitude = in.readDouble();
}
@Override
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable StopRecordingParams;

View file

@ -0,0 +1,42 @@
package net.osmand.aidl.note;
import android.os.Parcel;
import android.os.Parcelable;
public class StopRecordingParams implements Parcelable {
public StopRecordingParams() {
}
public StopRecordingParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<StopRecordingParams> CREATOR = new Creator<StopRecordingParams>() {
@Override
public StopRecordingParams createFromParcel(Parcel in) {
return new StopRecordingParams(in);
}
@Override
public StopRecordingParams[] newArray(int size) {
return new StopRecordingParams[size];
}
};
@Override
public void writeToParcel(Parcel out, int flags) {
}
private void readFromParcel(Parcel in) {
}
@Override
public int describeContents() {
return 0;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable TakePhotoNoteParams;

View file

@ -0,0 +1,56 @@
package net.osmand.aidl.note;
import android.os.Parcel;
import android.os.Parcelable;
public class TakePhotoNoteParams implements Parcelable {
private double latitude;
private double longitude;
public TakePhotoNoteParams(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public TakePhotoNoteParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<TakePhotoNoteParams> CREATOR = new Creator<TakePhotoNoteParams>() {
@Override
public TakePhotoNoteParams createFromParcel(Parcel in) {
return new TakePhotoNoteParams(in);
}
@Override
public TakePhotoNoteParams[] newArray(int size) {
return new TakePhotoNoteParams[size];
}
};
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(latitude);
out.writeDouble(longitude);
}
private void readFromParcel(Parcel in) {
latitude = in.readDouble();
longitude = in.readDouble();
}
@Override
public int describeContents() {
return 0;
}
}

View file

@ -35,13 +35,15 @@ public class MapMarkersHelper {
public boolean history; public boolean history;
public boolean selected; public boolean selected;
public int dist; public int dist;
public long creationDate;
public MapMarker(LatLon point, PointDescription name, int colorIndex, public MapMarker(LatLon point, PointDescription name, int colorIndex,
boolean selected, int index) { boolean selected, long creationDate, int index) {
this.point = point; this.point = point;
this.pointDescription = name; this.pointDescription = name;
this.colorIndex = colorIndex; this.colorIndex = colorIndex;
this.selected = selected; this.selected = selected;
this.creationDate = creationDate;
this.index = index; this.index = index;
} }
@ -169,6 +171,7 @@ public class MapMarkersHelper {
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size()); List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
List<Integer> colors = settings.getMapMarkersColors(ips.size()); List<Integer> colors = settings.getMapMarkersColors(ips.size());
List<Boolean> selections = settings.getMapMarkersSelections(ips.size()); List<Boolean> selections = settings.getMapMarkersSelections(ips.size());
List<Long> creationDates = settings.getMapMarkersCreationDates(ips.size());
int colorIndex = 0; int colorIndex = 0;
for (int i = 0; i < ips.size(); i++) { for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) { if (colors.size() > i) {
@ -176,15 +179,21 @@ public class MapMarkersHelper {
} }
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex,
selections.get(i), i); selections.get(i), creationDates.get(i), i);
mapMarkers.add(mapMarker); mapMarkers.add(mapMarker);
} }
ips = settings.getMapMarkersHistoryPoints(); ips = settings.getMapMarkersHistoryPoints();
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size()); desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
colors = settings.getMapMarkersHistoryColors(ips.size());
creationDates = settings.getMapMarkersHistoryCreationDates(ips.size());
for (int i = 0; i < ips.size(); i++) { for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) {
colorIndex = colors.get(i);
}
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), 0, false, i); PointDescription.deserializeFromString(desc.get(i), ips.get(i)),
colorIndex, false, creationDates.get(i), i);
mapMarker.history = true; mapMarker.history = true;
mapMarkersHistory.add(mapMarker); mapMarkersHistory.add(mapMarker);
} }
@ -207,10 +216,10 @@ public class MapMarkersHelper {
} }
if (history) { if (history) {
settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex); mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.creationDate);
} else { } else {
settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected); mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected, mapMarker.creationDate);
} }
updateMarker(mapMarker); updateMarker(mapMarker);
} }
@ -312,6 +321,12 @@ public class MapMarkersHelper {
refresh(); refresh();
} }
public void addMapMarker(MapMarker marker, int index) {
settings.insertMapMarker(marker.getLatitude(), marker.getLongitude(), marker.pointDescription,
marker.colorIndex, marker.selected, marker.creationDate, index);
readFromSettings();
}
public void addMapMarker(LatLon point, PointDescription historyName) { public void addMapMarker(LatLon point, PointDescription historyName) {
List<LatLon> points = new ArrayList<>(1); List<LatLon> points = new ArrayList<>(1);
List<PointDescription> historyNames = new ArrayList<>(1); List<PointDescription> historyNames = new ArrayList<>(1);
@ -376,7 +391,7 @@ public class MapMarkersHelper {
public void updateMapMarker(MapMarker marker, boolean refresh) { public void updateMapMarker(MapMarker marker, boolean refresh) {
if (marker != null) { if (marker != null) {
settings.updateMapMarker(marker.getLatitude(), marker.getLongitude(), settings.updateMapMarker(marker.getLatitude(), marker.getLongitude(),
marker.pointDescription, marker.colorIndex, marker.selected); marker.pointDescription, marker.colorIndex, marker.selected, marker.creationDate);
if (refresh) { if (refresh) {
readFromSettings(); readFromSettings();
refresh(); refresh();
@ -387,7 +402,7 @@ public class MapMarkersHelper {
public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) { public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) {
if (marker != null) { if (marker != null) {
settings.moveMapMarker(new LatLon(marker.getLatitude(), marker.getLongitude()), latLon, settings.moveMapMarker(new LatLon(marker.getLatitude(), marker.getLongitude()), latLon,
marker.pointDescription, marker.colorIndex, marker.selected); marker.pointDescription, marker.colorIndex, marker.selected, marker.creationDate);
marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude()); marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude());
readFromSettings(); readFromSettings();
refresh(); refresh();
@ -404,7 +419,8 @@ public class MapMarkersHelper {
public void addMapMarkerHistory(MapMarker marker) { public void addMapMarkerHistory(MapMarker marker) {
if (marker != null) { if (marker != null) {
settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, marker.colorIndex, 0); settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(),
marker.pointDescription, marker.colorIndex, marker.creationDate, 0);
readFromSettings(); readFromSettings();
refresh(); refresh();
} }
@ -424,25 +440,29 @@ public class MapMarkersHelper {
List<String> names = new ArrayList<>(markers.size()); List<String> names = new ArrayList<>(markers.size());
List<Integer> colors = new ArrayList<>(markers.size()); List<Integer> colors = new ArrayList<>(markers.size());
List<Boolean> selections = new ArrayList<>(markers.size()); List<Boolean> selections = new ArrayList<>(markers.size());
List<Long> creationDates = new ArrayList<>(markers.size());
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
ls.add(marker.point); ls.add(marker.point);
names.add(PointDescription.serializeToString(marker.pointDescription)); names.add(PointDescription.serializeToString(marker.pointDescription));
colors.add(marker.colorIndex); colors.add(marker.colorIndex);
selections.add(marker.selected); selections.add(marker.selected);
creationDates.add(marker.creationDate);
} }
settings.saveMapMarkers(ls, names, colors, selections); settings.saveMapMarkers(ls, names, colors, selections, creationDates);
} }
if (markersHistory != null) { if (markersHistory != null) {
List<LatLon> ls = new ArrayList<>(markersHistory.size()); List<LatLon> ls = new ArrayList<>(markersHistory.size());
List<String> names = new ArrayList<>(markersHistory.size()); List<String> names = new ArrayList<>(markersHistory.size());
List<Integer> colors = new ArrayList<>(markersHistory.size()); List<Integer> colors = new ArrayList<>(markersHistory.size());
List<Long> creationDates = new ArrayList<>(markersHistory.size());
for (MapMarker marker : markersHistory) { for (MapMarker marker : markersHistory) {
ls.add(marker.point); ls.add(marker.point);
names.add(PointDescription.serializeToString(marker.pointDescription)); names.add(PointDescription.serializeToString(marker.pointDescription));
colors.add(marker.colorIndex); colors.add(marker.colorIndex);
creationDates.add(marker.creationDate);
} }
settings.saveMapMarkersHistory(ls, names, colors); settings.saveMapMarkersHistory(ls, names, colors, creationDates);
} }
if (markers != null || markersHistory != null) { if (markers != null || markersHistory != null) {

View file

@ -1783,8 +1783,11 @@ public class OsmandSettings {
public final static String MAP_MARKERS_COLOR = "map_markers_color"; //$NON-NLS-1$ public final static String MAP_MARKERS_COLOR = "map_markers_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$ public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$
public final static String MAP_MARKERS_SELECTION = "map_markers_selection"; //$NON-NLS-1$ public final static String MAP_MARKERS_SELECTION = "map_markers_selection"; //$NON-NLS-1$
public final static String MAP_MARKERS_CREATION_DATE = "map_markers_creation_date"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$ public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_COLOR = "map_markers_history_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$ public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_CREATION_DATE = "map_markers_history_creation_date"; //$NON-NLS-1$
public final static int MAP_MARKERS_HISTORY_LIMIT = 30; public final static int MAP_MARKERS_HISTORY_LIMIT = 30;
private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage(); private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage(); private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
@ -1896,6 +1899,7 @@ public class OsmandSettings {
.remove(MAP_MARKERS_DESCRIPTION) .remove(MAP_MARKERS_DESCRIPTION)
.remove(MAP_MARKERS_COLOR) .remove(MAP_MARKERS_COLOR)
.remove(MAP_MARKERS_SELECTION) .remove(MAP_MARKERS_SELECTION)
.remove(MAP_MARKERS_CREATION_DATE)
.commit(); .commit();
} }
@ -1903,6 +1907,8 @@ public class OsmandSettings {
return settingsAPI.edit(globalPreferences) return settingsAPI.edit(globalPreferences)
.remove(MAP_MARKERS_HISTORY_POINT) .remove(MAP_MARKERS_HISTORY_POINT)
.remove(MAP_MARKERS_HISTORY_DESCRIPTION) .remove(MAP_MARKERS_HISTORY_DESCRIPTION)
.remove(MAP_MARKERS_HISTORY_COLOR)
.remove(MAP_MARKERS_HISTORY_CREATION_DATE)
.commit(); .commit();
} }
@ -1927,18 +1933,175 @@ public class OsmandSettings {
private class MapMarkersHistoryStorage extends MapPointsStorage { private class MapMarkersHistoryStorage extends MapPointsStorage {
protected String colorsKey;
protected String creationDatesKey;
public MapMarkersHistoryStorage() { public MapMarkersHistoryStorage() {
pointsKey = MAP_MARKERS_HISTORY_POINT; pointsKey = MAP_MARKERS_HISTORY_POINT;
descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION; descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION;
colorsKey = MAP_MARKERS_HISTORY_COLOR;
creationDatesKey = MAP_MARKERS_HISTORY_CREATION_DATE;
}
public List<Integer> getColors(int sz) {
List<Integer> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, colorsKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String colorStr = tok.nextToken();
list.add(Integer.parseInt(colorStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
int i = 0;
while (list.size() < sz) {
list.add(i % MapMarkersHelper.MAP_MARKERS_COLORS_COUNT);
i++;
}
return list;
}
public List<Long> getCreationDates(int sz) {
List<Long> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, creationDatesKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String creationDateStr = tok.nextToken();
list.add(Long.parseLong(creationDateStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add(0L);
}
return list;
}
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Long> cds) {
while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) {
ps.remove(ps.size() - 1);
ds.remove(ds.size() - 1);
cs.remove(cs.size() - 1);
cds.remove(cds.size() - 1);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + ""));
}
StringBuilder tb = new StringBuilder();
for (int i = 0; i < ds.size(); i++) {
if (i > 0) {
tb.append("--");
}
if (ds.get(i) == null) {
tb.append("");
} else {
tb.append(ds.get(i));
}
}
StringBuilder cb = new StringBuilder();
for (int i = 0; i < cs.size(); i++) {
if (i > 0) {
cb.append(",");
}
cb.append(Integer.toString(cs.get(i)));
}
StringBuilder cdb = new StringBuilder();
if (cds != null) {
for (int i = 0; i < cds.size(); i++) {
if (i > 0) {
cdb.append(",");
}
cdb.append(Long.toString(cds.get(i)));
}
}
return settingsAPI.edit(globalPreferences)
.putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString())
.putString(colorsKey, cb.toString())
.putString(creationDatesKey, cdb.toString())
.commit();
}
public boolean insertPoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex,
long creationDate, int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
List<Long> cds = getCreationDates(ps.size());
ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex);
cds.add(index, creationDate);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds, cs, cds);
}
public boolean updatePoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex,
long creationDate) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
List<Long> cds = getCreationDates(ps.size());
int index = ps.indexOf(new LatLon(latitude, longitude));
if (index != -1) {
ds.set(index, PointDescription.serializeToString(historyDescription));
if (cs.size() > index) {
cs.set(index, colorIndex);
}
if (cds.size() > index) {
cds.set(index, creationDate);
}
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds, cs, cds);
} else {
return false;
}
}
@Override
public boolean deletePoint(int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
List<Long> cds = getCreationDates(ps.size());
ps.remove(index);
ds.remove(index);
cds.remove(index);
if (cs.size() > index) {
cs.remove(index);
}
return savePoints(ps, ds, cs, cds);
} }
@Override @Override
public boolean savePoints(List<LatLon> ps, List<String> ds) { public boolean savePoints(List<LatLon> ps, List<String> ds) {
while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) { return false;
ps.remove(ps.size() - 1);
ds.remove(ds.size() - 1);
} }
return super.savePoints(ps, ds);
@Override
public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) {
return false;
}
@Override
public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) {
return false;
} }
} }
@ -1946,12 +2109,14 @@ public class OsmandSettings {
protected String colorsKey; protected String colorsKey;
protected String selectionKey; protected String selectionKey;
protected String creationDatesKey;
public MapMarkersStorage() { public MapMarkersStorage() {
pointsKey = MAP_MARKERS_POINT; pointsKey = MAP_MARKERS_POINT;
descriptionsKey = MAP_MARKERS_DESCRIPTION; descriptionsKey = MAP_MARKERS_DESCRIPTION;
colorsKey = MAP_MARKERS_COLOR; colorsKey = MAP_MARKERS_COLOR;
selectionKey = MAP_MARKERS_SELECTION; selectionKey = MAP_MARKERS_SELECTION;
creationDatesKey = MAP_MARKERS_CREATION_DATE;
} }
public List<Integer> getColors(int sz) { public List<Integer> getColors(int sz) {
@ -1994,21 +2159,42 @@ public class OsmandSettings {
return list; return list;
} }
public List<Long> getCreationDates(int sz) {
List<Long> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, creationDatesKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String creationDateStr = tok.nextToken();
list.add(Long.parseLong(creationDateStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add(0L);
}
return list;
}
public boolean insertPoint(double latitude, double longitude, public boolean insertPoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int pos, PointDescription historyDescription, int colorIndex,
boolean selected, int index) { boolean selected, long creationDate, int index) {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
List<Long> cds = getCreationDates(ps.size());
ps.add(index, new LatLon(latitude, longitude)); ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription)); ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex); cs.add(index, colorIndex);
bs.add(index, selected); bs.add(index, selected);
cds.add(index, creationDate == 0 ? System.currentTimeMillis() : creationDate);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
} }
return savePoints(ps, ds, cs, bs); return savePoints(ps, ds, cs, bs, cds);
} }
public boolean insertPoints(double[] latitudes, double[] longitudes, public boolean insertPoints(double[] latitudes, double[] longitudes,
@ -2018,6 +2204,7 @@ public class OsmandSettings {
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
List<Long> cds = getCreationDates(ps.size());
for (int i = 0; i < latitudes.length; i++) { for (int i = 0; i < latitudes.length; i++) {
double latitude = latitudes[i]; double latitude = latitudes[i];
double longitude = longitudes[i]; double longitude = longitudes[i];
@ -2029,20 +2216,22 @@ public class OsmandSettings {
ds.add(index, PointDescription.serializeToString(historyDescription)); ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex); cs.add(index, colorIndex);
bs.add(index, selected); bs.add(index, selected);
cds.add(index, System.currentTimeMillis());
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
} }
} }
return savePoints(ps, ds, cs, bs); return savePoints(ps, ds, cs, bs, cds);
} }
public boolean updatePoint(double latitude, double longitude, public boolean updatePoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, PointDescription historyDescription, int colorIndex,
boolean selected) { boolean selected, long creationDate) {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
List<Long> cds = getCreationDates(ps.size());
int index = ps.indexOf(new LatLon(latitude, longitude)); int index = ps.indexOf(new LatLon(latitude, longitude));
if (index != -1) { if (index != -1) {
ds.set(index, PointDescription.serializeToString(historyDescription)); ds.set(index, PointDescription.serializeToString(historyDescription));
@ -2052,10 +2241,13 @@ public class OsmandSettings {
if (bs.size() > index) { if (bs.size() > index) {
bs.set(index, selected); bs.set(index, selected);
} }
if (cds.size() > index) {
cds.set(index, creationDate);
}
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
} }
return savePoints(ps, ds, cs, bs); return savePoints(ps, ds, cs, bs, cds);
} else { } else {
return false; return false;
} }
@ -2065,11 +2257,13 @@ public class OsmandSettings {
LatLon latLonNew, LatLon latLonNew,
PointDescription historyDescription, PointDescription historyDescription,
int colorIndex, int colorIndex,
boolean selected) { boolean selected,
long creationDate) {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
List<Long> cds = getCreationDates(ps.size());
int index = ps.indexOf(latLonEx); int index = ps.indexOf(latLonEx);
if (index != -1) { if (index != -1) {
if (ps.size() > index) { if (ps.size() > index) {
@ -2082,12 +2276,15 @@ public class OsmandSettings {
if (bs.size() > index) { if (bs.size() > index) {
bs.set(index, selected); bs.set(index, selected);
} }
if (cds.size() > index) {
cds.set(index, creationDate);
}
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
double lat = latLonNew.getLatitude(); double lat = latLonNew.getLatitude();
double lon = latLonNew.getLongitude(); double lon = latLonNew.getLongitude();
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(lat, lon, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(lat, lon, historyDescription);
} }
return savePoints(ps, ds, cs, bs); return savePoints(ps, ds, cs, bs, cds);
} else { } else {
return false; return false;
} }
@ -2099,19 +2296,21 @@ public class OsmandSettings {
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
List<Boolean> bs = getSelections(ps.size()); List<Boolean> bs = getSelections(ps.size());
List<Long> cds = getCreationDates(ps.size());
ps.remove(index); ps.remove(index);
ds.remove(index); ds.remove(index);
cds.remove(index);
if (cs.size() > index) { if (cs.size() > index) {
cs.remove(index); cs.remove(index);
} }
if (bs.size() > index) { if (bs.size() > index) {
bs.remove(index); bs.remove(index);
} }
return savePoints(ps, ds, cs, bs); return savePoints(ps, ds, cs, bs, cds);
} }
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs, public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs,
List<Boolean> bs) { List<Boolean> bs, List<Long> cds) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) { for (int i = 0; i < ps.size(); i++) {
if (i > 0) { if (i > 0) {
@ -2146,11 +2345,21 @@ public class OsmandSettings {
bb.append(Boolean.toString(bs.get(i))); bb.append(Boolean.toString(bs.get(i)));
} }
} }
StringBuilder cdb = new StringBuilder();
if (cds != null) {
for (int i = 0; i < cds.size(); i++) {
if (i > 0) {
cdb.append(",");
}
cdb.append(Long.toString(cds.get(i)));
}
}
return settingsAPI.edit(globalPreferences) return settingsAPI.edit(globalPreferences)
.putString(pointsKey, sb.toString()) .putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString()) .putString(descriptionsKey, tb.toString())
.putString(colorsKey, cb.toString()) .putString(colorsKey, cb.toString())
.putString(selectionKey, bb.toString()) .putString(selectionKey, bb.toString())
.putString(creationDatesKey, cdb.toString())
.commit(); .commit();
} }
@ -2344,15 +2553,19 @@ public class OsmandSettings {
return mapMarkersStorage.getSelections(sz); return mapMarkersStorage.getSelections(sz);
} }
public List<Long> getMapMarkersCreationDates(int sz) {
return mapMarkersStorage.getCreationDates(sz);
}
public List<LatLon> getMapMarkersPoints() { public List<LatLon> getMapMarkersPoints() {
return mapMarkersStorage.getPoints(); return mapMarkersStorage.getPoints();
} }
public boolean insertMapMarker(double latitude, double longitude, public boolean insertMapMarker(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int pos, PointDescription historyDescription, int colorIndex,
boolean selected, int index) { boolean selected, long creationDate, int index) {
return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex,
index, selected, pos); selected, creationDate, index);
} }
public boolean insertMapMarkers(double[] latitudes, double[] longitudes, public boolean insertMapMarkers(double[] latitudes, double[] longitudes,
@ -2363,24 +2576,27 @@ public class OsmandSettings {
} }
public boolean updateMapMarker(double latitude, double longitude, public boolean updateMapMarker(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, boolean selected) { PointDescription historyDescription, int colorIndex, boolean selected,
return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, selected); long creationDate) {
return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, selected, creationDate);
} }
public boolean moveMapMarker(LatLon latLonEx, public boolean moveMapMarker(LatLon latLonEx,
LatLon latLonNew, LatLon latLonNew,
PointDescription historyDescription, PointDescription historyDescription,
int colorIndex, int colorIndex,
boolean selected) { boolean selected,
return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, selected); long creationDate) {
return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, selected, creationDate);
} }
public boolean deleteMapMarker(int index) { public boolean deleteMapMarker(int index) {
return mapMarkersStorage.deletePoint(index); return mapMarkersStorage.deletePoint(index);
} }
public boolean saveMapMarkers(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Boolean> bs) { public boolean saveMapMarkers(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Boolean> bs,
return mapMarkersStorage.savePoints(ps, ds, cs, bs); List<Long> cds) {
return mapMarkersStorage.savePoints(ps, ds, cs, bs, cds);
} }
@ -2392,22 +2608,31 @@ public class OsmandSettings {
return mapMarkersHistoryStorage.getPoints(); return mapMarkersHistoryStorage.getPoints();
} }
public List<Long> getMapMarkersHistoryCreationDates(int sz) {
return mapMarkersHistoryStorage.getCreationDates(sz);
}
public List<Integer> getMapMarkersHistoryColors(int sz) {
return mapMarkersHistoryStorage.getColors(sz);
}
public boolean insertMapMarkerHistory(double latitude, double longitude, public boolean insertMapMarkerHistory(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int index) { PointDescription historyDescription, int colorIndex,
return mapMarkersHistoryStorage.insertPoint(latitude, longitude, historyDescription, index); long creationDate, int index) {
return mapMarkersHistoryStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, creationDate, index);
} }
public boolean updateMapMarkerHistory(double latitude, double longitude, public boolean updateMapMarkerHistory(double latitude, double longitude,
PointDescription historyDescription, int colorIndex) { PointDescription historyDescription, int colorIndex, long creationDate) {
return mapMarkersHistoryStorage.updatePoint(latitude, longitude, historyDescription); return mapMarkersHistoryStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, creationDate);
} }
public boolean deleteMapMarkerHistory(int index) { public boolean deleteMapMarkerHistory(int index) {
return mapMarkersHistoryStorage.deletePoint(index); return mapMarkersHistoryStorage.deletePoint(index);
} }
public boolean saveMapMarkersHistory(List<LatLon> ps, List<String> ds, List<Integer> cs) { public boolean saveMapMarkersHistory(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Long> cds) {
return mapMarkersHistoryStorage.savePoints(ps, ds); return mapMarkersHistoryStorage.savePoints(ps, ds, cs, cds);
} }

View file

@ -641,7 +641,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
recordVideo(latitude, longitude, mapActivity); recordVideo(latitude, longitude, mapActivity, false);
return true; return true;
} }
}) })
@ -651,7 +651,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
takePhoto(latitude, longitude, mapActivity, false); takePhoto(latitude, longitude, mapActivity, false, false);
return true; return true;
} }
@ -769,9 +769,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
private void takeAction(final MapActivity mapActivity, double lon, double lat, int action) { private void takeAction(final MapActivity mapActivity, double lon, double lat, int action) {
if (action == AV_DEFAULT_ACTION_VIDEO) { if (action == AV_DEFAULT_ACTION_VIDEO) {
recordVideo(lat, lon, mapActivity); recordVideo(lat, lon, mapActivity, false);
} else if (action == AV_DEFAULT_ACTION_TAKEPICTURE) { } else if (action == AV_DEFAULT_ACTION_TAKEPICTURE) {
takePhoto(lat, lon, mapActivity, false); takePhoto(lat, lon, mapActivity, false, false);
} else if (action == AV_DEFAULT_ACTION_AUDIO) { } else if (action == AV_DEFAULT_ACTION_AUDIO) {
recordAudio(lat, lon, mapActivity); recordAudio(lat, lon, mapActivity);
} }
@ -874,8 +874,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
public void recordVideo(final double lat, final double lon, final MapActivity mapActivity) { public void recordVideo(final double lat, final double lon, final MapActivity mapActivity, final boolean forceExternal) {
if (AV_EXTERNAL_RECORDER.get()) { if (AV_EXTERNAL_RECORDER.get() || forceExternal) {
captureVideoExternal(lat, lon, mapActivity); captureVideoExternal(lat, lon, mapActivity);
} else { } else {
if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.CAMERA) if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.CAMERA)
@ -1192,10 +1192,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
public void takePhoto(final double lat, final double lon, final MapActivity mapActivity, public void takePhoto(final double lat, final double lon, final MapActivity mapActivity,
final boolean forceInternal) { final boolean forceInternal, final boolean forceExternal) {
if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.CAMERA) if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) { == PackageManager.PERMISSION_GRANTED) {
if (!AV_EXTERNAL_PHOTO_CAM.get() || forceInternal) { if ((!AV_EXTERNAL_PHOTO_CAM.get() || forceInternal) && !forceExternal) {
takePhotoInternalOrExternal(lat, lon, mapActivity); takePhotoInternalOrExternal(lat, lon, mapActivity);
} else { } else {
takePhotoExternal(lat, lon, mapActivity); takePhotoExternal(lat, lon, mapActivity);

View file

@ -31,7 +31,7 @@ public class TakePhotoNoteAction extends QuickAction {
AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class); AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
if (plugin != null) if (plugin != null)
plugin.takePhoto(latLon.getLatitude(), latLon.getLongitude(), activity, false); plugin.takePhoto(latLon.getLatitude(), latLon.getLongitude(), activity, false, false);
} }
@Override @Override

View file

@ -31,7 +31,7 @@ public class TakeVideoNoteAction extends QuickAction {
AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class); AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
if (plugin != null) if (plugin != null)
plugin.recordVideo(latLon.getLatitude(), latLon.getLongitude(), activity); plugin.recordVideo(latLon.getLatitude(), latLon.getLongitude(), activity, false);
} }
@Override @Override

View file

@ -285,9 +285,9 @@ public class ExternalApiHelper {
if (API_CMD_RECORD_AUDIO.equals(cmd)) { if (API_CMD_RECORD_AUDIO.equals(cmd)) {
plugin.recordAudio(lat, lon, mapActivity); plugin.recordAudio(lat, lon, mapActivity);
} else if (API_CMD_RECORD_VIDEO.equals(cmd)) { } else if (API_CMD_RECORD_VIDEO.equals(cmd)) {
plugin.recordVideo(lat, lon, mapActivity); plugin.recordVideo(lat, lon, mapActivity, false);
} else if (API_CMD_RECORD_PHOTO.equals(cmd)) { } else if (API_CMD_RECORD_PHOTO.equals(cmd)) {
plugin.takePhoto(lat, lon, mapActivity, true); plugin.takePhoto(lat, lon, mapActivity, true, false);
} }
} }

View file

@ -121,6 +121,12 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
return null; return null;
} }
void updateAdapter() {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
private void updateLocationUi() { private void updateLocationUi() {
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) { if (mapActivity != null) {

View file

@ -78,11 +78,17 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
case R.id.action_active: case R.id.action_active:
((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate(); ((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate();
if (viewPager.getCurrentItem() != 0) {
((MapMarkersActiveFragment) adapter.getItem(0)).updateAdapter();
}
viewPager.setCurrentItem(0); viewPager.setCurrentItem(0);
optionsButton.setVisibility(View.VISIBLE); optionsButton.setVisibility(View.VISIBLE);
return true; return true;
case R.id.action_history: case R.id.action_history:
((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate();
if (viewPager.getCurrentItem() != 1) {
((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter();
}
viewPager.setCurrentItem(1); viewPager.setCurrentItem(1);
optionsButton.setVisibility(View.GONE); optionsButton.setVisibility(View.GONE);
return true; return true;

View file

@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -9,11 +10,15 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter;
public class MapMarkersHistoryFragment extends Fragment { public class MapMarkersHistoryFragment extends Fragment {
MapMarkersHistoryAdapter adapter;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -21,8 +26,27 @@ public class MapMarkersHistoryFragment extends Fragment {
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
recyclerView.setAdapter(new MapMarkersHistoryAdapter(mapActivity.getMyApplication())); adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {
@Override
public void onItemClick(View view) {
int pos = recyclerView.indexOfChild(view);
MapMarker marker = adapter.getItem(pos);
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, new PointDescription(PointDescription.POINT_TYPE_LOCATION, marker.getPointDescription(mapActivity).getName()),
false, null);
MapActivity.launchMapActivityMoveToTop(mapActivity);
((DialogFragment) getParentFragment()).dismiss();
}
});
recyclerView.setAdapter(adapter);
return recyclerView; return recyclerView;
} }
void updateAdapter() {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
} }

View file

@ -17,7 +17,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
final TextView distance; final TextView distance;
final TextView point; final TextView point;
final TextView description; final TextView description;
final ImageButton options; final ImageButton optionsBtn;
public MapMarkerItemViewHolder(View view) { public MapMarkerItemViewHolder(View view) {
super(view); super(view);
@ -28,6 +28,6 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
distance = (TextView) view.findViewById(R.id.map_marker_distance); distance = (TextView) view.findViewById(R.id.map_marker_distance);
point = (TextView) view.findViewById(R.id.map_marker_point_text_view); point = (TextView) view.findViewById(R.id.map_marker_point_text_view);
description = (TextView) view.findViewById(R.id.map_marker_description); description = (TextView) view.findViewById(R.id.map_marker_description);
options = (ImageButton) view.findViewById(R.id.map_marker_options_button); optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button);
} }
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers.adapters; package net.osmand.plus.mapmarkers.adapters;
import android.support.design.widget.Snackbar;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -87,6 +88,42 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
holder.title.setText(marker.getName(mapActivity)); holder.title.setText(marker.getName(mapActivity));
holder.description.setText(marker.creationDate + "");
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final int position = holder.getAdapterPosition();
if (position < 0) {
return;
}
final MapMarker marker = markers.get(position);
final boolean[] undone = new boolean[1];
mapActivity.getMyApplication().getMapMarkersHelper().removeMapMarker(marker.index);
notifyItemRemoved(position);
Snackbar.make(holder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
undone[0] = true;
mapActivity.getMyApplication().getMapMarkersHelper().addMapMarker(marker, position);
notifyItemInserted(position);
}
})
.addCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
if (!undone[0]) {
mapActivity.getMyApplication().getMapMarkersHelper().addMapMarkerHistory(marker);
}
}
}).show();
}
});
DashLocationFragment.updateLocationView(useCenter, location, DashLocationFragment.updateLocationView(useCenter, location,
heading, holder.iconDirection, holder.distance, heading, holder.iconDirection, holder.distance,
marker.getLatitude(), marker.getLongitude(), marker.getLatitude(), marker.getLongitude(),

View file

@ -16,20 +16,31 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
private OsmandApplication app; private OsmandApplication app;
private List<MapMarker> markers; private List<MapMarker> markers;
private MapMarkersHistoryAdapterListener listener;
public MapMarkersHistoryAdapter(OsmandApplication app) { public MapMarkersHistoryAdapter(OsmandApplication app) {
this.app = app; this.app = app;
markers = app.getMapMarkersHelper().getMapMarkersHistory(); markers = app.getMapMarkersHelper().getMapMarkersHistory();
} }
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
this.listener = listener;
}
@Override @Override
public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onItemClick(view);
}
});
return new MapMarkerItemViewHolder(view); return new MapMarkerItemViewHolder(view);
} }
@Override @Override
public void onBindViewHolder(MapMarkerItemViewHolder holder, int pos) { public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
IconsCache iconsCache = app.getIconsCache(); IconsCache iconsCache = app.getIconsCache();
MapMarker marker = markers.get(pos); MapMarker marker = markers.get(pos);
@ -39,10 +50,34 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color));
holder.title.setText(marker.getName(app)); holder.title.setText(marker.getName(app));
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_refresh_dark));
holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = holder.getAdapterPosition();
if (position < 0) {
return;
}
MapMarker marker = markers.get(position);
app.getMapMarkersHelper().removeMapMarkerHistory(marker);
app.getMapMarkersHelper().addMapMarker(marker, 0);
notifyItemRemoved(position);
}
});
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return markers.size(); return markers.size();
} }
public MapMarker getItem(int position) {
return markers.get(position);
}
public interface MapMarkersHistoryAdapterListener {
void onItemClick(View view);
}
} }

View file

@ -180,8 +180,10 @@ public class MeasurementEditingContext {
before.points.clear(); before.points.clear();
after.points.clear(); after.points.clear();
if (inSnapToRoadMode) { if (inSnapToRoadMode) {
if (beforeCacheForSnap != null && afterCacheForSnap != null) {
beforeCacheForSnap.points.clear(); beforeCacheForSnap.points.clear();
afterCacheForSnap.points.clear(); afterCacheForSnap.points.clear();
}
needUpdateCacheForSnap = true; needUpdateCacheForSnap = true;
} else { } else {
beforeCacheForSnap = null; beforeCacheForSnap = null;

View file

@ -1395,7 +1395,7 @@ public class MeasurementToolFragment extends Fragment {
hidePointsList(); hidePointsList();
return; return;
} }
if (editingCtx.getPointsCount() < 1 || saved) { if (editingCtx.getPointsCount() == 0 || saved) {
dismiss(mapActivity); dismiss(mapActivity);
return; return;
} }