Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch

This commit is contained in:
PavelRatushny 2017-09-19 18:41:13 +03:00
commit 77b4f070e9
5 changed files with 160 additions and 144 deletions

View file

@ -115,6 +115,67 @@
</LinearLayout>
<LinearLayout
android:id="@+id/show_arrows_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/show_arrows_on_the_map"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/show_arrows_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:clickable="false"/>
</LinearLayout>
<LinearLayout
android:id="@+id/show_guide_line_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/show_guide_line"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/show_guide_line_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:clickable="false"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/bottom_sheet_content_padding_small"
android:background="?attr/dashboard_divider"/>
<RelativeLayout
android:id="@+id/top_bar_row"
android:layout_width="match_parent"
@ -148,15 +209,15 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<RadioButton
android:focusable="false"
android:clickable="false"
android:background="@null"
android:id="@+id/top_bar_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout>
<RelativeLayout
@ -192,15 +253,15 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<RadioButton
android:focusable="false"
android:clickable="false"
android:background="@null"
android:id="@+id/widget_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout>
<RelativeLayout
@ -235,15 +296,15 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<RadioButton
android:focusable="false"
android:clickable="false"
android:background="@null"
android:id="@+id/none_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout>
</LinearLayout>

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="show_guide_line">Show guide line</string>
<string name="show_arrows_on_the_map">Show arrows on the map</string>
<string name="show_passed">Show passed</string>
<string name="hide_passed">Hide passed</string>
<string name="remove_from_map_markers">Remove from Map Markers</string>

View file

