Allow save gpx points as favorites

This commit is contained in:
Victor Shcherb 2014-06-11 22:15:22 +02:00
parent 8f87964750
commit 311a944d3d
11 changed files with 91 additions and 24 deletions

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="save_as_favorites_points">Save as group of favorites</string>
<string name="select_destination_and_intermediate_points">Select waypoints</string> <string name="select_destination_and_intermediate_points">Select waypoints</string>
<string name="layer_amenity_label">Text labels</string> <string name="layer_amenity_label">Text labels</string>
<string name="loading_smth">Loading %1$s &#8230;</string> <string name="loading_smth">Loading %1$s &#8230;</string>

View file

@ -133,7 +133,7 @@ public class TargetPointsHelper {
updateRouteAndReferesh(updateRoute); updateRouteAndReferesh(updateRoute);
} }
private void updateRouteAndReferesh(boolean updateRoute) { public void updateRouteAndReferesh(boolean updateRoute) {
if(updateRoute && ( routingHelper.isRouteBeingCalculated() || routingHelper.isRouteCalculated() || if(updateRoute && ( routingHelper.isRouteBeingCalculated() || routingHelper.isRouteCalculated() ||
routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode())) { routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode())) {
updateRoutingHelper(); updateRoutingHelper();
@ -141,7 +141,7 @@ public class TargetPointsHelper {
updateListeners(); updateListeners();
} }
public void updateRoutingHelper() { private void updateRoutingHelper() {
LatLon start = settings.getPointToStart(); LatLon start = settings.getPointToStart();
Location lastKnownLocation = ctx.getLocationProvider().getLastKnownLocation(); Location lastKnownLocation = ctx.getLocationProvider().getLastKnownLocation();
if((routingHelper.isFollowingMode() && lastKnownLocation != null) || start == null) { if((routingHelper.isFollowingMode() && lastKnownLocation != null) || start == null) {

View file

@ -360,6 +360,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
Builder b = new AlertDialog.Builder(getActivity()); Builder b = new AlertDialog.Builder(getActivity());
if(f.exists()){ if(f.exists()){
final EditText editText = new EditText(getActivity()); final EditText editText = new EditText(getActivity());
editText.setPadding(7, 3, 7, 3);
editText.setText(f.getName()); editText.setText(f.getName());
b.setView(editText); b.setView(editText);
b.setPositiveButton(R.string.default_buttons_save, new DialogInterface.OnClickListener() { b.setPositiveButton(R.string.default_buttons_save, new DialogInterface.OnClickListener() {

View file

@ -61,7 +61,6 @@ import com.actionbarsherlock.view.ActionMode.Callback;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuItem.OnActionExpandListener;
import com.actionbarsherlock.widget.SearchView; import com.actionbarsherlock.widget.SearchView;
import com.actionbarsherlock.widget.SearchView.OnQueryTextListener; import com.actionbarsherlock.widget.SearchView.OnQueryTextListener;
@ -160,6 +159,10 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
// Sort Favs by distance on Search tab, but sort alphabetically here // Sort Favs by distance on Search tab, but sort alphabetically here
favouritesAdapter.sort(favoritesComparator); favouritesAdapter.sort(favoritesComparator);
if(favouritesAdapter.getGroupCount() > 0 &&
"".equals(favouritesAdapter.getGroup(0))) {
getListView().expandGroup(0);
}
} }
@ -397,7 +400,6 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
createMenuItem(menu, SELECT_DESTINATIONS_ACTION_MODE_ID, R.string.select_destination_and_intermediate_points, createMenuItem(menu, SELECT_DESTINATIONS_ACTION_MODE_ID, R.string.select_destination_and_intermediate_points,
R.drawable.ic_action_flage_light, R.drawable.ic_action_flage_dark, R.drawable.ic_action_flage_light, R.drawable.ic_action_flage_dark,
MenuItem.SHOW_AS_ACTION_IF_ROOM); MenuItem.SHOW_AS_ACTION_IF_ROOM);
updateSelectionMode(actionMode);
favoritesSelected.clear(); favoritesSelected.clear();
groupsToDelete.clear(); groupsToDelete.clear();
favouritesAdapter.notifyDataSetInvalidated(); favouritesAdapter.notifyDataSetInvalidated();
@ -419,6 +421,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == SELECT_DESTINATIONS_ACTION_MODE_ID) { if (item.getItemId() == SELECT_DESTINATIONS_ACTION_MODE_ID) {
mode.finish();
selectDestinationImpl(); selectDestinationImpl();
} }
return true; return true;
@ -435,7 +438,9 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
targetPointsHelper.getIntermediatePoints().size() + 1, targetPointsHelper.getIntermediatePoints().size() + 1,
getString(R.string.favorite) + ": " + fp.getName()); getString(R.string.favorite) + ": " + fp.getName());
} }
targetPointsHelper.updateRoutingHelper(); if(getMyApplication().getRoutingHelper().isRouteCalculated()) {
targetPointsHelper.updateRouteAndReferesh(true);
}
IntermediatePointsDialog.openIntermediatePointsDialog(getActivity(), getMyApplication(), false); IntermediatePointsDialog.openIntermediatePointsDialog(getActivity(), getMyApplication(), false);
//MapActivity.launchMapActivityMoveToTop(getActivity()); //MapActivity.launchMapActivityMoveToTop(getActivity());
} }
@ -471,6 +476,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == DELETE_ACTION_ID) { if (item.getItemId() == DELETE_ACTION_ID) {
mode.finish();
deleteFavoritesAction(); deleteFavoritesAction();
} }
return true; return true;
@ -659,6 +665,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
List<String> groups = new ArrayList<String>(); List<String> groups = new ArrayList<String>();
Filter myFilter; Filter myFilter;
public void setFavoriteGroups(Map<String, List<FavouritePoint>> favoriteGroups) { public void setFavoriteGroups(Map<String, List<FavouritePoint>> favoriteGroups) {
this.sourceFavoriteGroups = favoriteGroups; this.sourceFavoriteGroups = favoriteGroups;
synchronizeGroups(); synchronizeGroups();
@ -754,7 +761,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
adjustIndicator(groupPosition, isExpanded, row); adjustIndicator(groupPosition, isExpanded, row);
TextView label = (TextView) row.findViewById(R.id.category_name); TextView label = (TextView) row.findViewById(R.id.category_name);
final String model = getGroup(groupPosition); final String model = getGroup(groupPosition);
label.setText(model); label.setText(model.length() == 0? getString(R.string.favourites_activity) : model);
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item); final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
if (selectionMode) { if (selectionMode) {
@ -774,6 +781,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
} else { } else {
groupsToDelete.remove(model); groupsToDelete.remove(model);
} }
updateSelectionMode(actionMode);
} }
}); });
} else { } else {
@ -822,6 +830,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
favouritesAdapter.notifyDataSetInvalidated(); favouritesAdapter.notifyDataSetInvalidated();
} }
} }
updateSelectionMode(actionMode);
} }
}); });
} else { } else {

View file

@ -289,7 +289,7 @@ public class IntermediatePointsDialog {
app.getTargetPointsHelper().removeWayPoint(cnt == 0, i); app.getTargetPointsHelper().removeWayPoint(cnt == 0, i);
} }
} }
// FIXME // FIXME delete location when point is removed
// if(mapActivity instanceof MapActivity) { // if(mapActivity instanceof MapActivity) {
// ((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, ""); // ((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, "");
// } // }

View file

@ -290,7 +290,7 @@ public class MapActivity extends AccessibleActivity {
!Algorithms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation() )|| !Algorithms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation() )||
!Algorithms.objectEquals(targets.getIntermediatePoints(), routingHelper.getIntermediatePoints()) !Algorithms.objectEquals(targets.getIntermediatePoints(), routingHelper.getIntermediatePoints())
)) { )) {
targets.updateRoutingHelper(); targets.updateRouteAndReferesh(true);
} }
app.getLocationProvider().resumeAllUpdates(); app.getLocationProvider().resumeAllUpdates();

View file

@ -545,7 +545,7 @@ public class MapActivityActions implements DialogProvider {
// then set gpx // then set gpx
setGPXRouteParams(gpxFile); setGPXRouteParams(gpxFile);
// then update start and destination point // then update start and destination point
targets.updateRoutingHelper(); targets.updateRouteAndReferesh(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.getMapView().refreshMap(true); mapActivity.getMapView().refreshMap(true);

View file

@ -2,10 +2,14 @@ package net.osmand.plus.activities;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
import java.io.File;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
@ -14,6 +18,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.AvailableGPXFragment.LoadGpxTask;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import android.app.Activity; import android.app.Activity;
@ -26,11 +31,13 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.EditText;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.Filter; import android.widget.Filter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.SectionIndexer; import android.widget.SectionIndexer;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
@ -86,6 +93,40 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
protected void saveAsFavorites(final GpxDisplayGroup model) {
Builder b = new AlertDialog.Builder(getActivity());
final EditText editText = new EditText(getActivity());
String name = model.getName();
if(name.indexOf('\n') > 0) {
name = name.substring(0, name.indexOf('\n'));
}
editText.setText(name);
editText.setPadding(7, 3, 7, 3);
b.setTitle(R.string.save_as_favorites_points);
b.setView(editText);
b.setPositiveButton(R.string.default_buttons_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
saveFavoritesImpl(model.getModifiableList(), editText.getText().toString());
}
});
b.setNegativeButton(R.string.default_buttons_cancel, null);
b.show();
}
protected void saveFavoritesImpl(List<GpxDisplayItem> modifiableList, String category) {
FavouritesDbHelper fdb = getMyApplication().getFavorites();
for(GpxDisplayItem i : modifiableList) {
if (i.locationStart != null) {
FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.locationStart.name,
category);
fdb.addFavourite(fp);
}
}
}
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.export_fav, R.drawable.ic_action_search_light, // MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.export_fav, R.drawable.ic_action_search_light,
@ -345,9 +386,8 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
final GpxDisplayGroup model = getGroup(groupPosition); final GpxDisplayGroup model = getGroup(groupPosition);
label.setText(model.getGroupName()); label.setText(model.getGroupName());
final ImageView ch = (ImageView) row.findViewById(R.id.check_item); final ImageView ch = (ImageView) row.findViewById(R.id.check_item);
if(model.getType() != GpxDisplayItemType.TRACK_SEGMENT) {
ch.setVisibility(View.INVISIBLE); if(model.getType() == GpxDisplayItemType.TRACK_SEGMENT) {
} else {
ch.setVisibility(View.VISIBLE); ch.setVisibility(View.VISIBLE);
ch.setImageDrawable(getActivity().getResources().getDrawable( ch.setImageDrawable(getActivity().getResources().getDrawable(
app.getSettings().isLightContent() ? R.drawable.ic_action_settings_light app.getSettings().isLightContent() ? R.drawable.ic_action_settings_light
@ -359,11 +399,27 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
} }
}); });
} else if(model.getType() == GpxDisplayItemType.TRACK_POINTS ||
model.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
ch.setVisibility(View.VISIBLE);
ch.setImageDrawable(getActivity().getResources().getDrawable(
app.getSettings().isLightContent() ? R.drawable.ic_action_fav_light
: R.drawable.ic_action_fav_dark));
ch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveAsFavorites(model);
}
});
} else {
ch.setVisibility(View.INVISIBLE);
} }
return row; return row;
} }
@Override @Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
ViewGroup parent) { ViewGroup parent) {

View file

@ -174,7 +174,7 @@ public class FailSafeFuntions {
app.getTargetPointsHelper().setStartPoint(null, false, null); app.getTargetPointsHelper().setStartPoint(null, false, null);
app.getSettings().FOLLOW_THE_ROUTE.set(true); app.getSettings().FOLLOW_THE_ROUTE.set(true);
routingHelper.setFollowingMode(true); routingHelper.setFollowingMode(true);
app.getTargetPointsHelper().updateRoutingHelper(); app.getTargetPointsHelper().updateRouteAndReferesh(true);
app.initVoiceCommandPlayer(ma); app.initVoiceCommandPlayer(ma);
} }

