Add support for showing current track

This commit is contained in:
Victor Shcherb 2012-01-25 23:09:13 +01:00
parent d81f8af243
commit fd1b3c0abf
15 changed files with 137 additions and 47 deletions

View file

@ -12,7 +12,7 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:b
android:layout_marginLeft="3dp" android:layout_marginTop="3dp"
android:text="@string/app_name" android:textColor="#000000" android:typeface="serif" android:textSize="20sp"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"
android:layout_marginLeft="12dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:text="0.5.1 beta(b6)" android:gravity="right"
android:layout_marginLeft="12dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:text="@string/app_version" android:gravity="right"
android:textColor="#000000" android:typeface="serif" android:id="@+id/TextVersion" android:textSize="13sp"/>
<ImageView android:src="@drawable/help_icon" android:id="@+id/HelpButton" android:layout_marginTop="7dp"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="4dp"

View file

@ -12,7 +12,7 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:b
android:layout_marginLeft="4dp" android:layout_marginTop="8dp"
android:text="@string/app_name" android:textColor="#000000" android:typeface="serif" android:textSize="30sp"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"
android:layout_marginLeft="24dp" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:text="0.5.1 beta(b6)" android:gravity="right"
android:layout_marginLeft="24dp" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:text="@string/app_version" android:gravity="right"
android:textColor="#000000" android:typeface="serif" android:id="@+id/TextVersion" android:textSize="18sp"/>
<ImageView android:src="@drawable/help_icon" android:id="@+id/HelpButton" android:layout_marginTop="9dp"
android:focusable="true" android:clickable="true"

View file

@ -12,7 +12,7 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:b
android:layout_marginLeft="3dp" android:layout_marginTop="8dp"
android:text="@string/app_name" android:textColor="#000000" android:typeface="serif" android:textSize="22sp"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"
android:layout_marginLeft="24dp" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:text="0.5.1 beta(b6)" android:gravity="right"
android:layout_marginLeft="24dp" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:text="@string/app_version" android:gravity="right"
android:textColor="#000000" android:typeface="serif" android:id="@+id/TextVersion" android:textSize="20sp"/>
<ImageView android:id="@+id/HelpButton" android:layout_marginRight="0dp" android:layout_marginTop="9dp"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="7dp"

View file

@ -12,7 +12,7 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:b
android:layout_marginLeft="2dp" android:layout_marginTop="3dp"
android:text="@string/app_name" android:textColor="#000000" android:typeface="serif" android:textSize="20sp"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"
android:layout_marginLeft="12dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:text="0.5.1 beta(b6)" android:gravity="right"
android:layout_marginLeft="12dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:text="@string/app_version" android:gravity="right"
android:textColor="#000000" android:typeface="serif" android:id="@+id/TextVersion" android:textSize="13sp"/>
<ImageView android:id="@+id/HelpButton" android:clickable="true" android:layout_marginTop="7dp" android:layout_marginLeft="4dp"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/help_icon"

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="gpx_monitoring_disabled_warn">Please enable GPX monitoring in the settings</string>
<string name="show_current_gpx_title">Show current track</string>
<string name="tip_recent_changes_0_7_0_t">Changes in 0.7.0 :
\n\t- Offline wikipedia data with articles
\n\t- Updated maps

View file

@ -68,6 +68,18 @@ public class GPXUtilities {
public double ele = Double.NaN;
public double speed = 0;
public double hdop = Double.NaN;
public WptPt(){}
public WptPt(double lat, double lon, long time, double ele, double speed, double hdop) {
this.lat = lat;
this.lon = lon;
this.time = time;
this.ele = ele;
this.speed = speed;
this.hdop = hdop;
}
}

View file

@ -115,6 +115,15 @@ public class FavouritesDbHelper extends SQLiteOpenHelper {
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);
}
public List<FavouritePoint> getFavouritePoints() {
checkFavoritePoints();
return cachedFavoritePoints;

View file

@ -174,6 +174,7 @@ public class OsmandSettings {
return internetConnectionAvailable;
}
/////////////// PREFERENCES classes ////////////////
public abstract class CommonPreference<T> implements OsmandPreference<T> {
@ -1046,6 +1047,9 @@ public class OsmandSettings {
public final OsmandPreference<Integer> SERVICE_OFF_INTERVAL = new IntPreference("service_off_interval",
5 * 60 * 1000, true);
public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
new BooleanPreference("show_current_gpx_track", false, true, true);
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Integer> SERVICE_OFF_WAIT_INTERVAL = new IntPreference("service_off_wait_interval",
90 * 1000, true);

View file

@ -163,7 +163,7 @@ public class LocalIndexesActivity extends ExpandableListActivity {
OsmandSettings settings = OsmandSettings.getOsmandSettings(LocalIndexesActivity.this);
settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
}
((OsmandApplication) getApplication()).setGpxFileToDisplay(info.getGpxFile());
((OsmandApplication) getApplication()).setGpxFileToDisplay(info.getGpxFile(), false);
MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this);
}
} else if (resId == R.string.local_index_mi_rename) {

View file

@ -9,6 +9,7 @@ import com.google.android.apps.analytics.easytracking.TrackedActivity;
import net.osmand.Algoritms;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.LogUtil;
import net.osmand.Version;
import net.osmand.data.MapTileDownloader.DownloadRequest;
@ -665,8 +666,15 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
if (!location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(),
location.getAccuracy(), location.getTime(), settings);
if(settings.SHOW_CURRENT_GPX_TRACK.get()) {
WptPt pt = new GPXUtilities.WptPt(location.getLatitude(), location.getLongitude(), location.getTime(), location.getAltitude(), location.getSpeed(),
location.getAccuracy());
mapLayers.getGpxLayer().addTrackPoint(pt);
}
}
}
registerUnregisterSensor(location);
updateSpeedBearing(location);
mapLayers.getLocationLayer().setLastKnownLocation(location);

