Skip to content

incrementally numbered waypoints #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/java/net/osmtracker/OSMTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static final class Preferences {
public final static String KEY_OUTPUT_GPX_HDOP_APPROXIMATION = "gpx.hdop.approximation";
public final static String KEY_OUTPUT_DIR_PER_TRACK = "gpx.directory_per_track";
public final static String KEY_OUTPUT_COMPASS = "gpx.compass_heading";
public final static String KEY_INCREMENTAL_WAYPOINT_COUNTER ="gpx.incremental_waypoint_counter";

public final static String KEY_UI_PICTURE_SOURCE = "ui.picture.source";
public final static String KEY_UI_BUTTONS_LAYOUT = "ui.buttons.layout";
Expand All @@ -53,6 +54,7 @@ public static final class Preferences {
public final static boolean VAL_GPS_CHECKSTARTUP = true;
public final static boolean VAL_GPS_IGNORE_CLOCK = false;
public final static String VAL_GPS_LOGGING_INTERVAL = "0";
public final static String VAL_INCREMENTAL_WAYPOINT_COUNTER = "0";

public final static String VAL_OUTPUT_FILENAME_NAME = "name";
public final static String VAL_OUTPUT_FILENAME_NAME_DATE = "name_date";
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/net/osmtracker/activity/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,23 @@ public class Preferences extends PreferenceActivity {
* water_supply_icons <- icon directory
*/

/**
* Utility to place cursor at end of EditTextPreference
*/
public static final String ICONS_DIR_SUFFIX = "_icons";

final OnPreferenceClickListener _moveCursorToEndClickListener =
new OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference preference)
{
EditTextPreference editPref = (EditTextPreference)preference;
editPref.getEditText().setSelection( editPref.getText().length() );
return true;
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -166,6 +181,19 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});

// Counter value for incremental waypoints
((EditTextPreference)findPreference(OSMTracker.Preferences.KEY_INCREMENTAL_WAYPOINT_COUNTER)).setOnPreferenceClickListener(_moveCursorToEndClickListener);
pref = findPreference(OSMTracker.Preferences.KEY_INCREMENTAL_WAYPOINT_COUNTER);
String incremental_waypoint_counter_current = prefs.getString(OSMTracker.Preferences.KEY_INCREMENTAL_WAYPOINT_COUNTER,OSMTracker.Preferences.VAL_INCREMENTAL_WAYPOINT_COUNTER);
pref.setSummary(getResources().getString(R.string.prefs_incremental_waypoint_counter_summary) + ": " + incremental_waypoint_counter_current);
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
((EditTextPreference)preference).setSummary(getResources().getString(R.string.prefs_incremental_waypoint_counter_summary) + ": " + newValue.toString());
return true;
}
});

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.osmtracker.listener;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.preference.PreferenceManager;

import net.osmtracker.activity.TrackLogger;
import net.osmtracker.db.TrackContentProvider;

import java.util.UUID;

