Merge pull request #6945 from osmandapp/CoordinatesWidget
Add Coordinates widget
This commit is contained in:
commit
7936ca86bb
15 changed files with 519 additions and 102 deletions
|
@ -16,6 +16,10 @@ public class LocationConvert {
|
||||||
public static final int UTM_FORMAT = 3;
|
public static final int UTM_FORMAT = 3;
|
||||||
public static final int OLC_FORMAT = 4;
|
public static final int OLC_FORMAT = 4;
|
||||||
private static final char DELIM = ':';
|
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$
|
DecimalFormat df = new DecimalFormat("##0.00000", new DecimalFormatSymbols(Locale.US)); //$NON-NLS-1$
|
||||||
if (outputType == FORMAT_MINUTES || outputType == FORMAT_SECONDS) {
|
if (outputType == FORMAT_MINUTES || outputType == FORMAT_SECONDS) {
|
||||||
int degrees = (int) Math.floor(coordinate);
|
coordinate = formatCoordinate(coordinate, sb, DELIM);
|
||||||
sb.append(degrees);
|
|
||||||
sb.append(DELIM);
|
|
||||||
coordinate -= degrees;
|
|
||||||
coordinate *= 60.0;
|
|
||||||
if (outputType == FORMAT_SECONDS) {
|
if (outputType == FORMAT_SECONDS) {
|
||||||
int minutes = (int) Math.floor(coordinate);
|
coordinate = formatCoordinate(coordinate, sb, DELIM);
|
||||||
sb.append(minutes);
|
|
||||||
sb.append(DELIM);
|
|
||||||
coordinate -= minutes;
|
|
||||||
coordinate *= 60.0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append(df.format(coordinate));
|
sb.append(df.format(coordinate));
|
||||||
return sb.toString();
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,103 @@
|
||||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
android:orientation="vertical">
|
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/activity_background_light"
|
||||||
|
android:textSize="@dimen/map_top_widget_text_size"
|
||||||
|
tools: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:maxLines="1"
|
||||||
|
android:textColor="@color/activity_background_light"
|
||||||
|
android:textSize="@dimen/map_top_widget_text_size"
|
||||||
|
tools:textStyle="bold"
|
||||||
|
tools:text="W 120°31′12″" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/map_markers_top_bar"
|
android:id="@+id/map_markers_top_bar"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
|
|
@ -8,7 +8,104 @@
|
||||||
|
|
||||||
<!-- TOP ROW -->
|
<!-- TOP ROW -->
|
||||||
|
|
||||||
<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/activity_background_light"
|
||||||
|
android:textSize="@dimen/map_top_widget_text_size"
|
||||||
|
tools: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:maxLines="1"
|
||||||
|
android:textColor="@color/activity_background_light"
|
||||||
|
android:textSize="@dimen/map_top_widget_text_size"
|
||||||
|
tools:textStyle="bold"
|
||||||
|
tools:text="W 120°31′12″" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
android:id="@+id/map_top_bar"
|
android:id="@+id/map_top_bar"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="map_trans_seek_size">120dp</dimen>
|
<dimen name="map_trans_seek_size">120dp</dimen>
|
||||||
<dimen name="map_widget_text_size">35sp</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_widget_text_size_small">23sp</dimen>
|
||||||
<dimen name="map_button_text_size">23sp</dimen>
|
<dimen name="map_button_text_size">23sp</dimen>
|
||||||
<dimen name="map_route_buttons_width">90dp</dimen>
|
<dimen name="map_route_buttons_width">90dp</dimen>
|
||||||
|
@ -132,6 +133,7 @@
|
||||||
<dimen name="bottom_sheet_content_margin_small">12dp</dimen>
|
<dimen name="bottom_sheet_content_margin_small">12dp</dimen>
|
||||||
<dimen name="content_padding">24dp</dimen>
|
<dimen name="content_padding">24dp</dimen>
|
||||||
<dimen name="content_padding_small">18dp</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="bottom_sheet_content_padding_small">12dp</dimen>
|
||||||
<dimen name="measurement_tool_divider_margin">12dp</dimen>
|
<dimen name="measurement_tool_divider_margin">12dp</dimen>
|
||||||
<dimen name="measurement_tool_content_padding_medium">18dp</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_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_widget_text_size_small">15sp</dimen>
|
||||||
<dimen name="map_button_text_size">18sp</dimen>
|
<dimen name="map_button_text_size">18sp</dimen>
|
||||||
<dimen name="map_alarm_text_size">25sp</dimen>
|
<dimen name="map_alarm_text_size">25sp</dimen>
|
||||||
|
@ -223,6 +224,7 @@
|
||||||
<dimen name="bottom_sheet_content_margin_small">8dp</dimen>
|
<dimen name="bottom_sheet_content_margin_small">8dp</dimen>
|
||||||
<dimen name="content_padding">16dp</dimen>
|
<dimen name="content_padding">16dp</dimen>
|
||||||
<dimen name="content_padding_small">12dp</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="bottom_sheet_content_padding_small">8dp</dimen>
|
||||||
<dimen name="measurement_tool_divider_margin">8dp</dimen>
|
<dimen name="measurement_tool_divider_margin">8dp</dimen>
|
||||||
<dimen name="measurement_tool_content_padding_medium">12dp</dimen>
|
<dimen name="measurement_tool_content_padding_medium">12dp</dimen>
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<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_moved">Moved %1$d files (%2$s).</string>
|
||||||
<string name="files_copied">Copied %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>
|
<string name="files_failed">Failed to copy %1$d files (%2$s).</string>
|
||||||
|
|
|
@ -298,6 +298,12 @@ public class AndroidUtils {
|
||||||
tv.setTextColor(ContextCompat.getColor(view.getContext(), colorId));
|
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")
|
@SuppressLint("NewApi")
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static void setBackground(Context ctx, View view, boolean night, int lightResId, int darkResId) {
|
public static void setBackground(Context ctx, View view, boolean night, int lightResId, int darkResId) {
|
||||||
|
|
|
@ -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_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 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();
|
public final OsmandPreference<Boolean> ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeGlobal().cache();
|
||||||
|
|
|
@ -918,7 +918,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
if (color == TopToolbarController.NO_COLOR) {
|
if (color == TopToolbarController.NO_COLOR) {
|
||||||
boolean mapTopBar = findViewById(R.id.map_top_bar).getVisibility() == View.VISIBLE;
|
boolean mapTopBar = findViewById(R.id.map_top_bar).getVisibility() == View.VISIBLE;
|
||||||
boolean markerTopBar = findViewById(R.id.map_markers_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;
|
colorId = night ? R.color.status_bar_route_dark : R.color.status_bar_route_light;
|
||||||
} else if (markerTopBar && mapControlsVisible) {
|
} else if (markerTopBar && mapControlsVisible) {
|
||||||
colorId = R.color.status_bar_dark;
|
colorId = R.color.status_bar_dark;
|
||||||
|
|
|
@ -1820,6 +1820,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
||||||
return directionInfo;
|
return directionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldShowTopControls() {
|
||||||
|
return shouldShowTopControls(isVisible());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldShowTopControls(boolean menuVisible) {
|
||||||
|
return !menuVisible || !portraitMode || getCurrentMenuState() == MenuState.HEADER_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
WeakReference<MapRouteInfoMenuFragment> fragmentRef = findMenuFragment();
|
WeakReference<MapRouteInfoMenuFragment> fragmentRef = findMenuFragment();
|
||||||
if (fragmentRef != null) {
|
if (fragmentRef != null) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints;
|
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
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.TopTextView;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
||||||
|
@ -56,6 +57,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
private DrawSettings drawSettings;
|
private DrawSettings drawSettings;
|
||||||
private TopTextView streetNameView;
|
private TopTextView streetNameView;
|
||||||
private TopToolbarView topToolbarView;
|
private TopToolbarView topToolbarView;
|
||||||
|
private TopCoordinatesView topCoordinatesView;
|
||||||
|
|
||||||
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
@ -139,8 +141,12 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
OsmandApplication app = view.getApplication();
|
OsmandApplication app = view.getApplication();
|
||||||
lanesControl = ric.createLanesControl(map, view);
|
lanesControl = ric.createLanesControl(map, view);
|
||||||
|
|
||||||
|
TextState ts = calculateTextState();
|
||||||
streetNameView = new TopTextView(map.getMyApplication(), map);
|
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);
|
topToolbarView = new TopToolbarView(map);
|
||||||
updateTopToolbar(false);
|
updateTopToolbar(false);
|
||||||
|
@ -256,6 +262,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
updateReg(ts, reg);
|
updateReg(ts, reg);
|
||||||
}
|
}
|
||||||
updateStreetName(nightMode, ts);
|
updateStreetName(nightMode, ts);
|
||||||
|
updateTopCoordinates(nightMode, ts);
|
||||||
updateTopToolbar(nightMode);
|
updateTopToolbar(nightMode);
|
||||||
lanesControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius / 2);
|
lanesControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius / 2);
|
||||||
rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity()));
|
rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity()));
|
||||||
|
@ -275,6 +282,10 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
topToolbarView.updateColors(nightMode);
|
topToolbarView.updateColors(nightMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateTopCoordinates(boolean nightMode, TextState ts) {
|
||||||
|
topCoordinatesView.updateColors(nightMode, ts.textBold);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateReg(TextState ts, MapWidgetRegInfo reg) {
|
private void updateReg(TextState ts, MapWidgetRegInfo reg) {
|
||||||
View v = reg.widget != null ? reg.widget.getView().findViewById(R.id.widget_bg) : null;
|
View v = reg.widget != null ? reg.widget.getView().findViewById(R.id.widget_bg) : null;
|
||||||
if(v != null) {
|
if(v != null) {
|
||||||
|
@ -329,6 +340,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
mapInfoControls.updateInfo(settings.getApplicationMode(), drawSettings, expanded);
|
mapInfoControls.updateInfo(settings.getApplicationMode(), drawSettings, expanded);
|
||||||
streetNameView.updateInfo(drawSettings);
|
streetNameView.updateInfo(drawSettings);
|
||||||
topToolbarView.updateInfo();
|
topToolbarView.updateInfo();
|
||||||
|
topCoordinatesView.updateInfo();
|
||||||
alarmControl.updateInfo(drawSettings);
|
alarmControl.updateInfo(drawSettings);
|
||||||
rulerControl.updateInfo(tileBox, drawSettings);
|
rulerControl.updateInfo(tileBox, drawSettings);
|
||||||
lanesControl.updateInfo(drawSettings);
|
lanesControl.updateInfo(drawSettings);
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
package net.osmand.plus.views.mapwidgets;
|
package net.osmand.plus.views.mapwidgets;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.ColorRes;
|
import android.support.annotation.ColorRes;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
import android.text.ClipboardManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
|
@ -18,9 +25,15 @@ import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
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.Location;
|
||||||
|
import net.osmand.LocationConvert;
|
||||||
import net.osmand.binary.RouteDataObject;
|
import net.osmand.binary.RouteDataObject;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.CurrentPositionHelper;
|
import net.osmand.plus.CurrentPositionHelper;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmAndLocationProvider;
|
import net.osmand.plus.OsmAndLocationProvider;
|
||||||
|
@ -29,6 +42,7 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.RulerMode;
|
import net.osmand.plus.OsmandSettings.RulerMode;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.actions.StartGPSStatus;
|
import net.osmand.plus.activities.actions.StartGPSStatus;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
@ -499,28 +513,28 @@ public class MapInfoWidgetsFactory {
|
||||||
SwitchCompat switchCompat = view.getTopBarSwitch();
|
SwitchCompat switchCompat = view.getTopBarSwitch();
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
titleView.setText(title);
|
titleView.setText(title);
|
||||||
view.updateVisibility(titleView, true);
|
AndroidUiHelper.updateVisibility(titleView, true);
|
||||||
} else {
|
} else {
|
||||||
view.updateVisibility(titleView, false);
|
AndroidUiHelper.updateVisibility(titleView, false);
|
||||||
}
|
}
|
||||||
if (description != null) {
|
if (description != null) {
|
||||||
descrView.setText(description);
|
descrView.setText(description);
|
||||||
view.updateVisibility(descrView, true);
|
AndroidUiHelper.updateVisibility(descrView, true);
|
||||||
} else {
|
} else {
|
||||||
view.updateVisibility(descrView, false);
|
AndroidUiHelper.updateVisibility(descrView, false);
|
||||||
}
|
}
|
||||||
if (bottomView != null) {
|
if (bottomView != null) {
|
||||||
bottomViewLayout.removeAllViews();
|
bottomViewLayout.removeAllViews();
|
||||||
bottomViewLayout.addView(bottomView);
|
bottomViewLayout.addView(bottomView);
|
||||||
view.updateVisibility(bottomViewLayout, true);
|
AndroidUiHelper.updateVisibility(bottomViewLayout, true);
|
||||||
} else {
|
} else {
|
||||||
view.updateVisibility(bottomViewLayout, false);
|
AndroidUiHelper.updateVisibility(bottomViewLayout, false);
|
||||||
}
|
}
|
||||||
view.updateVisibility(switchCompat, topBarSwitchVisible);
|
AndroidUiHelper.updateVisibility(switchCompat, topBarSwitchVisible);
|
||||||
if (topBarSwitchVisible) {
|
if (topBarSwitchVisible) {
|
||||||
switchCompat.setChecked(topBarSwitchChecked);
|
switchCompat.setChecked(topBarSwitchChecked);
|
||||||
if (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) {
|
if (view.getShadowView() != null) {
|
||||||
|
@ -564,7 +578,7 @@ public class MapInfoWidgetsFactory {
|
||||||
descrView = (TextView) map.findViewById(R.id.widget_top_bar_description);
|
descrView = (TextView) map.findViewById(R.id.widget_top_bar_description);
|
||||||
topBarSwitch = (SwitchCompat) map.findViewById(R.id.widget_top_bar_switch);
|
topBarSwitch = (SwitchCompat) map.findViewById(R.id.widget_top_bar_switch);
|
||||||
shadowView = map.findViewById(R.id.widget_top_bar_shadow);
|
shadowView = map.findViewById(R.id.widget_top_bar_shadow);
|
||||||
updateVisibility(false);
|
AndroidUiHelper.updateVisibility(topbar, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapActivity getMap() {
|
public MapActivity getMap() {
|
||||||
|
@ -656,23 +670,6 @@ public class MapInfoWidgetsFactory {
|
||||||
updateInfo();
|
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) {
|
private void initToolbar(TopToolbarController controller) {
|
||||||
backButton.setOnClickListener(controller.onBackButtonClickListener);
|
backButton.setOnClickListener(controller.onBackButtonClickListener);
|
||||||
topBarTitleLayout.setOnClickListener(controller.onTitleClickListener);
|
topBarTitleLayout.setOnClickListener(controller.onTitleClickListener);
|
||||||
|
@ -692,7 +689,7 @@ public class MapInfoWidgetsFactory {
|
||||||
initToolbar(defaultController);
|
initToolbar(defaultController);
|
||||||
defaultController.updateToolbar(this);
|
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));
|
(!map.getContextMenu().isVisible() || controller.getType() == TopToolbarControllerType.CONTEXT_MENU));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,26 +836,13 @@ public class MapInfoWidgetsFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateVisibility(boolean visible) {
|
public boolean updateVisibility(boolean visible) {
|
||||||
boolean res = updateVisibility(topBar, visible);
|
boolean res = AndroidUiHelper.updateVisibility(topBar, visible);
|
||||||
if (res) {
|
if (res) {
|
||||||
map.updateStatusBarColor();
|
map.updateStatusBarColor();
|
||||||
}
|
}
|
||||||
return res;
|
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) {
|
public void updateTextColor(boolean nightMode, int textColor, int textShadowColor, boolean bold, int rad) {
|
||||||
this.shadowRad = rad;
|
this.shadowRad = rad;
|
||||||
TextInfoWidget.updateTextColor(addressText, addressTextShadow, textColor, textShadowColor, bold, rad);
|
TextInfoWidget.updateTextColor(addressText, addressTextShadow, textColor, textShadowColor, bold, rad);
|
||||||
|
@ -943,15 +927,15 @@ public class MapInfoWidgetsFactory {
|
||||||
updateVisibility(false);
|
updateVisibility(false);
|
||||||
} else if (!showNextTurn && updateWaypoint()) {
|
} else if (!showNextTurn && updateWaypoint()) {
|
||||||
updateVisibility(true);
|
updateVisibility(true);
|
||||||
updateVisibility(addressText, false);
|
AndroidUiHelper.updateVisibility(addressText, false);
|
||||||
updateVisibility(addressTextShadow, false);
|
AndroidUiHelper.updateVisibility(addressTextShadow, false);
|
||||||
} else if (text == null) {
|
} else if (text == null) {
|
||||||
updateVisibility(false);
|
updateVisibility(false);
|
||||||
} else {
|
} else {
|
||||||
updateVisibility(true);
|
updateVisibility(true);
|
||||||
updateVisibility(waypointInfoBar, false);
|
AndroidUiHelper.updateVisibility(waypointInfoBar, false);
|
||||||
updateVisibility(addressText, true);
|
AndroidUiHelper.updateVisibility(addressText, true);
|
||||||
updateVisibility(addressTextShadow, shadowRad > 0);
|
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
|
||||||
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
|
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
|
||||||
this.showMarker = showMarker;
|
this.showMarker = showMarker;
|
||||||
int h = addressText.getHeight() / 4 * 3;
|
int h = addressText.getHeight() / 4 * 3;
|
||||||
|
@ -990,12 +974,12 @@ public class MapInfoWidgetsFactory {
|
||||||
this.lastPoint = pnt;
|
this.lastPoint = pnt;
|
||||||
if (pnt == null) {
|
if (pnt == null) {
|
||||||
topBar.setOnClickListener(null);
|
topBar.setOnClickListener(null);
|
||||||
updateVisibility(waypointInfoBar, false);
|
AndroidUiHelper.updateVisibility(waypointInfoBar, false);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
updateVisibility(addressText, false);
|
AndroidUiHelper.updateVisibility(addressText, false);
|
||||||
updateVisibility(addressTextShadow, false);
|
AndroidUiHelper.updateVisibility(addressTextShadow, false);
|
||||||
boolean updated = updateVisibility(waypointInfoBar, true);
|
boolean updated = AndroidUiHelper.updateVisibility(waypointInfoBar, true);
|
||||||
// pass top bar to make it clickable
|
// pass top bar to make it clickable
|
||||||
WaypointDialogHelper.updatePointInfoView(map.getMyApplication(), map, topBar, pnt, true,
|
WaypointDialogHelper.updatePointInfoView(map.getMyApplication(), map, topBar, pnt, true,
|
||||||
map.getMyApplication().getDaynightHelper().isNightModeForMapControls(), false, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class MapMarkersWidgetsFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateVisibility(boolean visible) {
|
public boolean updateVisibility(boolean visible) {
|
||||||
boolean res = updateVisibility(topBar, visible);
|
boolean res = AndroidUiHelper.updateVisibility(topBar, visible);
|
||||||
if (visible != cachedTopBarVisibility) {
|
if (visible != cachedTopBarVisibility) {
|
||||||
cachedTopBarVisibility = visible;
|
cachedTopBarVisibility = visible;
|
||||||
map.updateStatusBarColor();
|
map.updateStatusBarColor();
|
||||||
|
@ -161,19 +161,6 @@ public class MapMarkersWidgetsFactory {
|
||||||
return res;
|
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() {
|
public int getTopBarHeight() {
|
||||||
return topBar.getHeight();
|
return topBar.getHeight();
|
||||||
}
|
}
|
||||||
|
@ -227,9 +214,9 @@ public class MapMarkersWidgetsFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateUI(loc, heading, marker, arrowImg2nd, distText2nd, okButton2nd, addressText2nd, false, customLocation != null);
|
updateUI(loc, heading, marker, arrowImg2nd, distText2nd, okButton2nd, addressText2nd, false, customLocation != null);
|
||||||
updateVisibility(topBar2nd, true);
|
AndroidUiHelper.updateVisibility(topBar2nd, true);
|
||||||
} else {
|
} else {
|
||||||
updateVisibility(topBar2nd, false);
|
AndroidUiHelper.updateVisibility(topBar2nd, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVisibility(true);
|
updateVisibility(true);
|
||||||
|
@ -274,7 +261,7 @@ public class MapMarkersWidgetsFactory {
|
||||||
if (txt != null) {
|
if (txt != null) {
|
||||||
distText.setText(txt);
|
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;
|
String descr;
|
||||||
PointDescription pd = marker.getPointDescription(map);
|
PointDescription pd = marker.getPointDescription(map);
|
||||||
|
|
|
@ -322,6 +322,10 @@ public class MapWidgetRegistry {
|
||||||
if (mode != ApplicationMode.DEFAULT) {
|
if (mode != ApplicationMode.DEFAULT) {
|
||||||
addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME);
|
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)
|
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map)
|
||||||
.setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
|
.setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
|
||||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||||
|
|
|
@ -856,10 +856,10 @@ public class RouteInfoWidgetsFactory {
|
||||||
lanesText.invalidate();
|
lanesText.invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateVisibility(lanesShadowText, visible && shadowRadius > 0);
|
AndroidUiHelper.updateVisibility(lanesShadowText, visible && shadowRadius > 0);
|
||||||
updateVisibility(lanesText, visible);
|
AndroidUiHelper.updateVisibility(lanesText, visible);
|
||||||
updateVisibility(lanesView, visible);
|
AndroidUiHelper.updateVisibility(lanesView, visible);
|
||||||
updateVisibility(centerInfo, visible);
|
AndroidUiHelper.updateVisibility(centerInfo, visible);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1202,7 +1202,7 @@ public class RouteInfoWidgetsFactory {
|
||||||
layout.setLayoutParams(lp);
|
layout.setLayoutParams(lp);
|
||||||
layout.requestLayout();
|
layout.requestLayout();
|
||||||
}
|
}
|
||||||
updateVisibility(layout, visible);
|
AndroidUiHelper.updateVisibility(layout, visible);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1347,7 +1347,7 @@ public class RouteInfoWidgetsFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateVisibility(layout, visible);
|
AndroidUiHelper.updateVisibility(layout, visible);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,8 +1356,6 @@ public class RouteInfoWidgetsFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean distChanged(int oldDist, int dist){
|
public static boolean distChanged(int oldDist, int dist){
|
||||||
if (oldDist != 0 && Math.abs(oldDist - dist) < 10) {
|
if (oldDist != 0 && Math.abs(oldDist - dist) < 10) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1376,17 +1374,4 @@ public class RouteInfoWidgetsFactory {
|
||||||
public RulerWidget createRulerControl(OsmandApplication app, MapActivity map) {
|
public RulerWidget createRulerControl(OsmandApplication app, MapActivity map) {
|
||||||
return new RulerWidget(app, 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