main screen selector on map
This commit is contained in:
parent
8881e8a2ff
commit
4d2cca829d
7 changed files with 286 additions and 53 deletions
|
@ -4,7 +4,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="bottom"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.quickaction.QuickActionsWidget
|
||||
|
@ -13,12 +12,29 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<Space
|
||||
<FrameLayout
|
||||
android:id="@+id/map_quick_actions_button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
android:layout_weight="1"
|
||||
android:padding="8dp"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/map_quick_actions_button"
|
||||
android:layout_width="@dimen/map_button_size"
|
||||
android:layout_height="@dimen/map_button_size"
|
||||
android:background="@drawable/btn_circle_blue"
|
||||
android:contentDescription="@string/zoomIn"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:src="@drawable/ic_action_test_light"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/bottom_controls_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
@ -244,16 +260,6 @@
|
|||
android:layout_marginLeft="@dimen/map_button_spacing_land"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/map_quick_actions_button"
|
||||
android:layout_width="@dimen/map_button_size"
|
||||
android:layout_height="@dimen/map_button_size"
|
||||
android:background="@drawable/btn_circle_blue"
|
||||
android:contentDescription="@string/zoomIn"
|
||||
android:visibility="gone"
|
||||
android:layout_marginBottom="@dimen/map_button_spacing"
|
||||
tools:src="@drawable/ic_action_test_light"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/map_zoom_in_button"
|
||||
android:layout_width="@dimen/map_button_size"
|
||||
|
|
|
@ -4,21 +4,38 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="bottom"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.quickaction.QuickActionsWidget
|
||||
android:id="@+id/quick_action_widget"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:visibility="visible"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<Space
|
||||
<FrameLayout
|
||||
android:id="@+id/map_quick_actions_button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
android:layout_weight="1"
|
||||
android:padding="8dp"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/map_quick_actions_button"
|
||||
android:layout_width="@dimen/map_button_size"
|
||||
android:layout_height="@dimen/map_button_size"
|
||||
android:background="@drawable/btn_circle_blue"
|
||||
android:contentDescription="@string/zoomIn"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:src="@drawable/ic_action_test_light"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/bottom_controls_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
@ -176,16 +193,6 @@
|
|||
android:layout_marginLeft="@dimen/map_button_spacing"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/map_quick_actions_button"
|
||||
android:layout_width="@dimen/map_button_size"
|
||||
android:layout_height="@dimen/map_button_size"
|
||||
android:background="@drawable/btn_circle_blue"
|
||||
android:contentDescription="@string/zoomIn"
|
||||
android:visibility="gone"
|
||||
android:layout_marginBottom="@dimen/map_button_spacing"
|
||||
tools:src="@drawable/ic_action_test_light"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/map_zoom_in_button"
|
||||
android:layout_width="@dimen/map_button_size"
|
||||
|
|
|
@ -101,6 +101,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment;
|
|||
import net.osmand.plus.views.AnimateDraggingMapThread;
|
||||
import net.osmand.plus.views.MapControlsLayer;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.MapQuickActionLayer;
|
||||
import net.osmand.plus.views.OsmAndMapLayersView;
|
||||
import net.osmand.plus.views.OsmAndMapSurfaceView;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
|
@ -455,9 +456,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
this.startActivity(prevActivityIntent);
|
||||
prevActivityIntent = null;
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
if (getMapView().getLayerByClass(MapQuickActionLayer.class).onBackPressed())
|
||||
return;
|
||||
|
||||
super.onBackPressed();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -170,8 +170,9 @@ public class MapActivityLayers {
|
|||
mapControlsLayer = new MapControlsLayer(activity);
|
||||
mapView.addLayer(mapControlsLayer, 11);
|
||||
// 12. quick actions layer
|
||||
mapQuickActionLayer = new MapQuickActionLayer(activity);
|
||||
mapQuickActionLayer = new MapQuickActionLayer(activity, contextMenuLayer);
|
||||
mapView.addLayer(mapQuickActionLayer, 12);
|
||||
contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer);
|
||||
|
||||
transparencyListener = new StateChangedListener<Integer>() {
|
||||
@Override
|
||||
|
|
|
@ -61,6 +61,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
private MapContextMenu menu;
|
||||
private MapMultiSelectionMenu multiSelectionMenu;
|
||||
private CallbackWithObject<LatLon> 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) {
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -20,6 +27,8 @@ import net.osmand.plus.quickaction.QuickActionsWidget;
|
|||
|
||||
public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRegistry.QuickActionUpdatesListener, QuickAction.QuickActionSelectionListener {
|
||||
|
||||
private final ContextMenuLayer contextMenuLayer;
|
||||
private ImageView contextMarker;
|
||||
private final MapActivity mapActivity;
|
||||
private final OsmandApplication app;
|
||||
private final OsmandSettings settings;
|
||||
|
@ -28,8 +37,15 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
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,38 +54,210 @@ 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);
|
||||
|
||||
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());
|
||||
quickActionsWidget.setVisibility(View.VISIBLE);
|
||||
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() {
|
||||
quickActionButton.setVisibility(settings.QUICK_ACTION.get() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue