diff --git a/OsmAnd-java/src/main/java/net/osmand/LocationConvert.java b/OsmAnd-java/src/main/java/net/osmand/LocationConvert.java index 9d0d8d21b0..5102498dea 100644 --- a/OsmAnd-java/src/main/java/net/osmand/LocationConvert.java +++ b/OsmAnd-java/src/main/java/net/osmand/LocationConvert.java @@ -16,6 +16,10 @@ public class LocationConvert { public static final int UTM_FORMAT = 3; public static final int OLC_FORMAT = 4; private static final char DELIM = ':'; + private static final char DELIMITER_DEGREES = '°'; + private static final char DELIMITER_MINUTES = '′'; + private static final char DELIMITER_SECONDS = '″'; + private static final char DELIMITER_SPACE = ' '; @@ -134,20 +138,86 @@ public class LocationConvert { DecimalFormat df = new DecimalFormat("##0.00000", new DecimalFormatSymbols(Locale.US)); //$NON-NLS-1$ if (outputType == FORMAT_MINUTES || outputType == FORMAT_SECONDS) { - int degrees = (int) Math.floor(coordinate); - sb.append(degrees); - sb.append(DELIM); - coordinate -= degrees; - coordinate *= 60.0; + coordinate = formatCoordinate(coordinate, sb, DELIM); if (outputType == FORMAT_SECONDS) { - int minutes = (int) Math.floor(coordinate); - sb.append(minutes); - sb.append(DELIM); - coordinate -= minutes; - coordinate *= 60.0; + coordinate = formatCoordinate(coordinate, sb, DELIM); } } sb.append(df.format(coordinate)); return sb.toString(); } -} + + public static String convertLatitude(double latitude, int outputType, boolean addCardinalDirection) { + if (latitude < -90.0 || latitude > 90.0 || Double.isNaN(latitude)) { + throw new IllegalArgumentException("latitude=" + latitude); + } + if ((outputType != FORMAT_DEGREES) && (outputType != FORMAT_MINUTES) && (outputType != FORMAT_SECONDS)) { + throw new IllegalArgumentException("outputType=" + outputType); + } + + StringBuilder sb = new StringBuilder(); + + // Handle negative values and append cardinal directions if necessary + if (addCardinalDirection) { + sb.append(latitude < 0 ? 'S' : 'N'); + } else if (latitude < 0) { + sb.append('-'); + } + if (latitude < 0) { + latitude = -latitude; + } + + return formatDegrees(latitude, outputType, sb); + } + + public static String convertLongitude(double longitude, int outputType, boolean addCardinalDirection) { + if (longitude < -180.0 || longitude > 180.0 || Double.isNaN(longitude)) { + throw new IllegalArgumentException("longitude=" + longitude); + } + if ((outputType != FORMAT_DEGREES) && (outputType != FORMAT_MINUTES) && (outputType != FORMAT_SECONDS)) { + throw new IllegalArgumentException("outputType=" + outputType); + } + + StringBuilder sb = new StringBuilder(); + + // Handle negative values and append cardinal directions if necessary + if (addCardinalDirection) { + sb.append(longitude < 0 ? 'W' : 'E'); + } else if (longitude < 0) { + sb.append('-'); + } + if (longitude < 0) { + longitude = -longitude; + } + + return formatDegrees(longitude, outputType, sb); + } + + private static double formatCoordinate(double coordinate, StringBuilder sb, char delimiter) { + int deg = (int) Math.floor(coordinate); + sb.append(deg); + sb.append(delimiter); + coordinate -= deg; + coordinate *= 60.0; + return coordinate; + } + + private static String formatDegrees(double coordinate, int outputType, StringBuilder sb) { + if (outputType == FORMAT_DEGREES) { + sb.append(new DecimalFormat("##0.0000", new DecimalFormatSymbols(Locale.US)).format(coordinate)); + sb.append(DELIMITER_DEGREES); + } else if (outputType == FORMAT_MINUTES) { + coordinate = formatCoordinate(coordinate, sb, DELIMITER_DEGREES); + sb.append(DELIMITER_SPACE); + sb.append(new DecimalFormat("##0.00", new DecimalFormatSymbols(Locale.US)).format(coordinate)); + sb.append(DELIMITER_MINUTES); + } else if (outputType == FORMAT_SECONDS) { + coordinate = formatCoordinate(coordinate, sb, DELIMITER_DEGREES); + sb.append(DELIMITER_SPACE); + coordinate = formatCoordinate(coordinate, sb, DELIMITER_MINUTES); + sb.append(DELIMITER_SPACE); + formatCoordinate(coordinate, sb, DELIMITER_SECONDS); + } + return sb.toString(); + } +} \ No newline at end of file diff --git a/OsmAnd/res/layout-land/map_hud_top.xml b/OsmAnd/res/layout-land/map_hud_top.xml index cd42f72365..55bc73daac 100644 --- a/OsmAnd/res/layout-land/map_hud_top.xml +++ b/OsmAnd/res/layout-land/map_hud_top.xml @@ -6,6 +6,103 @@ xmlns:osmand="http://schemas.android.com/apk/res-auto" android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + 120dp 35sp + 33sp 23sp 23sp 90dp @@ -132,6 +133,7 @@ 12dp 24dp 18dp + 12dp 12dp 12dp 18dp diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 7abb319aaf..bc2cfd42b0 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -127,6 +127,7 @@ 23sp + 22sp 15sp 18sp 25sp @@ -223,6 +224,7 @@ 8dp 16dp 12dp + 8dp 8dp 8dp 12dp diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index dc3bfe1545..5878b76139 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Searching GPS + Coordinates widget Moved %1$d files (%2$s). Copied %1$d files (%2$s). Failed to copy %1$d files (%2$s). diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index af578f1538..8e26f7c55b 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -298,6 +298,12 @@ public class AndroidUtils { tv.setTextColor(ContextCompat.getColor(view.getContext(), colorId)); } + public static void setSnackbarTextMaxLines(Snackbar snackbar, int maxLines) { + View view = snackbar.getView(); + TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); + tv.setMaxLines(maxLines); + } + @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static void setBackground(Context ctx, View view, boolean night, int lightResId, int darkResId) { diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 0c35009b16..10281399ba 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1448,6 +1448,8 @@ public class OsmandSettings { public final OsmandPreference SHOW_MAP_MARKERS = new BooleanPreference("show_map_markers", true).makeGlobal(); + public final OsmandPreference SHOW_COORDINATES_WIDGET = new BooleanPreference("show_coordinates_widget", false).makeGlobal(); + public final CommonPreference NOTES_SORT_BY_MODE = new EnumIntPreference<>("notes_sort_by_mode", NotesSortByMode.BY_DATE, NotesSortByMode.values()); public final OsmandPreference ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeGlobal().cache(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 5bd53c26cf..6450d5b065 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -918,7 +918,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (color == TopToolbarController.NO_COLOR) { boolean mapTopBar = findViewById(R.id.map_top_bar).getVisibility() == View.VISIBLE; boolean markerTopBar = findViewById(R.id.map_markers_top_bar).getVisibility() == View.VISIBLE; - if (mapTopBar && mapControlsVisible) { + boolean coordinatesTopBar = findViewById(R.id.coordinates_top_bar).getVisibility() == View.VISIBLE; + if (coordinatesTopBar && mapControlsVisible) { + colorId = night ? R.color.status_bar_main_dark : R.color.status_bar_main_dark; + } else if (mapTopBar && mapControlsVisible) { colorId = night ? R.color.status_bar_route_dark : R.color.status_bar_route_light; } else if (markerTopBar && mapControlsVisible) { colorId = R.color.status_bar_dark; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 2d71bd0ce1..13778f2304 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1820,6 +1820,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener return directionInfo; } + public boolean shouldShowTopControls() { + return shouldShowTopControls(isVisible()); + } + + public boolean shouldShowTopControls(boolean menuVisible) { + return !menuVisible || !portraitMode || getCurrentMenuState() == MenuState.HEADER_ONLY; + } + public boolean isVisible() { WeakReference fragmentRef = findMenuFragment(); if (fragmentRef != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 3f2502a039..9f23043f1f 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -18,6 +18,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopCoordinatesView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; @@ -56,6 +57,7 @@ public class MapInfoLayer extends OsmandMapLayer { private DrawSettings drawSettings; private TopTextView streetNameView; private TopToolbarView topToolbarView; + private TopCoordinatesView topCoordinatesView; public MapInfoLayer(MapActivity map, RouteLayer layer){ this.map = map; @@ -139,8 +141,12 @@ public class MapInfoLayer extends OsmandMapLayer { OsmandApplication app = view.getApplication(); lanesControl = ric.createLanesControl(map, view); + TextState ts = calculateTextState(); streetNameView = new TopTextView(map.getMyApplication(), map); - updateStreetName(false, calculateTextState()); + updateStreetName(false, ts); + + topCoordinatesView = new TopCoordinatesView(map.getMyApplication(), map); + updateTopCoordinates(false, ts); topToolbarView = new TopToolbarView(map); updateTopToolbar(false); @@ -256,6 +262,7 @@ public class MapInfoLayer extends OsmandMapLayer { updateReg(ts, reg); } updateStreetName(nightMode, ts); + updateTopCoordinates(nightMode, ts); updateTopToolbar(nightMode); lanesControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius / 2); rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity())); @@ -275,6 +282,10 @@ public class MapInfoLayer extends OsmandMapLayer { topToolbarView.updateColors(nightMode); } + private void updateTopCoordinates(boolean nightMode, TextState ts) { + topCoordinatesView.updateColors(nightMode, ts.textBold); + } + private void updateReg(TextState ts, MapWidgetRegInfo reg) { View v = reg.widget != null ? reg.widget.getView().findViewById(R.id.widget_bg) : null; if(v != null) { @@ -329,6 +340,7 @@ public class MapInfoLayer extends OsmandMapLayer { mapInfoControls.updateInfo(settings.getApplicationMode(), drawSettings, expanded); streetNameView.updateInfo(drawSettings); topToolbarView.updateInfo(); + topCoordinatesView.updateInfo(); alarmControl.updateInfo(drawSettings); rulerControl.updateInfo(tileBox, drawSettings); lanesControl.updateInfo(drawSettings); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index d7d5c160fa..a5da7b556e 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -1,15 +1,22 @@ package net.osmand.plus.views.mapwidgets; +import android.annotation.SuppressLint; +import android.app.Activity; import android.content.Context; +import android.content.Intent; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v7.widget.SwitchCompat; +import android.text.ClipboardManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.CompoundButton.OnCheckedChangeListener; @@ -18,9 +25,15 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.jwetherell.openmap.common.LatLonPoint; +import com.jwetherell.openmap.common.UTMPoint; + +import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.LocationConvert; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.plus.CurrentPositionHelper; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider; @@ -29,6 +42,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.RulerMode; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.actions.StartGPSStatus; import net.osmand.plus.helpers.AndroidUiHelper; @@ -499,28 +513,28 @@ public class MapInfoWidgetsFactory { SwitchCompat switchCompat = view.getTopBarSwitch(); if (title != null) { titleView.setText(title); - view.updateVisibility(titleView, true); + AndroidUiHelper.updateVisibility(titleView, true); } else { - view.updateVisibility(titleView, false); + AndroidUiHelper.updateVisibility(titleView, false); } if (description != null) { descrView.setText(description); - view.updateVisibility(descrView, true); + AndroidUiHelper.updateVisibility(descrView, true); } else { - view.updateVisibility(descrView, false); + AndroidUiHelper.updateVisibility(descrView, false); } if (bottomView != null) { bottomViewLayout.removeAllViews(); bottomViewLayout.addView(bottomView); - view.updateVisibility(bottomViewLayout, true); + AndroidUiHelper.updateVisibility(bottomViewLayout, true); } else { - view.updateVisibility(bottomViewLayout, false); + AndroidUiHelper.updateVisibility(bottomViewLayout, false); } - view.updateVisibility(switchCompat, topBarSwitchVisible); + AndroidUiHelper.updateVisibility(switchCompat, topBarSwitchVisible); if (topBarSwitchVisible) { switchCompat.setChecked(topBarSwitchChecked); if (topBarSwitchChecked) { - DrawableCompat.setTint(switchCompat.getTrackDrawable(), ContextCompat.getColor(switchCompat.getContext(),R.color.map_toolbar_switch_track_color)); + DrawableCompat.setTint(switchCompat.getTrackDrawable(), ContextCompat.getColor(switchCompat.getContext(), R.color.map_toolbar_switch_track_color)); } } if (view.getShadowView() != null) { @@ -564,7 +578,7 @@ public class MapInfoWidgetsFactory { descrView = (TextView) map.findViewById(R.id.widget_top_bar_description); topBarSwitch = (SwitchCompat) map.findViewById(R.id.widget_top_bar_switch); shadowView = map.findViewById(R.id.widget_top_bar_shadow); - updateVisibility(false); + AndroidUiHelper.updateVisibility(topbar, false); } public MapActivity getMap() { @@ -656,23 +670,6 @@ public class MapInfoWidgetsFactory { updateInfo(); } - public boolean updateVisibility(boolean visible) { - return updateVisibility(topbar, visible); - } - - public boolean updateVisibility(View v, boolean visible) { - if (visible != (v.getVisibility() == View.VISIBLE)) { - if (visible) { - v.setVisibility(View.VISIBLE); - } else { - v.setVisibility(View.GONE); - } - v.invalidate(); - return true; - } - return false; - } - private void initToolbar(TopToolbarController controller) { backButton.setOnClickListener(controller.onBackButtonClickListener); topBarTitleLayout.setOnClickListener(controller.onTitleClickListener); @@ -692,7 +689,7 @@ public class MapInfoWidgetsFactory { initToolbar(defaultController); defaultController.updateToolbar(this); } - updateVisibility(controller != null && !MapRouteInfoMenu.chooseRoutesVisible && !MapRouteInfoMenu.waypointsVisible && + AndroidUiHelper.updateVisibility(topbar, controller != null && !MapRouteInfoMenu.chooseRoutesVisible && !MapRouteInfoMenu.waypointsVisible && (!map.getContextMenu().isVisible() || controller.getType() == TopToolbarControllerType.CONTEXT_MENU)); } @@ -839,26 +836,13 @@ public class MapInfoWidgetsFactory { } public boolean updateVisibility(boolean visible) { - boolean res = updateVisibility(topBar, visible); + boolean res = AndroidUiHelper.updateVisibility(topBar, visible); if (res) { map.updateStatusBarColor(); } return res; } - public boolean updateVisibility(View v, boolean visible) { - if (visible != (v.getVisibility() == View.VISIBLE)) { - if (visible) { - v.setVisibility(View.VISIBLE); - } else { - v.setVisibility(View.GONE); - } - v.invalidate(); - return true; - } - return false; - } - public void updateTextColor(boolean nightMode, int textColor, int textShadowColor, boolean bold, int rad) { this.shadowRad = rad; TextInfoWidget.updateTextColor(addressText, addressTextShadow, textColor, textShadowColor, bold, rad); @@ -943,15 +927,15 @@ public class MapInfoWidgetsFactory { updateVisibility(false); } else if (!showNextTurn && updateWaypoint()) { updateVisibility(true); - updateVisibility(addressText, false); - updateVisibility(addressTextShadow, false); + AndroidUiHelper.updateVisibility(addressText, false); + AndroidUiHelper.updateVisibility(addressTextShadow, false); } else if (text == null) { updateVisibility(false); } else { updateVisibility(true); - updateVisibility(waypointInfoBar, false); - updateVisibility(addressText, true); - updateVisibility(addressTextShadow, shadowRad > 0); + AndroidUiHelper.updateVisibility(waypointInfoBar, false); + AndroidUiHelper.updateVisibility(addressText, true); + AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0); boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker; this.showMarker = showMarker; int h = addressText.getHeight() / 4 * 3; @@ -990,12 +974,12 @@ public class MapInfoWidgetsFactory { this.lastPoint = pnt; if (pnt == null) { topBar.setOnClickListener(null); - updateVisibility(waypointInfoBar, false); + AndroidUiHelper.updateVisibility(waypointInfoBar, false); return false; } else { - updateVisibility(addressText, false); - updateVisibility(addressTextShadow, false); - boolean updated = updateVisibility(waypointInfoBar, true); + AndroidUiHelper.updateVisibility(addressText, false); + AndroidUiHelper.updateVisibility(addressTextShadow, false); + boolean updated = AndroidUiHelper.updateVisibility(waypointInfoBar, true); // pass top bar to make it clickable WaypointDialogHelper.updatePointInfoView(map.getMyApplication(), map, topBar, pnt, true, map.getMyApplication().getDaynightHelper().isNightModeForMapControls(), false, true); @@ -1031,4 +1015,160 @@ public class MapInfoWidgetsFactory { } } + + public static class TopCoordinatesView { + private final MapActivity map; + private OsmandSettings settings; + private UiUtilities iconsCache; + + private OsmAndLocationProvider locationProvider; + private View topBar; + private View coordinatesRow; + private View latCoordinatesContainer; + private View lonCoordinatesContainer; + private TextView latitudeText; + private TextView longitudeText; + private ImageView latitudeIcon; + private ImageView longitudeIcon; + private View coordinatesDivider; + + private Location lastKnownLocation; + private boolean nightMode; + + public TopCoordinatesView(OsmandApplication app, MapActivity map) { + topBar = map.findViewById(R.id.coordinates_top_bar); + coordinatesRow = (LinearLayout) map.findViewById(R.id.coordinates_row); + latCoordinatesContainer = (LinearLayout) map.findViewById(R.id.lat_coordinates_container); + lonCoordinatesContainer = (LinearLayout) map.findViewById(R.id.lon_coordinates_container); + latitudeText = (TextView) map.findViewById(R.id.lat_coordinates); + longitudeText = (TextView) map.findViewById(R.id.lon_coordinates); + latitudeIcon = (ImageView) map.findViewById(R.id.lat_icon); + longitudeIcon = (ImageView) map.findViewById(R.id.lon_icon); + coordinatesDivider = map.findViewById(R.id.coordinates_divider); + this.map = map; + settings = app.getSettings(); + iconsCache = app.getUIUtilities(); + locationProvider = app.getLocationProvider(); + updateVisibility(false); + coordinatesRow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (lastKnownLocation != null) { + String coordinates = latitudeText.getText().toString(); + if (lonCoordinatesContainer.getVisibility() == View.VISIBLE) { + coordinates += ", " + longitudeText.getText().toString(); + } + copyToClipboard(coordinates); + } + } + }); + } + + @SuppressLint("SetTextI18n") + public boolean updateInfo() { + boolean visible = settings.SHOW_COORDINATES_WIDGET.get() && map.getContextMenu().shouldShowTopControls() + && map.getMapRouteInfoMenu().shouldShowTopControls() && !map.isTopToolbarActive() + && !MapRouteInfoMenu.chooseRoutesVisible && !MapRouteInfoMenu.waypointsVisible; + + updateVisibility(visible); + if (visible) { + lastKnownLocation = locationProvider.getLastKnownLocation(); + if (lastKnownLocation != null) { + int f = settings.COORDINATES_FORMAT.get(); + double lat = lastKnownLocation.getLatitude(); + double lon = lastKnownLocation.getLongitude(); + + if (f == PointDescription.UTM_FORMAT) { + AndroidUiHelper.updateVisibility(lonCoordinatesContainer, false); + AndroidUiHelper.updateVisibility(coordinatesDivider, false); + AndroidUiHelper.updateVisibility(latitudeIcon, true); + latitudeIcon.setImageDrawable(iconsCache.getIcon(nightMode ? R.drawable.widget_coordinates_utm_night : R.drawable.widget_coordinates_utm_day)); + UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon)); + String utmLocation = pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " + ((long) pnt.northing); + latitudeText.setText(utmLocation); + } else if (f == PointDescription.OLC_FORMAT) { + AndroidUiHelper.updateVisibility(lonCoordinatesContainer, false); + AndroidUiHelper.updateVisibility(coordinatesDivider, false); + AndroidUiHelper.updateVisibility(latitudeIcon, true); + latitudeIcon.setImageDrawable(iconsCache.getIcon(nightMode ? R.drawable.widget_coordinates_utm_night : R.drawable.widget_coordinates_utm_day)); + String olcLocation; + try { + olcLocation = PointDescription.getLocationOlcName(lat, lon); + } catch (RuntimeException e) { + e.printStackTrace(); + olcLocation = "0, 0"; + } + latitudeText.setText(olcLocation); + } else { + AndroidUiHelper.updateVisibility(lonCoordinatesContainer, true); + AndroidUiHelper.updateVisibility(coordinatesDivider, true); + AndroidUiHelper.updateVisibility(latitudeIcon, true); + String latitude = ""; + String longitude = ""; + try { + latitude = LocationConvert.convertLatitude(lat, f, true); + longitude = LocationConvert.convertLongitude(lon, f, true); + } catch (RuntimeException e) { + e.printStackTrace(); + } + latitudeIcon.setImageDrawable(iconsCache.getIcon(nightMode ? R.drawable.widget_coordinates_latitude_night : R.drawable.widget_coordinates_latitude_day)); + longitudeIcon.setImageDrawable(iconsCache.getIcon(nightMode ? R.drawable.widget_coordinates_longitude_night : R.drawable.widget_coordinates_longitude_day)); + latitudeText.setText(latitude); + longitudeText.setText(longitude); + } + } else { + AndroidUiHelper.updateVisibility(lonCoordinatesContainer, false); + AndroidUiHelper.updateVisibility(coordinatesDivider, false); + AndroidUiHelper.updateVisibility(latitudeIcon, false); + GPSInfo gpsInfo = locationProvider.getGPSInfo(); + latitudeText.setText(map.getString(R.string.searching_gps) + "…" + gpsInfo.usedSatellites + "/" + gpsInfo.foundSatellites); + } + } + return false; + } + + private void copyToClipboard(@NonNull String text) { + Object systemService = map.getSystemService(Activity.CLIPBOARD_SERVICE); + if (systemService instanceof ClipboardManager) { + ((ClipboardManager) systemService).setText(text); + showShareSnackbar(text, map); + } + } + + private void showShareSnackbar(@NonNull final String text, @NonNull final Context ctx) { + Snackbar snackbar = Snackbar.make(map.getLayout(), ctx.getResources().getString(R.string.copied_to_clipboard) + ":\n" + text, Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_share, new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setAction(Intent.ACTION_SEND); + intent.putExtra(Intent.EXTRA_TEXT, text); + intent.setType("text/plain"); + ctx.startActivity(Intent.createChooser(intent, ctx.getString(R.string.send_location))); + } + }); + AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark); + AndroidUtils.setSnackbarTextMaxLines(snackbar, 5); + snackbar.show(); + } + + public boolean updateVisibility(boolean visible) { + boolean res = AndroidUiHelper.updateVisibility(topBar, visible); + if (res) { + map.updateStatusBarColor(); + } + return res; + } + + public void updateColors(boolean nightMode, boolean bold) { + this.nightMode = nightMode; + topBar.setBackgroundColor(ContextCompat.getColor(map, nightMode ? R.color.activity_background_dark : R.color.activity_background_dark)); + int textColor = ContextCompat.getColor(map, nightMode ? R.color.activity_background_light : R.color.activity_background_light); + latitudeText.setTextColor(textColor); + longitudeText.setTextColor(textColor); + coordinatesDivider.setBackgroundColor(ContextCompat.getColor(map, nightMode ? R.color.divider_dark : R.color.divider_dark)); + latitudeText.setTypeface(Typeface.DEFAULT, bold ? Typeface.BOLD : Typeface.NORMAL); + longitudeText.setTypeface(Typeface.DEFAULT, bold ? Typeface.BOLD : Typeface.NORMAL); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 47b310b17b..2a09f6e854 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -153,7 +153,7 @@ public class MapMarkersWidgetsFactory { } public boolean updateVisibility(boolean visible) { - boolean res = updateVisibility(topBar, visible); + boolean res = AndroidUiHelper.updateVisibility(topBar, visible); if (visible != cachedTopBarVisibility) { cachedTopBarVisibility = visible; map.updateStatusBarColor(); @@ -161,19 +161,6 @@ public class MapMarkersWidgetsFactory { return res; } - public boolean updateVisibility(View v, boolean visible) { - if (visible != (v.getVisibility() == View.VISIBLE)) { - if (visible) { - v.setVisibility(View.VISIBLE); - } else { - v.setVisibility(View.GONE); - } - v.invalidate(); - return true; - } - return false; - } - public int getTopBarHeight() { return topBar.getHeight(); } @@ -227,9 +214,9 @@ public class MapMarkersWidgetsFactory { } } updateUI(loc, heading, marker, arrowImg2nd, distText2nd, okButton2nd, addressText2nd, false, customLocation != null); - updateVisibility(topBar2nd, true); + AndroidUiHelper.updateVisibility(topBar2nd, true); } else { - updateVisibility(topBar2nd, false); + AndroidUiHelper.updateVisibility(topBar2nd, false); } updateVisibility(true); @@ -274,7 +261,7 @@ public class MapMarkersWidgetsFactory { if (txt != null) { distText.setText(txt); } - updateVisibility(okButton, !customLocation && loc != null && dist < MIN_DIST_OK_VISIBLE); + AndroidUiHelper.updateVisibility(okButton, !customLocation && loc != null && dist < MIN_DIST_OK_VISIBLE); String descr; PointDescription pd = marker.getPointDescription(map); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index fa5676abf6..e9608d29e2 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -322,6 +322,10 @@ public class MapWidgetRegistry { if (mode != ApplicationMode.DEFAULT) { addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME); } + cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.coordinates_widget, map) + .setIcon(R.drawable.ic_action_coordinates_widget) + .setSelected(settings.SHOW_COORDINATES_WIDGET.get()) + .setListener(new ApearanceItemClickListener(settings.SHOW_COORDINATES_WIDGET, map)).createItem()); cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map) .setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map)) .setListener(new ContextMenuAdapter.ItemClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index b74610bd87..c6a127c655 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -856,10 +856,10 @@ public class RouteInfoWidgetsFactory { lanesText.invalidate(); } } - updateVisibility(lanesShadowText, visible && shadowRadius > 0); - updateVisibility(lanesText, visible); - updateVisibility(lanesView, visible); - updateVisibility(centerInfo, visible); + AndroidUiHelper.updateVisibility(lanesShadowText, visible && shadowRadius > 0); + AndroidUiHelper.updateVisibility(lanesText, visible); + AndroidUiHelper.updateVisibility(lanesView, visible); + AndroidUiHelper.updateVisibility(centerInfo, visible); return true; } } @@ -1202,7 +1202,7 @@ public class RouteInfoWidgetsFactory { layout.setLayoutParams(lp); layout.requestLayout(); } - updateVisibility(layout, visible); + AndroidUiHelper.updateVisibility(layout, visible); return true; } @@ -1347,7 +1347,7 @@ public class RouteInfoWidgetsFactory { } } } - updateVisibility(layout, visible); + AndroidUiHelper.updateVisibility(layout, visible); return true; } @@ -1356,8 +1356,6 @@ public class RouteInfoWidgetsFactory { } } - - public static boolean distChanged(int oldDist, int dist){ if (oldDist != 0 && Math.abs(oldDist - dist) < 10) { return false; @@ -1376,17 +1374,4 @@ public class RouteInfoWidgetsFactory { public RulerWidget createRulerControl(OsmandApplication app, MapActivity map) { return new RulerWidget(app, map); } - - protected static boolean updateVisibility(View view, boolean visible) { - if (visible != (view.getVisibility() == View.VISIBLE)) { - if (visible) { - view.setVisibility(View.VISIBLE); - } else { - view.setVisibility(View.GONE); - } - view.invalidate(); - return true; - } - return false; - } }