Revert waypoints dialog (due to crashes) and fix configure map/screen

This commit is contained in:
Victor Shcherb 2014-10-26 11:35:13 +01:00
parent c48252680d
commit d543ccd9a8
16 changed files with 674 additions and 703 deletions

View file

@ -20,7 +20,6 @@ public class ContextMenuAdapter {
isCategory.clear();
itemNames.clear();
checkListeners.clear();
itemListeners.clear();
selectedList.clear();
layoutIds.clear();
iconList.clear();
@ -33,6 +32,22 @@ public class ContextMenuAdapter {
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked);
}
public static abstract class OnRowItemClick implements OnContextMenuClick {
public OnRowItemClick() {
}
//boolean return type needed to desribe if drawer needed to be close or not
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
return false;
} else {
return onContextMenuClick(adapter, itemId, pos, false);
}
}
}
private final Context ctx;
private View anchor;
private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
@ -41,7 +56,6 @@ public class ContextMenuAdapter {
final TIntArrayList isCategory = new TIntArrayList();
final ArrayList<String> itemNames = new ArrayList<String>();
final ArrayList<OnContextMenuClick> checkListeners = new ArrayList<ContextMenuAdapter.OnContextMenuClick>();
final ArrayList<OnContextMenuClick> itemListeners = new ArrayList<ContextMenuAdapter.OnContextMenuClick>();
final TIntArrayList selectedList = new TIntArrayList();
final TIntArrayList loadingList = new TIntArrayList();
final TIntArrayList layoutIds = new TIntArrayList();
@ -73,10 +87,6 @@ public class ContextMenuAdapter {
return checkListeners.get(i);
}
public OnContextMenuClick getItemClickAdapter(int i) {
return itemListeners.get(i);
}
public String getItemName(int pos){
return itemNames.get(pos);
}
@ -290,9 +300,10 @@ public class ContextMenuAdapter {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
OnContextMenuClick ca = getClickAdapter(position);
if(ca != null) {
if (ca != null) {
ca.onContextMenuClick(la, getElementId(position), position, isChecked);
}
selectedList.set(position, isChecked ? 1 : 0);
}
});
ch.setVisibility(View.VISIBLE);

View file

@ -16,6 +16,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.content.Intent;
@ -115,7 +116,7 @@ public class FavouritesListFragment extends SherlockListFragment implements Sear
};
ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
qa.setAnchor(v);
MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(), getActivity(),
DirectionsDialogs.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(), getActivity(),
true, false);
MapActivityActions.showObjectContextMenu(qa, getActivity(), onshow);
} else {

View file

@ -27,6 +27,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.util.MapUtils;
import android.app.Activity;
@ -168,7 +169,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
settings.SHOW_FAVORITES.set(true);
}
};
MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(),
DirectionsDialogs.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(),
getActivity(), true, false);
Item edit = qa.item(R.string.favourites_context_menu_edit).icons(
R.drawable.ic_action_edit_dark, R.drawable.ic_action_edit_light);

View file

