Context menu - fix call from dashboard

This commit is contained in:
Alexey Kulish 2015-09-23 15:57:57 +03:00
parent bdcdb34af1
commit 430e725884
5 changed files with 82 additions and 69 deletions

View file

@ -157,7 +157,7 @@ public class MapActivity extends AccessibleActivity {
app = getMyApplication(); app = getMyApplication();
settings = app.getSettings(); settings = app.getSettings();
app.applyTheme(this); app.applyTheme(this);
contextMenuOnMap = new MapContextMenu(app); contextMenuOnMap = new MapContextMenu(app, this);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE); supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Full screen is not used here // Full screen is not used here

View file

@ -1,10 +1,24 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import java.io.File; import android.app.Activity;
import java.text.MessageFormat; import android.app.AlertDialog;
import java.util.ArrayList; import android.app.AlertDialog.Builder;
import java.util.Date; import android.app.Dialog;
import java.util.List; import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import net.londatiga.android.ActionItem; import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction; import net.londatiga.android.QuickAction;
@ -45,24 +59,11 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import android.app.Activity; import java.io.File;
import android.app.AlertDialog; import java.text.MessageFormat;
import android.app.AlertDialog.Builder; import java.util.ArrayList;
import android.app.Dialog; import java.util.Date;
import android.content.DialogInterface; import java.util.List;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MapActivityActions implements DialogProvider { public class MapActivityActions implements DialogProvider {
private static final Log LOG = PlatformUtil.getLog(MapActivityActions.class); private static final Log LOG = PlatformUtil.getLog(MapActivityActions.class);
@ -653,7 +654,7 @@ public class MapActivityActions implements DialogProvider {
.listen(new OnContextMenuClick() { .listen(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); mapActivity.getMapLayers().getContextMenuLayer().showContextMenu(mapView.getLatitude(), mapView.getLongitude(), true);
return true; return true;
} }
}).reg(); }).reg();

View file