View file

@ -209,6 +209,9 @@ public class MapActivityActions implements DialogProvider {
double longitude = args.getDouble(KEY_LONGITUDE);
String name = editText.getText().toString();
mapActivity.getSavingTrackHelper().insertPointData(latitude, longitude, System.currentTimeMillis(), name);
if(OsmandSettings.getOsmandSettings(mapActivity).SHOW_CURRENT_GPX_TRACK.get()) {
getMyApplication().favorites.addFavoritePointToGPXFile(new FavouritePoint(latitude, longitude, name, ""));
}
Toast.makeText(mapActivity, MessageFormat.format(getString(R.string.add_waypoint_dialog_added), name), Toast.LENGTH_SHORT)
.show();
dialog.dismiss();
@ -622,7 +625,7 @@ public class MapActivityActions implements DialogProvider {
builder.show();
return true;
}
}, false);
}, false, false);
}
private ApplicationMode getAppMode(ToggleButton[] buttons, OsmandSettings settings){

View file

@ -255,7 +255,7 @@ public class MapActivityLayers {
selectedList.add(underlayLayer.getMap() != null ? 1 : 0);
layers.add(R.string.layer_gpx_layer);
selectedList.add(gpxLayer.isVisible() ? 1 : 0);
selectedList.add(getApplication().getGpxFileToDisplay() != null ? 1 : 0);
if(routeInfoLayer.couldBeVisible()){
layers.add(R.string.layer_route);
selectedList.add(routeInfoLayer.isUserDefinedVisible() ? 1 : 0);
@ -317,8 +317,8 @@ public class MapActivityLayers {
mapTileLayer, mapVectorLayer);
}
} else if(layers.get(item) == R.string.layer_gpx_layer){
if(gpxLayer.isVisible()){
getApplication().setGpxFileToDisplay(null);
if(getApplication().getGpxFileToDisplay() != null){
getApplication().setGpxFileToDisplay(null, false);
gpxLayer.clearCurrentGPX();
} else {
dialog.dismiss();
@ -345,15 +345,27 @@ public class MapActivityLayers {
selectGPXFileLayer(new CallbackWithObject<GPXFile>() {
@Override
public boolean processResult(GPXFile result) {
settings.SHOW_FAVORITES.set(true);
if (result != null) {
getApplication().setGpxFileToDisplay(result);
updateGPXLayer();
mapView.refreshMap();
GPXFile toShow = result;
if (toShow == null) {
if(!settings.SAVE_TRACK_TO_GPX.get()){
Toast.makeText(activity, R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_SHORT).show();
return true;
}
Map<String, GPXFile> data = activity.getSavingTrackHelper().collectRecordedData();
if(data.isEmpty()){
toShow = new GPXFile();
} else {
toShow = data.values().iterator().next();
}
}
settings.SHOW_FAVORITES.set(true);
getApplication().setGpxFileToDisplay(toShow, result == null);
updateGPXLayer();
mapView.refreshMap();
return true;
}
}, true);
}, true, true);
}
private void updateGPXLayer(){
@ -365,7 +377,8 @@ public class MapActivityLayers {
}
}
public void selectGPXFileLayer(final CallbackWithObject<GPXFile> callbackWithObject, final boolean convertCloudmade) {
public void selectGPXFileLayer(final CallbackWithObject<GPXFile> callbackWithObject, final boolean convertCloudmade,
final boolean showCurrentGpx) {
final List<String> list = new ArrayList<String>();
final OsmandSettings settings = getApplication().getSettings();
final File dir = settings.extendOsmandPath(ResourceManager.GPX_PATH);
@ -395,35 +408,42 @@ public class MapActivityLayers {
if(list.isEmpty()){
Toast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
} else {
}
if(!list.isEmpty() || showCurrentGpx){
Builder builder = new AlertDialog.Builder(activity);
if(showCurrentGpx){
list.add(0, getString(R.string.show_current_gpx_title));
}
builder.setItems(list.toArray(new String[list.size()]), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
final ProgressDialog dlg = ProgressDialog.show(activity, getString(R.string.loading),
getString(R.string.loading_data));
final File f = new File(dir, list.get(which));
new Thread(new Runnable() {
@Override
public void run() {
final GPXFile res = GPXUtilities.loadGPXFile(activity, f, convertCloudmade);
dlg.dismiss();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if(res.warning != null){
Toast.makeText(activity, res.warning, Toast.LENGTH_LONG).show();
} else {
callbackWithObject.processResult(res);
if(showCurrentGpx && which == 0){
callbackWithObject.processResult(null);
} else {
final ProgressDialog dlg = ProgressDialog.show(activity, getString(R.string.loading),
getString(R.string.loading_data));
final File f = new File(dir, list.get(which));
new Thread(new Runnable() {
@Override
public void run() {
final GPXFile res = GPXUtilities.loadGPXFile(activity, f, convertCloudmade);
dlg.dismiss();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (res.warning != null) {
Toast.makeText(activity, res.warning, Toast.LENGTH_LONG).show();
} else {
callbackWithObject.processResult(res);
}
}
}
});
}
});
}
}, "Loading gpx").start(); //$NON-NLS-1$
}, "Loading gpx").start(); //$NON-NLS-1$
}
}
});
@ -636,6 +656,10 @@ public class MapActivityLayers {
return navigationLayer;
}
public GPXLayer getGpxLayer() {
return gpxLayer;
}
public ContextMenuLayer getContextMenuLayer() {
return contextMenuLayer;
}

View file

@ -110,8 +110,9 @@ public class OsmandApplication extends Application {
return poiFilters;
}
public void setGpxFileToDisplay(GPXFile gpxFileToDisplay) {
public void setGpxFileToDisplay(GPXFile gpxFileToDisplay, boolean showCurrentGpxFile) {
this.gpxFileToDisplay = gpxFileToDisplay;
osmandSettings.SHOW_CURRENT_GPX_TRACK.set(showCurrentGpxFile);
if(gpxFileToDisplay == null){
getFavorites().setFavoritePointsFromGPXFile(null);
} else {

View file

@ -123,17 +123,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
* @return warnings
*/
public List<String> saveDataToGpx() {
SQLiteDatabase db = getReadableDatabase();
List<String> warnings = new ArrayList<String>();
File dir = OsmandSettings.getOsmandSettings(ctx).getExternalStorageDirectory();
if (db != null && dir.canWrite()) {
if (dir.canWrite()) {
dir = new File(dir, ResourceManager.GPX_PATH);
dir.mkdirs();
if (dir.exists()) {
Map<String, GPXFile> data = new LinkedHashMap<String, GPXFile>();
collectDBPoints(db, data);
collectDBTracks(db, data);
Map<String, GPXFile> data = collectRecordedData();
// save file
for (final String f : data.keySet()) {
@ -156,7 +153,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
}
db = getWritableDatabase();
SQLiteDatabase db = getWritableDatabase();
if (db != null && warnings.isEmpty()) {
// remove all from db
db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -165,6 +162,16 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
return warnings;
}
public Map<String, GPXFile> collectRecordedData() {
Map<String, GPXFile> data = new LinkedHashMap<String, GPXFile>();
SQLiteDatabase db = getReadableDatabase();
if(db != null) {
collectDBPoints(db, data);
collectDBTracks(db, data);
}
return data;
}
private void collectDBPoints(SQLiteDatabase db, Map<String, GPXFile> dataTracks) {
Cursor query = db.rawQuery("SELECT " + POINT_COL_LAT + "," + POINT_COL_LON + "," + POINT_COL_DATE + "," //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ POINT_COL_DESCRIPTION + " FROM " + POINT_NAME+" ORDER BY " + TRACK_COL_DATE +" ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -243,7 +250,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
public void insertData(double lat, double lon, double alt, double speed, double hdop, long time, OsmandSettings settings){
if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get()*1000) {
if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() * 1000) {
execWithClose(updateScript, new Object[] { lat, lon, alt, speed, hdop, time });
lastTimeUpdated = time;
}

View file

@ -6,6 +6,7 @@ import java.util.List;
import net.osmand.GPXUtilities.Track;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.OsmandSettings;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@ -24,6 +25,9 @@ public class GPXLayer extends OsmandMapLayer {
private Paint paint;
private Path path;
private OsmandSettings settings;
private void initUI() {
paint = new Paint();
@ -41,6 +45,7 @@ public class GPXLayer extends OsmandMapLayer {
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
settings = OsmandSettings.getOsmandSettings(view.getContext());
initUI();
}
@ -96,8 +101,8 @@ public class GPXLayer extends OsmandMapLayer {
}
public boolean isVisible(){
return !points.isEmpty();
public boolean isShowingCurrentTrack(){
return settings.SHOW_CURRENT_GPX_TRACK.get();
}
@ -120,6 +125,21 @@ public class GPXLayer extends OsmandMapLayer {
}
}
public void addTrackPoint(WptPt pt){
if(points.size() == 0){
points.add(new ArrayList<WptPt>());
}
List<WptPt> last = points.get(points.size() - 1);
if(last.size() == 0 || last.get(last.size() - 1).time - pt.time < 6 * 60 * 1000) {
// 6 minutes same segment
last.add(pt);
} else {
ArrayList<WptPt> l = new ArrayList<WptPt>();
l.add(pt);
points.add(l);
}
}
@Override
public void destroyLayer() {