Merge pull request #11033 from osmandapp/master

update test branch
This commit is contained in:
Hardy 2021-02-28 19:23:26 +01:00 committed by GitHub
commit aea6a7f492
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 31 deletions

View file

@ -12,6 +12,7 @@
--> -->
<string name="track_recording_will_be_continued">The recording will be continued.</string>
<string name="map_widget_distance_by_tap">Distance by tap</string> <string name="map_widget_distance_by_tap">Distance by tap</string>
<string name="quick_action_coordinates_widget_descr">A toggle to show or hide the Coordinates widget on the map.</string> <string name="quick_action_coordinates_widget_descr">A toggle to show or hide the Coordinates widget on the map.</string>
<string name="quick_action_coordinates_widget_show">Show Coordinates widget</string> <string name="quick_action_coordinates_widget_show">Show Coordinates widget</string>

View file

@ -66,14 +66,17 @@ public class RasterMapMenu {
final CommonPreference<Boolean> hidePolygonsPref = final CommonPreference<Boolean> hidePolygonsPref =
mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons"); mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
final CommonPreference<Boolean> hideWaterPolygonsPref =
mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("hideWaterPolygons");
String mapTypeDescr = mapTypePreference.get(); String mapTypeDescr = mapTypePreference.get();
if (mapTypeDescr!=null && mapTypeDescr.contains(".sqlitedb")) { if (mapTypeDescr!=null && mapTypeDescr.contains(".sqlitedb")) {
mapTypeDescr = mapTypeDescr.replaceFirst(".sqlitedb", ""); mapTypeDescr = mapTypeDescr.replaceFirst(".sqlitedb", "");
} }
final boolean selected = mapTypeDescr != null; final boolean mapSelected = mapTypeDescr != null;
final int toggleActionStringId = selected ? R.string.shared_string_on final int toggleActionStringId = mapSelected ? R.string.shared_string_on
: R.string.shared_string_off; : R.string.shared_string_off;
final OnMapSelectedCallback onMapSelectedCallback = final OnMapSelectedCallback onMapSelectedCallback =
@ -81,6 +84,10 @@ public class RasterMapMenu {
@Override @Override
public void onMapSelected(boolean canceled) { public void onMapSelected(boolean canceled) {
mapActivity.getDashboard().refreshContent(true); mapActivity.getDashboard().refreshContent(true);
boolean refreshToHidePolygons = type == RasterMapType.UNDERLAY;
if (refreshToHidePolygons) {
mapActivity.refreshMapComplete();
}
} }
}; };
final MapActivityLayers mapLayers = mapActivity.getMapLayers(); final MapActivityLayers mapLayers = mapActivity.getMapLayers();
@ -89,7 +96,7 @@ public class RasterMapMenu {
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter,
View view, int itemId, int pos) { View view, int itemId, int pos) {
if (itemId == mapTypeString) { if (itemId == mapTypeString) {
if (selected) { if (mapSelected) {
plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference, plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference,
exMapTypePreference, true, mapActivity, onMapSelectedCallback); exMapTypePreference, true, mapActivity, onMapSelectedCallback);
} }
@ -111,6 +118,7 @@ public class RasterMapMenu {
}); });
} else if (itemId == R.string.show_polygons) { } else if (itemId == R.string.show_polygons) {
hidePolygonsPref.set(!isChecked); hidePolygonsPref.set(!isChecked);
hideWaterPolygonsPref.set(!isChecked);
mapActivity.refreshMapComplete(); mapActivity.refreshMapComplete();
} else if (itemId == R.string.show_transparency_seekbar) { } else if (itemId == R.string.show_transparency_seekbar) {
if (isChecked) { if (isChecked) {
@ -126,13 +134,13 @@ public class RasterMapMenu {
} }
}; };
mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none); mapTypeDescr = mapSelected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(toggleActionStringId, mapActivity) .setTitleId(toggleActionStringId, mapActivity)
.hideDivider(true) .hideDivider(true)
.setListener(l) .setListener(l)
.setSelected(selected).createItem()); .setSelected(mapSelected).createItem());
if (selected) { if (mapSelected) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(mapTypeString, mapActivity) .setTitleId(mapTypeString, mapActivity)
.hideDivider(true) .hideDivider(true)

View file

@ -22,10 +22,10 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.helpers.CustomBarChartRenderer; import net.osmand.plus.helpers.CustomBarChartRenderer;
import net.osmand.router.RouteStatisticsHelper;
import net.osmand.router.RouteStatisticsHelper.RouteStatistics;
import net.osmand.router.RouteStatisticsHelper.RouteSegmentAttribute; import net.osmand.router.RouteStatisticsHelper.RouteSegmentAttribute;
import net.osmand.router.RouteStatisticsHelper.RouteStatistics;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -140,7 +140,7 @@ public class CustomGraphAdapter extends BaseGraphAdapter<HorizontalBarChart, Bar
private void attachLegend(List<RouteSegmentAttribute> list, private void attachLegend(List<RouteSegmentAttribute> list,
String propertyNameToFullSpan) { String propertyNameToFullSpan) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
LayoutInflater inflater = LayoutInflater.from(app); LayoutInflater inflater = UiUtilities.getInflater(app, isNightMode());
for (RouteSegmentAttribute segment : list) { for (RouteSegmentAttribute segment : list) {
View view = inflater.inflate(R.layout.route_details_legend, legendContainer, false); View view = inflater.inflate(R.layout.route_details_legend, legendContainer, false);
int segmentColor = segment.getColor(); int segmentColor = segment.getColor();

View file

@ -90,11 +90,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
@Override @Override
public void onClick(View v) { public void onClick(View v) {
tag = (ItemType) buttonSave.getTag(); tag = (ItemType) buttonSave.getTag();
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) { if (plugin != null && app.getSavingTrackHelper().hasDataToSave()) {
plugin.saveCurrentTrack(null, mapActivity); plugin.saveCurrentTrack(null, mapActivity);
app.getNotificationHelper().refreshNotifications(); app.getNotificationHelper().refreshNotifications();
dismiss();
} }
dismiss();
} }
}) })
.create()); .create());