@ -29,6 +29,7 @@ public class MapContextMenu {
private OsmandApplication app; private OsmandApplication app;
private OsmandSettings settings; private OsmandSettings settings;
private final MapActivity mapActivity;
private PointDescription pointDescription; private PointDescription pointDescription;
private Object object; private Object object;
@ -44,7 +45,7 @@ public class MapContextMenu {
private static final String KEY_CTX_MENU_TYPE_STR = "key_ctx_menu_type_str"; private static final String KEY_CTX_MENU_TYPE_STR = "key_ctx_menu_type_str";
private static final String KEY_CTX_MENU_STREET_STR = "key_ctx_menu_street_str"; private static final String KEY_CTX_MENU_STREET_STR = "key_ctx_menu_street_str";
public boolean isMenuVisible(MapActivity mapActivity) { public boolean isMenuVisible() {
return mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment") != null; return mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment") != null;
} }
@ -56,16 +57,17 @@ public class MapContextMenu {
return object; return object;
} }
public MapContextMenu(OsmandApplication app) { public MapContextMenu(OsmandApplication app, MapActivity mapActivity) {
this.app = app; this.app = app;
this.mapActivity = mapActivity;
settings = app.getSettings(); settings = app.getSettings();
} }
public void show(MapActivity mapActivity, PointDescription pointDescription, Object object) { public void show(PointDescription pointDescription, Object object) {
if (isMenuVisible(mapActivity)) { if (isMenuVisible()) {
if (this.object == null || !this.object.equals(object)) { if (this.object == null || !this.object.equals(object)) {
hide(mapActivity); hide();
} else { } else {
return; return;
} }
@ -80,25 +82,25 @@ public class MapContextMenu {
acquireLeftIconId(); acquireLeftIconId();
acquireNameAndType(); acquireNameAndType();
acquireStreetName(mapActivity, new LatLon(pointDescription.getLat(), pointDescription.getLon())); acquireStreetName(new LatLon(pointDescription.getLat(), pointDescription.getLon()));
MapContextMenuFragment.showInstance(mapActivity); MapContextMenuFragment.showInstance(mapActivity);
} }
public void hide(MapActivity mapActivity) { public void hide() {
MapContextMenuFragment fragment = findMenuFragment(mapActivity); MapContextMenuFragment fragment = findMenuFragment();
if (fragment != null) if (fragment != null)
fragment.dismissMenu(); fragment.dismissMenu();
} }
public void refreshMenuTitle(MapActivity mapActivity) { public void refreshMenuTitle() {
MapContextMenuFragment fragment = findMenuFragment(mapActivity); MapContextMenuFragment fragment = findMenuFragment();
if (fragment != null) if (fragment != null)
fragment.refreshTitle(); fragment.refreshTitle();
} }
private MapContextMenuFragment findMenuFragment(MapActivity mapActivity) { private MapContextMenuFragment findMenuFragment() {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment"); Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment");
if (fragment != null) if (fragment != null)
return (MapContextMenuFragment)fragment; return (MapContextMenuFragment)fragment;
@ -114,7 +116,7 @@ public class MapContextMenu {
return nameStr; return nameStr;
} }
public String getLocationStr(MapActivity mapActivity) { public String getLocationStr() {
if (Algorithms.isEmpty(streetStr)) if (Algorithms.isEmpty(streetStr))
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", ""); return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", "");
else else
@ -179,7 +181,7 @@ public class MapContextMenu {
} }
} }
private void acquireStreetName(final MapActivity activity, final LatLon loc) { private void acquireStreetName(final LatLon loc) {
Location ll = new Location(""); Location ll = new Location("");
ll.setLatitude(loc.getLatitude()); ll.setLatitude(loc.getLatitude());
ll.setLongitude(loc.getLongitude()); ll.setLongitude(loc.getLongitude());
@ -199,9 +201,9 @@ public class MapContextMenu {
nameStr = streetStr; nameStr = streetStr;
streetStr = null; streetStr = null;
} }
activity.runOnUiThread(new Runnable() { mapActivity.runOnUiThread(new Runnable() {
public void run() { public void run() {
refreshMenuTitle(activity); refreshMenuTitle();
} }
}); });
} }
@ -235,11 +237,11 @@ public class MapContextMenu {
return null; return null;
} }
public void buttonNavigatePressed(MapActivity mapActivity) { public void buttonNavigatePressed() {
mapActivity.getMapActions().showNavigationContextMenuPoint(pointDescription.getLat(), pointDescription.getLon()); mapActivity.getMapActions().showNavigationContextMenuPoint(pointDescription.getLat(), pointDescription.getLon());
} }
public void buttonFavoritePressed(MapActivity mapActivity) { public void buttonFavoritePressed() {
if (object != null && object instanceof FavouritePoint) { if (object != null && object instanceof FavouritePoint) {
mapActivity.getMapActions().editFavoritePoint((FavouritePoint)object); mapActivity.getMapActions().editFavoritePoint((FavouritePoint)object);
} else { } else {
@ -247,11 +249,11 @@ public class MapContextMenu {
} }
} }
public void buttonSharePressed(MapActivity mapActivity) { public void buttonSharePressed() {
mapActivity.getMapActions().shareLocation(pointDescription.getLat(), pointDescription.getLon()); mapActivity.getMapActions().shareLocation(pointDescription.getLat(), pointDescription.getLon());
} }
public void buttonMorePressed(MapActivity mapActivity) { public void buttonMorePressed() {
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(mapActivity); final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(mapActivity);
if (object != null) { if (object != null) {
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {

View file

@ -351,7 +351,7 @@ public class MapContextMenuFragment extends Fragment {
buttonNavigate.setOnClickListener(new View.OnClickListener() { buttonNavigate.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonNavigatePressed(getMapActivity()); getCtxMenu().buttonNavigatePressed();
} }
}); });
@ -361,7 +361,7 @@ public class MapContextMenuFragment extends Fragment {
buttonFavorite.setOnClickListener(new View.OnClickListener() { buttonFavorite.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonFavoritePressed(getMapActivity()); getCtxMenu().buttonFavoritePressed();
} }
}); });
@ -371,7 +371,7 @@ public class MapContextMenuFragment extends Fragment {
buttonShare.setOnClickListener(new View.OnClickListener() { buttonShare.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonSharePressed(getMapActivity()); getCtxMenu().buttonSharePressed();
} }
}); });
@ -381,7 +381,7 @@ public class MapContextMenuFragment extends Fragment {
buttonMore.setOnClickListener(new View.OnClickListener() { buttonMore.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonMorePressed(getMapActivity()); getCtxMenu().buttonMorePressed();
} }
}); });
@ -434,7 +434,7 @@ public class MapContextMenuFragment extends Fragment {
// Text line 2 // Text line 2
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2); TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
line2.setText(getCtxMenu().getLocationStr(getMapActivity())); line2.setText(getCtxMenu().getLocationStr());
} }
private int getPosY() { private int getPosY() {

View file

@ -22,6 +22,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -270,6 +271,23 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (disableLongPressOnMap()) { if (disableLongPressOnMap()) {
return false; return false;
} }
showContextMenu(point, tileBox, true);
view.refreshMap();
return true;
}
public boolean showContextMenu(double latitude, double longitude, boolean showUnknownLocation) {
RotatedTileBox cp = activity.getMapView().getCurrentRotatedTileBox().copy();
float x = cp.getPixXFromLatLon(latitude, longitude);
float y = cp.getPixYFromLatLon(latitude, longitude);
return showContextMenu(new PointF(x, y), activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation);
}
public boolean showContextMenu(PointF point, boolean showUnknownLocation) {
return showContextMenu(point, activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation);
}
public boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
LatLon latLon = selectObjectsForContextMenu(tileBox, point); LatLon latLon = selectObjectsForContextMenu(tileBox, point);
if (latLon != null) { if (latLon != null) {
if (selectedObjects.size() == 1) { if (selectedObjects.size() == 1) {
@ -277,20 +295,21 @@ public class ContextMenuLayer extends OsmandMapLayer {
selectedObj = selectedObjects.keySet().iterator().next(); selectedObj = selectedObjects.keySet().iterator().next();
contextObject = selectedObjects.get(selectedObj); contextObject = selectedObjects.get(selectedObj);
showMapContextMenu(latLon); showMapContextMenu(latLon);
return true;
} else if (selectedObjects.size() > 1) { } else if (selectedObjects.size() > 1) {
showContextMenuForSelectedObjects(latLon); showContextMenuForSelectedObjects(latLon);
return true;
} }
} else { } else if (showUnknownLocation) {
setLocation(null, ""); setLocation(null, "");
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y); final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y); final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
selectedObj = null; selectedObj = null;
contextObject = null; contextObject = null;
showMapContextMenu(new LatLon(lat, lon)); showMapContextMenu(new LatLon(lat, lon));
//setLocation(new LatLon(lat, lon), null); return true;
} }
view.refreshMap(); return false;
return true;
} }
public boolean disableSingleTap() { public boolean disableSingleTap() {
@ -454,22 +473,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
return true; return true;
} else if (!disableSingleTap()) { } else if (!disableSingleTap()) {
LatLon latLon = selectObjectsForContextMenu(tileBox, point); boolean res = showContextMenu(point, tileBox, false);
if (latLon != null) { if (res) {
if (selectedObjects.size() == 1) { return true;
setLocation(null, "");
selectedObj = selectedObjects.keySet().iterator().next();
contextObject = selectedObjects.get(selectedObj);
showMapContextMenu(latLon);
return true;
} else if (selectedObjects.size() > 1) {
showContextMenuForSelectedObjects(latLon);
return true;
}
} }
} }
activity.getContextMenu().hide(activity); activity.getContextMenu().hide();
return false; return false;
} }
@ -515,7 +525,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
this.latLon = new LatLon(pointDescription.getLat(), pointDescription.getLon()); this.latLon = new LatLon(pointDescription.getLat(), pointDescription.getLon());
showMapContextMenuMarker(); showMapContextMenuMarker();
activity.getContextMenu().show(activity, pointDescription, selectedObj); activity.getContextMenu().show(pointDescription, selectedObj);
} }
@ -523,8 +533,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if (movementListener.onTouchEvent(event)) { if (movementListener.onTouchEvent(event)) {
if (activity.getContextMenu().isMenuVisible(activity)) { if (activity.getContextMenu().isMenuVisible()) {
activity.getContextMenu().hide(activity); activity.getContextMenu().hide();
} }
} }