View file

@ -290,7 +290,7 @@ public class RoutingHelper {
recalculateRouteInBackground(false, currentLocation, finalLocation, intermediatePoints, currentGPXRoute, recalculateRouteInBackground(false, currentLocation, finalLocation, intermediatePoints, currentGPXRoute,
previousRoute.isCalculated() ? previousRoute : null); previousRoute.isCalculated() ? previousRoute : null);
} }
double projectDist = mode.hasFastSpeed() ? posTolerance : posTolerance / 2; double projectDist = mode != null && mode.hasFastSpeed() ? posTolerance : posTolerance / 2;
if(returnUpdatedLocation && locationProjection != null && currentLocation.distanceTo(locationProjection) < projectDist) { if(returnUpdatedLocation && locationProjection != null && currentLocation.distanceTo(locationProjection) < projectDist) {
return locationProjection; return locationProjection;
} else { } else {

View file

@ -183,7 +183,7 @@ public class MapRoutePreferencesControl extends MapControls {
update = true; update = true;
} }
if(update) { if(update) {
tg.updateRoutingHelper(); tg.updateRouteAndReferesh(true);
} }
} }
} else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) { } else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
@ -361,7 +361,7 @@ public class MapRoutePreferencesControl extends MapControls {
@Override @Override
public boolean processResult(GPXFile[] result) { public boolean processResult(GPXFile[] result) {
mapActivity.getMapActions().setGPXRouteParams(result[0]); mapActivity.getMapActions().setGPXRouteParams(result[0]);
mapActivity.getMyApplication().getTargetPointsHelper().updateRoutingHelper(); mapActivity.getMyApplication().getTargetPointsHelper().updateRouteAndReferesh(true);
updateSpinnerItems(gpxSpinner); updateSpinnerItems(gpxSpinner);
updateParameters(); updateParameters();
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();