Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-16 16:36:49 +02:00
commit 0ed6dc5a13
4 changed files with 77 additions and 24 deletions

View file

@ -17,6 +17,7 @@ import android.os.Message;
import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.NotificationCompat; import android.support.v7.app.NotificationCompat;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -545,8 +546,8 @@ public class MapActivity extends AccessibleActivity {
dashboardOnMap.hideDashboard(); dashboardOnMap.hideDashboard();
} }
if (mapLabelToShow != null) { if (mapLabelToShow != null) {
contextMenuOnMap.setMapCenter(latLonToShow);
contextMenuOnMap.show(latLonToShow, mapLabelToShow, toShow); contextMenuOnMap.show(latLonToShow, mapLabelToShow, toShow);
//mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow.getFullPlainName(this));
} }
if (!latLonToShow.equals(cur)) { if (!latLonToShow.equals(cur)) {
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(),

View file

@ -7,9 +7,11 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.PopupMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -34,6 +36,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment; import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -190,6 +193,22 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
private void selectModelOptions(final HistoryEntry model, View v) {
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
MenuItem item = optionsMenu.getMenu().add(
R.string.shared_string_delete).setIcon(
getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_delete_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
helper.remove(model);
historyAdapter.remove(model);
return true;
}
});
optionsMenu.show();
}
class HistoryAdapter extends ArrayAdapter<HistoryEntry> { class HistoryAdapter extends ArrayAdapter<HistoryEntry> {
private LatLon location; private LatLon location;
@ -222,7 +241,7 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
options.setOnClickListener(new View.OnClickListener() { options.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
selectModel(historyEntry); selectModelOptions(historyEntry, v);
} }
}); });
return row; return row;

View file

