Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-09-17 23:40:51 +02:00
commit fd1a621d86
2 changed files with 81 additions and 20 deletions

View file

@ -1,17 +1,22 @@
package net.osmand.plus.mapcontextmenu; package net.osmand.plus.mapcontextmenu;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.Toast;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.sections.AmenityInfoMenuController; import net.osmand.plus.mapcontextmenu.sections.AmenityInfoMenuController;
import net.osmand.plus.mapcontextmenu.sections.MenuController; import net.osmand.plus.mapcontextmenu.sections.MenuController;
@ -57,28 +62,32 @@ public class MapContextMenu {
this.pointDescription = pointDescription; this.pointDescription = pointDescription;
this.object = object; this.object = object;
foundStreetName = null;
acquireStretName(); acquireStretName(mapActivity, new LatLon(pointDescription.getLat(), pointDescription.getLon()));
MapContextMenuFragment.showInstance(mapActivity); MapContextMenuFragment.showInstance(mapActivity);
} }
public void hide(MapActivity mapActivity) { public void hide(MapActivity mapActivity) {
MapContextMenuFragment fragment = findMenuFragment(mapActivity);
if (fragment != null)
fragment.dismissMenu();
}
public void refreshMenuTitle(MapActivity mapActivity) {
MapContextMenuFragment fragment = findMenuFragment(mapActivity);
if (fragment != null)
fragment.refreshTitle();
}
private MapContextMenuFragment findMenuFragment(MapActivity mapActivity) {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment"); Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag("MapContextMenuFragment");
if (fragment != null) if (fragment != null)
((MapContextMenuFragment)fragment).dismissMenu(); return (MapContextMenuFragment)fragment;
} else
return null;
private void acquireStretName() {
RouteDataObject rt = app.getLocationProvider().getLastKnownRouteSegment();
if(rt != null) {
foundStreetName = RoutingHelper.formatStreetName(rt.getName(settings.MAP_PREFERRED_LOCALE.get()),
rt.getRef(), rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
} else {
foundStreetName = null;
}
} }
public int getLeftIconId() { public int getLeftIconId() {
@ -135,6 +144,46 @@ public class MapContextMenu {
return foundStreetName; return foundStreetName;
} }
private void acquireStretName(final MapActivity activity, final LatLon loc) {
new AsyncTask<LatLon, Void, RouteDataObject>() {
Exception e = null;
@Override
protected RouteDataObject doInBackground(LatLon... params) {
try {
return app.getLocationProvider().findRoute(loc.getLatitude(), loc.getLongitude());
} catch (Exception e) {
this.e = e;
e.printStackTrace();
return null;
}
}
protected void onPostExecute(RouteDataObject result) {
if(e != null) {
//Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
foundStreetName = null;
} else if(result != null) {
foundStreetName = RoutingHelper.formatStreetName(result.getName(settings.MAP_PREFERRED_LOCALE.get()),
result.getRef(), result.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
if (foundStreetName != null && foundStreetName.trim().length() == 0) {
foundStreetName = null;
}
} else {
foundStreetName = null;
}
if (foundStreetName != null) {
activity.runOnUiThread(new Runnable() {
public void run() {
refreshMenuTitle(activity);
}
});
}
};
}.execute(loc);
}
public MenuController getMenuController() { public MenuController getMenuController() {
if (object != null) { if (object != null) {

View file

@ -9,6 +9,7 @@ import android.graphics.PointF;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.GestureDetector; import android.view.GestureDetector;
@ -360,13 +361,7 @@ public class MapContextMenuFragment extends Fragment {
light ? R.color.osmand_orange : R.color.osmand_orange_dark)); light ? R.color.osmand_orange : R.color.osmand_orange_dark));
} }
// Text line 1 setAddressLocation();
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
line1.setText(getCtxMenu().getAddressStr());
// Text line 2
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
line2.setText(getCtxMenu().getLocationStr(getMapActivity()));
// Close button // Close button
final ImageView closeButtonView = (ImageView)view.findViewById(R.id.context_menu_close_btn_view); final ImageView closeButtonView = (ImageView)view.findViewById(R.id.context_menu_close_btn_view);
@ -440,6 +435,16 @@ public class MapContextMenuFragment extends Fragment {
return view; return view;
} }
private void setAddressLocation() {
// Text line 1
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
line1.setText(getCtxMenu().getAddressStr());
// Text line 2
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
line2.setText(getCtxMenu().getLocationStr(getMapActivity()));
}
private int getPosY() { private int getPosY() {
int destinationState; int destinationState;
int minHalfY; int minHalfY;
@ -506,7 +511,14 @@ public class MapContextMenuFragment extends Fragment {
} }
public void dismissMenu() { public void dismissMenu() {
getActivity().getSupportFragmentManager().popBackStack(); FragmentActivity activity = getActivity();
if (activity != null) {
activity.getSupportFragmentManager().popBackStack();
}
}
public void refreshTitle() {
setAddressLocation();
} }
public OsmandApplication getMyApplication() { public OsmandApplication getMyApplication() {