View file

@ -1,6 +1,5 @@
package net.osmand.plus.monitoring; package net.osmand.plus.monitoring;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
@ -38,6 +37,7 @@ import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -61,6 +61,7 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -71,6 +72,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
public static final String TAG = TripRecordingActiveBottomSheet.class.getSimpleName(); public static final String TAG = TripRecordingActiveBottomSheet.class.getSimpleName();
private static final Log log = PlatformUtil.getLog(TripRecordingActiveBottomSheet.class); private static final Log log = PlatformUtil.getLog(TripRecordingActiveBottomSheet.class);
private static final String UPDATE_CURRENT_GPX_FILE = "update_current_gpx_file"; private static final String UPDATE_CURRENT_GPX_FILE = "update_current_gpx_file";
public static final String UPDATE_TRACK_ICON = "update_track_icon";
private static final int GENERAL_UPDATE_GPS_INTERVAL = 1000; private static final int GENERAL_UPDATE_GPS_INTERVAL = 1000;
private static final int GENERAL_UPDATE_SAVE_INTERVAL = 1000; private static final int GENERAL_UPDATE_SAVE_INTERVAL = 1000;
@ -131,7 +133,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
View buttonClear = itemView.findViewById(R.id.button_clear); View buttonClear = itemView.findViewById(R.id.button_clear);
final View buttonOnline = itemView.findViewById(R.id.button_online); final View buttonOnline = itemView.findViewById(R.id.button_online);
View buttonSegment = itemView.findViewById(R.id.button_segment); final View buttonSegment = itemView.findViewById(R.id.button_segment);
buttonSave = itemView.findViewById(R.id.button_save); buttonSave = itemView.findViewById(R.id.button_save);
final View buttonPause = itemView.findViewById(R.id.button_pause); final View buttonPause = itemView.findViewById(R.id.button_pause);
View buttonStop = itemView.findViewById(R.id.button_stop); View buttonStop = itemView.findViewById(R.id.button_stop);
@ -274,6 +276,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored); settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored);
updateStatus(); updateStatus();
createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true); createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true);
createItem(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored);
} }
}); });
@ -443,16 +446,21 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
@Override @Override
public void gpxSavingFinished(Exception errorMessage) { public void gpxSavingFinished(Exception errorMessage) {
String gpxFileName = Algorithms.getFileWithoutDirs(getGPXFile().path);
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
final Context context = getContext(); final Context context = getContext();
final SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir()); final SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
ArrayList<String> filenames = new ArrayList<>(result.getFilenames());
String fileName = "";
if (filenames.size() > 0) {
fileName = filenames.get(filenames.size() - 1) + IndexConstants.GPX_FILE_EXT;
}
String message = fileName + " " + app.getResources().getString(R.string.shared_string_is_saved) + ". "
+ app.getResources().getString(R.string.track_recording_will_be_continued);
if (mapActivity != null && context != null) { if (mapActivity != null && context != null) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity); final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
final FragmentManager fragmentManager = mapActivityRef.get().getSupportFragmentManager(); final FragmentManager fragmentManager = mapActivityRef.get().getSupportFragmentManager();
@SuppressLint({"StringFormatInvalid", "LocalSuppress"})
Snackbar snackbar = Snackbar.make(getView(), Snackbar snackbar = Snackbar.make(getView(),
app.getResources().getString(R.string.shared_string_file_is_saved, gpxFileName), message,
Snackbar.LENGTH_LONG) Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_rename, new View.OnClickListener() { .setAction(R.string.shared_string_rename, new View.OnClickListener() {
@Override @Override
@ -492,10 +500,12 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
} }
} }
public void show(boolean updateTrackIcon) { public void show(String... keys) {
show(); show();
if (updateTrackIcon && buttonAppearance != null) { for (String key : keys) {
updateTrackIcon(buttonAppearance); if (key.equals(UPDATE_TRACK_ICON)) {
updateTrackIcon(buttonAppearance);
}
} }
} }

View file

@ -106,10 +106,12 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
@Override @Override
public boolean init(@NonNull final OsmandApplication app, Activity activity) { public boolean init(@NonNull final OsmandApplication app, Activity activity) {
final CommonPreference<Boolean> hidePolygonsPref = settings.getCustomRenderBooleanProperty("noPolygons"); final CommonPreference<Boolean> hidePolygonsPref = settings.getCustomRenderBooleanProperty("noPolygons");
final CommonPreference<Boolean> hideWaterPolygonsPref = settings.getCustomRenderBooleanProperty("hideWaterPolygons");
underlayListener = new StateChangedListener<String>() { underlayListener = new StateChangedListener<String>() {
@Override @Override
public void stateChanged(String change) { public void stateChanged(String change) {
hidePolygonsPref.set(settings.MAP_UNDERLAY.get() != null); hidePolygonsPref.set(settings.MAP_UNDERLAY.get() != null);
hideWaterPolygonsPref.set(settings.MAP_UNDERLAY.get() != null);
} }
}; };
settings.MAP_UNDERLAY.addListener(underlayListener); settings.MAP_UNDERLAY.addListener(underlayListener);

View file

@ -79,24 +79,18 @@ public class RouteStatisticCard extends BaseCard {
((ImageView) view.findViewById(R.id.time_icon)).setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_time_span)); ((ImageView) view.findViewById(R.id.time_icon)).setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_time_span));
int dist = routingHelper.getLeftDistance(); int dist = routingHelper.getLeftDistance();
int time = routingHelper.getLeftTime();
int hours = time / (60 * 60);
int minutes = (time / 60) % 60;
TextView distanceTv = (TextView) view.findViewById(R.id.distance);
String text = OsmAndFormatter.getFormattedDistance(dist, app); String text = OsmAndFormatter.getFormattedDistance(dist, app);
SpannableStringBuilder distanceStr = new SpannableStringBuilder(text); SpannableStringBuilder distanceStr = new SpannableStringBuilder(text);
int spaceIndex = text.indexOf(" "); int spaceIndex = text.indexOf(" ");
if (spaceIndex != -1) { if (spaceIndex != -1) {
distanceStr.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, spaceIndex, 0); distanceStr.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, spaceIndex, 0);
} }
TextView distanceTv = (TextView) view.findViewById(R.id.distance);
distanceTv.setText(distanceStr); distanceTv.setText(distanceStr);
int time = routingHelper.getLeftTime();
SpannableStringBuilder timeStr = new SpannableStringBuilder(); SpannableStringBuilder timeStr = new SpannableStringBuilder();
if (hours > 0) { timeStr.append(OsmAndFormatter.getFormattedDuration(time, app));
timeStr.append(String.valueOf(hours)).append(" ").append(app.getString(R.string.osmand_parking_hour)).append(" ");
}
if (minutes > 0) {
timeStr.append(String.valueOf(minutes)).append(" ").append(app.getString(R.string.osmand_parking_minute));
}
spaceIndex = timeStr.toString().lastIndexOf(" "); spaceIndex = timeStr.toString().lastIndexOf(" ");
if (spaceIndex != -1) { if (spaceIndex != -1) {
timeStr.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, spaceIndex, 0); timeStr.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, spaceIndex, 0);