/**
* Listener for standard waypoint tag button.
* Sends an Intent to track waypoint. Waypoint name is the
* label of the button.
*
* @author Nicolas Guillaumin
*
*/
public class IncrementalWaypointOnclickListener implements OnClickListener {

private long currentTrackId;
private Context context;
private final SharedPreferences prefs;
private String incremental_waypoint_format;

public IncrementalWaypointOnclickListener(long trackId, String incremental_waypoint_format, Context context) {
currentTrackId = trackId;
this.context = context;
prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.incremental_waypoint_format = incremental_waypoint_format;
}

@Override
public void onClick(View view) {
Button button = (Button) view;
Integer wpnum = Integer.parseInt(prefs.getString(OSMTracker.Preferences.KEY_INCREMENTAL_WAYPOINT_COUNTER,OSMTracker.Preferences.VAL_INCREMENTAL_WAYPOINT_COUNTER));
String wptext = String.format(incremental_waypoint_format, wpnum);
// Send an intent to inform service to track the waypoint.
Intent intent = new Intent(OSMTracker.INTENT_TRACK_WP);
intent.putExtra(TrackContentProvider.Schema.COL_TRACK_ID, currentTrackId);
intent.putExtra(OSMTracker.INTENT_KEY_NAME, wptext);
intent.putExtra(OSMTracker.INTENT_KEY_UUID, UUID.randomUUID().toString());
view.getContext().sendBroadcast(intent);
wpnum++;
SharedPreferences.Editor editor = prefs.edit();
editor.putString(OSMTracker.Preferences.KEY_INCREMENTAL_WAYPOINT_COUNTER,Integer.toString(wpnum));
editor.commit();

// Inform user that the waypoint was tracked
Toast toast = Toast.makeText(view.getContext(), view.getContext().getResources().getString(R.string.tracklogger_tracked) + " " + wptext, Toast.LENGTH_LONG);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
v.setTextColor(Color.argb(200,255,0,0));
v.setTextSize(TypedValue.COMPLEX_UNIT_DIP,20);
toast.show();

}

}
12 changes: 10 additions & 2 deletions app/src/main/java/net/osmtracker/util/UserDefinedLayoutReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.osmtracker.activity.TrackLogger;
import net.osmtracker.layout.DisablableTableLayout;
import net.osmtracker.layout.UserDefinedLayout;
import net.osmtracker.listener.IncrementalWaypointOnclickListener;
import net.osmtracker.listener.PageButtonOnClickListener;
import net.osmtracker.listener.StillImageOnClickListener;
import net.osmtracker.listener.TagButtonOnClickListener;
Expand Down Expand Up @@ -79,7 +80,7 @@ public class UserDefinedLayoutReader {
* Lister bound to picture buttons
*/
private StillImageOnClickListener stillImageOnClickListener;

/**
* {@link Resources} to retrieve String resources
*/
Expand Down Expand Up @@ -283,7 +284,12 @@ public void inflateButton(TableRow row) {
button.setText(findLabel(parser.getAttributeValue(null, XmlSchema.ATTR_LABEL), resources));
buttonIcon = iconResolver.getIcon(parser.getAttributeValue(null, XmlSchema.ATTR_ICON));
button.setOnClickListener(new TagButtonOnClickListener(currentTrackId));
} else if (XmlSchema.ATTR_VAL_VOICEREC.equals(buttonType)) {
} else if (XmlSchema.ATTR_VAL_INCREMENTAL_WAYPOINT.equals(buttonType)) {
button.setText(resources.getString(R.string.gpsstatus_record_incremental_waypoint));
buttonIcon = iconResolver.getIcon(parser.getAttributeValue(null, XmlSchema.ATTR_ICON));
String incremental_waypoint_format = parser.getAttributeValue(null,XmlSchema.ATTR_FORMAT);
button.setOnClickListener(new IncrementalWaypointOnclickListener(currentTrackId, incremental_waypoint_format, context));
} else if ((XmlSchema.ATTR_VAL_VOICEREC.equals(buttonType))) {
// Voice record button
button.setText(resources.getString(R.string.gpsstatus_record_voicerec));
buttonIcon = resources.getDrawable(R.drawable.voice_32x32);
Expand Down Expand Up @@ -369,12 +375,14 @@ private static final class XmlSchema {
public static final String ATTR_TARGETLAYOUT = "targetlayout";
public static final String ATTR_ICON = "icon";
public static final String ATTR_ICONPOS = "iconpos";
public static final String ATTR_FORMAT = "format";

public static final String ATTR_VAL_TAG = "tag";
public static final String ATTR_VAL_PAGE = "page";
public static final String ATTR_VAL_VOICEREC = "voicerec";
public static final String ATTR_VAL_TEXTNOTE = "textnote";
public static final String ATTR_VAL_PICTURE = "picture";
public static final String ATTR_VAL_INCREMENTAL_WAYPOINT = "incwp";

public static final String ATTR_VAL_ICONPOS_TOP = "top";
public static final String ATTR_VAL_ICONPOS_RIGHT = "right";
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<string name="prefs_gps_logging_interval_summary">Use 0 for the shortest possible (affects battery life)</string>
<string name="prefs_gps_logging_interval_seconds">seconds</string>

<string name="prefs_incremental_waypoint_counter">Incremental waypoint counter</string>
<string name="prefs_incremental_waypoint_counter_summary">Next value for incremental waypoints (normally you shouldn\'t change this)</string>

<string name="prefs_ui">User interface</string>

<string name="prefs_ui_picture_source">Default photo source</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<string name="gpsstatus_record_voicerec">Voice record</string>
<string name="gpsstatus_record_stillimage">Take photo</string>
<string name="gpsstatus_record_textnote">Text note</string>
<string name="gpsstatus_record_incremental_waypoint">Incremental waypoint</string>

<!-- Menu -->
<string name="menu_settings">Settings</string>
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/xml/default_buttons_layout.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layouts>
<layout name="root">
<row>
<button type="incwp" icon="button_tourism_attraction" label="Waypoint" format="WPT_%04d"/>
</row>

<row>
<button type="voicerec" icon="voice_32x32" />
<button type="picture" icon="camera_32x32" />
<button type="textnote" icon="text_32x32" />
</row>

<row>
<button type="page" label="@string/tag.misc" icon="button_misc" targetlayout="misc" />
<button type="page" label="@string/tag.restriction" icon="button_restriction" targetlayout="restriction" />
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<com.android.internal.preference.YesNoPreference android:key="osm.oauth.clear-data"
android:title="@string/prefs_osm_clear_oauth_data" android:summary="@string/prefs_osm_clear_oauth_data_summary"
android:dialogMessage="@string/prefs_osm_clear_oauth_data_dialog" android:dialogIcon="@android:drawable/ic_dialog_alert" />

<EditTextPreference android:key="gpx.incremental_waypoint_counter"
android:title="@string/prefs_incremental_waypoint_counter"
android:defaultValue="0"
android:summary="@string/prefs_incremental_waypoint_counter_summary"
android:numeric="integer"/>
<PreferenceCategory android:title="@string/prefs_gps">
<Preference android:summary="@string/prefs_gps_os_settings_summary"
android:title="@string/prefs_gps_os_settings" android:key="gps.ossettings"></Preference>
Expand Down