Added top map markers widget

This commit is contained in:
Alexey Kulish 2016-02-13 14:32:25 +03:00
parent faa85cdf54
commit 4b8ea58845
6 changed files with 408 additions and 11 deletions

View file

@ -139,10 +139,185 @@
android:id="@+id/waypoint_close"
android:layout_width="@dimen/map_address_height"
android:layout_height="@dimen/map_address_height"
android:background="@drawable/btn_circle_transparent"
android:background="@drawable/bottom_shadow"
android:src="@drawable/ic_action_test_light"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:minHeight="@dimen/map_address_height">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/map_address_height"
android:background="@color/markers_top_bar_background">
<LinearLayout
android:id="@+id/map_marker_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/map_marker_arrow"
android:layout_width="60dp"
android:layout_height="40dp"
android:src="@drawable/map_arrow_to_destination"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/map_marker_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="26sp"
android:textColor="@color/color_white"
android:text="500 m"/>
<TextView
android:id="@+id/map_marker_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textColor="@color/marker_top_2nd_line_color"
android:textStyle="bold"
android:maxLines="1"
android:ellipsize="end"
android:textSize="@dimen/default_list_text_size"
android:text="Dmitrievskaya st., 45"/>
</LinearLayout>
<ImageButton
android:id="@+id/marker_btn_ok"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_done"/>
<ImageButton
android:id="@+id/marker_btn_more"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar_2nd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/map_address_height"
android:background="@color/markers_top_bar_2nd_background"
android:visibility="visible">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal"/>
<LinearLayout
android:id="@+id/map_marker_row_2nd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/map_marker_arrow_2nd"
android:layout_width="60dp"
android:layout_height="30dp"
android:src="@drawable/map_arrow_to_destination"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/map_marker_dist_2nd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="@dimen/default_list_text_size_large"
android:textColor="@color/color_white"
android:text="500 m"/>
<TextView
android:id="@+id/map_marker_address_2nd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/marker_top_2nd_line_color"
android:maxLines="1"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:textStyle="bold"
android:textSize="@dimen/default_desc_text_size"
android:text=" - Dmitrievskaya st., 45"/>
</LinearLayout>
<ImageButton
android:id="@+id/marker_btn_ok_2dn"
android:layout_width="50dp"
android:layout_height="48dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_done"/>
<ImageButton
android:id="@+id/marker_btn_more_2nd"
android:layout_width="50dp"
android:layout_height="48dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal"/>
</LinearLayout>
</FrameLayout>
<!-- Widgets -->
<FrameLayout

View file

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="markers_top_bar_background">#145256</color>
<color name="markers_top_bar_2nd_background">#0e3b3e</color>
<color name="marker_top_2nd_line_color">#588689</color>
<color name="marker_blue">#2196f3</color>
<color name="marker_green">#73b825</color>
<color name="marker_orange">#ff9800</color>

View file