@ -37,6 +37,8 @@ public class MapContextMenu {
private Object object; private Object object;
MenuController menuController; MenuController menuController;
private LatLon mapCenter;
private int leftIconId; private int leftIconId;
private Drawable leftIcon; private Drawable leftIcon;
private String nameStr; private String nameStr;
@ -55,6 +57,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";
private static final String KEY_CTX_MENU_ADDR_UNKNOWN = "key_ctx_menu_addr_unknown"; 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";
public boolean isActive() { public boolean isActive() {
return active; return active;
@ -68,6 +71,14 @@ public class MapContextMenu {
return latLon; return latLon;
} }
public LatLon getMapCenter() {
return mapCenter;
}
public void setMapCenter(LatLon mapCenter) {
this.mapCenter = mapCenter;
}
public PointDescription getPointDescription() { public PointDescription getPointDescription() {
return pointDescription; return pointDescription;
} }
@ -388,6 +399,7 @@ public class MapContextMenu {
bundle.putString(KEY_CTX_MENU_TYPE_STR, typeStr); bundle.putString(KEY_CTX_MENU_TYPE_STR, typeStr);
bundle.putString(KEY_CTX_MENU_STREET_STR, streetStr); bundle.putString(KEY_CTX_MENU_STREET_STR, streetStr);
bundle.putString(KEY_CTX_MENU_ADDR_UNKNOWN, Boolean.toString(addressUnknown)); bundle.putString(KEY_CTX_MENU_ADDR_UNKNOWN, Boolean.toString(addressUnknown));
bundle.putSerializable(KEY_CTX_MENU_MAP_CENTER, mapCenter);
} }
public void restoreMenuState(Bundle bundle) { public void restoreMenuState(Bundle bundle) {
@ -406,6 +418,11 @@ public class MapContextMenu {
active = false; active = false;
} }
Object mapCenterObj = bundle.getSerializable(KEY_CTX_MENU_MAP_CENTER);
if (mapCenterObj != null) {
mapCenter = (LatLon) mapCenterObj;
}
nameStr = bundle.getString(KEY_CTX_MENU_NAME_STR); nameStr = bundle.getString(KEY_CTX_MENU_NAME_STR);
typeStr = bundle.getString(KEY_CTX_MENU_TYPE_STR); typeStr = bundle.getString(KEY_CTX_MENU_TYPE_STR);
streetStr = bundle.getString(KEY_CTX_MENU_STREET_STR); streetStr = bundle.getString(KEY_CTX_MENU_STREET_STR);

View file

@ -74,10 +74,10 @@ public class MapContextMenuFragment extends Fragment {
private int markerPaddingXPx; private int markerPaddingXPx;
private OsmandMapTileView map; private OsmandMapTileView map;
private double origMapCenterLat; private LatLon mapCenter;
private double origMapCenterLon;
private int origMarkerX; private int origMarkerX;
private int origMarkerY; private int origMarkerY;
private boolean customMapCenter;
private class SingleTapConfirm implements OnGestureListener { private class SingleTapConfirm implements OnGestureListener {
@ -135,13 +135,20 @@ public class MapContextMenuFragment extends Fragment {
} }
map = getMapActivity().getMapView(); map = getMapActivity().getMapView();
origMapCenterLat = map.getLatitude(); RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
origMapCenterLon = map.getLongitude(); customMapCenter = menu.getMapCenter() != null;
RotatedTileBox box = map.getCurrentRotatedTileBox(); if (!customMapCenter) {
mapCenter = box.getCenterLatLon();
menu.setMapCenter(mapCenter);
double markerLat = menu.getLatLon().getLatitude(); double markerLat = menu.getLatLon().getLatitude();
double markerLon = menu.getLatLon().getLongitude(); double markerLon = menu.getLatLon().getLongitude();
origMarkerX = (int)box.getPixXFromLatLon(markerLat, markerLon); origMarkerX = (int)box.getPixXFromLatLon(markerLat, markerLon);
origMarkerY = (int)box.getPixYFromLatLon(markerLat, markerLon); origMarkerY = (int)box.getPixYFromLatLon(markerLat, markerLon);
} else {
mapCenter = menu.getMapCenter();
origMarkerX = box.getCenterPixelX();
origMarkerY = box.getCenterPixelY();
}
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false); view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
mainView = view.findViewById(R.id.context_menu_main); mainView = view.findViewById(R.id.context_menu_main);
@ -409,7 +416,8 @@ public class MapContextMenuFragment extends Fragment {
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
map.setLatLon(origMapCenterLat, origMapCenterLon); map.setLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
menu.setMapCenter(null);
getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(true); getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(true);
} }
@ -447,6 +455,11 @@ public class MapContextMenuFragment extends Fragment {
obs.removeGlobalOnLayoutListener(this); obs.removeGlobalOnLayoutListener(this);
} }
if (origMarkerX == 0 && origMarkerY == 0) {
origMarkerX = view.getWidth() / 2;
origMarkerY = view.getHeight() / 2;
}
doLayoutMenu(); doLayoutMenu();
} }
@ -454,25 +467,24 @@ public class MapContextMenuFragment extends Fragment {
} }
private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef) { private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef) {
MapActivity ctx = getMapActivity(); AnimateDraggingMapThread thread = map.getAnimatedDraggingThread();
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread(); int fZoom = map.getZoom();
int fZoom = ctx.getMapView().getZoom();
double flat = latLon.getLatitude(); double flat = latLon.getLatitude();
double flon = latLon.getLongitude(); double flon = latLon.getLongitude();
RotatedTileBox cp = ctx.getMapView().getCurrentRotatedTileBox().copy(); RotatedTileBox cp = map.getCurrentRotatedTileBox().copy();
if (ignoreCoef) { if (ignoreCoef) {
cp.setCenterLocation(0.5f, 0.5f); cp.setCenterLocation(0.5f, 0.5f);
} else { } else {
cp.setCenterLocation(0.5f, ctx.getMapView().getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f); cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
} }
cp.setLatLonCenter(flat, flon); cp.setLatLonCenter(flat, flon);
flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2); flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2); flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
if (updateCoords) { if (updateCoords) {
origMapCenterLat = flat; mapCenter = new LatLon(flat, flon);
origMapCenterLon = flon; menu.setMapCenter(mapCenter);
origMarkerX = cp.getCenterPixelX(); origMarkerX = cp.getCenterPixelX();
origMarkerY = cp.getCenterPixelY(); origMarkerY = cp.getCenterPixelY();
} }
@ -558,15 +570,19 @@ public class MapContextMenuFragment extends Fragment {
mainView.setPadding(0, y, 0, 0); mainView.setPadding(0, y, 0, 0);
fabView.setPadding(0, getFabY(y), 0, 0); fabView.setPadding(0, getFabY(y), 0, 0);
} }
if (!customMapCenter) {
adjustMapPosition(y, animated); adjustMapPosition(y, animated);
} else {
customMapCenter = false;
}
} }
private void adjustMapPosition(int y, boolean animated) { private void adjustMapPosition(int y, boolean animated) {
double markerLat = menu.getLatLon().getLatitude(); double markerLat = menu.getLatLon().getLatitude();
double markerLon = menu.getLatLon().getLongitude(); double markerLon = menu.getLatLon().getLongitude();
RotatedTileBox box = map.getCurrentRotatedTileBox(); RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
LatLon latlon = new LatLon(origMapCenterLat, origMapCenterLon); LatLon latlon = mapCenter;
if (menu.isLandscapeLayout()) { if (menu.isLandscapeLayout()) {
int markerX = (int)box.getPixXFromLatLon(markerLat, markerLon); int markerX = (int)box.getPixXFromLatLon(markerLat, markerLon);
int x = dpToPx(menu.getLandscapeWidthDp()); int x = dpToPx(menu.getLandscapeWidthDp());