Context menu: added osm bug, fixes compass

This commit is contained in:
Alexey Kulish 2015-11-09 15:48:50 +03:00
parent 342c58dc4b
commit d3d1ac3ed4
4 changed files with 118 additions and 49 deletions

View file

@ -680,11 +680,8 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
TextView distanceText = (TextView) view.findViewById(R.id.distance);
ImageView direction = (ImageView) view.findViewById(R.id.direction);
boolean mapLinked = getMapActivity().getMapViewTrackingUtilities().isMapLinkedToLocation() && menu.getMyLocation() != null;
float myHeading = menu.getHeading() == null ? 0f : menu.getHeading();
float h = !mapLinked ? -getMapActivity().getMapRotate() : myHeading;
DashLocationFragment.updateLocationView(!mapLinked, menu.getMyLocation(), h, direction, distanceText,
DashLocationFragment.updateLocationView(false, menu.getMyLocation(), myHeading, direction, distanceText,
menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, getMyApplication(), getActivity());
}
@ -910,10 +907,6 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
}
public void updateLocation(boolean centerChanged, boolean locationChanged, boolean compassChanged) {
boolean mapLinkedToLocation = getMapActivity().getMapViewTrackingUtilities().isMapLinkedToLocation();
if (compassChanged && !mapLinkedToLocation) {
return;
}
updateDistanceDirection();
}
}

View file

@ -23,11 +23,14 @@ import net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController;
import net.osmand.plus.mapcontextmenu.controllers.OsMoMenuController;
import net.osmand.plus.mapcontextmenu.controllers.OsmBugMenuController;
import net.osmand.plus.mapcontextmenu.controllers.ParkingPositionMenuController;
import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController;
import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController;
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
import net.osmand.plus.mapcontextmenu.other.ShareMenu;
import net.osmand.plus.osmedit.OsmBugsLayer;
import net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
@ -89,6 +92,8 @@ public abstract class MenuController extends BaseMenuController {
menuController = new WptPtMenuController(app, mapActivity, pointDescription, (WptPt) object);
} else if (object instanceof BinaryMapDataObject) {
menuController = new MapDataMenuController(app, mapActivity, pointDescription, (BinaryMapDataObject) object);
} else if (object instanceof OpenStreetNote) {
menuController = new OsmBugMenuController(app, mapActivity, pointDescription, (OpenStreetNote) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);
@ -213,11 +218,11 @@ public abstract class MenuController extends BaseMenuController {
}
public boolean needStreetName() {
return true;
return !displayDistanceDirection();
}
public boolean needTypeStr() {
return menuType != MenuType.STANDARD;
return true;
}
public boolean displayStreetNameInTitle() {
@ -238,7 +243,7 @@ public abstract class MenuController extends BaseMenuController {
public String getTypeStr() { return ""; }
public String getNameStr() { return ""; }
public String getNameStr() { return pointDescription.getName(); }
public void share(LatLon latLon, String title) {
ShareMenu.show(latLon, title, getMapActivity());

View file

@ -0,0 +1,72 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
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.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms;
public class OsmBugMenuController extends MenuController {
private OsmEditingPlugin plugin;
private OpenStreetNote bug;
public OsmBugMenuController(OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final OpenStreetNote bug) {
super(new MenuBuilder(app), pointDescription, mapActivity);
plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
this.bug = bug;
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
if (plugin != null) {
plugin.getBugsLayer(getMapActivity()).commentBug(bug);
}
}
};
leftTitleButtonController.caption = getMapActivity().getString(R.string.poi_dialog_comment);
leftTitleButtonController.leftIconId = R.drawable.ic_action_note_dark;
rightTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
if (plugin != null) {
plugin.getBugsLayer(getMapActivity()).closeBug(bug);
}
}
};
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_close);
rightTitleButtonController.leftIconId = R.drawable.ic_action_remove_dark;
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
@Override
public Drawable getLeftIcon() {
return getIcon(R.drawable.ic_action_gabout_dark, R.color.osmand_orange_dark, R.color.osmand_orange);
}
@Override
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
super.addPlainMenuItems(typeStr, pointDescription, latLon);
for (String description : bug.getCommentDescriptionList()) {
addPlainMenuItem(R.drawable.ic_action_note_dark, description, true);
}
}
}