@ -3,6 +3,7 @@ package net.osmand.plus.base;
import android.content.Context;
import android.view.WindowManager;
import net.osmand.FloatMath;
import net.osmand.Location;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder;
@ -47,10 +48,13 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
private boolean isUserZoomed = false;
private String locationProvider;
private boolean showRouteFinishDialog = false;
private Location myLocation;
private Float heading;
public MapViewTrackingUtilities(OsmandApplication app){
this.app = app;
settings = app.getSettings();
myLocation = app.getLocationProvider().getLastKnownLocation();
app.getLocationProvider().addLocationListener(this);
app.getLocationProvider().addCompassListener(this);
addTargetPointListener(app);
@ -95,12 +99,21 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
}
}
public Location getMyLocation() {
return myLocation;
}
public Float getHeading() {
return heading;
}
public String getLocationProvider() {
return locationProvider;
}
@Override
public void updateCompassValue(float val) {
heading = val;
if (mapView != null) {
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_COMPASS && !routePlanningMode) {
if (Math.abs(MapUtils.degreesDiff(mapView.getRotate(), -val)) > 1) {
@ -128,6 +141,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
@Override
public void updateLocation(Location location) {
myLocation = location;
showViewAngle = false;
if (location != null) {
locationProvider = location.getProvider();

View file

@ -84,7 +84,7 @@ public class MapMarkerDialogHelper {
if (obj instanceof MapMarker) {
MapMarker marker = (MapMarker) obj;
if (!marker.history) {
showOnMap(marker);
showMarkerOnMap(mapActivity, marker);
} else {
showHistoryOnMap(marker);
}
@ -316,12 +316,7 @@ public class MapMarkerDialogHelper {
}
int dist = (int) mes[0];
//if (dist > 0) {
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
//} else {
// textDist.setText("");
//}
waypointDeviation.setVisibility(View.GONE);
@ -396,8 +391,8 @@ public class MapMarkerDialogHelper {
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
}
public void showOnMap(MapMarker marker) {
app.getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
public static void showMarkerOnMap(MapActivity mapActivity, MapMarker marker) {
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, marker.getPointDescription(mapActivity), true, marker);
MapActivity.launchMapActivityMoveToTop(mapActivity);
}
@ -492,6 +487,10 @@ public class MapMarkerDialogHelper {
}
public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) {
return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, getMapMarkerColorId(colorIndex));
}
public static int getMapMarkerColorId(int colorIndex) {
int colorId;
switch (colorIndex) {
case 0:
@ -505,7 +504,7 @@ public class MapMarkerDialogHelper {
break;
case 3:
colorId = R.color.marker_red;
break;
break;
case 4:
colorId = R.color.marker_yellow;
break;
@ -518,7 +517,7 @@ public class MapMarkerDialogHelper {
default:
colorId = R.color.marker_blue;
}
return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, colorId);
return colorId;
}
public void updateLocation(ListView listView, boolean compassChanged) {

View file

@ -16,6 +16,7 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.mapwidgets.MapMarkersWidget;
import java.util.ArrayList;
import java.util.List;
@ -26,6 +27,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
private final MapActivity map;
private OsmandMapTileView view;
private MapMarkersWidget widget;
private Paint bitmapPaint;
private Bitmap markerBitmapBlue;
private Bitmap markerBitmapGreen;
@ -70,6 +73,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
bitmapPaintDestYellow = createPaintDest(R.color.marker_yellow);
bitmapPaintDestTeal = createPaintDest(R.color.marker_teal);
bitmapPaintDestPurple = createPaintDest(R.color.marker_purple);
widget = new MapMarkersWidget(map);
}
private Paint createPaintDest(int colorId) {
@ -132,6 +137,9 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
widget.updateInfo(tb.getZoom());
if (tb.getZoom() < 3) {
return;
}

View file

@ -0,0 +1,197 @@
package net.osmand.plus.views.mapwidgets;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.Location;
import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.helpers.MapMarkerDialogHelper;
import net.osmand.plus.views.DirectionDrawable;
import net.osmand.util.Algorithms;
import java.util.List;
public class MapMarkersWidget {
public static final int MIN_DIST_OK_VISIBLE = 50;
private final MapActivity map;
private MapMarkersHelper helper;
private int screenOrientation;
private View topBar;
private View topBar2nd;
private View rowView;
private View rowView2nd;
private ImageView arrowImg;
private ImageView arrowImg2nd;
private TextView distText;
private TextView distText2nd;
private TextView addressText;
private TextView addressText2nd;
private ImageButton okButton;
private ImageButton okButton2nd;
private ImageButton moreButton;
private ImageButton moreButton2nd;
public MapMarkersWidget(MapActivity map) {
this.map = map;
helper = map.getMyApplication().getMapMarkersHelper();
screenOrientation = DashLocationFragment.getScreenOrientation(map);
topBar = map.findViewById(R.id.map_markers_top_bar);
topBar2nd = map.findViewById(R.id.map_markers_top_bar_2nd);
rowView = map.findViewById(R.id.map_marker_row);
rowView2nd = map.findViewById(R.id.map_marker_row_2nd);
arrowImg = (ImageView) map.findViewById(R.id.map_marker_arrow);
arrowImg2nd = (ImageView) map.findViewById(R.id.map_marker_arrow_2nd);
distText = (TextView) map.findViewById(R.id.map_marker_dist);
distText2nd = (TextView) map.findViewById(R.id.map_marker_dist_2nd);
addressText = (TextView) map.findViewById(R.id.map_marker_address);
addressText2nd = (TextView) map.findViewById(R.id.map_marker_address_2nd);
okButton = (ImageButton) map.findViewById(R.id.marker_btn_ok);
okButton2nd = (ImageButton) map.findViewById(R.id.marker_btn_ok_2dn);
moreButton = (ImageButton) map.findViewById(R.id.marker_btn_more);
moreButton2nd = (ImageButton) map.findViewById(R.id.marker_btn_more_2nd);
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMarkerOnMap(0);
}
});
rowView2nd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMarkerOnMap(1);
}
});
IconsCache iconsCache = map.getMyApplication().getIconsCache();
moreButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color));
moreButton2nd.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color));
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeMarker(0);
}
});
okButton2nd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeMarker(1);
}
});
updateVisibility(false);
}
private void removeMarker(int index) {
if (helper.getActiveMapMarkers().size() > index) {
MapMarker marker = helper.getActiveMapMarkers().get(index);
helper.removeMapMarker(marker.index);
helper.addMapMarkerHistory(marker);
}
}
private void showMarkerOnMap(int index) {
if (helper.getActiveMapMarkers().size() > index) {
MapMarker marker = helper.getActiveMapMarkers().get(index);
MapMarkerDialogHelper.showMarkerOnMap(map, marker);
}
}
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;
}
public void updateInfo(int zoom) {
List<MapMarker> markers = helper.getActiveMapMarkers();
if (zoom < 3 || markers.size() == 0 || map.getMyApplication().getRoutingHelper().isFollowingMode()
|| map.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().isVisible()) {
updateVisibility(false);
return;
}
Location loc = map.getMapViewTrackingUtilities().getMyLocation();
Float heading = map.getMapViewTrackingUtilities().getHeading();
MapMarker marker = markers.get(0);
updateUI(loc, heading, marker, arrowImg, distText, okButton, addressText, true);
if (markers.size() > 1) {
marker = markers.get(1);
updateUI(loc, heading, marker, arrowImg2nd, distText2nd, okButton2nd, addressText2nd, false);
updateVisibility(topBar2nd, true);
} else {
updateVisibility(topBar2nd, false);
}
updateVisibility(true);
}
private void updateUI(Location loc, Float heading, MapMarker marker, ImageView arrowImg,
TextView distText, ImageButton okButton, TextView addressText, boolean firstLine) {
float[] mes = new float[2];
if (loc != null && marker.point != null) {
Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
}
boolean newImage = false;
DirectionDrawable dd;
if (!(arrowImg.getDrawable() instanceof DirectionDrawable)) {
newImage = true;
dd = new DirectionDrawable(map, arrowImg.getWidth(), arrowImg.getHeight());
} else {
dd = (DirectionDrawable) arrowImg.getDrawable();
}
dd.setImage(R.drawable.map_arrow_to_destination, MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex));
if (loc == null || heading == null || marker.point == null) {
dd.setAngle(0);
} else {
dd.setAngle(mes[1] - heading + 90 + screenOrientation);
}
if (newImage) {
arrowImg.setImageDrawable(dd);
}
arrowImg.invalidate();
int dist = (int) mes[0];
distText.setText(OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication()));
updateVisibility(okButton, dist < MIN_DIST_OK_VISIBLE);
String descr;
PointDescription pd = marker.getPointDescription(map);
if (Algorithms.isEmpty(pd.getName())) {
descr = pd.getTypeName();
} else {
descr = pd.getName();
}
if (!firstLine) {
descr = "" + descr;
}
addressText.setText(descr);
}
}