@ -713,6 +713,9 @@ public class OsmandSettings {
public final CommonPreference<RulerMode> RULER_MODE = new EnumIntPreference<>("ruler_mode", RulerMode.FIRST, RulerMode.values()).makeGlobal();
public final CommonPreference<Boolean> SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", true).makeGlobal();
public final CommonPreference<Boolean> SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", true).makeGlobal();
public final CommonPreference<Boolean> USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal();
public final CommonPreference<String> MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal();
public final CommonPreference<String> MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal();

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
@ -12,6 +13,7 @@ import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
@ -19,6 +21,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -38,8 +41,9 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final OsmandSettings settings = getMyApplication().getSettings();
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
night = !getMyApplication().getSettings().isLightContent();
night = !settings.isLightContent();
final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container);
@ -47,7 +51,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
}
OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get();
OsmandSettings.MapMarkersMode mode = settings.MAP_MARKERS_MODE.get();
highlightSelectedItem(mode, true);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
@ -84,6 +88,32 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
}
CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch);
showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(!settings.SHOW_ARROWS_TO_FIRST_MARKERS.get());
if (getMapActivity() != null) {
getMapActivity().refreshMap();
}
dismiss();
}
});
CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch);
showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
settings.SHOW_LINES_TO_FIRST_MARKERS.set(!settings.SHOW_LINES_TO_FIRST_MARKERS.get());
if (getMapActivity() != null) {
getMapActivity().refreshMap();
}
dismiss();
}
});
ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon);
topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color));
topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue));
@ -157,6 +187,14 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
}
}
private MapActivity getMapActivity() {
Activity activity = getActivity();
if (activity != null) {
return (MapActivity) activity;
}
return null;
}
private void highlightSelectedItem(OsmandSettings.MapMarkersMode mode, boolean check) {
int iconBgColor = check ? R.color.dashboard_blue : R.color.on_map_icon_color;
int iconColor = check ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue;

View file

@ -8,13 +8,9 @@ import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import net.osmand.Location;
import net.osmand.data.LatLon;
@ -23,7 +19,6 @@ import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -39,8 +34,6 @@ import java.util.List;
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider,
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
protected static final int DIST_TO_SHOW = 80;
protected static final long USE_FINGER_LOCATION_DELAY = 1000;
private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6;
private final MapActivity map;
private OsmandMapTileView view;
@ -66,17 +59,11 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
private Bitmap arrowToDestination;
private float[] calculations = new float[2];
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
private Paint paint;
private Path path;
private List<LatLon> route = new ArrayList<>();
private LatLon fingerLocation;
private boolean hasMoved;
private boolean moving;
private boolean useFingerLocation;
private GestureDetector longTapDetector;
private Handler handler;
private ContextMenuLayer contextMenuLayer;
public MapMarkersLayer(MapActivity map) {
@ -190,50 +177,23 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
handler = new Handler();
initUI();
longTapDetector = new GestureDetector(view.getContext(), new GestureDetector.OnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
cancelFingerAction();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
});
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom());
Location myLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
widgetsFactory.updateInfo(myLoc == null
? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom());
OsmandSettings settings = map.getMyApplication().getSettings();
if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) {
return;
}
lineAttrs.updatePaints(view, nightMode, tileBox);
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
if (route.size() > 0) {
path.reset();
@ -259,6 +219,17 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
}
List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
if (settings.SHOW_LINES_TO_FIRST_MARKERS.get()) {
int locX = myLoc == null ? tileBox.getCenterPixelX() : tileBox.getPixXFromLonNoRot(myLoc.getLongitude());
int locY = myLoc == null ? tileBox.getCenterPixelY() : tileBox.getPixYFromLatNoRot(myLoc.getLatitude());
for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) {
int markerX = tileBox.getPixXFromLonNoRot(activeMapMarkers.get(i).getLongitude());
int markerY = tileBox.getPixYFromLatNoRot(activeMapMarkers.get(i).getLatitude());
canvas.drawLine(locX, locY, markerX, markerY, lineAttrs.paint);
}
}
for (MapMarker marker : activeMapMarkers) {
if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker)
&& !isInMotion(marker)) {
@ -273,34 +244,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
}
}
boolean show = useFingerLocation ||
(map.getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.WIDGETS
&& map.getMyApplication().getSettings().SHOW_DESTINATION_ARROW.get());
if (show) {
LatLon loc = fingerLocation;
if (!useFingerLocation) {
loc = tileBox.getCenterLatLon();
}
if (loc != null) {
List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
int i = 0;
for (MapMarker marker : mapMarkers) {
if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) {
canvas.save();
net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(),
marker.getLatitude(), marker.getLongitude(), calculations);
float bearing = calculations[1] - 90;
float radiusBearing = DIST_TO_SHOW * tileBox.getDensity();
final QuadPoint cp = tileBox.getCenterPixelPoint();
canvas.rotate(bearing, cp.x, cp.y);
canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity());
canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
canvas.restore();
}
i++;
if (i > 1) {
break;
}
if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) {
LatLon loc = myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude());
List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
int i = 0;
for (MapMarker marker : mapMarkers) {
if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) {
canvas.save();
net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(),
marker.getLatitude(), marker.getLongitude(), calculations);
float bearing = calculations[1] - 90;
float radiusBearing = DIST_TO_SHOW * tileBox.getDensity();
final QuadPoint cp = tileBox.getCenterPixelPoint();
canvas.rotate(bearing, cp.x, cp.y);
canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity());
canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
canvas.restore();
}
i++;
if (i > 1) {
break;
}
}
}
@ -354,57 +317,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
public void destroyLayer() {
}
@Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if (!longTapDetector.onTouchEvent(event)) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
float x = event.getX();
float y = event.getY();
fingerLocation = tileBox.getLatLonFromPixel(x, y);
hasMoved = false;
moving = true;
break;
case MotionEvent.ACTION_MOVE:
if (!hasMoved) {
if (!handler.hasMessages(MAP_REFRESH_MESSAGE)) {
Message msg = Message.obtain(handler, new Runnable() {
@Override
public void run() {
handler.removeMessages(MAP_REFRESH_MESSAGE);
if (moving) {
if (!useFingerLocation) {
useFingerLocation = true;
map.refreshMap();
}
}
}
});
msg.what = MAP_REFRESH_MESSAGE;
handler.sendMessageDelayed(msg, USE_FINGER_LOCATION_DELAY);
}
hasMoved = true;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
cancelFingerAction();
break;
}
}
return super.onTouchEvent(event, tileBox);
}
private void cancelFingerAction() {
handler.removeMessages(MAP_REFRESH_MESSAGE);
useFingerLocation = false;
moving = false;
fingerLocation = null;
map.refreshMap();
}
@Override
public boolean drawInScreenPixels() {
return false;