@ -26,6 +26,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXUtilities;
@ -44,10 +45,10 @@ import net.osmand.plus.activities.actions.ShareLocation;
import net.osmand.plus.activities.actions.StartGPSStatus;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.configuremap.ConfigureMapMenu;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.osmo.OsMoPositionLayer;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
@ -82,7 +83,6 @@ import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@ -92,7 +92,7 @@ public class MapActivityActions implements DialogProvider {
public static final String KEY_LONGITUDE = "longitude";
public static final String KEY_LATITUDE = "latitude";
public static final String KEY_NAME = "name";
public static final String KEY_FAVORITE = "favorite";
public static final String KEY_ZOOM = "zoom";
private static final int DIALOG_ADD_FAVORITE = 100;
@ -141,187 +141,7 @@ public class MapActivityActions implements DialogProvider {
return bundle;
}
public static void prepareAddFavouriteDialog(Activity activity, Dialog dialog, Bundle args, double lat, double lon, String name) {
final Resources resources = activity.getResources();
if(name == null) {
name = resources.getString(R.string.add_favorite_dialog_default_favourite_name);
}
OsmandApplication app = (OsmandApplication) activity.getApplication();
final FavouritePoint point = new FavouritePoint(lat, lon, name, app.getSettings().LAST_FAV_CATEGORY_ENTERED.get());
args.putSerializable(KEY_FAVORITE, point);
final EditText editText = (EditText) dialog.findViewById(R.id.Name);
editText.setText(point.getName());
editText.selectAll();
editText.requestFocus();
final AutoCompleteTextView cat = (AutoCompleteTextView) dialog.findViewById(R.id.Category);
cat.setText(point.getCategory());
AndroidUtils.softKeyboardDelayed(editText);
}
public static Dialog createAddFavouriteDialog(final Activity activity, final Bundle args) {
Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.favourites_context_menu_edit);
final View v = activity.getLayoutInflater().inflate(R.layout.favourite_edit_dialog, null, false);
final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
builder.setView(v);
final EditText editText = (EditText) v.findViewById(R.id.Name);
final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
List<FavoriteGroup> gs = helper.getFavoriteGroups();
String[] list = new String[gs.size()];
for (int i = 0; i < list.length; i++) {
list[i] = gs.get(i).name;
}
cat.setAdapter(new ArrayAdapter<String>(activity, R.layout.list_textview, list));
builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.setNeutralButton(R.string.update_existing, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// Don't use showDialog because it is impossible to refresh favorite items list
Dialog dlg = createReplaceFavouriteDialog(activity, args);
if(dlg != null) {
dlg.show();
}
// mapActivity.showDialog(DIALOG_REPLACE_FAVORITE);
}
});
builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
OsmandApplication app = (OsmandApplication) activity.getApplication();
String categoryStr = cat.getText().toString().trim();
final FavouritesDbHelper helper = app.getFavorites();
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr);
point.setName(editText.getText().toString().trim());
point.setCategory(categoryStr);
boolean added = helper.addFavourite(point);
if (added) {
AccessibleToast.makeText(activity, MessageFormat.format(
activity.getString(R.string.add_favorite_dialog_favourite_added_template), point.getName()), Toast.LENGTH_SHORT)
.show();
}
if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap(true);
}
}
});
return builder.create();
}
protected static Dialog createReplaceFavouriteDialog(final Activity activity, final Bundle args) {
final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
final List<FavouritePoint> points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
final Collator ci = java.text.Collator.getInstance();
final boolean distance = args.containsKey("DISTANCE");
Collections.sort(points, new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint o1, FavouritePoint o2) {
if (distance && activity instanceof MapActivity) {
float f1 = (float) MapUtils.getDistance(((MapActivity) activity).getMapLocation(), o1.getLatitude(),
o1.getLongitude());
float f2 = (float) MapUtils.getDistance(((MapActivity) activity).getMapLocation(), o2.getLatitude(),
o2.getLongitude());
return Float.compare(f1, f2);
}
return ci.compare(o1.getCategory() + " " + o1.getName(), o2.getCategory() + " " + o2.getName());
}
});
final String[] names = new String[points.size()];
if(points.size() == 0){
AccessibleToast.makeText(activity, activity.getString(R.string.fav_points_not_exist), Toast.LENGTH_SHORT).show();
return null;
}
Builder b = new AlertDialog.Builder(activity);
final FavouritePoint[] favs = new FavouritePoint[points.size()];
Iterator<FavouritePoint> it = points.iterator();
int i=0;
while (it.hasNext()) {
FavouritePoint fp = it.next();
// filter gpx points
favs[i] = fp;
if(fp.getCategory().trim().length() ==0){
names[i] = fp.getName();
} else {
names[i] = fp.getCategory() + ": " + fp.getName();
}
if(activity instanceof MapActivity) {
names[i] += " " + OsmAndFormatter.getFormattedDistance(
(float) MapUtils.getDistance(((MapActivity) activity).getMapLocation(), fp.getLatitude(),
fp.getLongitude()), ((MapActivity) activity).getMyApplication());
}
i++;
}
final int layout;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
layout = R.layout.list_menu_item;
} else {
layout = R.layout.list_menu_item_native;
}
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title,
names) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = activity.getLayoutInflater().inflate(layout, null);
int vl = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, activity.getResources()
.getDisplayMetrics());
final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(vl, vl);
ll.setMargins(vl / 4, vl / 4, vl / 4, vl / 4);
v.findViewById(R.id.icon).setLayoutParams(ll);
}
ImageView icon = (ImageView) v.findViewById(R.id.icon);
FavouritePoint fp = points.get(position);
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, fp.getColor()));
icon.setVisibility(View.VISIBLE);
TextView tv = (TextView) v.findViewById(R.id.title);
tv.setText(names[position]);
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
ch.setVisibility(View.INVISIBLE);
return v;
}
};
b.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FavouritePoint fv = favs[which];
FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
if (helper.editFavourite(fv, point.getLatitude(), point.getLongitude())) {
AccessibleToast.makeText(activity, activity.getString(R.string.fav_points_edited),
Toast.LENGTH_SHORT).show();
}
if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap();
}
}
});
if (activity instanceof MapActivity) {
b.setPositiveButton(distance ? R.string.sort_by_name : R.string.sort_by_distance,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (distance) {
args.remove("DISTANCE");
} else {
args.putBoolean("DISTANCE", true);
}
createReplaceFavouriteDialog(activity, args).show();
}
});
}
AlertDialog al = b.create();
return al;
}
public void addWaypoint(final double latitude, final double longitude){
String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
enhance(dialogBundle,latitude,longitude, name);
@ -705,9 +525,9 @@ public class MapActivityActions implements DialogProvider {
Bundle args = dialogBundle;
switch (id) {
case DIALOG_ADD_FAVORITE:
return createAddFavouriteDialog(mapActivity, args);
return FavoriteDialogs.createAddFavouriteDialog(mapActivity, args);
case DIALOG_REPLACE_FAVORITE:
return createReplaceFavouriteDialog(mapActivity, args);
return FavoriteDialogs.createReplaceFavouriteDialog(mapActivity, args);
case DIALOG_ADD_WAYPOINT:
return createAddWaypointDialog(args);
case DIALOG_RELOAD_TITLE:
@ -723,7 +543,7 @@ public class MapActivityActions implements DialogProvider {
Bundle args = dialogBundle;
switch (id) {
case DIALOG_ADD_FAVORITE:
prepareAddFavouriteDialog(mapActivity, dialog, args,
FavoriteDialogs.prepareAddFavouriteDialog(mapActivity, dialog, args,
args.getDouble(KEY_LATITUDE), args.getDouble(KEY_LONGITUDE),args.getString(KEY_NAME));
break;
case DIALOG_ADD_WAYPOINT:
@ -776,7 +596,12 @@ public class MapActivityActions implements DialogProvider {
@Override
public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
OnContextMenuClick click = cm.getClickAdapter(which);
if (click != null) {
if(click instanceof OnRowItemClick) {
boolean cl = ((OnRowItemClick) click).onRowItemClick(listAdapter, view, cm.getElementId(which), which);
if(cl) {
mDrawerLayout.closeDrawer(mDrawerList);
}
} else if (click != null) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
@ -908,10 +733,11 @@ public class MapActivityActions implements DialogProvider {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos,
boolean isChecked) {
final List<WaypointHelper.LocationPointWrapper> deletedPoints = new ArrayList<WaypointHelper.LocationPointWrapper>();
ContextMenuAdapter cm = waypointDialogHelper.setListAdapter(app.getMapActivity(),
mDrawerList, deletedPoints);
prepareOptionsMenu(cm);
// final List<WaypointHelper.LocationPointWrapper> deletedPoints = new ArrayList<WaypointHelper.LocationPointWrapper>();
// ContextMenuAdapter cm = waypointDialogHelper.setListAdapter(app.getMapActivity(),
// mDrawerList, deletedPoints);
// prepareOptionsMenu(cm);
WaypointDialogHelper.showWaypointsDialog(mapActivity);
return false;
}
}).reg();
@ -1124,75 +950,9 @@ public class MapActivityActions implements DialogProvider {
menu.show();
}
public static void createDirectionsActions(final ContextMenuAdapter qa , final LatLon location, final Object obj, final String name,
final int z, final Activity activity, final boolean saveHistory) {
createDirectionsActions(qa, location, obj, name, z, activity, saveHistory, true);
}
public static void createDirectionsActions(final ContextMenuAdapter qa , final LatLon location, final Object obj, final String name,
final int z, final Activity activity, final boolean saveHistory, boolean favorite) {
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
Item dir = qa.item(R.string.context_menu_item_directions_to).icons(
R.drawable.ic_action_gdirections_dark, R.drawable.ic_action_gdirections_light);
dir.listen(
new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivityActions.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
return true;
}
}).reg();
Item intermediate;
if (targetPointsHelper.getPointToNavigate() != null) {
intermediate = qa.item(R.string.context_menu_item_intermediate_point).icons(
R.drawable.ic_action_flage_dark,R.drawable.ic_action_flage_light);
} else {
intermediate = qa.item(R.string.context_menu_item_destination_point).icons(
R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_light);
}
intermediate.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
return true;
}
}).reg();
Item showOnMap = qa.item(R.string.show_poi_on_map).icons(
R.drawable.ic_action_marker_dark, R.drawable.ic_action_marker_light );
showOnMap.listen(
new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, saveHistory ? name : null, name,
obj); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(activity);
return true;
}
}).reg();
if (favorite) {
Item addToFavorite = qa.item(R.string.add_to_favourite).icons(
R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_light);
addToFavorite.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Bundle args = new Bundle();
Dialog dlg = createAddFavouriteDialog(activity, args);
dlg.show();
prepareAddFavouriteDialog(activity, dlg, args, location.getLatitude(), location.getLongitude(),
name);
return true;
}
}).reg();
}
}
public static void showObjectContextMenu(final ContextMenuAdapter qa, final Activity activity,
final OnClickListener onShow) {
@ -1239,67 +999,6 @@ public class MapActivityActions implements DialogProvider {
view.show();
}
}
public static void directionsToDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) {
final OsmandApplication ctx = (OsmandApplication) act.getApplication();
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
if (targetPointsHelper.getIntermediatePoints().size() > 0) {
Builder builder = new AlertDialog.Builder(act);
builder.setTitle(R.string.new_directions_point_dialog);
builder.setItems(
new String[] { act.getString(R.string.keep_intermediate_points),
act.getString(R.string.clear_intermediate_points)},
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 1) {
targetPointsHelper.clearPointToNavigate(false);
}
ctx.getSettings().navigateDialog();
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
MapActivity.launchMapActivityMoveToTop(act);
}
});
builder.show();
} else {
ctx.getSettings().navigateDialog();
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
MapActivity.launchMapActivityMoveToTop(act);
}
}
public static void addWaypointDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) {
final OsmandApplication ctx = (OsmandApplication) act.getApplication();
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
if (targetPointsHelper.getPointToNavigate() != null) {
Builder builder = new AlertDialog.Builder(act);
builder.setTitle(R.string.new_destination_point_dialog);
builder.setItems(
new String[] { act.getString(R.string.replace_destination_point),
act.getString(R.string.keep_and_add_destination_point),
act.getString(R.string.add_as_first_destination_point), act.getString(R.string.add_as_last_destination_point) },
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
} else if (which == 1) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true,
targetPointsHelper.getIntermediatePoints().size() + 1, name);
} else if (which == 2) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, 0, name);
} else {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, targetPointsHelper.getIntermediatePoints().size(), name);
}
MapActivity.launchMapActivityMoveToTop(act);
}
});
builder.show();
} else {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
MapActivity.launchMapActivityMoveToTop(act);
}
}
}