View file

@ -46,6 +46,7 @@ import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider, DialogProvider {
@ -412,14 +413,17 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
builder.setView(view);
((EditText)view.findViewById(R.id.userNameEditText)).setText(getUserName());
((EditText)view.findViewById(R.id.passwordEditText)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
AndroidUtils.softKeyboardDelayed((EditText)view.findViewById(R.id.messageEditText));
AndroidUtils.softKeyboardDelayed((EditText) view.findViewById(R.id.messageEditText));
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.setPositiveButton(R.string.osb_comment_dialog_add_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
OpenStreetNote bug = (OpenStreetNote) args.getSerializable(KEY_BUG);
String text = getTextAndUpdateUserPwd(view);
addingCommentAsync(bug, text, getUserName());
if (bug != null) {
String text = getTextAndUpdateUserPwd(view);
addingCommentAsync(bug, text, getUserName());
activity.getContextMenu().close();
}
}
});
return builder.create();
@ -459,11 +463,12 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
OpenStreetNote bug = (OpenStreetNote) args.getSerializable(KEY_BUG);
String us = activity.getMyApplication().getSettings().USER_NAME.get();
String pwd = activity.getMyApplication().getSettings().USER_PASSWORD.get();
if(us.length() == 0 || pwd.length() == 0) {
if (us.length() == 0 || pwd.length() == 0) {
AccessibleToast.makeText(activity, activity.getString(R.string.osb_author_or_password_not_specified),
Toast.LENGTH_SHORT).show();
}
closingAsync(bug, "");
activity.getContextMenu().close();
}
});
return builder.create();
@ -497,31 +502,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
executeTaskInBackground(task);
}
@Override
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
if(o instanceof OpenStreetNote) {
final OpenStreetNote bug = (OpenStreetNote) o;
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.osb_comment_menu_item) {
commentBug(bug);
} else if (itemId == R.string.osb_close_menu_item) {
closeBug(bug);
}
return true;
}
};
adapter.item(R.string.osb_comment_menu_item).iconColor(
R.drawable.ic_action_note_dark
).listen(listener).reg();
adapter.item(R.string.osb_close_menu_item).iconColor(
R.drawable.ic_action_remove_dark
).listen(listener).reg();
}
}
@Override
public String getObjectDescription(Object o) {
if(o instanceof OpenStreetNote){
@ -533,7 +513,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
@Override
public PointDescription getObjectName(Object o) {
if(o instanceof OpenStreetNote){
return new PointDescription(PointDescription.POINT_TYPE_OSM_NOTE, ((OpenStreetNote)o).getCommentDescription());
return new PointDescription(PointDescription.POINT_TYPE_OSM_NOTE, activity.getString(R.string.osb_bug_name), "");
}
return null;
}
@ -605,20 +585,39 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public String getCommentDescription() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < comments.size(); i++) {
if (i < dates.size()) {
sb.append(dates.get(i)).append(" ");
for (String s : getCommentDescriptionList()) {
if (sb.length() > 0) {
sb.append("\n");
}
if (i < users.size()) {
sb.append(users.get(i)).append(" : ");
}
sb.append(comments.get(i)).append("\n");
sb.append(s);
}
return sb.toString();
}
public List<String> getCommentDescriptionList() {
List<String> res = new ArrayList<>(comments.size());
for (int i = 0; i < comments.size(); i++) {
StringBuilder sb = new StringBuilder();
boolean needLineFeed = false;
if (i < dates.size()) {
sb.append(dates.get(i)).append(" ");
needLineFeed = true;
}
if (i < users.size()) {
sb.append(users.get(i)).append(":");
needLineFeed = true;
}
if (needLineFeed) {
sb.append("\n");
}
sb.append(comments.get(i));
res.add(sb.toString());
}
return res;
}
public long getId() {
return id;