Allow save gpx points as favorites
This commit is contained in:
parent
8f87964750
commit
311a944d3d
11 changed files with 91 additions and 24 deletions
|
@ -9,6 +9,7 @@
|
|||
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
|
||||
-->
|
||||
<string name="save_as_favorites_points">Save as group of favorites</string>
|
||||
<string name="select_destination_and_intermediate_points">Select waypoints</string>
|
||||
<string name="layer_amenity_label">Text labels</string>
|
||||
<string name="loading_smth">Loading %1$s …</string>
|
||||
|
|
|
@ -133,7 +133,7 @@ public class TargetPointsHelper {
|
|||
updateRouteAndReferesh(updateRoute);
|
||||
}
|
||||
|
||||
private void updateRouteAndReferesh(boolean updateRoute) {
|
||||
public void updateRouteAndReferesh(boolean updateRoute) {
|
||||
if(updateRoute && ( routingHelper.isRouteBeingCalculated() || routingHelper.isRouteCalculated() ||
|
||||
routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode())) {
|
||||
updateRoutingHelper();
|
||||
|
@ -141,7 +141,7 @@ public class TargetPointsHelper {
|
|||
updateListeners();
|
||||
}
|
||||
|
||||
public void updateRoutingHelper() {
|
||||
private void updateRoutingHelper() {
|
||||
LatLon start = settings.getPointToStart();
|
||||
Location lastKnownLocation = ctx.getLocationProvider().getLastKnownLocation();
|
||||
if((routingHelper.isFollowingMode() && lastKnownLocation != null) || start == null) {
|
||||
|
|
|
@ -360,6 +360,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
Builder b = new AlertDialog.Builder(getActivity());
|
||||
if(f.exists()){
|
||||
final EditText editText = new EditText(getActivity());
|
||||
editText.setPadding(7, 3, 7, 3);
|
||||
editText.setText(f.getName());
|
||||
b.setView(editText);
|
||||
b.setPositiveButton(R.string.default_buttons_save, new DialogInterface.OnClickListener() {
|
||||
|
|
|
@ -61,7 +61,6 @@ import com.actionbarsherlock.view.ActionMode.Callback;
|
|||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.MenuItem.OnActionExpandListener;
|
||||
import com.actionbarsherlock.widget.SearchView;
|
||||
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
|
||||
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,
|
||||
R.drawable.ic_action_flage_light, R.drawable.ic_action_flage_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
updateSelectionMode(actionMode);
|
||||
favoritesSelected.clear();
|
||||
groupsToDelete.clear();
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
|
@ -419,6 +421,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if (item.getItemId() == SELECT_DESTINATIONS_ACTION_MODE_ID) {
|
||||
mode.finish();
|
||||
selectDestinationImpl();
|
||||
}
|
||||
return true;
|
||||
|
@ -435,7 +438,9 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
targetPointsHelper.getIntermediatePoints().size() + 1,
|
||||
getString(R.string.favorite) + ": " + fp.getName());
|
||||
}
|
||||
targetPointsHelper.updateRoutingHelper();
|
||||
if(getMyApplication().getRoutingHelper().isRouteCalculated()) {
|
||||
targetPointsHelper.updateRouteAndReferesh(true);
|
||||
}
|
||||
IntermediatePointsDialog.openIntermediatePointsDialog(getActivity(), getMyApplication(), false);
|
||||
//MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
|
@ -471,6 +476,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if (item.getItemId() == DELETE_ACTION_ID) {
|
||||
mode.finish();
|
||||
deleteFavoritesAction();
|
||||
}
|
||||
return true;
|
||||
|
@ -658,6 +664,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
Map<String, List<FavouritePoint>> favoriteGroups = new LinkedHashMap<String, List<FavouritePoint>>();
|
||||
List<String> groups = new ArrayList<String>();
|
||||
Filter myFilter;
|
||||
|
||||
|
||||
public void setFavoriteGroups(Map<String, List<FavouritePoint>> favoriteGroups) {
|
||||
this.sourceFavoriteGroups = favoriteGroups;
|
||||
|
@ -754,7 +761,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
adjustIndicator(groupPosition, isExpanded, row);
|
||||
TextView label = (TextView) row.findViewById(R.id.category_name);
|
||||
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);
|
||||
|
||||
if (selectionMode) {
|
||||
|
@ -774,6 +781,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
} else {
|
||||
groupsToDelete.remove(model);
|
||||
}
|
||||
updateSelectionMode(actionMode);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -822,6 +830,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
updateSelectionMode(actionMode);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -105,20 +105,20 @@ public class IntermediatePointsDialog {
|
|||
|
||||
}
|
||||
});
|
||||
if (!changeOrder && intermediates.size()>1) {
|
||||
if (!changeOrder && intermediates.size() > 1) {
|
||||
builder.setNeutralButton(R.string.intermediate_points_change_order, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
openIntermediatePointsDialog(activity, app, true);
|
||||
}
|
||||
});
|
||||
} else if(intermediates.size()>1) {
|
||||
builder.setNeutralButton(R.string.intermediate_items_sort_by_distance, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface d, int which) {
|
||||
//Do nothing here. We override the onclick
|
||||
}
|
||||
});
|
||||
} else if (intermediates.size() > 1) {
|
||||
builder.setNeutralButton(R.string.intermediate_items_sort_by_distance, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface d, int which) {
|
||||
// Do nothing here. We override the onclick
|
||||
}
|
||||
});
|
||||
}
|
||||
AlertDialog dlg = builder.create();
|
||||
if (changeOrder) {
|
||||
|
@ -289,7 +289,7 @@ public class IntermediatePointsDialog {
|
|||
app.getTargetPointsHelper().removeWayPoint(cnt == 0, i);
|
||||
}
|
||||
}
|
||||
// FIXME
|
||||
// FIXME delete location when point is removed
|
||||
// if(mapActivity instanceof MapActivity) {
|
||||
// ((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, "");
|
||||
// }
|
||||
|
|
|
@ -290,7 +290,7 @@ public class MapActivity extends AccessibleActivity {
|
|||
!Algorithms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation() )||
|
||||
!Algorithms.objectEquals(targets.getIntermediatePoints(), routingHelper.getIntermediatePoints())
|
||||
)) {
|
||||
targets.updateRoutingHelper();
|
||||
targets.updateRouteAndReferesh(true);
|
||||
}
|
||||
app.getLocationProvider().resumeAllUpdates();
|
||||
|
||||
|
|
|
@ -545,7 +545,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
// then set gpx
|
||||
setGPXRouteParams(gpxFile);
|
||||
// then update start and destination point
|
||||
targets.updateRoutingHelper();
|
||||
targets.updateRouteAndReferesh(true);
|
||||
|
||||
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
|
||||
mapActivity.getMapView().refreshMap(true);
|
||||
|
|
|
@ -2,10 +2,14 @@ package net.osmand.plus.activities;
|
|||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
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.GpxDisplayGroup;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
|
@ -14,6 +18,7 @@ import net.osmand.plus.OsmAndFormatter;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.AvailableGPXFragment.LoadGpxTask;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.Activity;
|
||||
|
@ -26,11 +31,13 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.Filter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SectionIndexer;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
|
@ -85,6 +92,40 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
|
|||
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem 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
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
|
@ -345,9 +386,8 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
|
|||
final GpxDisplayGroup model = getGroup(groupPosition);
|
||||
label.setText(model.getGroupName());
|
||||
final ImageView ch = (ImageView) row.findViewById(R.id.check_item);
|
||||
if(model.getType() != GpxDisplayItemType.TRACK_SEGMENT) {
|
||||
ch.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
|
||||
if(model.getType() == GpxDisplayItemType.TRACK_SEGMENT) {
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setImageDrawable(getActivity().getResources().getDrawable(
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
|
||||
ViewGroup parent) {
|
||||
|
|
|
@ -174,7 +174,7 @@ public class FailSafeFuntions {
|
|||
app.getTargetPointsHelper().setStartPoint(null, false, null);
|
||||
app.getSettings().FOLLOW_THE_ROUTE.set(true);
|
||||
routingHelper.setFollowingMode(true);
|
||||
app.getTargetPointsHelper().updateRoutingHelper();
|
||||
app.getTargetPointsHelper().updateRouteAndReferesh(true);
|
||||
app.initVoiceCommandPlayer(ma);
|
||||
}
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ public class RoutingHelper {
|
|||
recalculateRouteInBackground(false, currentLocation, finalLocation, intermediatePoints, currentGPXRoute,
|
||||
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) {
|
||||
return locationProjection;
|
||||
} else {
|
||||
|
|
|
@ -183,7 +183,7 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
update = true;
|
||||
}
|
||||
if(update) {
|
||||
tg.updateRoutingHelper();
|
||||
tg.updateRouteAndReferesh(true);
|
||||
}
|
||||
}
|
||||
} else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
|
||||
|
@ -361,7 +361,7 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
@Override
|
||||
public boolean processResult(GPXFile[] result) {
|
||||
mapActivity.getMapActions().setGPXRouteParams(result[0]);
|
||||
mapActivity.getMyApplication().getTargetPointsHelper().updateRoutingHelper();
|
||||
mapActivity.getMyApplication().getTargetPointsHelper().updateRouteAndReferesh(true);
|
||||
updateSpinnerItems(gpxSpinner);
|
||||
updateParameters();
|
||||
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||
|
|
Loading…
Reference in a new issue