View file

@ -6,8 +6,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import android.opengl.GLSurfaceView;
import android.widget.*;
import net.osmand.CallbackWithObject;
import net.osmand.ResultMatcher;
import net.osmand.StateChangedListener;
@ -15,12 +13,19 @@ import net.osmand.access.AccessibleToast;
import net.osmand.data.AmenityType;
import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.MapVectorLayer;
@ -32,25 +37,22 @@ import net.osmand.plus.views.FavoritesLayer;
import net.osmand.plus.views.GPXLayer;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.MapTextLayer;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.POIMapLayer;
import net.osmand.plus.views.PointLocationLayer;
import net.osmand.plus.views.PointNavigationLayer;
import net.osmand.plus.views.RouteLayer;
import net.osmand.plus.views.MapTextLayer;
import net.osmand.plus.views.TransportInfoLayer;
import net.osmand.plus.views.TransportStopsLayer;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.opengl.GLSurfaceView;
import android.widget.ListAdapter;
import android.widget.Toast;
/**
* Object is responsible to maintain layers using by map activity
@ -77,11 +79,9 @@ public class MapActivityLayers {
private ContextMenuLayer contextMenuLayer;
private MapControlsLayer mapControlsLayer;
private DownloadedRegionsLayer downloadedRegionsLayer;
private GpxSelectionHelper gpxSelectionHelper;
public MapActivityLayers(MapActivity activity) {
this.activity = activity;
gpxSelectionHelper = getApplication().getSelectedGpxHelper();
}
public OsmandApplication getApplication(){

View file

@ -12,6 +12,8 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.util.MapUtils;
import android.app.Dialog;
import android.content.Intent;
@ -306,13 +308,13 @@ public class NavigatePointFragment extends SherlockFragment implements SearchAct
double lon = convert(((TextView) view.findViewById(R.id.LongitudeEdit)).getText().toString());
if(mode == ADD_TO_FAVORITE) {
Bundle b = new Bundle();
Dialog dlg = MapActivityActions.createAddFavouriteDialog(getActivity(), b);
Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), b);
dlg.show();
MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, lat, lon, getString(R.string.point_on_map, lat, lon));
FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, b, lat, lon, getString(R.string.point_on_map, lat, lon));
} else if (mode == NAVIGATE_TO) {
MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon));
DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon));
} else if (mode == ADD_WAYPOINT) {
MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon));
DirectionsDialogs.addWaypointDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon));
} else if (mode == SHOW_ON_MAP){
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
app.getSettings().setMapLocationToShow(lat, lon, Math.max(12, app.getSettings().getLastKnownMapZoom()),

View file

@ -22,6 +22,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.Algorithms;
import android.app.Activity;
import android.app.AlertDialog;
@ -631,7 +632,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
String name = app.getString(R.string.favorite) + ": " + child.name;
LatLon location = new LatLon(child.locationStart.lat, child.locationStart.lon);
OsmandSettings settings = app.getSettings();
MapActivityActions.createDirectionsActions(qa, location, child.locationStart, name, settings.getLastKnownMapZoom(), getMyActivity(),
DirectionsDialogs.createDirectionsActions(qa, location, child.locationStart, name, settings.getLastKnownMapZoom(), getMyActivity(),
true, false);
MapActivityActions.showObjectContextMenu(qa, getMyActivity(), null);
} else {

View file

@ -9,7 +9,8 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.util.Algorithms;
import android.app.Dialog;
@ -334,9 +335,9 @@ public class SearchAddressFragment extends SherlockFragment {
}
if(mode == ADD_TO_FAVORITE) {
Bundle b = new Bundle();
Dialog dlg = MapActivityActions.createAddFavouriteDialog(getActivity(), b);
Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), b);
dlg.show();
MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(), searchPoint.getLongitude(), ai.objectName);
FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(), searchPoint.getLongitude(), ai.objectName);
} else if(mode == SELECT_POINT ){
Intent intent = getActivity().getIntent();
intent.putExtra(SELECT_ADDRESS_POINT_INTENT_KEY, ai.objectName);
@ -346,9 +347,9 @@ public class SearchAddressFragment extends SherlockFragment {
getActivity().finish();
} else {
if (mode == NAVIGATE_TO) {
MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), ai.historyName);
DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), ai.historyName);
} else if (mode == ADD_WAYPOINT) {
MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), ai.historyName);
DirectionsDialogs.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), ai.historyName);
} else if (mode == SHOW_ON_MAP) {
osmandSettings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), ai.zoom, ai.historyName);
MapActivity.launchMapActivityMoveToTop(getActivity());

View file

@ -19,6 +19,7 @@ import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -230,7 +231,7 @@ public class SearchAddressOnlineFragment extends SherlockFragment implements Sea
Place item = adapter.getItem(position);
ContextMenuAdapter qa = new ContextMenuAdapter(view.getContext());
qa.setAnchor(view);
MapActivityActions.createDirectionsActions(qa, new LatLon(item.lat, item.lon), item,
DirectionsDialogs.createDirectionsActions(qa, new LatLon(item.lat, item.lon), item,
getString(R.string.address)+ " : " + item.displayName, Math.max(15, settings.getLastKnownMapZoom()),
getActivity(), true);
MapActivityActions.showObjectContextMenu(qa, getActivity(), null);

View file

@ -22,9 +22,10 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.OsmandListActivity;
import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.dialogs.FavoriteDialogs;
import org.apache.commons.logging.Log;
@ -588,15 +589,15 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
if (ai != null) {
if (mode == ADD_TO_FAVORITE) {
Bundle b = new Bundle();
Dialog dlg = MapActivityActions.createAddFavouriteDialog(getActivity(), b);
Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), b);
dlg.show();
MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(),
FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(),
searchPoint.getLongitude(), ai.objectName);
} else if (mode == NAVIGATE_TO) {
MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(),
DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(),
searchPoint.getLongitude(), ai.historyName);
} else if (mode == ADD_WAYPOINT) {
MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(),
DirectionsDialogs.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(),
searchPoint.getLongitude(), ai.historyName);
} else if (mode == SHOW_ON_MAP) {
settings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), ai.zoom,

View file

@ -12,6 +12,7 @@ import net.osmand.plus.SearchHistoryHelper;
import net.osmand.plus.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.MapUtils;
import android.content.Intent;
import android.os.Bundle;
@ -119,7 +120,7 @@ public class SearchHistoryFragment extends SherlockListFragment implements Sear
helper.selectEntry(model);
}
};
MapActivityActions.createDirectionsActions(qa, new LatLon(model.getLat(), model.getLon()),
DirectionsDialogs.createDirectionsActions(qa, new LatLon(model.getLat(), model.getLon()),
model, name, settings.getLastKnownMapZoom(), getActivity(), false);
MapActivityActions.showObjectContextMenu(qa, getActivity(), onShow);
}

View file

@ -39,6 +39,7 @@ import net.osmand.plus.activities.EditPOIFilterActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.OsmandListActivity;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser;
@ -569,10 +570,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
String name = poiSimpleFormat;
int z = Math.max(16, settings.getLastKnownMapZoom());
MapActivityActions.createDirectionsActions(adapter, amenity.getLocation(), amenity, name, z, this, true );
DirectionsDialogs.createDirectionsActions(adapter, amenity.getLocation(), amenity, name, z, this, true );
final String d = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false);
if(d.toString().trim().length() > 0) {
Item poiDescr = adapter.item(R.string.poi_context_menu_showdescription).icons(

View file

@ -1,4 +1,4 @@
package net.osmand.plus.configuremap;
package net.osmand.plus.dialogs;
import java.util.ArrayList;
import java.util.Arrays;
@ -8,6 +8,7 @@ import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -21,6 +22,7 @@ import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRulesStorage;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;
@ -44,11 +46,13 @@ public class ConfigureMapMenu {
return adapter;
}
private final class LayerMenuListener implements OnContextMenuClick {
private final class LayerMenuListener extends OnRowItemClick {
private MapActivity ma;
private ContextMenuAdapter cm;
private LayerMenuListener(MapActivity ma) {
private LayerMenuListener(MapActivity ma, ContextMenuAdapter cm) {
this.ma = ma;
this.cm = cm;
}
private List<String> getAlreadySelectedGpx() {
@ -60,6 +64,19 @@ public class ConfigureMapMenu {
}
return files;
}
@Override
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
if(itemId == R.string.layer_poi && cm.getSelection(pos) == 1) {
ma.getMapLayers().selectPOIFilterLayer(ma.getMapView(), null);
return false;
} else if(itemId == R.string.layer_gpx_layer && cm.getSelection(pos) == 1) {
ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView());
return false;
} else {
return super.onRowItemClick(adapter, view, itemId, pos);
}
}
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
@ -93,7 +110,7 @@ public class ConfigureMapMenu {
private void createLayersItems(ContextMenuAdapter adapter , MapActivity activity) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
LayerMenuListener l = new LayerMenuListener(activity);
LayerMenuListener l = new LayerMenuListener(activity, adapter);
adapter.item(R.string.layers_category_show).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
// String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
adapter.item(R.string.layer_poi).selected(settings.SHOW_POI_OVER_MAP.get() ? 1 : 0)
@ -158,8 +175,8 @@ public class ConfigureMapMenu {
AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
adapter.setItemDescription(pos, getRenderDescr(activity));
ad.notifyDataSetInvalidated();
dialog.dismiss();
activity.getMapActions().prepareOptionsMenu(createListAdapter(activity));
}
});
@ -307,8 +324,4 @@ public class ConfigureMapMenu {
}
}
}

View file

@ -0,0 +1,151 @@
package net.osmand.plus.dialogs;
import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class DirectionsDialogs {
public static void directionsToDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) {
final OsmandApplication ctx = (OsmandApplication) act.getApplication();
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
if (targetPointsHelper.getIntermediatePoints().size() > 0) {
Builder builder = new AlertDialog.Builder(act);
builder.setTitle(R.string.new_directions_point_dialog);
builder.setItems(
new String[] { act.getString(R.string.keep_intermediate_points),
act.getString(R.string.clear_intermediate_points)},
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 1) {
targetPointsHelper.clearPointToNavigate(false);
}
ctx.getSettings().navigateDialog();
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
MapActivity.launchMapActivityMoveToTop(act);
}
});
builder.show();
} else {
ctx.getSettings().navigateDialog();
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
MapActivity.launchMapActivityMoveToTop(act);
}
}
public static void createDirectionsActions(final ContextMenuAdapter qa , final LatLon location, final Object obj, final String name,
final int z, final Activity activity, final boolean saveHistory) {
createDirectionsActions(qa, location, obj, name, z, activity, saveHistory, true);
}
public static void createDirectionsActions(final ContextMenuAdapter qa , final LatLon location, final Object obj, final String name,
final int z, final Activity activity, final boolean saveHistory, boolean favorite) {
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
Item dir = qa.item(R.string.context_menu_item_directions_to).icons(
R.drawable.ic_action_gdirections_dark, R.drawable.ic_action_gdirections_light);
dir.listen(
new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
return true;
}
}).reg();
Item intermediate;
if (targetPointsHelper.getPointToNavigate() != null) {
intermediate = qa.item(R.string.context_menu_item_intermediate_point).icons(
R.drawable.ic_action_flage_dark,R.drawable.ic_action_flage_light);
} else {
intermediate = qa.item(R.string.context_menu_item_destination_point).icons(
R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_light);
}
intermediate.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
return true;
}
}).reg();
Item showOnMap = qa.item(R.string.show_poi_on_map).icons(
R.drawable.ic_action_marker_dark, R.drawable.ic_action_marker_light );
showOnMap.listen(
new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, saveHistory ? name : null, name,
obj); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(activity);
return true;
}
}).reg();
if (favorite) {
Item addToFavorite = qa.item(R.string.add_to_favourite).icons(
R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_light);
addToFavorite.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Bundle args = new Bundle();
Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(activity, args);
dlg.show();
FavoriteDialogs.prepareAddFavouriteDialog(activity, dlg, args, location.getLatitude(), location.getLongitude(),
name);
return true;
}
}).reg();
}
}
public static void addWaypointDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) {
final OsmandApplication ctx = (OsmandApplication) act.getApplication();
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
if (targetPointsHelper.getPointToNavigate() != null) {
Builder builder = new AlertDialog.Builder(act);
builder.setTitle(R.string.new_destination_point_dialog);
builder.setItems(
new String[] { act.getString(R.string.replace_destination_point),
act.getString(R.string.keep_and_add_destination_point),
act.getString(R.string.add_as_first_destination_point), act.getString(R.string.add_as_last_destination_point) },
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
} else if (which == 1) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true,
targetPointsHelper.getIntermediatePoints().size() + 1, name);
} else if (which == 2) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, 0, name);
} else {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, targetPointsHelper.getIntermediatePoints().size(), name);
}
MapActivity.launchMapActivityMoveToTop(act);
}
});
builder.show();
} else {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
MapActivity.launchMapActivityMoveToTop(act);
}
}
}

View file

@ -0,0 +1,226 @@
package net.osmand.plus.dialogs;
import java.text.Collator;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import net.osmand.AndroidUtils;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class FavoriteDialogs {
public static final String KEY_FAVORITE = "favorite";
public static Dialog createReplaceFavouriteDialog(final Activity activity, final Bundle args) {
final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
final List<FavouritePoint> points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
final Collator ci = java.text.Collator.getInstance();
final boolean distance = args.containsKey("DISTANCE");
Collections.sort(points, new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint o1, FavouritePoint o2) {
if (distance && activity instanceof MapActivity) {
float f1 = (float) MapUtils.getDistance(((MapActivity) activity).getMapLocation(), o1.getLatitude(),
o1.getLongitude());
float f2 = (float) MapUtils.getDistance(((MapActivity) activity).getMapLocation(), o2.getLatitude(),
o2.getLongitude());
return Float.compare(f1, f2);
}
return ci.compare(o1.getCategory() + " " + o1.getName(), o2.getCategory() + " " + o2.getName());
}
});
final String[] names = new String[points.size()];
if(points.size() == 0){
AccessibleToast.makeText(activity, activity.getString(R.string.fav_points_not_exist), Toast.LENGTH_SHORT).show();
return null;
}
Builder b = new AlertDialog.Builder(activity);
final FavouritePoint[] favs = new FavouritePoint[points.size()];
Iterator<FavouritePoint> it = points.iterator();
int i=0;
while (it.hasNext()) {
FavouritePoint fp = it.next();
// filter gpx points
favs[i] = fp;
if(fp.getCategory().trim().length() ==0){
names[i] = fp.getName();
} else {
names[i] = fp.getCategory() + ": " + fp.getName();
}
if(activity instanceof MapActivity) {
names[i] += " " + OsmAndFormatter.getFormattedDistance(
(float) MapUtils.getDistance(((MapActivity) activity).getMapLocation(), fp.getLatitude(),
fp.getLongitude()), ((MapActivity) activity).getMyApplication());
}
i++;
}
final int layout;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
layout = R.layout.list_menu_item;
} else {
layout = R.layout.list_menu_item_native;
}
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title,
names) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = activity.getLayoutInflater().inflate(layout, null);
int vl = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, activity.getResources()
.getDisplayMetrics());
final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(vl, vl);
ll.setMargins(vl / 4, vl / 4, vl / 4, vl / 4);
v.findViewById(R.id.icon).setLayoutParams(ll);
}
ImageView icon = (ImageView) v.findViewById(R.id.icon);
FavouritePoint fp = points.get(position);
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, fp.getColor()));
icon.setVisibility(View.VISIBLE);
TextView tv = (TextView) v.findViewById(R.id.title);
tv.setText(names[position]);
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
ch.setVisibility(View.INVISIBLE);
return v;
}
};
b.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FavouritePoint fv = favs[which];
FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
if (helper.editFavourite(fv, point.getLatitude(), point.getLongitude())) {
AccessibleToast.makeText(activity, activity.getString(R.string.fav_points_edited),
Toast.LENGTH_SHORT).show();
}
if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap();
}
}
});
if (activity instanceof MapActivity) {
b.setPositiveButton(distance ? R.string.sort_by_name : R.string.sort_by_distance,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (distance) {
args.remove("DISTANCE");
} else {
args.putBoolean("DISTANCE", true);
}
createReplaceFavouriteDialog(activity, args).show();
}
});
}
AlertDialog al = b.create();
return al;
}
public static void prepareAddFavouriteDialog(Activity activity, Dialog dialog, Bundle args, double lat, double lon, String name) {
final Resources resources = activity.getResources();
if(name == null) {
name = resources.getString(R.string.add_favorite_dialog_default_favourite_name);
}
OsmandApplication app = (OsmandApplication) activity.getApplication();
final FavouritePoint point = new FavouritePoint(lat, lon, name, app.getSettings().LAST_FAV_CATEGORY_ENTERED.get());
args.putSerializable(KEY_FAVORITE, point);
final EditText editText = (EditText) dialog.findViewById(R.id.Name);
editText.setText(point.getName());
editText.selectAll();
editText.requestFocus();
final AutoCompleteTextView cat = (AutoCompleteTextView) dialog.findViewById(R.id.Category);
cat.setText(point.getCategory());
AndroidUtils.softKeyboardDelayed(editText);
}
public static Dialog createAddFavouriteDialog(final Activity activity, final Bundle args) {
Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.favourites_context_menu_edit);
final View v = activity.getLayoutInflater().inflate(R.layout.favourite_edit_dialog, null, false);
final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
builder.setView(v);
final EditText editText = (EditText) v.findViewById(R.id.Name);
final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
List<FavoriteGroup> gs = helper.getFavoriteGroups();
String[] list = new String[gs.size()];
for (int i = 0; i < list.length; i++) {
list[i] = gs.get(i).name;
}
cat.setAdapter(new ArrayAdapter<String>(activity, R.layout.list_textview, list));
builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.setNeutralButton(R.string.update_existing, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// Don't use showDialog because it is impossible to refresh favorite items list
Dialog dlg = createReplaceFavouriteDialog(activity, args);
if(dlg != null) {
dlg.show();
}
// mapActivity.showDialog(DIALOG_REPLACE_FAVORITE);
}
});
builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
OsmandApplication app = (OsmandApplication) activity.getApplication();
String categoryStr = cat.getText().toString().trim();
final FavouritesDbHelper helper = app.getFavorites();
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr);
point.setName(editText.getText().toString().trim());
point.setCategory(categoryStr);
boolean added = helper.addFavourite(point);
if (added) {
AccessibleToast.makeText(activity, MessageFormat.format(
activity.getString(R.string.add_favorite_dialog_favourite_added_template), point.getName()), Toast.LENGTH_SHORT)
.show();
}
if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap(true);
}
}
});
return builder.create();
}
}

View file

@ -6,9 +6,11 @@ import java.util.List;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.views.AnimateDraggingMapThread;
@ -49,9 +51,6 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
private LinearLayout mainLayout;
private WaypointHelper waypointHelper;
private final static String POI_RADIUS = "poi_radius";
private final static String SEARCH_RADIUS = "favorite_radius";
public final static boolean OVERLAP_LAYOUT = true; // only true is supported
private View closePointDialog;
private List<LocationPointWrapper> many = new ArrayList<WaypointHelper.LocationPointWrapper>();
@ -62,9 +61,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
waypointHelper = this.app.getWaypointHelper();
this.mapActivity = mapActivity;
this.mainLayout = (LinearLayout) mapActivity.findViewById(R.id.dialog_layout);
if(mainLayout == null) {
throw new IllegalStateException();
}
}
public void init() {
@ -139,6 +136,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
});
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(ctx));
// Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation();
int dist = wh.getRouteDistance(ps);
String dd = OsmAndFormatter.getFormattedDistance(dist, app);
if (ps.deviationDistance > 0) {
@ -146,6 +144,9 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
textDist.setText(dd);
text.setText(point.getName(app));
// ((Spannable) text.getText()).setSpan(
// new ForegroundColorSpan(ctx.getResources().getColor(R.color.color_distance)), 0, distance.length() - 1,
// 0);
}
public void removeDialog() {
@ -199,16 +200,14 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
public static void showWaypointsDialogFlat(FragmentActivity fragmentActivity) {
Bundle args = new Bundle();
args.putBoolean(WaypointDialogFragment.FLAT_ARG, true);
//TODO remove this method totally
WaypointDialogFragment wdf = new WaypointDialogFragment(new WaypointDialogHelper(null));
WaypointDialogFragment wdf = new WaypointDialogFragment();
wdf.setArguments(args);
fragmentActivity.getSupportFragmentManager().beginTransaction().add(wdf, "tag").commit();
}
public static void showWaypointsDialog(FragmentActivity fragmentActivity) {
Bundle args = new Bundle();
//TODO remove this method totally
WaypointDialogFragment wdf = new WaypointDialogFragment(new WaypointDialogHelper(null));
WaypointDialogFragment wdf = new WaypointDialogFragment();
wdf.setArguments(args);
fragmentActivity.getSupportFragmentManager().beginTransaction().add(wdf, "tag").commit();
}
@ -217,14 +216,9 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
WaypointHelper waypointHelper;
private OsmandApplication app;
private WaypointDialogHelper dialogHelper;
public static final String FLAT_ARG = "FLAT_ARG";
public WaypointDialogFragment(WaypointDialogHelper helper){
this.dialogHelper = helper;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@ -234,7 +228,80 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return createWaypointsDialogFlat(waypointHelper.getAllPoints());
if (getArguments() != null && getArguments().getBoolean(FLAT_ARG)) {
return createWaypointsDialogFlat(waypointHelper.getAllPoints());
}
return createWaypointsDialog();
}
private void selectPoi(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
final boolean enable) {
if (getActivity() instanceof MapActivity && !PoiFilter.CUSTOM_FILTER_ID.equals(app.getSettings().getPoiFilterForMap())) {
MapActivity map = (MapActivity) getActivity();
final PoiFilter[] selected = new PoiFilter[1];
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected);
dlg.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (selected != null) {
enableType(running, listAdapter, type, enable);
}
}
});
} else {
enableType(running, listAdapter, type, enable);
}
}
private void enableType(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
final boolean enable) {
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
}
;
@Override
protected Void doInBackground(Void... params) {
app.getWaypointHelper().enableWaypointType(type, enable);
return null;
}
protected void onPostExecute(Void result) {
running[0] = -1;
listAdapter.clear();
for (Object point : getPoints()) {
listAdapter.add(point);
}
listAdapter.notifyDataSetChanged();
}
}.execute((Void) null);
}
protected String getHeader(int type, boolean checked) {
FragmentActivity ctx = getActivity();
String str = ctx.getString(R.string.waypoints);
switch (type) {
case WaypointHelper.TARGETS:
str = ctx.getString(R.string.targets);
break;
case WaypointHelper.ALARMS:
str = ctx.getString(R.string.way_alarms);
break;
case WaypointHelper.FAVORITES:
str = ctx.getString(R.string.my_favorites);
break;
case WaypointHelper.WAYPOINTS:
str = ctx.getString(R.string.waypoints);
break;
case WaypointHelper.POI:
str = waypointHelper.getPoiFilter() == null || !checked ? ctx.getString(R.string.poi) : waypointHelper
.getPoiFilter().getName();
break;
}
return str;
}
public AlertDialog createWaypointsDialogFlat(final List<LocationPointWrapper> points) {
@ -290,6 +357,113 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
return builder.create();
}
public AlertDialog createWaypointsDialog() {
final List<Object> points = getPoints();
final List<LocationPointWrapper> deletedPoints = new ArrayList<WaypointHelper.LocationPointWrapper>();
final FragmentActivity ctx = getActivity();
final ListView listView = new ListView(ctx);
final int[] running = new int[]{-1};
final ArrayAdapter<Object> listAdapter = new ArrayAdapter<Object>(ctx,
R.layout.waypoint_reached, R.id.title, points) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
final ArrayAdapter<Object> thisAdapter = this;
boolean labelView = (getItem(position) instanceof Integer);
boolean viewText = v != null && v.findViewById(R.id.info_close) == null;
if (v == null || viewText != labelView) {
v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null);
}
if (labelView) {
final int type = (Integer) getItem(position);
final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item);
btn.setVisibility(waypointHelper.isTypeConfigurable(type) ? View.VISIBLE : View.GONE);
btn.setOnCheckedChangeListener(null);
final boolean checked = waypointHelper.isTypeEnabled(type);
btn.setChecked(checked);
btn.setEnabled(running[0] == -1);
v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
running[0] = position;
thisAdapter.notifyDataSetInvalidated();
if (type == WaypointHelper.POI && isChecked) {
selectPoi(running, thisAdapter, type, isChecked);
} else {
enableType(running, thisAdapter, type, isChecked);
}
}
});
TextView tv = (TextView) v.findViewById(R.id.header_text);
tv.setText(getHeader(type, checked));
} else {
updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), WaypointDialogFragment.this);
View remove = v.findViewById(R.id.info_close);
((ImageButton) remove).setImageDrawable(ctx.getResources().getDrawable(
app.getSettings().isLightContent() ? R.drawable.ic_action_gremove_light
: R.drawable.ic_action_gremove_dark));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LocationPointWrapper point = (LocationPointWrapper) points.get(position);
remove(point);
deletedPoints.add(point);
notifyDataSetChanged();
}
});
}
return v;
}
};
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
if (listAdapter.getItem(item) instanceof LocationPointWrapper) {
LocationPointWrapper ps = (LocationPointWrapper) listAdapter.getItem(item);
showOnMap(app, ctx, ps.getPoint(), WaypointDialogFragment.this);
}
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setView(listView);
builder.setNeutralButton(R.string.flat_list_waypoints, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showWaypointsDialogFlat(getActivity());
}
});
builder.setPositiveButton(R.string.default_buttons_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
waypointHelper.removeVisibleLocationPoint(deletedPoints);
}
});
builder.setNegativeButton(ctx.getString(R.string.default_buttons_cancel), null);
return builder.create();
}
protected List<Object> getPoints() {
final List<Object> points = new ArrayList<Object>();
for (int i = 0; i < WaypointHelper.MAX; i++) {
List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
if (waypointHelper.isTypeVisible(i)) {
points.add(new Integer(i));
if (tp != null && tp.size() > 0) {
points.addAll(tp);
}
}
}
return points;
}
}
@ -325,315 +499,5 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
}
public ContextMenuAdapter setListAdapter(final Activity ctx, ListView mDrawerList, final List<LocationPointWrapper> deletedPoints){
final ContextMenuAdapter adapter = new ContextMenuAdapter(ctx);
registerPoints(adapter, ctx, mDrawerList);
mDrawerList.setAdapter(adapter.createListAdapter(mapActivity, mapActivity.getMyApplication().getSettings().isLightContentMenu()));
return adapter;
// return new ArrayAdapter<Object>(ctx,
// R.layout.waypoint_reached, R.id.title, points) {
//
// @Override
// public View getView(final int position, View convertView, ViewGroup parent) {
// // User super class to create the View
// View v = convertView;
// final ArrayAdapter<Object> thisAdapter = this;
// boolean labelView = (getItem(position) instanceof Integer);
// boolean viewText = v != null && v.findViewById(R.id.info_close) == null;
// if (v == null || viewText != labelView) {
// v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null);
// }
// if (getItem(position) instanceof String && getItem(position).equals(POI_RADIUS)){
// v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null);
// v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
// final TextView radius = (TextView) v.findViewById(R.id.radius);
// radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getPoiSearchDeviationRadius(), app));
// radius.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
// String[] names = new String[length];
// int selected = 0;
// for (int i = 0; i < length; i++) {
// names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
// if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getPoiSearchDeviationRadius()){
// selected = i;
// }
// }
// new AlertDialog.Builder(ctx)
// .setSingleChoiceItems(names, selected, new OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
// int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
// if (waypointHelper.getPoiSearchDeviationRadius() != value){
// running[0] = position;
// thisAdapter.notifyDataSetInvalidated();
// waypointHelper.setPoiSearchDeviationRadius(value);
// radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
// recalculatePoints(running, thisAdapter, WaypointHelper.POI);
// dialogInterface.dismiss();
// }
// }
// }).setTitle(app.getString(R.string.search_radius_proximity)+ " " + app.getString(R.string.poi))
// .setNegativeButton(R.string.default_buttons_cancel, null)
// .show();
// }
// });
// } else if (getItem(position) instanceof String && getItem(position).equals(SEARCH_RADIUS)){
// v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null);
// v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
// final TextView radius = (TextView) v.findViewById(R.id.radius);
// radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getSearchDeviationRadius(), app));
// radius.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
// String[] names = new String[length];
// int selected = 0;
// for (int i = 0; i < length; i++) {
// names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
// if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getSearchDeviationRadius()){
// selected = i;
// }
// }
// new AlertDialog.Builder(ctx)
// .setSingleChoiceItems(names, selected, new OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
// int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
// if (waypointHelper.getSearchDeviationRadius() != value){
// running[0] = position;
// thisAdapter.notifyDataSetInvalidated();
// waypointHelper.setSearchDeviationRadius(value);
// radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
// recalculatePoints(running, thisAdapter, -1);
// dialogInterface.dismiss();
// }
// }
// }).setTitle(app.getString(R.string.search_radius_proximity))
// .setNegativeButton(R.string.default_buttons_cancel, null)
// .show();
// }
// });
// } else if (labelView) {
// v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null);
// final int type = (Integer) getItem(position);
// ImageView sort = (ImageView) v.findViewById(R.id.sort);
// //sort button in Destination header
// if (type == 0 && sort != null){
// sort.setVisibility(View.VISIBLE);
// if (app.getSettings().isLightContent()){
// sort.setImageResource(R.drawable.ic_sort_waypoint_white);
// } else {
// sort.setImageResource(R.drawable.ic_sort_waypoint_dark);
// }
// sort.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// IntermediatePointsDialog.openIntermediatePointsDialog(ctx, app, true);
// }
// });
// }
// final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item);
// btn.setVisibility(waypointHelper.isTypeConfigurable(type) ? View.VISIBLE : View.GONE);
// btn.setOnCheckedChangeListener(null);
// final boolean checked = waypointHelper.isTypeEnabled(type);
// btn.setChecked(checked);
// btn.setEnabled(running[0] == -1);
// v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
// btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//
// @Override
// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// running[0] = position;
// thisAdapter.notifyDataSetInvalidated();
// if (type == WaypointHelper.POI && isChecked) {
// selectPoi(running, thisAdapter, type, isChecked, mapActivity);
// } else {
// enableType(running, thisAdapter, type, isChecked);
// }
// }
//
// });
// TextView tv = (TextView) v.findViewById(R.id.header_text);
// tv.setText(getHeader(ctx, type, checked));
// } else {
// v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
// updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), null);
// View remove = v.findViewById(R.id.info_close);
// ((ImageButton) remove).setImageDrawable(ctx.getResources().getDrawable(
// app.getSettings().isLightContent() ? R.drawable.ic_action_gremove_light
// : R.drawable.ic_action_gremove_dark));
// remove.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// LocationPointWrapper point = (LocationPointWrapper) points.get(position);
// remove(point);
// deletedPoints.add(point);
// notifyDataSetChanged();
// }
// });
// }
// return v;
// }
// };
}
protected String getHeader(Activity ctx, int type, boolean checked) {
String str = ctx.getString(R.string.waypoints);
switch (type) {
case WaypointHelper.TARGETS:
str = ctx.getString(R.string.targets);
break;
case WaypointHelper.ALARMS:
str = ctx.getString(R.string.way_alarms);
break;
case WaypointHelper.FAVORITES:
str = ctx.getString(R.string.my_favorites);
break;
case WaypointHelper.WAYPOINTS:
str = ctx.getString(R.string.waypoints);
break;
case WaypointHelper.POI:
str = waypointHelper.getPoiFilter() == null || !checked ? ctx.getString(R.string.poi) : waypointHelper
.getPoiFilter().getName();
break;
}
return str;
}
private void selectPoi(final int[] running, final ContextMenuAdapter menuAdapter, final int type,
final boolean enable, MapActivity map, final ListView drawerlist) {
if (!PoiFilter.CUSTOM_FILTER_ID.equals(app.getSettings().getPoiFilterForMap())) {
final PoiFilter[] selected = new PoiFilter[1];
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected);
dlg.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (selected != null) {
enableType(running, menuAdapter, type, enable, drawerlist);
}
}
});
} else {
enableType(running, menuAdapter, type, enable, drawerlist);
}
}
private void recalculatePoints(final int[] running, final ContextMenuAdapter menuAdapter, final int type, final ListView mDrawerList){
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
app.getWaypointHelper().recalculatePoints(type);
return null;
}
protected void onPostExecute(Void result) {
running[0] = -1;
menuAdapter.clearAll();
registerPoints(menuAdapter, mapActivity, mDrawerList);
}
}.execute((Void) null);
}
protected void registerPoints(final ContextMenuAdapter adapter, final Activity ctx, final ListView drawerList) {
final int[] running = new int[] { -1 };
for (int i = 0; i < WaypointHelper.MAX; i++) {
if (waypointHelper.isTypeVisible(i)) {
List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
final boolean checked = waypointHelper.isTypeEnabled(i);
final int type = i;
adapter.item(getHeader(ctx, i, checked)).layout(R.layout.drawer_list_poi_header)
.listen(new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> ra, int itemId, int pos, boolean isChecked) {
running[0] = pos;
ra.notifyDataSetChanged();
if (type == WaypointHelper.POI && isChecked) {
selectPoi(running, adapter, type, isChecked, mapActivity, drawerList);
} else {
enableType(running, adapter, type, isChecked, drawerList);
}
return false;
}
}).loading(0).reg();
if (i == WaypointHelper.POI && checked) {
Item item = createRadiusProximityItem(adapter, ctx, drawerList, running, WaypointHelper.POI);
item.loading(0).selected(app.getSettings().SHOW_POI_OVER_MAP.get() ? 1 : 0).reg();
} else if (i == WaypointHelper.FAVORITES && checked) {
Item item = createRadiusProximityItem(adapter, ctx, drawerList, running, WaypointHelper.FAVORITES);
item.loading(0).selected(app.getSettings().SHOW_FAVORITES.get() ? 1 : 0).reg();
}
if (tp != null && tp.size() > 0) {
for (LocationPointWrapper p : tp) {
WaypointHelper wh = app.getWaypointHelper();
int dist = wh.getRouteDistance(p);
String dd = OsmAndFormatter.getFormattedDistance(dist, app);
if (p.deviationDistance > 0) {
dd += "\n+" + OsmAndFormatter.getFormattedDistance(p.deviationDistance, app);
}
adapter.item(p.getPoint().getName(ctx)).icon(p.getDrawableId(ctx)).description(dd)
.layout(R.layout.drawer_list_waypoint).reg();
}
// points.addAll(tp);
}
}
}
}
protected Item createRadiusProximityItem(final ContextMenuAdapter adapter, final Activity ctx,
final ListView drawerList, final int[] running, final int type) {
return adapter.item(ctx.getString(R.string.search_radius_proximity)).listen(
new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> ra, int itemId, final int pos, boolean isChecked) {
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
String[] names = new String[length];
int selected = 0;
for (int i = 0; i < length; i++) {
names[i] = OsmAndFormatter
.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getSearchDeviationRadius(type)) {
selected = i;
}
}
new AlertDialog.Builder(ctx).setSingleChoiceItems(names, selected, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
if (waypointHelper.getSearchDeviationRadius(type) != value) {
running[0] = pos;
waypointHelper.setSearchDeviationRadius(value, type);
// radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
recalculatePoints(running, adapter, -1, drawerList);
dialogInterface.dismiss();
}
}
}).setTitle(app.getString(R.string.search_radius_proximity))
.setNegativeButton(R.string.default_buttons_cancel, null).show();
return false;
}
});
}
private void enableType(final int[] running, final ContextMenuAdapter menuAdapter, final int type,
final boolean enable, final ListView drawerList) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
app.getWaypointHelper().enableWaypointType(type, enable);
return null;
}
protected void onPostExecute(Void result) {
running[0] = -1;
menuAdapter.clearAll();
registerPoints(menuAdapter, mapActivity, drawerList);
}
}.execute((Void) null);
}
}
}