View file

@ -848,7 +848,8 @@ public class OsmandSettings {
public final OsmandPreference<DrivingRegion> DRIVING_REGION = new EnumStringPreference<DrivingRegion>(this, public final OsmandPreference<DrivingRegion> DRIVING_REGION = new EnumStringPreference<DrivingRegion>(this,
"default_driving_region", DrivingRegion.EUROPE_ASIA, DrivingRegion.values()) { "default_driving_region", DrivingRegion.EUROPE_ASIA, DrivingRegion.values()) {
public boolean setValue(Object prefs, DrivingRegion val) { public boolean setValue(Object prefs, DrivingRegion val) {
if (val != null) { boolean overrideMetricSystem = !DRIVING_REGION_AUTOMATIC.getValue(prefs, DRIVING_REGION_AUTOMATIC.getDefaultValue());
if (overrideMetricSystem && val != null) {
METRIC_SYSTEM.set(val.defMetrics); METRIC_SYSTEM.set(val.defMetrics);
} }
return super.setValue(prefs, val); return super.setValue(prefs, val);

View file

@ -64,6 +64,7 @@ import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems;
import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.UPDATE_TRACK_ICON;
public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener { public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener {
@ -385,7 +386,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
if (target instanceof TripRecordingBottomSheet) { if (target instanceof TripRecordingBottomSheet) {
((TripRecordingBottomSheet) target).show(); ((TripRecordingBottomSheet) target).show();
} else if (target instanceof TripRecordingActiveBottomSheet) { } else if (target instanceof TripRecordingActiveBottomSheet) {
((TripRecordingActiveBottomSheet) target).show(true); ((TripRecordingActiveBottomSheet) target).show(UPDATE_TRACK_ICON);
} }
} }