diff --git a/OsmAnd/res/layout-land/map_hud_bottom.xml b/OsmAnd/res/layout-land/map_hud_bottom.xml index 0dee4517b0..d5f0d5e17e 100644 --- a/OsmAnd/res/layout-land/map_hud_bottom.xml +++ b/OsmAnd/res/layout-land/map_hud_bottom.xml @@ -4,7 +4,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom" - android:animateLayoutChanges="true" android:orientation="vertical"> - + android:layout_weight="1" + android:padding="8dp" + android:animateLayoutChanges="true"> + + + + @@ -244,16 +260,6 @@ android:layout_marginLeft="@dimen/map_button_spacing_land" android:orientation="vertical"> - - - + android:layout_weight="1" + android:padding="8dp" + android:animateLayoutChanges="true"> + + + + @@ -176,16 +193,6 @@ android:layout_marginLeft="@dimen/map_button_spacing" android:orientation="vertical"> - - () { @Override diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 891519bda7..593808d086 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -61,6 +61,7 @@ public class ContextMenuLayer extends OsmandMapLayer { private MapContextMenu menu; private MapMultiSelectionMenu multiSelectionMenu; private CallbackWithObject selectOnMap = null; + private MapQuickActionLayer mapQuickActionLayer; private ImageView contextMarker; private Paint paint; @@ -145,6 +146,9 @@ public class ContextMenuLayer extends OsmandMapLayer { canvas.drawBitmap(pressedBitmap, x - pressedBitmap.getWidth() / 2, y - pressedBitmap.getHeight() / 2, paint); } + if (mapQuickActionLayer!= null && mapQuickActionLayer.isInChangeMarkerPositionMode()) + return; + if (mInChangeMarkerPositionMode) { if (menu.getObject() == null) { canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight()); @@ -651,6 +655,10 @@ public class ContextMenuLayer extends OsmandMapLayer { multiSelectionMenu.show(latLon, selectedObjects); } + public void setMapQuickActionLayer(MapQuickActionLayer mapQuickActionLayer) { + this.mapQuickActionLayer = mapQuickActionLayer; + } + @Override public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 7c4ec4cf59..c26526562a 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -2,7 +2,6 @@ package net.osmand.plus.views; import android.Manifest; import android.annotation.SuppressLint; -import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; @@ -27,6 +26,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.SeekBar; import android.widget.TextView; + import net.osmand.AndroidUtils; import net.osmand.core.android.MapRendererContext; import net.osmand.data.LatLon; @@ -395,6 +395,9 @@ public class MapControlsLayer extends OsmandMapLayer { backToMenuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + if (mapActivity.getMapView().getLayerByClass(MapQuickActionLayer.class).setLayerState(true)) + return; + MapActivity.clearPrevActivityIntent(); if (dash) { mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); @@ -412,6 +415,9 @@ public class MapControlsLayer extends OsmandMapLayer { routePlanButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + if (mapActivity.getMapView().getLayerByClass(MapQuickActionLayer.class).setLayerState(true)) + return; + doRoute(false); } }); diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index e233271a3b..43bd23c641 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -1,16 +1,23 @@ package net.osmand.plus.views; +import android.content.Context; import android.graphics.Canvas; +import android.graphics.PointF; +import android.support.v4.content.ContextCompat; +import android.view.MotionEvent; import android.view.View; +import android.widget.FrameLayout; import android.widget.ImageButton; +import android.widget.ImageView; +import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.quickaction.QuickAction; -import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionsWidget; @@ -18,18 +25,27 @@ import net.osmand.plus.quickaction.QuickActionsWidget; * Created by okorsun on 23.12.16. */ -public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRegistry.QuickActionUpdatesListener, QuickAction.QuickActionSelectionListener{ +public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRegistry.QuickActionUpdatesListener, QuickAction.QuickActionSelectionListener { - private final MapActivity mapActivity; - private final OsmandApplication app; - private final OsmandSettings settings; + private final ContextMenuLayer contextMenuLayer; + private ImageView contextMarker; + private final MapActivity mapActivity; + private final OsmandApplication app; + private final OsmandSettings settings; private final QuickActionRegistry quickActionRegistry; - private ImageButton quickActionButton; + private ImageButton quickActionButton; private QuickActionsWidget quickActionsWidget; - public MapQuickActionLayer(MapActivity activity) { + private OsmandMapTileView view; + private boolean wasCollapseButtonVisible; + + + private boolean inChangeMarkerPositionMode; + + public MapQuickActionLayer(MapActivity activity, ContextMenuLayer contextMenuLayer) { this.mapActivity = activity; + this.contextMenuLayer = contextMenuLayer; app = activity.getMyApplication(); settings = activity.getMyApplication().getSettings(); quickActionRegistry = activity.getMapLayers().getQuickActionRegistry(); @@ -38,29 +54,198 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe @Override public void initLayer(OsmandMapTileView view) { + this.view = view; + quickActionsWidget = (QuickActionsWidget) mapActivity.findViewById(R.id.quick_action_widget); quickActionButton = (ImageButton) mapActivity.findViewById(R.id.map_quick_actions_button); quickActionButton.setVisibility(settings.QUICK_ACTION.get() ? View.VISIBLE : View.GONE); - quickActionButton.setImageResource(R.drawable.ic_action_quit_dark); + quickActionButton.setImageResource(R.drawable.map_quick_action); quickActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + setLayerState(quickActionsWidget.getVisibility() == View.VISIBLE); - if (quickActionsWidget.getVisibility() == View.VISIBLE){ - - quickActionsWidget.setVisibility(View.GONE); - quickActionRegistry.setUpdatesListener(null); - quickActionsWidget.setSelectionListener(null); - - }else { - - quickActionsWidget.setActions(quickActionRegistry.getQuickActions()); - quickActionsWidget.setVisibility(View.VISIBLE); - quickActionRegistry.setUpdatesListener(MapQuickActionLayer.this); - quickActionsWidget.setSelectionListener(MapQuickActionLayer.this); - } } }); + + + Context context = view.getContext(); + contextMarker = new ImageView(context); + contextMarker.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)); + contextMarker.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.map_pin_context_menu)); + contextMarker.setClickable(true); + int minw = contextMarker.getDrawable().getMinimumWidth(); + int minh = contextMarker.getDrawable().getMinimumHeight(); + contextMarker.layout(0, 0, minw, minh); + + setCloseWidgetOnTouch(mapActivity.findViewById(R.id.map_quick_actions_button_container)); + setCloseWidgetOnTouch(mapActivity.findViewById(R.id.bottom_controls_container)); + +// quickActionButton.setOnTouchListener(new View.OnTouchListener() { +// private int lastAction; +// private int initialMarginX; +// private int initialMarginY; +// private float initialTouchX; +// private float initialTouchY; +// +// @Override +// public boolean onTouch(View v, MotionEvent event) { +// switch (event.getAction()) { +// case MotionEvent.ACTION_DOWN: +// FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) v.getLayoutParams(); +// +// +// initialMarginX = params.rightMargin; +// initialMarginY = params.bottomMargin; +// +// //get the touch location +// initialTouchX = event.getRawX(); +// initialTouchY = event.getRawY(); +// +// lastAction = event.getAction(); +// return true; +// +// case MotionEvent.ACTION_UP: +// if (lastAction == MotionEvent.ACTION_DOWN) { +// setLayerState(); +// } +// lastAction = event.getAction(); +// return true; +// case MotionEvent.ACTION_MOVE: +// int deltaX = (int) (initialTouchX - event.getRawX()); +// int deltaY = (int) (initialTouchY - event.getRawY()); +// if (deltaX < 10 && deltaY < 10) +// return false; +// +// int newMarginX = initialMarginX + deltaX; +// int newMarginY = initialMarginY + deltaY; +// +// FrameLayout parent = (FrameLayout) v.getParent(); +// FrameLayout.LayoutParams param = (FrameLayout.LayoutParams) v.getLayoutParams(); +// if (v.getHeight() + newMarginY <= parent.getHeight() && newMarginY > 0) +// param.bottomMargin = newMarginY; +// +// if (v.getWidth() + newMarginX <= parent.getWidth() && newMarginX > 0) { +// param.rightMargin = newMarginX; +// } +// +// v.setLayoutParams(param); +// +// +// lastAction = event.getAction(); +// return true; +// } +// return false; +// } +// }); + } + + /** + * @param isClosed + * @return true, if state was changed + */ + public boolean setLayerState(boolean isClosed) { + if ((quickActionsWidget.getVisibility() == View.VISIBLE) != isClosed) // check if state change is needed + return false; + + quickActionButton.setImageResource(isClosed ? R.drawable.map_quick_action : R.drawable.map_action_cancel); + quickActionsWidget.setVisibility(isClosed ? View.GONE : View.VISIBLE); + + if (isClosed) { + quitMovingMarker(); + quickActionRegistry.setUpdatesListener(null); + quickActionsWidget.setSelectionListener(null); + } else { + enterMovingMode(mapActivity.getMapView().getCurrentRotatedTileBox()); + quickActionsWidget.setActions(quickActionRegistry.getQuickActions()); + quickActionRegistry.setUpdatesListener(MapQuickActionLayer.this); + quickActionsWidget.setSelectionListener(MapQuickActionLayer.this); + } + +// if (isClosed) { +// contextMenuLayer.quitMovingMarker(); +// } +// else { +// LatLon centerLatLon = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon(); +// contextMenuLayer.showContextMenu(centerLatLon.getLatitude(), centerLatLon.getLongitude(), false); +// contextMenuLayer.enterMovingMode(mapActivity.getMapView().getCurrentRotatedTileBox()); +// } + return true; + } + + private void setCloseWidgetOnTouch(View view) { + view.setOnTouchListener(new View.OnTouchListener() { + private float initialTouchX; + private float initialTouchY; + + @Override + public boolean onTouch(View v, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + initialTouchX = event.getRawX(); + initialTouchY = event.getRawY(); + break; + case MotionEvent.ACTION_UP: + int deltaX = (int) (initialTouchX - event.getRawX()); + int deltaY = (int) (initialTouchY - event.getRawY()); + if (deltaX < 10 && deltaY < 10) { + setLayerState(true); + } + + } + return false; + } + }); + } + + private void enterMovingMode(RotatedTileBox tileBox) { + MapContextMenu menu = mapActivity.getContextMenu(); + + menu.updateMapCenter(null); + menu.hide(); + + LatLon ll = tileBox.getCenterLatLon(); + RotatedTileBox rb = new RotatedTileBox(tileBox); + rb.setCenterLocation(0.5f, 0.5f); + rb.setLatLonCenter(ll.getLatitude(), ll.getLongitude()); + double lat = rb.getLatFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); + double lon = rb.getLonFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); + view.setLatLon(lat, lon); + + inChangeMarkerPositionMode = true; + mark(View.INVISIBLE, R.id.map_ruler_layout, + R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); + + View collapseButton = mapActivity.findViewById(R.id.map_collapse_button); + if (collapseButton != null && collapseButton.getVisibility() == View.VISIBLE) { + wasCollapseButtonVisible = true; + collapseButton.setVisibility(View.INVISIBLE); + } else { + wasCollapseButtonVisible = false; + } + + view.refreshMap(); + } + + private void quitMovingMarker() { + inChangeMarkerPositionMode = false; + mark(View.VISIBLE, R.id.map_ruler_layout, + R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); + + View collapseButton = mapActivity.findViewById(R.id.map_collapse_button); + if (collapseButton != null && wasCollapseButtonVisible) { + collapseButton.setVisibility(View.VISIBLE); + } + view.refreshMap(); + } + + private void mark(int status, int... widgets) { + for (int widget : widgets) { + View v = mapActivity.findViewById(widget); + if (v != null) { + v.setVisibility(status); + } + } } public void refreshLayer() { @@ -68,8 +253,11 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe } @Override - public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { - // do nothing + public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) { + if (inChangeMarkerPositionMode) { + canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight()); + contextMarker.draw(canvas); + } } @Override @@ -92,4 +280,16 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe public void onActionSelected(QuickAction action) { action.execute(mapActivity); } + + public PointF getMovableCenterPoint(RotatedTileBox tb) { + return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2); + } + + public boolean isInChangeMarkerPositionMode() { + return inChangeMarkerPositionMode; + } + + public boolean onBackPressed() { + return setLayerState(true); + } }