Add topbar coordinates widget
This commit is contained in:
parent
a7edef6e12
commit
32c56a693e
13 changed files with 483 additions and 92 deletions
|
@ -133,6 +133,67 @@ public class LocationConvert {
|
|||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat("##0.00000", new DecimalFormatSymbols(Locale.US)); //$NON-NLS-1$
|
||||
coordinate = convertMinutesAndSeconds(coordinate, outputType, sb);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat("##0.00000", new DecimalFormatSymbols(Locale.US));
|
||||
latitude = convertMinutesAndSeconds(latitude, outputType, sb);
|
||||
|
||||
sb.append(df.format(latitude));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat("##0.00000", new DecimalFormatSymbols(Locale.US));
|
||||
longitude = convertMinutesAndSeconds(longitude, outputType, sb);
|
||||
|
||||
sb.append(df.format(longitude));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static double convertMinutesAndSeconds(double coordinate, int outputType, StringBuilder sb) {
|
||||
if (outputType == FORMAT_MINUTES || outputType == FORMAT_SECONDS) {
|
||||
int degrees = (int) Math.floor(coordinate);
|
||||
sb.append(degrees);
|
||||
|
@ -147,7 +208,6 @@ public class LocationConvert {
|
|||
coordinate *= 60.0;
|
||||
}
|
||||
}
|
||||
sb.append(df.format(coordinate));
|
||||
return sb.toString();
|
||||
return coordinate;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,104 @@
|
|||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/coordinates_top_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:minHeight="@dimen/map_address_height"
|
||||
android:visibility="visible"
|
||||
tools:background="@color/activity_background_dark"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/coordinates_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lat_coordinates_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/lat_icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="@dimen/content_padding_half"
|
||||
android:layout_marginEnd="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_marginBottom="@dimen/content_padding_half"
|
||||
android:src="@drawable/widget_coordinates_latitude_day" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lat_coordinates"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/map_top_widget_text_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="N 20°96′60″" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/coordinates_divider"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
tools:background="@color/map_progress_bar_bg_light" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lon_coordinates_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/lon_icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="@dimen/content_padding_half"
|
||||
android:layout_marginEnd="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_marginBottom="@dimen/content_padding_half"
|
||||
android:src="@drawable/widget_coordinates_longitude_day" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lon_coordinates"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/map_top_widget_text_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="W 120°31′12″" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/map_markers_top_bar"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -299,7 +299,105 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
<FrameLayout
|
||||
android:id="@+id/coordinates_top_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:minHeight="@dimen/map_address_height"
|
||||
android:visibility="visible"
|
||||
tools:background="@color/activity_background_dark"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/coordinates_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lat_coordinates_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/lat_icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="@dimen/content_padding_half"
|
||||
android:layout_marginEnd="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_marginBottom="@dimen/content_padding_half"
|
||||
android:src="@drawable/widget_coordinates_latitude_day" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lat_coordinates"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/map_top_widget_text_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="N 20°96′60″" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/coordinates_divider"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
tools:background="@color/map_progress_bar_bg_light" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lon_coordinates_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/lon_icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="@dimen/content_padding_half"
|
||||
android:layout_marginEnd="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_marginBottom="@dimen/content_padding_half"
|
||||
android:src="@drawable/widget_coordinates_longitude_day" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lon_coordinates"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/map_top_widget_text_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="W 120°31′12″" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/map_markers_top_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<resources>
|
||||
<dimen name="map_trans_seek_size">120dp</dimen>
|
||||
<dimen name="map_widget_text_size">35sp</dimen>
|
||||
<dimen name="map_top_widget_text_size">33sp</dimen>
|
||||
<dimen name="map_widget_text_size_small">23sp</dimen>
|
||||
<dimen name="map_button_text_size">23sp</dimen>
|
||||
<dimen name="map_route_buttons_width">90dp</dimen>
|
||||
|
@ -132,6 +133,7 @@
|
|||
<dimen name="bottom_sheet_content_margin_small">12dp</dimen>
|
||||
<dimen name="content_padding">24dp</dimen>
|
||||
<dimen name="content_padding_small">18dp</dimen>
|
||||
<dimen name="content_padding_half">12dp</dimen>
|
||||
<dimen name="bottom_sheet_content_padding_small">12dp</dimen>
|
||||
<dimen name="measurement_tool_divider_margin">12dp</dimen>
|
||||
<dimen name="measurement_tool_content_padding_medium">18dp</dimen>
|
||||
|
|
|
@ -127,6 +127,7 @@
|
|||
|
||||
|
||||
<dimen name="map_widget_text_size">23sp</dimen>
|
||||
<dimen name="map_top_widget_text_size">22sp</dimen>
|
||||
<dimen name="map_widget_text_size_small">15sp</dimen>
|
||||
<dimen name="map_button_text_size">18sp</dimen>
|
||||
<dimen name="map_alarm_text_size">25sp</dimen>
|
||||
|
@ -223,6 +224,7 @@
|
|||
<dimen name="bottom_sheet_content_margin_small">8dp</dimen>
|
||||
<dimen name="content_padding">16dp</dimen>
|
||||
<dimen name="content_padding_small">12dp</dimen>
|
||||
<dimen name="content_padding_half">8dp</dimen>
|
||||
<dimen name="bottom_sheet_content_padding_small">8dp</dimen>
|
||||
<dimen name="measurement_tool_divider_margin">8dp</dimen>
|
||||
<dimen name="measurement_tool_content_padding_medium">12dp</dimen>
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="coordinates_copy_to_clipboard">Coordinates copy to clipboard</string>
|
||||
<string name="searching_gps">Searching GPS</string>
|
||||
<string name="coordinates_widget">Coordinates widget</string>
|
||||
<string name="files_moved">Moved %1$d files (%2$s).</string>
|
||||
<string name="files_copied">Copied %1$d files (%2$s).</string>
|
||||
<string name="files_failed">Failed to copy %1$d files (%2$s).</string>
|
||||
|
|
|
@ -1448,6 +1448,8 @@ public class OsmandSettings {
|
|||
|
||||
public final OsmandPreference<Boolean> SHOW_MAP_MARKERS = new BooleanPreference("show_map_markers", true).makeGlobal();
|
||||
|
||||
public final OsmandPreference<Boolean> SHOW_COORDINATES_WIDGET = new BooleanPreference("show_coordinates_widget", false).makeGlobal();
|
||||
|
||||
public final CommonPreference<NotesSortByMode> NOTES_SORT_BY_MODE = new EnumIntPreference<>("notes_sort_by_mode", NotesSortByMode.BY_DATE, NotesSortByMode.values());
|
||||
|
||||
public final OsmandPreference<Boolean> ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeGlobal().cache();
|
||||
|
|
|
@ -918,8 +918,11 @@ 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;
|
||||
boolean coordinatesTopBar = findViewById(R.id.coordinates_top_bar).getVisibility() == View.VISIBLE;
|
||||
if (mapTopBar && mapControlsVisible) {
|
||||
colorId = night ? R.color.status_bar_route_dark : R.color.status_bar_route_light;
|
||||
} else if (coordinatesTopBar && mapControlsVisible) {
|
||||
colorId = night ? R.color.status_bar_main_dark : R.color.status_bar_main_dark;
|
||||
} else if (markerTopBar && mapControlsVisible) {
|
||||
colorId = R.color.status_bar_dark;
|
||||
} else {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,155 @@ 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();
|
||||
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);
|
||||
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);
|
||||
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(), R.string.coordinates_copy_to_clipboard, 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue