Merge branch 'r2.3' of https://github.com/osmandapp/Osmand into r2.3

This commit is contained in:
GaidamakUA 2016-03-21 11:59:49 +02:00
commit a3d95d0213
9 changed files with 152 additions and 45 deletions

View file

@ -2004,19 +2004,27 @@ public class OsmandSettings {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
int i = ps.indexOf(new LatLon(latitude, longitude)); int i = ps.indexOf(new LatLon(latitude, longitude));
ds.set(i, PointDescription.serializeToString(historyDescription)); if (i != -1) {
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { ds.set(i, PointDescription.serializeToString(historyDescription));
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds);
} else {
return false;
} }
return savePoints(ps, ds);
} }
public boolean deletePoint(int index) { public boolean deletePoint(int index) {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
ps.remove(index); if (index < ps.size()) {
ds.remove(index); ps.remove(index);
return savePoints(ps, ds); ds.remove(index);
return savePoints(ps, ds);
} else {
return false;
}
} }
public boolean savePoints(List<LatLon> ps, List<String> ds) { public boolean savePoints(List<LatLon> ps, List<String> ds) {

View file

@ -138,10 +138,12 @@ public class TargetPointsHelper {
AddressLookupRequest lookupRequest = new AddressLookupRequest(targetPoint.point, new GeocodingLookupService.OnAddressLookupResult() { AddressLookupRequest lookupRequest = new AddressLookupRequest(targetPoint.point, new GeocodingLookupService.OnAddressLookupResult() {
@Override @Override
public void geocodingDone(String address) { public void geocodingDone(String address) {
targetPoint.pointDescription.setName(address); if (intermediatePoints.contains(targetPoint)) {
settings.updateIntermediatePoint(targetPoint.point.getLatitude(), targetPoint.point.getLongitude(), targetPoint.pointDescription.setName(address);
targetPoint.pointDescription); settings.updateIntermediatePoint(targetPoint.point.getLatitude(), targetPoint.point.getLongitude(),
updateRouteAndRefresh(false); targetPoint.pointDescription);
updateRouteAndRefresh(false);
}
} }
}, null); }, null);
ctx.getGeocodingLookupService().lookupAddress(lookupRequest); ctx.getGeocodingLookupService().lookupAddress(lookupRequest);
@ -156,10 +158,12 @@ public class TargetPointsHelper {
@Override @Override
public void geocodingDone(String address) { public void geocodingDone(String address) {
startPointRequest = null; startPointRequest = null;
pointToStart.pointDescription.setName(address); if (pointToStart != null) {
settings.setPointToStart(pointToStart.point.getLatitude(), pointToStart.point.getLongitude(), pointToStart.pointDescription.setName(address);
pointToStart.pointDescription); settings.setPointToStart(pointToStart.point.getLatitude(), pointToStart.point.getLongitude(),
updateRouteAndRefresh(false); pointToStart.pointDescription);
updateRouteAndRefresh(false);
}
} }
}, null); }, null);
ctx.getGeocodingLookupService().lookupAddress(startPointRequest); ctx.getGeocodingLookupService().lookupAddress(startPointRequest);
@ -174,10 +178,12 @@ public class TargetPointsHelper {
@Override @Override
public void geocodingDone(String address) { public void geocodingDone(String address) {
targetPointRequest = null; targetPointRequest = null;
pointToNavigate.pointDescription.setName(address); if (pointToNavigate != null) {
settings.setPointToNavigate(pointToNavigate.point.getLatitude(), pointToNavigate.point.getLongitude(), pointToNavigate.pointDescription.setName(address);
pointToNavigate.pointDescription); settings.setPointToNavigate(pointToNavigate.point.getLatitude(), pointToNavigate.point.getLongitude(),
updateRouteAndRefresh(false); pointToNavigate.pointDescription);
updateRouteAndRefresh(false);
}
} }
}, null); }, null);
ctx.getGeocodingLookupService().lookupAddress(targetPointRequest); ctx.getGeocodingLookupService().lookupAddress(targetPointRequest);

