Context menu small refactor + work on OsMo menu

This commit is contained in:
Alexey Kulish 2015-10-29 15:00:44 +03:00
parent 484124438d
commit 962bdfdf35
15 changed files with 90 additions and 148 deletions

View file

@ -7,7 +7,7 @@ import java.io.Serializable;
/**
*/
public interface LocationPoint extends Serializable {
public interface LocationPoint {
public double getLatitude();

View file

@ -16,7 +16,7 @@ import net.osmand.util.Algorithms;
import android.content.Context;
import android.support.annotation.NonNull;
public class PointDescription implements Serializable {
public class PointDescription {
private String type = "";
private String name = "";
private String typeName;
@ -24,8 +24,6 @@ public class PointDescription implements Serializable {
private double lat = 0;
private double lon = 0;
private static final long serialVersionUID = 4078409090417168638L;
public static final String POINT_TYPE_FAVORITE = "favorite";
public static final String POINT_TYPE_WPT = "wpt";
public static final String POINT_TYPE_POI = "poi";

View file

@ -98,6 +98,7 @@ public class MapActivity extends AccessibleActivity {
private static final Log LOG = PlatformUtil.getLog(MapActivity.class);
private static MapViewTrackingUtilities mapViewTrackingUtilities;
private static MapContextMenu mapContextMenu = new MapContextMenu();
/**
* Called when the activity is first created.
@ -129,7 +130,6 @@ public class MapActivity extends AccessibleActivity {
private boolean intentLocation = false;
private DashboardOnMap dashboardOnMap = new DashboardOnMap(this);
private MapContextMenu contextMenuOnMap;
private FavoritePointEditor favoritePointEditor;
private AppInitializeListener initListener;
private IMapDownloaderCallback downloaderCallback;
@ -161,8 +161,8 @@ public class MapActivity extends AccessibleActivity {
app = getMyApplication();
settings = app.getSettings();
app.applyTheme(this);
contextMenuOnMap = new MapContextMenu(this);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
mapContextMenu.setMapActivity(this);
super.onCreate(savedInstanceState);
// Full screen is not used here
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
@ -529,9 +529,9 @@ public class MapActivity extends AccessibleActivity {
dashboardOnMap.hideDashboard();
}
if (mapLabelToShow != null) {
contextMenuOnMap.setMapCenter(latLonToShow);
contextMenuOnMap.setMapPosition(mapView.getMapPosition());
contextMenuOnMap.show(latLonToShow, mapLabelToShow, toShow);
mapContextMenu.setMapCenter(latLonToShow);
mapContextMenu.setMapPosition(mapView.getMapPosition());
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
}
if (!latLonToShow.equals(cur)) {
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(),
@ -967,7 +967,7 @@ public class MapActivity extends AccessibleActivity {
}
public MapContextMenu getContextMenu() {
return contextMenuOnMap;
return mapContextMenu;
}
public FavoritePointEditor getFavoritePointEditor() {

View file

@ -51,7 +51,7 @@ public class SearchHistoryHelper {
}
};
public static class HistoryEntry implements Serializable {
public static class HistoryEntry {
double lat;
double lon;
PointDescription name;

View file

@ -1,6 +1,5 @@
package net.osmand.plus.mapcontextmenu;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
@ -16,7 +15,7 @@ import net.osmand.plus.views.OsmandMapLayer;
public class MapContextMenu extends MenuTitleController {
private final MapActivity mapActivity;
private MapActivity mapActivity;
private boolean active;
private LatLon latLon;
@ -29,22 +28,20 @@ public class MapContextMenu extends MenuTitleController {
private int favActionIconId;
private static final String KEY_CTX_MENU_OBJECT = "key_ctx_menu_object";
private static final String KEY_CTX_MENU_ACTIVE = "key_ctx_menu_active";
private static final String KEY_CTX_MENU_LATLON = "key_ctx_menu_latlon";
private static final String KEY_CTX_MENU_POINT_DESC = "key_ctx_menu_point_desc";
private static final String KEY_CTX_MENU_NAME_STR = "key_ctx_menu_name_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_ADDR_UNKNOWN = "key_ctx_menu_addr_unknown";
private static final String KEY_CTX_MENU_MAP_CENTER = "key_ctx_menu_map_center";
private static final String KEY_CTX_MENU_MAP_POSITION = "key_ctx_menu_map_position";
@Override
public MapActivity getMapActivity() {
return mapActivity;
}
public void setMapActivity(MapActivity mapActivity) {
this.mapActivity = mapActivity;
if (active) {
acquireMenuController();
} else {
menuController = null;
}
}
public boolean isActive() {
return active;
}
@ -89,8 +86,7 @@ public class MapContextMenu extends MenuTitleController {
return menuController;
}
public MapContextMenu(MapActivity mapActivity) {
this.mapActivity = mapActivity;
public MapContextMenu() {
}
public boolean init(LatLon latLon, PointDescription pointDescription, Object object) {
@ -267,56 +263,6 @@ public class MapContextMenu extends MenuTitleController {
mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, object);
}
public void saveMenuState(Bundle bundle) {
if (menuController != null) {
menuController.saveEntityState(bundle, KEY_CTX_MENU_OBJECT);
}
bundle.putString(KEY_CTX_MENU_ACTIVE, Boolean.toString(active));
bundle.putSerializable(KEY_CTX_MENU_LATLON, latLon);
bundle.putSerializable(KEY_CTX_MENU_POINT_DESC, pointDescription);
bundle.putString(KEY_CTX_MENU_NAME_STR, nameStr);
bundle.putString(KEY_CTX_MENU_TYPE_STR, typeStr);
bundle.putString(KEY_CTX_MENU_STREET_STR, streetStr);
bundle.putString(KEY_CTX_MENU_ADDR_UNKNOWN, Boolean.toString(addressUnknown));
bundle.putSerializable(KEY_CTX_MENU_MAP_CENTER, mapCenter);
bundle.putInt(KEY_CTX_MENU_MAP_POSITION, mapPosition);
}
public void restoreMenuState(Bundle bundle) {
object = bundle.getSerializable(KEY_CTX_MENU_OBJECT);
Object pDescObj = bundle.getSerializable(KEY_CTX_MENU_POINT_DESC);
if (pDescObj != null) {
pointDescription = (PointDescription) pDescObj;
}
active = Boolean.parseBoolean(bundle.getString(KEY_CTX_MENU_ACTIVE));
Object latLonObj = bundle.getSerializable(KEY_CTX_MENU_LATLON);
if (latLonObj != null) {
latLon = (LatLon) latLonObj;
} else {
active = false;
}
acquireMenuController();
Object mapCenterObj = bundle.getSerializable(KEY_CTX_MENU_MAP_CENTER);
if (mapCenterObj != null) {
mapCenter = (LatLon) mapCenterObj;
}
nameStr = bundle.getString(KEY_CTX_MENU_NAME_STR);
typeStr = bundle.getString(KEY_CTX_MENU_TYPE_STR);
streetStr = bundle.getString(KEY_CTX_MENU_STREET_STR);
addressUnknown = Boolean.parseBoolean(bundle.getString(KEY_CTX_MENU_ADDR_UNKNOWN));
mapPosition = bundle.getInt(KEY_CTX_MENU_MAP_POSITION, 0);
acquireIcons();
if (menuController != null) {
menuController.addPlainMenuItems(typeStr, pointDescription, latLon);
}
}
public void setBaseFragmentVisibility(boolean visible) {
MapContextMenuFragment menuFragment = findMenuFragment();
if (menuFragment != null) {

View file

@ -111,12 +111,6 @@ public class MapContextMenuFragment extends Fragment {
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
menu.saveMenuState(outState);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -127,9 +121,6 @@ public class MapContextMenuFragment extends Fragment {
markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
menu = getMapActivity().getContextMenu();
if (savedInstanceState != null) {
menu.restoreMenuState(savedInstanceState);
}
map = getMapActivity().getMapView();
RotatedTileBox box = map.getCurrentRotatedTileBox().copy();

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import net.osmand.data.Amenity;
@ -10,7 +9,6 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.SearchHistoryHelper;
@ -18,9 +16,12 @@ import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
import net.osmand.plus.mapcontextmenu.details.HistoryMenuController;
import net.osmand.plus.mapcontextmenu.details.MyLocationMenuController;
import net.osmand.plus.mapcontextmenu.details.OsMoMenuController;
import net.osmand.plus.mapcontextmenu.details.ParkingPositionMenuController;
import net.osmand.plus.mapcontextmenu.details.PointDescriptionMenuController;
import net.osmand.plus.mapcontextmenu.details.TargetPointMenuController;
import net.osmand.plus.osmo.OsMoGroupsStorage;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
public abstract class MenuController extends BaseMenuController {
@ -56,11 +57,13 @@ public abstract class MenuController extends BaseMenuController {
menuController = new HistoryMenuController(app, mapActivity, (SearchHistoryHelper.HistoryEntry) object);
} else if (object instanceof TargetPoint) {
menuController = new TargetPointMenuController(app, mapActivity, (TargetPoint) object);
} else if (object instanceof OsMoDevice) {
menuController = new OsMoMenuController(app, mapActivity, (OsMoDevice) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription, (LatLon) object);
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);
} else if (pointDescription.isMyLocation()) {
menuController = new MyLocationMenuController(app, mapActivity, pointDescription, (LatLon) object);
menuController = new MyLocationMenuController(app, mapActivity, pointDescription);
}
}
} else {
@ -182,6 +185,4 @@ public abstract class MenuController extends BaseMenuController {
public String getTypeStr() { return ""; }
public String getNameStr() { return ""; }
public abstract void saveEntityState(Bundle bundle, String key);
}

View file

@ -1,7 +1,5 @@
package net.osmand.plus.mapcontextmenu.details;
import android.os.Bundle;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@ -86,9 +84,4 @@ public class AmenityMenuController extends MenuController {
public String getNameStr() {
return amenity.getName(getMapActivity().getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get());
}
@Override
public void saveEntityState(Bundle bundle, String key) {
bundle.putSerializable(key, amenity);
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import net.osmand.data.FavouritePoint;
@ -77,10 +76,4 @@ public class FavouritePointMenuController extends MenuController {
public String getNameStr() {
return fav.getName();
}
@Override
public void saveEntityState(Bundle bundle, String key) {
bundle.putSerializable(key, fav);
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -27,7 +26,7 @@ public class HistoryMenuController extends MenuController {
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN;
}
@Override
@ -68,9 +67,4 @@ public class HistoryMenuController extends MenuController {
public boolean needStreetName() {
return !entry.getName().isAddress();
}
@Override
public void saveEntityState(Bundle bundle, String key) {
bundle.putSerializable(key, entry);
}
}

View file

@ -1,9 +1,7 @@
package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
@ -13,13 +11,11 @@ import net.osmand.plus.mapcontextmenu.MenuController;
public class MyLocationMenuController extends MenuController {
private LatLon latLon;
private PointDescription pointDescription;
public MyLocationMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) {
public MyLocationMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription) {
super(new MenuBuilder(app), mapActivity);
this.pointDescription = pointDescription;
this.latLon = latLon;
}
@Override
@ -42,9 +38,4 @@ public class MyLocationMenuController extends MenuController {
public String getNameStr() {
return pointDescription.getTypeName();
}
@Override
public void saveEntityState(Bundle bundle, String key) {
bundle.putSerializable(key, latLon);
}
}

View file

@ -0,0 +1,60 @@
package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
public class OsMoMenuController extends MenuController {
private OsMoDevice device;
public OsMoMenuController(OsmandApplication app, MapActivity mapActivity, final OsMoDevice device) {
super(new MenuBuilder(app), mapActivity);
this.device = device;
}
@Override
protected int getInitialMenuStatePortrait() {
return MenuState.HEADER_ONLY;
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN;
}
@Override
public boolean needTypeStr() {
return true;
}
@Override
public Drawable getLeftIcon() {
if (isLight()) {
return getIconOrig(R.drawable.widget_osmo_connected_location_day);
} else {
return getIconOrig(R.drawable.widget_osmo_connected_location_night);
}
}
@Override
public String getNameStr() {
return device.getVisibleName();
}
@Override
public String getTypeStr() {
// todo
return "";
}
@Override
public boolean needStreetName() {
return false;
}
}

View file

@ -1,9 +1,7 @@
package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -17,14 +15,12 @@ import net.osmand.util.Algorithms;
public class ParkingPositionMenuController extends MenuController {
private PointDescription pointDescription;
private LatLon latLon;
ParkingPositionPlugin plugin;
String parkingDescription = "";
public ParkingPositionMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) {
public ParkingPositionMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription) {
super(new MenuBuilder(app), mapActivity);
this.pointDescription = pointDescription;
this.latLon = latLon;
plugin = OsmandPlugin.getPlugin(ParkingPositionPlugin.class);
if (plugin != null) {
StringBuilder sb = new StringBuilder();
@ -88,9 +84,4 @@ public class ParkingPositionMenuController extends MenuController {
public boolean needStreetName() {
return false;
}
@Override
public void saveEntityState(Bundle bundle, String key) {
bundle.putSerializable(key, latLon);
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
@ -73,8 +72,4 @@ public class PointDescriptionMenuController extends MenuController {
public boolean needStreetName() {
return !pointDescription.isAddress();
}
@Override
public void saveEntityState(Bundle bundle, String key) {
}
}

View file

@ -1,20 +1,14 @@
package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.util.Algorithms;
public class TargetPointMenuController extends MenuController {
@ -97,9 +91,4 @@ public class TargetPointMenuController extends MenuController {
public boolean needStreetName() {
return true;
}
@Override
public void saveEntityState(Bundle bundle, String key) {
bundle.putSerializable(key, targetPoint);
}
}