Initial refactoring

This commit is contained in:
Victor Shcherb 2014-06-08 10:50:40 +02:00
parent a00a477415
commit d4fe3288d2
24 changed files with 401 additions and 348 deletions

View file

@ -8,7 +8,6 @@ public class FavouritePoint implements Serializable {
private String category = "";
private double latitude;
private double longitude;
private boolean stored = false;
public FavouritePoint(){
@ -25,13 +24,6 @@ public class FavouritePoint implements Serializable {
return latitude;
}
public boolean isStored() {
return stored;
}
public void setStored(boolean stored) {
this.stored = stored;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}

View file

@ -124,7 +124,7 @@
<activity android:name="net.osmand.plus.activities.DownloadIndexActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/local_index_download"></activity>
<activity android:name="net.osmand.plus.activities.ShowRouteInfoActivity" android:label="@string/show_route"></activity>
<activity android:name="net.osmand.plus.activities.FavouritesListActivity" android:label="@string/favourites_list_activity"></activity>
<activity android:name="net.osmand.plus.activities.FavouritesActivity"></activity>
<activity android:name="net.osmand.plus.activities.FavouritesActivity" android:windowSoftInputMode="adjustPan"></activity>
<activity android:name="net.osmand.plus.activities.PluginsActivity"></activity>
<activity android:name="net.osmand.plus.activities.ContributionVersionActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/contribution_activity"></activity>

View file

@ -30,9 +30,6 @@ public class FavouritesDbHelper {
public static final String FILE_TO_SAVE = "favourites.gpx"; //$NON-NLS-1$
public static final String FILE_TO_BACKUP = "favourites_bak.gpx"; //$NON-NLS-1$
// externalize ?
private static final String GPX_GROUP = "Gpx";
private List<FavouritePoint> favoritePointsFromGPXFile = null;
private List<FavouritePoint> cachedFavoritePoints = new ArrayList<FavouritePoint>();
@ -96,15 +93,13 @@ public class FavouritesDbHelper {
public GPXFile asGpxFile() {
GPXFile gpx = new GPXFile();
for (FavouritePoint p : getFavouritePoints()) {
if (p.isStored()) {
WptPt pt = new WptPt();
pt.lat = p.getLatitude();
pt.lon = p.getLongitude();
pt.name = p.getName();
if (p.getCategory().length() > 0)
pt.category = p.getCategory();
gpx.points.add(pt);
}
WptPt pt = new WptPt();
pt.lat = p.getLatitude();
pt.lon = p.getLongitude();
pt.name = p.getName();
if (p.getCategory().length() > 0)
pt.category = p.getCategory();
gpx.points.add(pt);
}
return gpx;
}
@ -120,30 +115,7 @@ public class FavouritesDbHelper {
return favoritePointsFromGPXFile;
}
public void setFavoritePointsFromGPXFile(List<FavouritePoint> favoritePointsFromGPXFile) {
this.favoritePointsFromGPXFile = favoritePointsFromGPXFile;
if(favoritePointsFromGPXFile == null){
favoriteGroups.remove(GPX_GROUP);
} else {
checkFavoritePoints();
for(FavouritePoint t : favoritePointsFromGPXFile){
t.setCategory(GPX_GROUP);
t.setStored(false);
}
favoriteGroups.put(GPX_GROUP, favoritePointsFromGPXFile);
}
recalculateCachedFavPoints();
}
public void addFavoritePointToGPXFile(FavouritePoint fp) {
fp.setCategory(GPX_GROUP);
fp.setStored(false);
if (!favoriteGroups.containsKey(GPX_GROUP)) {
favoriteGroups.put(GPX_GROUP, new ArrayList<FavouritePoint>());
}
favoriteGroups.get(GPX_GROUP).add(fp);
recalculateCachedFavPoints();
}
public List<FavouritePoint> getFavouritePoints() {
checkFavoritePoints();
@ -227,7 +199,6 @@ public class FavouritesDbHelper {
if (fp != null) {
favoriteGroups.get(p.getCategory()).remove(fp);
cachedFavoritePoints.remove(fp);
fp.setStored(false);
}
backupSilently();
} finally{
@ -269,7 +240,6 @@ public class FavouritesDbHelper {
favoriteGroups.get(p.getCategory()).add(p);
cachedFavoritePoints.add(p);
}
p.setStored(true);
backupSilently();
} finally {
db.close();
@ -314,7 +284,6 @@ public class FavouritesDbHelper {
FavouritePoint p = new FavouritePoint();
p.setName(name);
p.setCategory(cat);
p.setStored(true);
p.setLatitude(query.getDouble(2));
p.setLongitude(query.getDouble(3));
favoriteGroups.get(cat).add(p);

View file

@ -350,8 +350,6 @@ public class GPXUtilities {
public String path = "";
public boolean showCurrentTrack;
public List<List<WptPt>> processedPointsToDisplay = new ArrayList<List<WptPt>>();
public boolean isCloudmadeRouteFile() {
return "cloudmade".equalsIgnoreCase(author);
}
@ -469,7 +467,7 @@ public class GPXUtilities {
return false;
}
public void proccessPoints() {
public List<List<WptPt>> proccessPoints() {
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();
boolean created = false;
for (Track t : tracks) {
@ -485,7 +483,7 @@ public class GPXUtilities {
tpoints.add(r.points);
}
}
processedPointsToDisplay = tpoints;
return tpoints;
}
public WptPt findPointToShow() {

View file

@ -0,0 +1,207 @@
package net.osmand.plus;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import android.content.Context;
import android.graphics.Bitmap;
public class GpxSelectionHelper {
private OsmandApplication app;
// save into settings
// public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
// new BooleanPreference("show_current_gpx_track", false).makeGlobal().cache();
private List<SelectedGpxFile> selectedGPXFiles = new java.util.concurrent.CopyOnWriteArrayList<SelectedGpxFile>();
public GpxSelectionHelper(OsmandApplication osmandApplication) {
this.app = osmandApplication;
}
public void clearAllGpxFileToShow() {
selectedGPXFiles.clear();
}
public boolean isShowingCurrentTrack() {
return getCurrentTrack() != null;
}
public boolean isShowingAnyGpxFiles() {
return !selectedGPXFiles.isEmpty();
}
public SelectedGpxFile getCurrentTrack() {
for(SelectedGpxFile s : selectedGPXFiles) {
if(s.isShowCurrentTrack()) {
return s;
}
}
return null;
}
public List<SelectedGpxFile> getSelectedGPXFiles() {
return selectedGPXFiles;
}
public void setToDisplayCurrentGpxFile(boolean show) {
if(show != isShowingCurrentTrack()) {
if(show) {
TODO_LOAD_CURRENT_BUFFER ;
SelectedGpxFile sg = new SelectedGpxFile();
sg.setGpxFile(new GPXFile());
sg.setShowCurrentTrack(true);
selectedGPXFiles.add(sg);
} else {
Iterator<SelectedGpxFile> it = selectedGPXFiles.iterator();
while(it.hasNext()) {
if(it.next().isShowCurrentTrack()) {
it.remove();
break;
}
}
}
}
TODO_SAVE_IN_SETTINGS;
}
public List<GpxDisplayGroup> getDisplayGroups() {
TODO;
}
public SelectedGpxFile getSelectedFileByPath(String path) {
for(SelectedGpxFile s : selectedGPXFiles) {
if(s.getGpxFile().path.equals(path)) {
return s;
}
}
return null;
}
public SelectedGpxFile setGpxFileToDisplay(GPXFile... gpx) {
// special case for gpx current route
SelectedGpxFile sf = getSelectedFileByPath(gpx.path);
boolean displayed = sf != null;
if(displayed != show) {
if(show) {
sf = new SelectedGpxFile();
sf.setGpxFile(gpx);
selectedGPXFiles.add(sf);
} else {
selectedGPXFiles.remove(sf);
}
}
return sf;
}
public SelectedGpxFile setGpxFileToDisplay(String path, boolean show) {
SelectedGpxFile sf = getSelectedFileByPath(path);
boolean displayed = sf != null;
if(displayed != show) {
if(show) {
TODO_ASYNC;
GPXFile r = GPXUtilities.loadGPXFile(app, new File(path));
sf = new SelectedGpxFile();
sf.setGpxFile(r);
selectedGPXFiles.add(sf);
} else {
selectedGPXFiles.remove(sf);
}
}
return sf;
}
public static class SelectedGpxFile {
private boolean showCurrentTrack;
private GPXFile gpxFile;
private int color;
private List<List<WptPt>> processedPointsToDisplay = new ArrayList<List<WptPt>>();
public void setGpxFile(GPXFile gpxFile) {
this.gpxFile = gpxFile;
this.processedPointsToDisplay = gpxFile.proccessPoints();
}
public List<List<WptPt>> getPointsToDisplay() {
return processedPointsToDisplay;
}
public List<List<WptPt>> getModifiablePointsToDisplay() {
return processedPointsToDisplay;
}
public GPXFile getGpxFile() {
return gpxFile;
}
public boolean isShowCurrentTrack() {
return showCurrentTrack;
}
public void setShowCurrentTrack(boolean showCurrentTrack) {
this.showCurrentTrack = showCurrentTrack;
}
public int getColor() {
return color;
}
}
public enum GpxDisplayItemType {
TRACK_SEGMENT,
TRACK_POINTS,
TRACK_ROUTE_POINTS
}
public static class GpxDisplayGroup {
private GpxDisplayItemType type = GpxDisplayItemType.TRACK_SEGMENT;
private List<GpxDisplayItem> list = new ArrayList<GpxDisplayItem>();
public GpxDisplayGroup cloneInstance() {
GpxDisplayGroup group = new GpxDisplayGroup();
group.type = type;
group.list = new ArrayList<GpxSelectionHelper.GpxDisplayItem>(list);
return group;
}
public List<GpxDisplayItem> getModifiableList() {
return list;
}
public GpxDisplayItemType getType() {
return type;
}
public void setType(GpxDisplayItemType type) {
this.type = type;
}
public String getGroupName(Context ctx) {
return TODO;
}
}
public static class GpxDisplayItem {
private boolean filter;
private String description;
private Bitmap image;
private String url;
public boolean isFilter() {
return filter;
}
public void setFilter(boolean filter) {
this.filter = filter;
}
}
}

View file

@ -82,10 +82,10 @@ public class OsmAndLocationSimulation {
boolean gpxNavigation = radioGPX.isChecked();
if (gpxNavigation) {
GpxUiHelper.selectGPXFile(ma, false, false,
new CallbackWithObject<GPXUtilities.GPXFile>() {
new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXUtilities.GPXFile result) {
GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result, app.getSettings());
public boolean processResult(GPXUtilities.GPXFile[] result) {
GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result[0], app.getSettings());
if(ch.isChecked()){
builder.setAnnounceWaypoints(true);
}

View file

@ -17,9 +17,6 @@ import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.activities.DayNightHelper;
import net.osmand.plus.activities.SavingTrackHelper;
@ -63,8 +60,8 @@ import android.util.TypedValue;
import android.view.accessibility.AccessibilityManager;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import btools.routingapp.BRouterServiceConnection;
@ -99,7 +96,7 @@ public class OsmandApplication extends Application {
// start variables
private ProgressImplementation startDialog;
private Handler uiHandler;
private GPXFile gpxFileToDisplay;
private GpxSelectionHelper selectedGpxHelper;
private SavingTrackHelper savingTrackHelper;
private LiveMonitoringHelper liveMonitoringHelper;
private TargetPointsHelper targetPointsHelper;
@ -150,6 +147,7 @@ public class OsmandApplication extends Application {
locationProvider = new OsmAndLocationProvider(this);
savingTrackHelper = new SavingTrackHelper(this);
liveMonitoringHelper = new LiveMonitoringHelper(this);
selectedGpxHelper = new GpxSelectionHelper(this);
uiHandler = new Handler();
rendererRegistry = new RendererRegistry();
targetPointsHelper = new TargetPointsHelper(this);
@ -229,30 +227,9 @@ public class OsmandApplication extends Application {
return poiFilters;
}
public void setGpxFileToDisplay(GPXFile gpxFileToDisplay, boolean showCurrentGpxFile) {
this.gpxFileToDisplay = gpxFileToDisplay;
osmandSettings.SHOW_CURRENT_GPX_TRACK.set(showCurrentGpxFile);
if (gpxFileToDisplay == null) {
getFavorites().setFavoritePointsFromGPXFile(null);
} else {
List<FavouritePoint> pts = new ArrayList<FavouritePoint>();
for (WptPt p : gpxFileToDisplay.points) {
FavouritePoint pt = new FavouritePoint();
pt.setLatitude(p.lat);
pt.setLongitude(p.lon);
if (p.name == null) {
p.name = "";
}
pt.setName(p.name);
pts.add(pt);
}
gpxFileToDisplay.proccessPoints();
getFavorites().setFavoritePointsFromGPXFile(pts);
}
}
public GPXFile getGpxFileToDisplay() {
return gpxFileToDisplay;
public GpxSelectionHelper getSelectedGpxHelper() {
return selectedGpxHelper;
}
public FavouritesDbHelper getFavorites() {

View file

@ -1650,8 +1650,6 @@ public class OsmandSettings {
public final OsmandPreference<Integer> SERVICE_OFF_INTERVAL = new IntPreference("service_off_interval",
5 * 60 * 1000).makeGlobal();
public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
new BooleanPreference("show_current_gpx_track", false).makeGlobal().cache();
public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal();

View file

@ -423,7 +423,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (loc != null) {
settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
e = false;
getMyApplication().setGpxFileToDisplay(info.gpx, false);
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(info.gpx);
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}

View file

@ -175,11 +175,7 @@ public class FavouritesListFragment extends SherlockListFragment implements Sear
TextView label = (TextView) row.findViewById(R.id.favourite_label);
ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon);
final FavouritePoint model = getItem(position);
if (model.isStored()) {
icon.setImageResource(R.drawable.list_favorite);
} else {
icon.setImageResource(R.drawable.opened_poi);
}
icon.setImageResource(R.drawable.list_favorite);
String distance = "";
if (location != null) {
int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(), location.getLatitude(), location

View file

@ -183,31 +183,29 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
};
MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(),
getActivity(), true, onshow, false);
if (point.isStored()) {
ActionItem edit = new ActionItem();
edit.setIcon(getResources().getDrawable(R.drawable.ic_action_edit_light));
edit.setTitle(getString(R.string.favourites_context_menu_edit));
edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
editPoint(point);
qa.dismiss();
}
});
qa.addActionItem(edit);
ActionItem edit = new ActionItem();
edit.setIcon(getResources().getDrawable(R.drawable.ic_action_edit_light));
edit.setTitle(getString(R.string.favourites_context_menu_edit));
edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
editPoint(point);
qa.dismiss();
}
});
qa.addActionItem(edit);
ActionItem delete = new ActionItem();
delete.setTitle(getString(R.string.favourites_context_menu_delete));
delete.setIcon(getResources().getDrawable(R.drawable.ic_action_delete_light));
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
deletePoint(point);
qa.dismiss();
}
});
qa.addActionItem(delete);
}
ActionItem delete = new ActionItem();
delete.setTitle(getString(R.string.favourites_context_menu_delete));
delete.setIcon(getResources().getDrawable(R.drawable.ic_action_delete_light));
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
deletePoint(point);
qa.dismiss();
}
});
qa.addActionItem(delete);
qa.show();
}
@ -698,11 +696,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon);
final FavouritePoint model = (FavouritePoint) getChild(groupPosition, childPosition);
row.setTag(model);
if (model.isStored()) {
icon.setImageResource(R.drawable.list_favorite);
} else {
icon.setImageResource(R.drawable.opened_poi);
}
icon.setImageResource(R.drawable.list_favorite);
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
@ -712,7 +706,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
new ForegroundColorSpan(getResources().getColor(R.color.color_distance)), 0, distance.length() - 1,
0);
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
if (selectionMode && model.isStored()) {
if (selectionMode) {
ch.setVisibility(View.VISIBLE);
ch.setChecked(favoritesToDelete.contains(model));
row.findViewById(R.id.favourite_icon).setVisibility(View.GONE);

View file

@ -29,6 +29,7 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -200,11 +201,9 @@ public class MapActivityActions implements DialogProvider {
while (it.hasNext()) {
FavouritePoint fp = it.next();
// filter gpx points
if (fp.isStored()) {
favs[i] = fp;
names[i] = fp.getName();
i++;
}
favs[i] = fp;
names[i] = fp.getName();
i++;
}
b.setItems(names, new DialogInterface.OnClickListener(){
@Override
@ -247,9 +246,6 @@ public class MapActivityActions implements DialogProvider {
String name = editText.getText().toString();
SavingTrackHelper savingTrackHelper = mapActivity.getMyApplication().getSavingTrackHelper();
savingTrackHelper.insertPointData(latitude, longitude, System.currentTimeMillis(), name);
if(settings.SHOW_CURRENT_GPX_TRACK.get()) {
getMyApplication().getFavorites().addFavoritePointToGPXFile(new FavouritePoint(latitude, longitude, name, ""));
}
AccessibleToast.makeText(mapActivity, MessageFormat.format(getString(R.string.add_waypoint_dialog_added), name), Toast.LENGTH_SHORT)
.show();
dialog.dismiss();
@ -500,14 +496,22 @@ public class MapActivityActions implements DialogProvider {
}
public void enterRoutePlanningMode(final LatLon from, final String fromName) {
final GPXFile gpxFile = mapActivity.getMyApplication().getGpxFileToDisplay();
List<SelectedGpxFile> selectedGPXFiles = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
GPXFile gpxFile = null;
for (SelectedGpxFile gs : selectedGPXFiles) {
if (!gs.isShowCurrentTrack()) {
gpxFile = gs.getGpxFile();
break;
}
}
if(gpxFile != null) {
final GPXFile f = gpxFile;
Builder bld = new AlertDialog.Builder(mapActivity);
bld.setMessage(R.string.use_displayed_track_for_navigation);
bld.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
enterRoutePlanningModeImpl(gpxFile, from, fromName);
enterRoutePlanningModeImpl(f, from, fromName);
}
});
bld.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {

View file

@ -254,8 +254,8 @@ public class MapActivityLayers {
} else if(itemId == R.string.layer_favorites){
settings.SHOW_FAVORITES.set(isChecked);
} else if(itemId == R.string.layer_gpx_layer){
if(getApplication().getGpxFileToDisplay() != null){
getApplication().setGpxFileToDisplay(null, false);
if(getApplication().getSelectedGpxHelper().isShowingAnyGpxFiles()){
getApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
} else {
dialog.dismiss();
showGPXFileLayer(mapView);
@ -281,7 +281,7 @@ public class MapActivityLayers {
adapter.item(R.string.layer_favorites).selected(settings.SHOW_FAVORITES.get() ? 1 : 0)
.icons(R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_light).reg();
adapter.item(R.string.layer_gpx_layer).selected(
getApplication().getGpxFileToDisplay() != null ? 1 : 0)
getApplication().getSelectedGpxHelper() != null ? 1 : 0)
// .icons(R.drawable.ic_action_foot_dark, R.drawable.ic_action_foot_light)
.icons(R.drawable.ic_action_polygom_dark, R.drawable.ic_action_polygom_light)
.reg();
@ -372,30 +372,24 @@ public class MapActivityLayers {
public void showGPXFileLayer(final OsmandMapTileView mapView){
final OsmandSettings settings = getApplication().getSettings();
GpxUiHelper.selectGPXFile(activity, true, true, new CallbackWithObject<GPXFile>() {
GpxUiHelper.selectGPXFile(activity, true, true, new CallbackWithObject<GPXFile[]>() {
@Override
public boolean processResult(GPXFile result) {
GPXFile toShow = result;
if (toShow == null || toShow.showCurrentTrack) {
if(!settings.SAVE_TRACK_TO_GPX.get()){
AccessibleToast.makeText(activity, R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_SHORT).show();
}
Map<String, GPXFile> data = getApplication().getSavingTrackHelper().collectRecordedData();
if(toShow == null) {
toShow = new GPXFile();
toShow.showCurrentTrack = true;
}
if(!data.isEmpty()) {
GPXFile last = data.values().iterator().next();
GPXUtilities.mergeGPXFileInto(toShow, last);
public boolean processResult(GPXFile[] result) {
WptPt locToShow = null;
for(GPXFile g : result) {
if(g.showCurrentTrack) {
if(!settings.SAVE_TRACK_TO_GPX.get()){
AccessibleToast.makeText(activity, R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_SHORT).show();
}
break;
}
if(!g.showCurrentTrack || locToShow == null) {
locToShow = g.findPointToShow();
}
}
settings.SHOW_FAVORITES.set(true);
getApplication().setGpxFileToDisplay(toShow, toShow.showCurrentTrack);
WptPt loc = toShow.findPointToShow();
if(loc != null){
mapView.getAnimatedDraggingThread().startMoving(loc.lat, loc.lon,
getApplication().getSelectedGpxHelper().setGpxFileToDisplay(result);
if(locToShow != null){
mapView.getAnimatedDraggingThread().startMoving(locToShow.lat, locToShow.lon,
mapView.getZoom(), true);
}
mapView.refreshMap();

View file

@ -16,6 +16,7 @@ import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -58,10 +59,15 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private LatLon lastPoint;
private float distance = 0;
private SelectedGpxFile currentTrack;
public SavingTrackHelper(OsmandApplication ctx){
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
this.ctx = ctx;
this.currentTrack = new SelectedGpxFile();
this.currentTrack.setShowCurrentTrack(true);
this.currentTrack.getGpxFile().showCurrentTrack = true;
this.currentTrack.getGpxFile().tracks.add(new Track());
updateScript = "INSERT INTO " + TRACK_NAME +
" (" +TRACK_COL_LAT +", " +TRACK_COL_LON+", " +TRACK_COL_ALTITUDE+", " +TRACK_COL_SPEED
+", " +TRACK_COL_HDOP+", " +TRACK_COL_DATE+ ")" +
@ -281,7 +287,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
lastTimeUpdated = 0;
lastPoint = null;
execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis()});
addTrackPoint(null, true);
addTrackPoint( null, true);
}
public void updateLocation(net.osmand.Location location) {
@ -306,34 +312,37 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
newSegment = true;
} else {
float[] lastInterval = new float[1];
net.osmand.Location.distanceBetween(lat, lon, lastPoint.getLatitude(), lastPoint.getLongitude(), lastInterval);
net.osmand.Location.distanceBetween(lat, lon, lastPoint.getLatitude(), lastPoint.getLongitude(),
lastInterval);
distance += lastInterval[0];
lastPoint = new LatLon(lat, lon);
}
lastTimeUpdated = time;
if (settings.SHOW_CURRENT_GPX_TRACK.get()) {
WptPt pt = new GPXUtilities.WptPt(lat, lon, time,
alt, speed, hdop);
addTrackPoint(pt, newSegment);
}
WptPt pt = new GPXUtilities.WptPt(lat, lon, time, alt, speed, hdop);
addTrackPoint(pt, newSegment);
}
}
private void addTrackPoint(WptPt pt, boolean newSegment) {
GPXFile file = ctx.getGpxFileToDisplay();
if (file != null && ctx.getSettings().SHOW_CURRENT_GPX_TRACK.get()) {
List<List<WptPt>> points = file.processedPointsToDisplay;
if (points.size() == 0 || newSegment) {
points.add(new ArrayList<WptPt>());
}
if (pt != null) {
List<WptPt> last = points.get(points.size() - 1);
last.add(pt);
}
List<List<WptPt>> points = currentTrack.getModifiablePointsToDisplay();
Track track = currentTrack.getGpxFile().tracks.get(0);
assert track.segments.size() == points.size();
if (points.size() == 0 || newSegment) {
points.add(new ArrayList<WptPt>());
track.segments.add(new TrkSegment());
}
if (pt != null) {
int ind = points.size() - 1;
List<WptPt> last = points.get(ind);
last.add(pt);
track.segments.get(ind).points.add(pt);
}
}
public void insertPointData(double lat, double lon, long time, String description) {
final WptPt pt = new WptPt(lat, lon, time, Double.NaN, 0, Double.NaN);
pt.name = description;
currentTrack.getGpxFile().points.add(pt);
execWithClose(updatePointsScript, new Object[] { lat, lon, time, description });
}
@ -358,4 +367,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
return lastTimeUpdated;
}
public GPXFile getCurrentGpx() {
return currentTrack.getGpxFile();
}
}

View file

@ -1,7 +1,13 @@
package net.osmand.plus.activities;
import java.text.Collator;
import java.util.ArrayList;
import java.util.List;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.app.Activity;
import android.view.LayoutInflater;
@ -10,11 +16,9 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.ActionMode.Callback;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
@ -26,22 +30,30 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
public static final int SEARCH_ID = -1;
public static final int ACTION_ID = 0;
protected static final int DELETE_ACTION_ID = 1;
private boolean selectionMode = false;
private ActionMode actionMode;
private SearchView searchView;
private OsmandApplication app;
private GpxSelectionHelper selectedGpxHelper;
private SelectedGPXAdapter adapter;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
final Collator collator = Collator.getInstance();
collator.setStrength(Collator.SECONDARY);
app = (OsmandApplication) activity.getApplication();
selectedGpxHelper = app.getSelectedGpxHelper();
adapter = new SelectedGPXAdapter();
setAdapter(adapter);
}
@Override
public void onResume() {
super.onResume();
adapter.setDisplayGroups(selectedGpxHelper.getDisplayGroups());
}
@ -85,56 +97,21 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
}
private void enterDeleteMode() {
actionMode = getSherlockActivity().startActionMode(new Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
selectionMode = true;
createMenuItem(menu, DELETE_ACTION_ID, R.string.default_buttons_delete,
R.drawable.ic_action_delete_light, R.drawable.ic_action_delete_dark,
MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
selectionMode = false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == DELETE_ACTION_ID) {
// TODO delete
}
return true;
}
});
}
class SelectedGPXAdapter extends OsmandBaseExpandableListAdapter implements Filterable {
class SelectedGPXAdapter extends OsmandBaseExpandableListAdapter {
Filter myFilter;
private List<GpxDisplayGroup> displayGroups = new ArrayList<GpxDisplayGroup>();
public void setDisplayGroups(List<GpxDisplayGroup> displayGroups) {
this.displayGroups = displayGroups;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
public GpxDisplayItem getChild(int groupPosition, int childPosition) {
GpxDisplayGroup group = getGroup(groupPosition);
return group.getModifiableList().get(childPosition);
}
@Override
@ -144,17 +121,17 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
@Override
public int getChildrenCount(int groupPosition) {
return 0;
return getGroup(groupPosition).getModifiableList().size();
}
@Override
public String getGroup(int groupPosition) {
return "";
public GpxDisplayGroup getGroup(int groupPosition) {
return displayGroups.get(groupPosition);
}
@Override
public int getGroupCount() {
return 0;
return displayGroups.size();
}
@Override
@ -182,10 +159,9 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
}
adjustIndicator(groupPosition, isExpanded, row);
TextView label = (TextView) row.findViewById(R.id.category_name);
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
// final String model = getGroup(groupPosition);
// label.setText(model);
//
final GpxDisplayGroup model = getGroup(groupPosition);
label.setText(model.getGroupName(app));
// final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
// if (selectionMode) {
// ch.setVisibility(View.VISIBLE);
// ch.setChecked(groupsToDelete.contains(model));
@ -264,77 +240,13 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
return row;
}
@Override
public Filter getFilter() {
if (myFilter == null) {
myFilter = new SearchFilter();
}
return myFilter;
}
}
private class SearchFilter extends Filter {
public SearchFilter() {
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
// if (constraint == null || constraint.length() == 0) {
// results.values = helper.getFavoriteGroups();
// results.count = 1;
// } else {
// TreeMap<String, List<FavouritePoint>> filter = new TreeMap<String, List<FavouritePoint>>(helper.getFavoriteGroups());
// TreeMap<String, List<FavouritePoint>> filterLists = new TreeMap<String, List<FavouritePoint>>();
// String cs = constraint.toString().toLowerCase();
// Iterator<Entry<String, List<FavouritePoint>>> ti = filter.entrySet().iterator();
// while(ti.hasNext()) {
// Entry<String, List<FavouritePoint>> next = ti.next();
// if(next.getKey().toLowerCase().indexOf(cs) == -1) {
// ti.remove();
// filterLists.put(next.getKey(), next.getValue());
// }
// }
// ti = filterLists.entrySet().iterator();
// while(ti.hasNext()) {
// Entry<String, List<FavouritePoint>> next = ti.next();
// final List<FavouritePoint> list = next.getValue();
// LinkedList<FavouritePoint> ll = new LinkedList<FavouritePoint>();
// for(FavouritePoint l : list) {
// if(l.getName().toLowerCase().indexOf(cs) != -1) {
// ll.add(l);
// }
//
// }
// if(ll.size() > 0) {
// filter.put(next.getKey(), ll);
// }
// }
// results.values = filter;
// results.count = filter.size();
// }
return results;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
// synchronized (adapter) {
// favouritesAdapter.setFavoriteGroups((Map<String, List<FavouritePoint>>) results.values);
// }
// favouritesAdapter.notifyDataSetChanged();
// if(constraint != null && constraint.length() > 1) {
// collapseTrees();
// }
}
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
return false;
}
}

View file

@ -22,7 +22,6 @@ import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.data.DataTileManager;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
@ -967,11 +966,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
&& OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
String name = f.getName();
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
savingTrackHelper.insertPointData(rec.lat, rec.lon, System.currentTimeMillis(), name);
if (app.getSettings().SHOW_CURRENT_GPX_TRACK.get()) {
app.getFavorites().addFavoritePointToGPXFile(new FavouritePoint(rec.lat, rec.lon, name, ""));
}
}
}

View file

@ -188,12 +188,13 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
protected void loadGpx(final MapActivity activity) {
GpxUiHelper.selectGPXFile(activity, false, false, new CallbackWithObject<GPXUtilities.GPXFile>() {
GpxUiHelper.selectGPXFile(activity, false, false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXFile result) {
public boolean processResult(GPXFile[] res) {
measurementPoints.clear();
if (result != null) {
if (res.length > 0 && res[0] != null) {
GPXFile result = res[0];
originalGPX = result;
for (Track t : result.tracks) {
for (TrkSegment s : t.segments) {

View file

@ -282,7 +282,7 @@ public class GpxImportHelper {
}
private void showGpxOnMap(final GPXUtilities.GPXFile result) {
application.setGpxFileToDisplay(result, true);
application.getSelectedGpxHelper().setGpxFileToDisplay(result);
final GPXUtilities.WptPt moveTo = result.findPointToShow();
if (moveTo != null) {
mapView.getAnimatedDraggingThread().startMoving(moveTo.lat, moveTo.lon, mapView.getZoom(), true);

View file

@ -85,7 +85,7 @@ public class GpxUiHelper {
}
public static void selectGPXFile(final Activity activity,
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile> callbackWithObject) {
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
final List<String> list = getSortedGPXFilenames(dir);
@ -114,11 +114,11 @@ public class GpxUiHelper {
final File dir, String filename, final int position) {
final Application app = activity.getApplication();
final File f = new File(dir, filename);
loadGPXFileInDifferentThread(activity, new CallbackWithObject<GPXUtilities.GPXFile>() {
loadGPXFileInDifferentThread(activity, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXFile result) {
cmAdapter.setItemName(position, cmAdapter.getItemName(position) + "\n" + getDescription((OsmandApplication) app, result, f));
public boolean processResult(GPXFile[] result) {
cmAdapter.setItemName(position, cmAdapter.getItemName(position) + "\n" + getDescription((OsmandApplication) app, result[0], f));
adapter.notifyDataSetInvalidated();
return true;
}
@ -126,7 +126,7 @@ public class GpxUiHelper {
}
private static void createDialog(final Activity activity, final boolean showCurrentGpx,
final boolean multipleChoice, final CallbackWithObject<GPXFile> callbackWithObject,
final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject,
final List<String> list, final ContextMenuAdapter adapter) {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
@ -209,8 +209,7 @@ public class GpxUiHelper {
public void onClick(DialogInterface dialog, int which) {
GPXFile currentGPX = null;
if (showCurrentGpx && adapter.getSelection(0) > 0) {
currentGPX = new GPXFile();
currentGPX.showCurrentTrack = true;
currentGPX = app.getSavingTrackHelper().getCurrentGpx();
}
List<String> s = new ArrayList<String>();
for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
@ -288,34 +287,39 @@ public class GpxUiHelper {
return getSortedGPXFilenames(dir, null);
}
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile> callbackWithObject,
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
final File dir, final GPXFile currentFile, final String... filename) {
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading),
activity.getString(R.string.loading_data));
new Thread(new Runnable() {
@Override
public void run() {
GPXFile r = currentFile;
for(String fname : filename) {
final GPXFile[] result = new GPXFile[filename.length + (currentFile == null ? 1 : 0)];
int k = 0;
String w = "";
if (currentFile != null) {
result[k++] = currentFile;
}
for (String fname : filename) {
final File f = new File(dir, fname);
GPXFile res = GPXUtilities.loadGPXFile(activity.getApplication(), f);
GPXUtilities.mergeGPXFileInto(res, r);
r = res;
if (res.warning != null && res.warning.length() > 0) {
w += res.warning + "\n";
}
result[k++] = res;
}
final GPXFile res = r;
dlg.dismiss();
if (res != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (res.warning != null) {
AccessibleToast.makeText(activity, res.warning, Toast.LENGTH_LONG).show();
} else {
callbackWithObject.processResult(res);
}
final String warn = w;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (warn.length() > 0) {
AccessibleToast.makeText(activity, warn, Toast.LENGTH_LONG).show();
} else {
callbackWithObject.processResult(result);
}
});
}
}
});
}
}, "Loading gpx").start(); //$NON-NLS-1$

View file

@ -367,7 +367,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
}
if(visible && (changed || makeVisible)) {
GPXFile selectGPXFile = GPXUtilities.loadGPXFile(app, f);
app.setGpxFileToDisplay(selectGPXFile, app.getSettings().SHOW_CURRENT_GPX_TRACK.get());
app.getSelectedGpxHelper().setGpxFileToDisplay(selectGPXFile);
}
} catch (JSONException e) {
e.printStackTrace();

View file

@ -136,8 +136,7 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
for (ColoredGPX cg : gpxArrayList){
cg.gpxFile.proccessPoints();
List<List<WptPt>> points = cg.gpxFile.processedPointsToDisplay;
List<List<WptPt>> points = cg.gpxFile.proccessPoints();
paint.setColor(cg.color);

View file

@ -280,7 +280,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
WptPt p = gpx.findPointToShow();
getMyApplication().getSettings().setMapLocationToShow(p.lat, p.lon,
getMyApplication().getSettings().getLastKnownMapZoom(), null);
getMyApplication().setGpxFileToDisplay(gpx, false);
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx);
}
}
MapActivity.launchMapActivityMoveToTop(getActivity());

View file

@ -4,9 +4,9 @@ import java.util.List;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.R;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
@ -26,11 +26,12 @@ public class GPXLayer extends OsmandMapLayer {
private Path path;
private OsmandSettings settings;
private RenderingRulesStorage cachedRrs;
private boolean cachedNightMode;
private int cachedColor;
private GpxSelectionHelper selectedGpxHelper;
private void initUI() {
@ -47,7 +48,7 @@ public class GPXLayer extends OsmandMapLayer {
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
settings = view.getSettings();
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
initUI();
}
@ -72,14 +73,19 @@ public class GPXLayer extends OsmandMapLayer {
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
GPXFile gpxFile = view.getApplication().getGpxFileToDisplay();
if(gpxFile == null){
return;
List<SelectedGpxFile> selectedGPXFiles = selectedGpxHelper.getSelectedGPXFiles();
int clr = getColor(settings);
if (!selectedGPXFiles.isEmpty()) {
for (SelectedGpxFile g : selectedGPXFiles) {
List<List<WptPt>> points = g.getPointsToDisplay();
int t = g.getColor();
paint.setColor(t == 0 ? clr : t);
drawSegments(canvas, tileBox, points);
}
}
List<List<WptPt>> points = gpxFile.processedPointsToDisplay;
paint.setColor(getColor(settings));
}
private void drawSegments(Canvas canvas, RotatedTileBox tileBox, List<List<WptPt>> points) {
final QuadRect latLonBounds = tileBox.getLatLonBounds();
for (List<WptPt> l : points) {
path.rewind();
@ -100,7 +106,6 @@ public class GPXLayer extends OsmandMapLayer {
}
if (startIndex != -1) {
drawSegment(canvas, tileBox, l, startIndex, l.size() - 1);
continue;
}
}
}
@ -124,11 +129,6 @@ public class GPXLayer extends OsmandMapLayer {
}
public boolean isShowingCurrentTrack(){
return settings.SHOW_CURRENT_GPX_TRACK.get();
}
@Override
public void destroyLayer() {

View file

@ -356,11 +356,11 @@ public class MapRoutePreferencesControl extends MapControls {
}
protected void openGPXFileSelection(final Spinner gpxSpinner) {
GpxUiHelper.selectGPXFile(mapActivity, false, false, new CallbackWithObject<GPXUtilities.GPXFile>() {
GpxUiHelper.selectGPXFile(mapActivity, false, false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXFile result) {
mapActivity.getMapActions().setGPXRouteParams(result);
public boolean processResult(GPXFile[] result) {
mapActivity.getMapActions().setGPXRouteParams(result[0]);
mapActivity.getMyApplication().getTargetPointsHelper().updateRoutingHelper();
updateSpinnerItems(gpxSpinner);
updateParameters();