View file

@ -486,6 +486,8 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
new RateUsBottomSheetDialog().show(getSupportFragmentManager(), "dialog"); new RateUsBottomSheetDialog().show(getSupportFragmentManager(), "dialog");
} }
} }
} else {
dashboardOnMap.updateDashboard();
} }
} }
dashboardOnMap.updateLocation(true, true, false); dashboardOnMap.updateLocation(true, true, false);

View file

@ -44,10 +44,10 @@ import java.util.Set;
public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
implements OnPreferenceChangeListener, OnPreferenceClickListener { implements OnPreferenceChangeListener, OnPreferenceClickListener {
public static final String INTENT_APP_MODE = "INTENT_APP_MODE";
protected OsmandSettings settings; protected OsmandSettings settings;
protected final boolean profileSettings ; protected final boolean profileSettings;
protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>(); protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>();
private ApplicationMode previousAppMode; private ApplicationMode previousAppMode;
@ -388,7 +388,14 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
super.onResume(); super.onResume();
if (profileSettings) { if (profileSettings) {
previousAppMode = settings.getApplicationMode(); previousAppMode = settings.getApplicationMode();
boolean found = setSelectedAppMode(previousAppMode); boolean found;
if (getIntent() != null && getIntent().hasExtra(INTENT_APP_MODE)) {
String modeStr = getIntent().getStringExtra(INTENT_APP_MODE);
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeStr, previousAppMode);
found = setSelectedAppMode(mode);
} else {
found = setSelectedAppMode(previousAppMode);
}
if (!found) { if (!found) {
getSpinner().setSelection(0); getSpinner().setSelection(0);
} }

View file

@ -804,14 +804,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} else { } else {
scrollView.setVisibility(View.GONE); scrollView.setVisibility(View.GONE);
listViewLayout.setVisibility(View.VISIBLE); listViewLayout.setVisibility(View.VISIBLE);
listView.scrollTo(0, 0);
listView.clearParams();
if (listView instanceof ObservableListView) {
onScrollChanged(listView.getScrollY(), false, false);
}
if (refresh) { if (refresh) {
refreshContent(false); refreshContent(false);
} else { } else {
listView.scrollTo(0, 0);
listView.clearParams();
onScrollChanged(listView.getScrollY(), false, false);
updateListAdapter(); updateListAdapter();
} }
updateListBackgroundHeight(); updateListBackgroundHeight();
@ -856,6 +854,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} }
} }
public void updateDashboard() {
if (visibleType == DashboardType.ROUTE_PREFERENCES) {
refreshContent(false);
}
}
private void applyDayNightMode() { private void applyDayNightMode() {
if (nightMode) { if (nightMode) {
if (listBackgroundView != null) { if (listBackgroundView != null) {

View file

@ -3,7 +3,6 @@ package net.osmand.plus.download.ui;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.StatFs; import android.os.StatFs;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -57,8 +56,8 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
hasExternalStoragePermission = DownloadActivity.hasPermissionToWriteExternalStorage(getActivity()); hasExternalStoragePermission = DownloadActivity.hasPermissionToWriteExternalStorage(getActivity());
internalStorage = getInternalStorageDirectory(getActivity()); internalStorage = getInternalStorageDirectory(getActivity());
sharedStorage = getSharedStorageDirectory(getActivity());
if (hasExternalStoragePermission) { if (hasExternalStoragePermission) {
sharedStorage = getSharedStorageDirectory(getActivity());
externalStorage = getMyApplication().getSettings().getSecondaryStorage(); externalStorage = getMyApplication().getSettings().getSecondaryStorage();
} }
@ -98,7 +97,7 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
sharedMemoryDescription.setText(getFreeSpace(sharedStorage)); sharedMemoryDescription.setText(getFreeSpace(sharedStorage));
View memoryStickRow = view.findViewById(R.id.memoryStickRow); View memoryStickRow = view.findViewById(R.id.memoryStickRow);
if (hasExternalStoragePermission) { if (hasExternalStoragePermission && externalStorage != null) {
memoryStickRow.setOnClickListener(externalMemoryOnClickListener); memoryStickRow.setOnClickListener(externalMemoryOnClickListener);
ImageView memoryStickImageView = (ImageView) view.findViewById(R.id.memoryStickImageView); ImageView memoryStickImageView = (ImageView) view.findViewById(R.id.memoryStickImageView);
memoryStickImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard)); memoryStickImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));

View file

@ -1,9 +1,8 @@
package net.osmand.plus.helpers; package net.osmand.plus.helpers;
import android.content.DialogInterface; import java.io.ByteArrayInputStream;
import android.content.Intent; import java.io.File;
import android.net.Uri; import java.util.Arrays;
import android.support.v7.app.AlertDialog;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -25,11 +24,15 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import android.content.DialogInterface;
import java.io.ByteArrayInputStream; import android.content.Intent;
import java.io.File; import android.net.Uri;
import android.support.v7.app.AlertDialog;
public class ExternalApiHelper { public class ExternalApiHelper {
@ -54,7 +57,9 @@ public class ExternalApiHelper {
public static final String API_CMD_STOP_GPX_REC = "stop_gpx_rec"; public static final String API_CMD_STOP_GPX_REC = "stop_gpx_rec";
public static final String API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS = "subscribe_voice_notifications"; public static final String API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS = "subscribe_voice_notifications";
public static final int VERSION_CODE = 1;
public static final String PARAM_NAME = "name"; public static final String PARAM_NAME = "name";
public static final String PARAM_DESC = "desc"; public static final String PARAM_DESC = "desc";
public static final String PARAM_CATEGORY = "category"; public static final String PARAM_CATEGORY = "category";
@ -75,9 +80,16 @@ public class ExternalApiHelper {
public static final String PARAM_DEST_LON = "dest_lon"; public static final String PARAM_DEST_LON = "dest_lon";
public static final String PARAM_PROFILE = "profile"; public static final String PARAM_PROFILE = "profile";
public static final String PARAM_VERSION = "version";
public static final String PARAM_ETA = "eta"; public static final String PARAM_ETA = "eta";
public static final String PARAM_TIME_LEFT = "time_left"; public static final String PARAM_TIME_LEFT = "time_left";
public static final String PARAM_DISTANCE_LEFT = "time_distance_left"; public static final String PARAM_DISTANCE_LEFT = "time_distance_left";
public static final String PARAM_NT_DISTANCE = "turn_distance";
public static final String PARAM_NT_IMMINENT = "turn_imminent";
public static final String PARAM_NT_DIRECTION_NAME = "turn_name";
public static final String PARAM_NT_DIRECTION_TURN = "turn_type";
public static final String PARAM_NT_DIRECTION_LANES = "turn_lanes";
public static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ public static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{
ApplicationMode.CAR, ApplicationMode.CAR,
@ -95,6 +107,7 @@ public class ExternalApiHelper {
public static final int RESULT_CODE_ERROR_GPX_NOT_FOUND = 20; public static final int RESULT_CODE_ERROR_GPX_NOT_FOUND = 20;
public static final int RESULT_CODE_ERROR_INVALID_PROFILE = 30; public static final int RESULT_CODE_ERROR_INVALID_PROFILE = 30;
private MapActivity mapActivity; private MapActivity mapActivity;
private int resultCode; private int resultCode;
private boolean finish; private boolean finish;
@ -260,13 +273,27 @@ public class ExternalApiHelper {
} }
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode()) { if (routingHelper.isRouteCalculated()) {
int time = routingHelper.getLeftTime(); int time = routingHelper.getLeftTime();
result.putExtra(PARAM_TIME_LEFT, time); result.putExtra(PARAM_TIME_LEFT, time);
long eta = time + System.currentTimeMillis() / 1000; long eta = time + System.currentTimeMillis() / 1000;
result.putExtra(PARAM_ETA, eta); result.putExtra(PARAM_ETA, eta);
result.putExtra(PARAM_DISTANCE_LEFT, routingHelper.getLeftDistance()); result.putExtra(PARAM_DISTANCE_LEFT, routingHelper.getLeftDistance());
NextDirectionInfo ni = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
if(ni.distanceTo > 0) {
updateTurnInfo("next_", result, ni);
ni = routingHelper.getNextRouteDirectionInfoAfter(ni, new NextDirectionInfo(), true);
if(ni.distanceTo > 0) {
updateTurnInfo("after_next", result, ni);
}
}
routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
if(ni.distanceTo > 0) {
updateTurnInfo("no_speak_next_", result, ni);
}
} }
result.putExtra(PARAM_VERSION, VERSION_CODE);
finish = true; finish = true;
resultCode = RESULT_CODE_OK; resultCode = RESULT_CODE_OK;
@ -359,6 +386,20 @@ public class ExternalApiHelper {
return result; return result;
} }
private void updateTurnInfo(String prefix, Intent result, NextDirectionInfo ni) {
result.putExtra(prefix + PARAM_NT_DISTANCE, ni.distanceTo);
result.putExtra(prefix + PARAM_NT_IMMINENT, ni.imminent);
if(ni.directionInfo != null && ni.directionInfo.getTurnType() != null) {
TurnType tt = ni.directionInfo.getTurnType();
RouteDirectionInfo a = ni.directionInfo;
result.putExtra(prefix + PARAM_NT_DIRECTION_NAME, RoutingHelper.formatStreetName(a.getStreetName(), a.getRef(), a.getDestinationName()));
result.putExtra(prefix + PARAM_NT_DIRECTION_TURN, tt.toXmlString());
if(tt.getLanes() != null) {
result.putExtra(prefix + PARAM_NT_DIRECTION_LANES, Arrays.toString(tt.getLanes()));
}
}
}
private void showOnMap(double lat, double lon, Object object, PointDescription pointDescription) { private void showOnMap(double lat, double lon, Object object, PointDescription pointDescription) {
MapContextMenu mapContextMenu = mapActivity.getContextMenu(); MapContextMenu mapContextMenu = mapActivity.getContextMenu();
mapContextMenu.setMapCenter(new LatLon(lat, lon)); mapContextMenu.setMapCenter(new LatLon(lat, lon));

View file

@ -70,6 +70,11 @@ public class RoutePreferencesMenu {
public static class LocalRoutingParameter { public static class LocalRoutingParameter {
public GeneralRouter.RoutingParameter routingParameter; public GeneralRouter.RoutingParameter routingParameter;
private ApplicationMode am;
public LocalRoutingParameter(ApplicationMode am) {
this.am = am;
}
public String getText(MapActivity mapActivity) { public String getText(MapActivity mapActivity) {
return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(), return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(),
@ -79,33 +84,66 @@ public class RoutePreferencesMenu {
public boolean isSelected(OsmandSettings settings) { public boolean isSelected(OsmandSettings settings) {
final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
.getId()); .getId());
return property.get(); if(am != null) {
return property.getModeValue(am);
} else {
return property.get();
}
} }
public void setSelected(OsmandSettings settings, boolean isChecked) { public void setSelected(OsmandSettings settings, boolean isChecked) {
final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
.getId()); .getId());
property.set(isChecked); if(am != null) {
property.setModeValue(am, isChecked);
} else {
property.set(isChecked);
}
} }
} }
private static class MuteSoundRoutingParameter extends LocalRoutingParameter { private static class MuteSoundRoutingParameter extends LocalRoutingParameter {
public MuteSoundRoutingParameter() {
super(null);
}
} }
private static class InterruptMusicRoutingParameter extends LocalRoutingParameter { private static class InterruptMusicRoutingParameter extends LocalRoutingParameter {
public InterruptMusicRoutingParameter() {
super(null);
}
} }
private static class VoiceGuidanceRoutingParameter extends LocalRoutingParameter { private static class VoiceGuidanceRoutingParameter extends LocalRoutingParameter {
public VoiceGuidanceRoutingParameter() {
super(null);
}
} }
private static class AvoidRoadsRoutingParameter extends LocalRoutingParameter { private static class AvoidRoadsRoutingParameter extends LocalRoutingParameter {
public AvoidRoadsRoutingParameter() {
super(null);
}
} }
private static class GpxLocalRoutingParameter extends LocalRoutingParameter { private static class GpxLocalRoutingParameter extends LocalRoutingParameter {
public GpxLocalRoutingParameter() {
super(null);
}
} }
private static class OtherSettingsRoutingParameter extends LocalRoutingParameter { private static class OtherSettingsRoutingParameter extends LocalRoutingParameter {
public OtherSettingsRoutingParameter() {
super(null);
}
} }
private static class OtherLocalRoutingParameter extends LocalRoutingParameter { private static class OtherLocalRoutingParameter extends LocalRoutingParameter {
@ -114,6 +152,7 @@ public class RoutePreferencesMenu {
public int id; public int id;
public OtherLocalRoutingParameter(int id, String text, boolean selected) { public OtherLocalRoutingParameter(int id, String text, boolean selected) {
super(null);
this.text = text; this.text = text;
this.selected = selected; this.selected = selected;
this.id = id; this.id = id;
@ -253,6 +292,7 @@ public class RoutePreferencesMenu {
if (obj instanceof OtherSettingsRoutingParameter) { if (obj instanceof OtherSettingsRoutingParameter) {
final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class); final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class);
settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true); settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true);
settings.putExtra(SettingsBaseActivity.INTENT_APP_MODE, routingHelper.getAppMode().getStringKey());
mapActivity.startActivity(settings); mapActivity.startActivity(settings);
} else if (obj instanceof MuteSoundRoutingParameter) { } else if (obj instanceof MuteSoundRoutingParameter) {
final CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item); final CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item);
@ -425,7 +465,7 @@ public class RoutePreferencesMenu {
ch.setOnCheckedChangeListener(null); ch.setOnCheckedChangeListener(null);
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) { if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
// if short route settings - it should be inverse of fast_route_mode // if short route settings - it should be inverse of fast_route_mode
ch.setChecked(!settings.FAST_ROUTE_MODE.get()); ch.setChecked(!settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode()));
} else { } else {
ch.setChecked(rp.isSelected(settings)); ch.setChecked(rp.isSelected(settings));
} }
@ -435,7 +475,7 @@ public class RoutePreferencesMenu {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// if short way that it should set valut to fast mode opposite of current // if short way that it should set valut to fast mode opposite of current
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) { if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
settings.FAST_ROUTE_MODE.set(!isChecked); settings.FAST_ROUTE_MODE.setModeValue(routingHelper.getAppMode(), !isChecked);
} }
rp.setSelected(settings, isChecked); rp.setSelected(settings, isChecked);
@ -550,7 +590,7 @@ public class RoutePreferencesMenu {
} }
for (GeneralRouter.RoutingParameter r : rm.getParameters().values()) { for (GeneralRouter.RoutingParameter r : rm.getParameters().values()) {
if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) { if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
LocalRoutingParameter rp = new LocalRoutingParameter(); LocalRoutingParameter rp = new LocalRoutingParameter(am);
rp.routingParameter = r; rp.routingParameter = r;
list.add(rp); list.add(rp);
} }

View file

@ -1043,7 +1043,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
@Override @Override
public void run() { public void run() {
String top = OsMoGroupsActivity.this.operation; String top = OsMoGroupsActivity.this.operation;
if (top.equals(operation) || (operation != null && operation.equals(top))) { if (operation != null && operation.equals(top)) {
hideProgressBar(); hideProgressBar();
} }
if (joinGroup && (operation != null && operation.startsWith("GROUP_CONNECT"))) { if (joinGroup && (operation != null && operation.startsWith("GROUP_CONNECT"))) {