Context menu - fix call from dashboard
This commit is contained in:
parent
bdcdb34af1
commit
430e725884
5 changed files with 82 additions and 69 deletions
|
@ -157,7 +157,7 @@ public class MapActivity extends AccessibleActivity {
|
|||
app = getMyApplication();
|
||||
settings = app.getSettings();
|
||||
app.applyTheme(this);
|
||||
contextMenuOnMap = new MapContextMenu(app);
|
||||
contextMenuOnMap = new MapContextMenu(app, this);
|
||||
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
// Full screen is not used here
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
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.QuickAction;
|
||||
|
@ -45,24 +59,11 @@ import net.osmand.util.MapUtils;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
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;
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class MapActivityActions implements DialogProvider {
|
||||
private static final Log LOG = PlatformUtil.getLog(MapActivityActions.class);
|
||||
|
@ -653,7 +654,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}).reg();
|
||||
|
|
|
@ -29,6 +29,7 @@ public class MapContextMenu {
|
|||
|
||||
private OsmandApplication app;
|
||||
private OsmandSettings settings;
|
||||
private final MapActivity mapActivity;
|
||||
|
||||
private PointDescription pointDescription;
|
||||
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_STREET_STR = "key_ctx_menu_street_str";
|
||||
|
||||
public boolean isMenuVisible(MapActivity mapActivity) {
|
||||
public boolean isMenuVisible() {
|
||||
return mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment") != null;
|
||||
}
|
||||
|
||||
|
@ -56,16 +57,17 @@ public class MapContextMenu {
|
|||
return object;
|
||||
}
|
||||
|
||||
public MapContextMenu(OsmandApplication app) {
|
||||
public MapContextMenu(OsmandApplication app, MapActivity mapActivity) {
|
||||
this.app = app;
|
||||
this.mapActivity = mapActivity;
|
||||
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)) {
|
||||
hide(mapActivity);
|
||||
hide();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -80,25 +82,25 @@ public class MapContextMenu {
|
|||
|
||||
acquireLeftIconId();
|
||||
acquireNameAndType();
|
||||
acquireStreetName(mapActivity, new LatLon(pointDescription.getLat(), pointDescription.getLon()));
|
||||
acquireStreetName(new LatLon(pointDescription.getLat(), pointDescription.getLon()));
|
||||
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
|
||||
}
|
||||
|
||||
public void hide(MapActivity mapActivity) {
|
||||
MapContextMenuFragment fragment = findMenuFragment(mapActivity);
|
||||
public void hide() {
|
||||
MapContextMenuFragment fragment = findMenuFragment();
|
||||
if (fragment != null)
|
||||
fragment.dismissMenu();
|
||||
}
|
||||
|
||||
public void refreshMenuTitle(MapActivity mapActivity) {
|
||||
MapContextMenuFragment fragment = findMenuFragment(mapActivity);
|
||||
public void refreshMenuTitle() {
|
||||
MapContextMenuFragment fragment = findMenuFragment();
|
||||
if (fragment != null)
|
||||
fragment.refreshTitle();
|
||||
}
|
||||
|
||||
private MapContextMenuFragment findMenuFragment(MapActivity mapActivity) {
|
||||
private MapContextMenuFragment findMenuFragment() {
|
||||
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment");
|
||||
if (fragment != null)
|
||||
return (MapContextMenuFragment)fragment;
|
||||
|
@ -114,7 +116,7 @@ public class MapContextMenu {
|
|||
return nameStr;
|
||||
}
|
||||
|
||||
public String getLocationStr(MapActivity mapActivity) {
|
||||
public String getLocationStr() {
|
||||
if (Algorithms.isEmpty(streetStr))
|
||||
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", "");
|
||||
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("");
|
||||
ll.setLatitude(loc.getLatitude());
|
||||
ll.setLongitude(loc.getLongitude());
|
||||
|
@ -199,9 +201,9 @@ public class MapContextMenu {
|
|||
nameStr = streetStr;
|
||||
streetStr = null;
|
||||
}
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
mapActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
refreshMenuTitle(activity);
|
||||
refreshMenuTitle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -235,11 +237,11 @@ public class MapContextMenu {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void buttonNavigatePressed(MapActivity mapActivity) {
|
||||
public void buttonNavigatePressed() {
|
||||
mapActivity.getMapActions().showNavigationContextMenuPoint(pointDescription.getLat(), pointDescription.getLon());
|
||||
}
|
||||
|
||||
public void buttonFavoritePressed(MapActivity mapActivity) {
|
||||
public void buttonFavoritePressed() {
|
||||
if (object != null && object instanceof FavouritePoint) {
|
||||
mapActivity.getMapActions().editFavoritePoint((FavouritePoint)object);
|
||||
} else {
|
||||
|
@ -247,11 +249,11 @@ public class MapContextMenu {
|
|||
}
|
||||
}
|
||||
|
||||
public void buttonSharePressed(MapActivity mapActivity) {
|
||||
public void buttonSharePressed() {
|
||||
mapActivity.getMapActions().shareLocation(pointDescription.getLat(), pointDescription.getLon());
|
||||
}
|
||||
|
||||
public void buttonMorePressed(MapActivity mapActivity) {
|
||||
public void buttonMorePressed() {
|
||||
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(mapActivity);
|
||||
if (object != null) {
|
||||
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
|
||||
|
|
|
@ -351,7 +351,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonNavigate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCtxMenu().buttonNavigatePressed(getMapActivity());
|
||||
getCtxMenu().buttonNavigatePressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -361,7 +361,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonFavorite.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCtxMenu().buttonFavoritePressed(getMapActivity());
|
||||
getCtxMenu().buttonFavoritePressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -371,7 +371,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonShare.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCtxMenu().buttonSharePressed(getMapActivity());
|
||||
getCtxMenu().buttonSharePressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -381,7 +381,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonMore.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCtxMenu().buttonMorePressed(getMapActivity());
|
||||
getCtxMenu().buttonMorePressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -434,7 +434,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
|
||||
// Text line 2
|
||||
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
||||
line2.setText(getCtxMenu().getLocationStr(getMapActivity()));
|
||||
line2.setText(getCtxMenu().getLocationStr());
|
||||
}
|
||||
|
||||
private int getPosY() {
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
|
@ -270,6 +271,23 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
if (disableLongPressOnMap()) {
|
||||
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);
|
||||
if (latLon != null) {
|
||||
if (selectedObjects.size() == 1) {
|
||||
|
@ -277,21 +295,22 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
selectedObj = selectedObjects.keySet().iterator().next();
|
||||
contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(latLon);
|
||||
return true;
|
||||
} else if (selectedObjects.size() > 1) {
|
||||
showContextMenuForSelectedObjects(latLon);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
} else if (showUnknownLocation) {
|
||||
setLocation(null, "");
|
||||
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
|
||||
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
|
||||
selectedObj = null;
|
||||
contextObject = null;
|
||||
showMapContextMenu(new LatLon(lat, lon));
|
||||
//setLocation(new LatLon(lat, lon), null);
|
||||
}
|
||||
view.refreshMap();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean disableSingleTap() {
|
||||
boolean res = false;
|
||||
|
@ -454,22 +473,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
}
|
||||
return true;
|
||||
} else if (!disableSingleTap()) {
|
||||
LatLon latLon = selectObjectsForContextMenu(tileBox, point);
|
||||
if (latLon != null) {
|
||||
if (selectedObjects.size() == 1) {
|
||||
setLocation(null, "");
|
||||
selectedObj = selectedObjects.keySet().iterator().next();
|
||||
contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(latLon);
|
||||
boolean res = showContextMenu(point, tileBox, false);
|
||||
if (res) {
|
||||
return true;
|
||||
} else if (selectedObjects.size() > 1) {
|
||||
showContextMenuForSelectedObjects(latLon);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activity.getContextMenu().hide(activity);
|
||||
activity.getContextMenu().hide();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -515,7 +525,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
this.latLon = new LatLon(pointDescription.getLat(), pointDescription.getLon());
|
||||
|
||||
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) {
|
||||
|
||||
if (movementListener.onTouchEvent(event)) {
|
||||
if (activity.getContextMenu().isMenuVisible(activity)) {
|
||||
activity.getContextMenu().hide(activity);
|
||||
if (activity.getContextMenu().isMenuVisible()) {
|
||||
activity.getContextMenu().hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue