Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

0.4 release

  • Loading branch information...
commit 2b07ac3cd67e561a699a17618cc2cd681c108b6f 1 parent 70b1439
@M66B authored
View
3  .classpath
@@ -3,5 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="output" path="bin"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
</classpath>
View
1  .gitignore
@@ -1,2 +1,3 @@
bin/
gen/
+.settings
View
3  AndroidManifest.xml
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="biz.bokhorst" android:versionCode="3" android:versionName="0.3">
+ package="biz.bokhorst" android:versionCode="4" android:versionName="0.4">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
View
6 README.md
@@ -70,6 +70,10 @@ Other application options:
* Min. accuracy: tracking will stop after this accuracy has been reached (default 20 meters)
* Geocode count: the number of addresses to show when reverse geocoding (default 5 addresses)
+Changelog
+---------
+See [here](http://wordpress.org/extend/plugins/backpacktrack-for-android/changelog/ "changelog")
+
Frequently Asked Questions
--------------------------
@@ -79,7 +83,7 @@ Read [here](http://blog.bokhorst.biz/5283/computers-en-internet/backpacktrack-fo
**Where can I download the Android application?**
-This is the [direct download link](https://github.com/downloads/M66B/BackPackTrack/BackPackTrack.apk "BackPackTrack for Android") to the latest version
+This is the [direct download link](https://github.com/downloads/M66B/BackPackTrack/BackPackTrack.0.4.apk "BackPackTrack for Android") to the latest version
on the [github project page](https://github.com/M66B/BackPackTrack "Android application").
**Why does the time of the locations differ from the clock time?**
View
36 proguard.cfg
@@ -1,36 +0,0 @@
--optimizationpasses 5
--dontusemixedcaseclassnames
--dontskipnonpubliclibraryclasses
--dontpreverify
--verbose
--optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-
--keep public class * extends android.app.Activity
--keep public class * extends android.app.Application
--keep public class * extends android.app.Service
--keep public class * extends android.content.BroadcastReceiver
--keep public class * extends android.content.ContentProvider
--keep public class * extends android.app.backup.BackupAgentHelper
--keep public class * extends android.preference.Preference
--keep public class com.android.vending.licensing.ILicensingService
-
--keepclasseswithmembernames class * {
- native <methods>;
-}
-
--keepclasseswithmembernames class * {
- public <init>(android.content.Context, android.util.AttributeSet);
-}
-
--keepclasseswithmembernames class * {
- public <init>(android.content.Context, android.util.AttributeSet, int);
-}
-
--keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
-}
-
--keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
-}
View
2  default.properties → project.properties
@@ -4,7 +4,7 @@
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
+# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
View
68 src/biz/bokhorst/BPTMap.java
@@ -1,22 +1,23 @@
package biz.bokhorst;
/*
- Copyright 2011 Marcel Bokhorst
+ Copyright 2011, 2012 Marcel Bokhorst
+ All Rights Reserved
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
import java.util.List;
@@ -72,17 +73,21 @@ public void onCreate(Bundle savedInstanceState) {
debug = isDebugBuild();
} catch (Exception e) {
}
- String apikey = debug ? getString(R.string.mvApikeyDebug) : getString(R.string.mvApikeyRelease);
+ String apikey = debug ? getString(R.string.mvApikeyDebug)
+ : getString(R.string.mvApikeyRelease);
// Create map view
mapView = new MapView(this, apikey);
mapView.setClickable(true);
- MapView.LayoutParams mvlp = new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
- ViewGroup.LayoutParams.FILL_PARENT, 0, 0, MapView.LayoutParams.CENTER);
+ MapView.LayoutParams mvlp = new MapView.LayoutParams(
+ ViewGroup.LayoutParams.FILL_PARENT,
+ ViewGroup.LayoutParams.FILL_PARENT, 0, 0,
+ MapView.LayoutParams.CENTER);
mapView.setLayoutParams(mvlp);
// Create layout
- RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
+ RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
+ RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
RelativeLayout rl = new RelativeLayout(this);
rl.setLayoutParams(lp);
@@ -103,7 +108,8 @@ public void onCreate(Bundle savedInstanceState) {
// Get map bounds
double minLat = Double.MAX_VALUE, maxLat = Double.MIN_VALUE;
double minLon = Double.MAX_VALUE, maxLon = Double.MIN_VALUE;
- String trackName = preferences.getString(Preferences.PREF_TRACKNAME, Preferences.PREF_TRACKNAME_DEFAULT);
+ String trackName = preferences.getString(Preferences.PREF_TRACKNAME,
+ Preferences.PREF_TRACKNAME_DEFAULT);
Cursor c = databaseHelper.getPointList(trackName, true);
c.moveToNext();
while (!c.isAfterLast()) {
@@ -128,7 +134,8 @@ public void onCreate(Bundle savedInstanceState) {
GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
MapController mc = mapView.getController();
mc.setCenter(p);
- mc.zoomToSpan((int) ((maxLat - minLat) * 1E6), (int) ((maxLon - minLon) * 1E6));
+ mc.zoomToSpan((int) ((maxLat - minLat) * 1E6),
+ (int) ((maxLon - minLon) * 1E6));
}
// Apply overlay
@@ -188,24 +195,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
class MapOverlay extends com.google.android.maps.Overlay {
@Override
- public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
+ public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
+ long when) {
super.draw(canvas, mapView, shadow);
// Get current tags
- String trackName = preferences.getString(Preferences.PREF_TRACKNAME, Preferences.PREF_TRACKNAME_DEFAULT);
+ String trackName = preferences.getString(
+ Preferences.PREF_TRACKNAME,
+ Preferences.PREF_TRACKNAME_DEFAULT);
// Draw waypoints
Cursor cTP = databaseHelper.getPointList(trackName, true);
cTP.moveToNext();
while (!cTP.isAfterLast()) {
- GeoPoint p = new GeoPoint((int) (cTP.getDouble(cTP.getColumnIndex("LATITUDE")) * 1E6), (int) (cTP
- .getDouble(cTP.getColumnIndex("LONGITUDE")) * 1E6));
+ GeoPoint p = new GeoPoint(
+ (int) (cTP.getDouble(cTP.getColumnIndex("LATITUDE")) * 1E6),
+ (int) (cTP.getDouble(cTP.getColumnIndex("LONGITUDE")) * 1E6));
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
- canvas.drawBitmap(bmp, screenPts.x, screenPts.y - bmp.getHeight(), null);
+ Bitmap bmp = BitmapFactory.decodeResource(getResources(),
+ R.drawable.marker);
+ canvas.drawBitmap(bmp, screenPts.x,
+ screenPts.y - bmp.getHeight(), null);
cTP.moveToNext();
}
cTP.close();
@@ -223,8 +236,9 @@ public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
Cursor cWpt = databaseHelper.getPointList(trackName, false);
cWpt.moveToNext();
while (!cWpt.isAfterLast()) {
- GeoPoint p = new GeoPoint((int) (cWpt.getDouble(cWpt.getColumnIndex("LATITUDE")) * 1E6), (int) (cWpt
- .getDouble(cWpt.getColumnIndex("LONGITUDE")) * 1E6));
+ GeoPoint p = new GeoPoint(
+ (int) (cWpt.getDouble(cWpt.getColumnIndex("LATITUDE")) * 1E6),
+ (int) (cWpt.getDouble(cWpt.getColumnIndex("LONGITUDE")) * 1E6));
if (prev != null) {
Point p1 = new Point();
Point p2 = new Point();
View
218 src/biz/bokhorst/BPTService.java
@@ -1,22 +1,23 @@
-/*
- Copyright 2011 Marcel Bokhorst
+package biz.bokhorst;
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
+/*
+ Copyright 2011, 2012 Marcel Bokhorst
+ All Rights Reserved
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-package biz.bokhorst;
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -41,25 +42,29 @@
import android.os.Messenger;
import android.preference.PreferenceManager;
import android.widget.Toast;
+import android.os.PowerManager;
-public class BPTService extends IntentService implements LocationListener, GpsStatus.Listener {
+public class BPTService extends IntentService implements LocationListener,
+ GpsStatus.Listener {
// Messages
public static final int MSG_REPLY = 1;
public static final int MSG_WAYPOINT = 2;
- private static final SimpleDateFormat TIME_FORMATTER = new SimpleDateFormat("HH:mm:ss");
+ private static final SimpleDateFormat TIME_FORMATTER = new SimpleDateFormat(
+ "HH:mm:ss");
// Helpers
private LocationManager locationManager = null;
private DatabaseHelper databaseHelper = null;
private SharedPreferences preferences = null;
- private Handler handler = null;
+ private PowerManager.WakeLock wakeLock = null;
+ private Handler taskHandler = null;
private Messenger clientMessenger = null;
// State
private boolean waypoint = false;
private boolean locating = false;
- private boolean fixwait = false;
+ private boolean locationwait = false;
private Location bestLocation = null;
private Date nextTrackTime;
@@ -78,7 +83,11 @@ public void handleMessage(Message msg) {
if (msg.replyTo != null)
clientMessenger = msg.replyTo;
waypoint = (msg.what == MSG_WAYPOINT);
- handler.post(TrackTask);
+
+ // Immediate start location
+ wakeLock.acquire();
+ taskHandler.removeCallbacks(PeriodicTrackTask);
+ taskHandler.post(PeriodicTrackTask);
}
}
@@ -86,6 +95,7 @@ public void handleMessage(Message msg) {
@Override
public IBinder onBind(Intent intent) {
+ // Save context
Context context = getApplicationContext();
// Build notification
@@ -93,11 +103,13 @@ public IBinder onBind(Intent intent) {
toLaunch.setAction("android.intent.action.MAIN");
toLaunch.addCategory("android.intent.category.LAUNCHER");
- PendingIntent intentBack = PendingIntent.getActivity(context, 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent intentBack = PendingIntent.getActivity(context, 0,
+ toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);
- Notification notification = new Notification(R.drawable.icon, getText(R.string.Running), System
- .currentTimeMillis());
- notification.setLatestEventInfo(context, getText(R.string.app_name), getText(R.string.Running), intentBack);
+ Notification notification = new Notification(R.drawable.icon,
+ getText(R.string.Running), System.currentTimeMillis());
+ notification.setLatestEventInfo(context, getText(R.string.app_name),
+ getText(R.string.Running), intentBack);
// Start foreground service
// Requires API level 5 (Android 2.0)
@@ -107,16 +119,33 @@ public IBinder onBind(Intent intent) {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
databaseHelper = new DatabaseHelper(context);
preferences = PreferenceManager.getDefaultSharedPreferences(context);
- handler = new Handler();
+ PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
+ "BPT");
+ taskHandler = new Handler();
return serverMessenger.getBinder();
}
@Override
public boolean onUnbind(Intent intent) {
- handler.removeCallbacks(TrackTask);
- stopLocating();
+ // Stop periodic track task (if any)
+ taskHandler.removeCallbacks(PeriodicTrackTask);
+
+ // Stop locating procedure (if any)
+ stopLocating(); // Removes other tasks
+
+ // Stop foreground service
stopForeground(true);
+
+ // Dispose helpers
+ taskHandler = null;
+ wakeLock.release();
+ wakeLock = null;
+ preferences = null;
+ databaseHelper = null;
+ locationManager = null;
+
return super.onUnbind(intent);
}
@@ -124,19 +153,27 @@ public boolean onUnbind(Intent intent) {
protected void startLocating() {
if (!locating) {
locating = true;
- fixwait = false;
- long timeout = Integer.parseInt(preferences.getString(Preferences.PREF_FIXTIMEOUT,
+
+ // Start waiting for fix
+ long timeout = Integer.parseInt(preferences.getString(
+ Preferences.PREF_FIXTIMEOUT,
Preferences.PREF_FIXTIMEOUT_DEFAULT)) * 1000L;
- handler.postDelayed(FixTimeoutTask, timeout);
+ taskHandler.postDelayed(FixTimeoutTask, timeout);
- // Request updates
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+ // Request location updates
+ locationwait = false;
+ locationManager.requestLocationUpdates(
+ LocationManager.GPS_PROVIDER, 0, 0, this);
locationManager.addGpsStatusListener(this);
+ // User feedback
Date timeoutTime = new Date(System.currentTimeMillis() + timeout);
- boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
- sendStage(String.format(getString(R.string.StageFixWait), TIME_FORMATTER.format(timeoutTime)));
- sendStatus(gpsEnabled ? getString(R.string.On) : getString(R.string.Off));
+ boolean gpsEnabled = locationManager
+ .isProviderEnabled(LocationManager.GPS_PROVIDER);
+ sendStage(String.format(getString(R.string.StageFixWait),
+ TIME_FORMATTER.format(timeoutTime)));
+ sendStatus(gpsEnabled ? getString(R.string.On)
+ : getString(R.string.Off));
sendSatellites(-1, -1);
}
}
@@ -145,12 +182,16 @@ protected void startLocating() {
protected void stopLocating() {
if (locating) {
locating = false;
- handler.removeCallbacks(FixTimeoutTask);
- handler.removeCallbacks(LocationWaitTask);
+ // Cancel fix/location tasks
+ taskHandler.removeCallbacks(FixTimeoutTask);
+ taskHandler.removeCallbacks(LocationWaitTimeoutTask);
+
+ // Disable location updates
locationManager.removeGpsStatusListener(this);
locationManager.removeUpdates(this);
+ // User feedback
sendStage(getString(R.string.na));
sendStatus(getString(R.string.na));
sendSatellites(-1, -1);
@@ -160,91 +201,138 @@ protected void stopLocating() {
@Override
public void onLocationChanged(Location location) {
if (locating) {
- handler.removeCallbacks(FixTimeoutTask);
- int minAccuracy = Integer.parseInt(preferences.getString(Preferences.PREF_MINACCURACY,
+ // Have location: stop fix timeout task
+ taskHandler.removeCallbacks(FixTimeoutTask);
+
+ // Get minimum accuracy
+ int minAccuracy = Integer.parseInt(preferences.getString(
+ Preferences.PREF_MINACCURACY,
Preferences.PREF_MINACCURACY_DEFAULT));
- if (fixwait) {
+
+ if (locationwait) {
// Record best location
if (location.getAccuracy() <= bestLocation.getAccuracy())
bestLocation = location;
// Check if minimum accuracy reached
if (location.getAccuracy() < minAccuracy) {
- handler.removeCallbacks(LocationWaitTask);
- handler.post(LocationWaitTask);
+ // Immediately handle location
+ taskHandler.removeCallbacks(LocationWaitTimeoutTask);
+ taskHandler.post(LocationWaitTimeoutTask);
}
} else {
- // Start waiting for accurate location
- fixwait = true;
+ // Start waiting for best location
+ locationwait = true;
+
+ // Current location is best location (for now)
bestLocation = location;
- long wait = Integer.parseInt(preferences.getString(Preferences.PREF_MAXWAIT,
+ long wait = Integer.parseInt(preferences.getString(
+ Preferences.PREF_MAXWAIT,
Preferences.PREF_MAXWAIT_DEFAULT)) * 1000L;
- handler.postDelayed(LocationWaitTask, wait);
+
+ // Wait for best location for some time
+ taskHandler.postDelayed(LocationWaitTimeoutTask, wait);
Date waitTime = new Date(System.currentTimeMillis() + wait);
- sendStage(String.format(getString(R.string.StageTrackWait), TIME_FORMATTER.format(waitTime),
- minAccuracy));
+
+ // User feedback
+ sendStage(String.format(getString(R.string.StageTrackWait),
+ TIME_FORMATTER.format(waitTime), minAccuracy));
}
}
- // Always update location
+ // User feedback
sendLocation(location);
}
- // Tracking timer
- final Runnable TrackTask = new Runnable() {
+ // Periodic tracking
+ final Runnable PeriodicTrackTask = new Runnable() {
public void run() {
+ // Start locating procedure
startLocating();
- long interval = Integer.parseInt(preferences.getString(Preferences.PREF_TRACKINTERVAL,
+
+ // Reschedule
+ long interval = Integer.parseInt(preferences.getString(
+ Preferences.PREF_TRACKINTERVAL,
Preferences.PREF_TRACKINTERVAL_DEFAULT)) * 60L * 1000L;
- handler.postDelayed(TrackTask, interval);
+ taskHandler.postDelayed(PeriodicTrackTask, interval);
+
+ // Prepare user feedback
nextTrackTime = new Date(System.currentTimeMillis() + interval);
}
};
// Fix wait done
- final Runnable LocationWaitTask = new Runnable() {
+ final Runnable LocationWaitTimeoutTask = new Runnable() {
public void run() {
+ // Stop locating procedure
stopLocating();
- sendLocation(bestLocation);
+
+ // Always make track point
makeTrackpoint(bestLocation);
+
+ // Make way point
if (waypoint) {
waypoint = false;
makeWaypoint(bestLocation);
}
- sendStage(String.format(getString(R.string.StageTracked), TIME_FORMATTER.format(nextTrackTime)));
+
+ // User feedback
+ sendLocation(bestLocation);
+ sendStage(String.format(getString(R.string.StageTracked),
+ TIME_FORMATTER.format(nextTrackTime)));
}
};
// Fix timeout
final Runnable FixTimeoutTask = new Runnable() {
public void run() {
+ // Stop locating procedure
stopLocating();
+
+ // Prevent way point
waypoint = false;
- sendStage(String.format(getString(R.string.StageFixTimeout), TIME_FORMATTER.format(nextTrackTime)));
- // Use last location if younger
- String trackName = preferences.getString(Preferences.PREF_TRACKNAME, Preferences.PREF_TRACKNAME_DEFAULT);
- Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
- sendLocation(location);
- if (location != null && location.getTime() > databaseHelper.getYoungest(trackName, false))
+ // Get last know location
+ String trackName = preferences.getString(
+ Preferences.PREF_TRACKNAME,
+ Preferences.PREF_TRACKNAME_DEFAULT);
+ Location location = locationManager
+ .getLastKnownLocation(LocationManager.GPS_PROVIDER);
+
+ // Use last known location if younger
+ if (location != null
+ && location.getTime() > databaseHelper.getYoungest(
+ trackName, false))
makeTrackpoint(location);
+
+ // User feedback
+ sendStage(String.format(getString(R.string.StageFixTimeout),
+ TIME_FORMATTER.format(nextTrackTime)));
+ sendLocation(location);
}
};
// Helper method create track point
protected void makeTrackpoint(Location location) {
- String trackName = preferences.getString(Preferences.PREF_TRACKNAME, Preferences.PREF_TRACKNAME_DEFAULT);
+ String trackName = preferences.getString(Preferences.PREF_TRACKNAME,
+ Preferences.PREF_TRACKNAME_DEFAULT);
databaseHelper.insertPoint(trackName, null, location, null, false);
+
+ // User feedback
sendMessage(BackPackTrack.MSG_UPDATETRACK, null);
- Toast.makeText(this, getString(R.string.TrackpointAdded), Toast.LENGTH_LONG).show();
+ Toast.makeText(this, getString(R.string.TrackpointAdded),
+ Toast.LENGTH_LONG).show();
}
// Helper create way point
private void makeWaypoint(Location location) {
- String trackName = preferences.getString(Preferences.PREF_TRACKNAME, Preferences.PREF_TRACKNAME_DEFAULT);
+ String trackName = preferences.getString(Preferences.PREF_TRACKNAME,
+ Preferences.PREF_TRACKNAME_DEFAULT);
int count = databaseHelper.countPoints(trackName, true);
String name = String.format("%03d", count + 1);
databaseHelper.insertPoint(trackName, null, location, name, true);
+
+ // User feedback
sendMessage(BackPackTrack.MSG_UPDATETRACK, null);
String msg = String.format(getString(R.string.WaypointAdded), name);
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
View
31 src/biz/bokhorst/BackPackTrack.java
@@ -1,21 +1,22 @@
package biz.bokhorst;
/*
- Copyright 2011 Marcel Bokhorst
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Copyright 2011, 2012 Marcel Bokhorst
+ All Rights Reserved
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import java.io.DataInputStream;
View
68 src/biz/bokhorst/DatabaseHelper.java
@@ -1,22 +1,23 @@
package biz.bokhorst;
/*
- Copyright 2011 Marcel Bokhorst
+ Copyright 2011, 2012 Marcel Bokhorst
+ All Rights Reserved
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
import android.content.ContentValues;
import android.content.Context;
@@ -34,10 +35,13 @@
private static final int DBVERSION = 4;
private Context _context;
- private static final String DBCREATE = "CREATE TABLE LOCATION (" + " ID INTEGER PRIMARY KEY AUTOINCREMENT,"
- + " TRACK TEXT NOT NULL," + " SEGMENT TEXT," + " LATITUDE REAL NOT NULL," + " LONGITUDE REAL NOT NULL,"
- + " ALTITUDE REAL NOT NULL," + " SPEED REAL NOT NULL," + " ACCURACY REAL NOT NULL,"
- + " TIME INTEGER NOT NULL," + " NAME TEXT, " + " WPT NOT NULL" + ");";
+ private static final String DBCREATE = "CREATE TABLE LOCATION ("
+ + " ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ + " TRACK TEXT NOT NULL," + " SEGMENT TEXT,"
+ + " LATITUDE REAL NOT NULL," + " LONGITUDE REAL NOT NULL,"
+ + " ALTITUDE REAL NOT NULL," + " SPEED REAL NOT NULL,"
+ + " ACCURACY REAL NOT NULL," + " TIME INTEGER NOT NULL,"
+ + " NAME TEXT, " + " WPT NOT NULL" + ");";
public DatabaseHelper(Context context) {
super(context, DBNAME, null, DBVERSION);
@@ -54,12 +58,14 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 3) {
db.execSQL("DROP TABLE LOCATION");
db.execSQL(DBCREATE);
- Toast.makeText(_context, "Database updated", Toast.LENGTH_LONG).show();
+ Toast.makeText(_context, "Database updated", Toast.LENGTH_LONG)
+ .show();
}
}
// Insert new trackpoint or waypoint
- public void insertPoint(String trackName, String segment, Location location, String name, boolean wpt) {
+ public void insertPoint(String trackName, String segment,
+ Location location, String name, boolean wpt) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("TRACK", trackName);
@@ -78,8 +84,9 @@ public void insertPoint(String trackName, String segment, Location location, Str
// Get point by id
public Location getLocation(long id) {
SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.rawQuery("SELECT LATITUDE, LONGITUDE, ALTITUDE, SPEED, ACCURACY, TIME FROM LOCATION"
- + " WHERE ID=" + Long.toString(id), new String[] {});
+ Cursor cursor = db.rawQuery(
+ "SELECT LATITUDE, LONGITUDE, ALTITUDE, SPEED, ACCURACY, TIME FROM LOCATION"
+ + " WHERE ID=" + Long.toString(id), new String[] {});
if (cursor.moveToFirst()) {
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(cursor.getDouble(0));
@@ -96,15 +103,19 @@ public Location getLocation(long id) {
// Get list of points
public Cursor getPointList(String trackName, boolean wpt) {
SQLiteDatabase db = this.getReadableDatabase();
- return db.rawQuery(
- "SELECT ID, TRACK, SEGMENT, LATITUDE, LONGITUDE, ALTITUDE, SPEED, ACCURACY, TIME, NAME FROM LOCATION"
- + " WHERE TRACK=? AND WPT=" + (wpt ? "1" : "0") + " ORDER BY TIME", new String[] { trackName });
+ return db
+ .rawQuery(
+ "SELECT ID, TRACK, SEGMENT, LATITUDE, LONGITUDE, ALTITUDE, SPEED, ACCURACY, TIME, NAME FROM LOCATION"
+ + " WHERE TRACK=? AND WPT="
+ + (wpt ? "1" : "0")
+ + " ORDER BY TIME DESC", new String[] { trackName });
}
// Get youngest point
public long getYoungest(String trackName, boolean wpt) {
SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.rawQuery("SELECT MAX(TIME) FROM LOCATION" + " WHERE TRACK=? AND WPT=" + (wpt ? "1" : "0"),
+ Cursor cursor = db.rawQuery("SELECT MAX(TIME) FROM LOCATION"
+ + " WHERE TRACK=? AND WPT=" + (wpt ? "1" : "0"),
new String[] { trackName });
if (cursor.moveToFirst())
return cursor.getLong(0);
@@ -114,13 +125,16 @@ public long getYoungest(String trackName, boolean wpt) {
// Get list of tracks
public Cursor getTrackList() {
SQLiteDatabase db = this.getReadableDatabase();
- return db.rawQuery("SELECT DISTINCT TRACK FROM LOCATION ORDER BY TRACK", new String[] {});
+ return db.rawQuery(
+ "SELECT DISTINCT TRACK FROM LOCATION ORDER BY TRACK",
+ new String[] {});
}
// Get count of points
public int countPoints(String trackName, boolean wpt) {
SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM LOCATION" + " WHERE TRACK=? AND WPT=" + (wpt ? "1" : "0"),
+ Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM LOCATION"
+ + " WHERE TRACK=? AND WPT=" + (wpt ? "1" : "0"),
new String[] { trackName });
if (cursor.moveToFirst())
return cursor.getInt(0);
View
93 src/biz/bokhorst/GPXFileWriter.java
@@ -1,22 +1,23 @@
package biz.bokhorst;
/*
- Copyright 2011 Marcel Bokhorst
+ Copyright 2011, 2012 Marcel Bokhorst
+ All Rights Reserved
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
import java.io.File;
import java.io.FileWriter;
@@ -31,14 +32,17 @@
// Some constants
private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
- private static final String TAG_GPX = "<gpx" + " xmlns=\"http://www.topografix.com/GPX/1/1\"" + " version=\"1.1\""
+ private static final String TAG_GPX = "<gpx"
+ + " xmlns=\"http://www.topografix.com/GPX/1/1\""
+ + " version=\"1.1\""
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">";
- private static final SimpleDateFormat POINT_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ private static final SimpleDateFormat POINT_DATE_FORMATTER = new SimpleDateFormat(
+ "yyyy-MM-dd'T'HH:mm:ss'Z'");
// Main logic
- public static void writeGpxFile(String trackName, Cursor cTrackPoints, Cursor cWayPoints, File target)
- throws IOException {
+ public static void writeGpxFile(String trackName, Cursor cTrackPoints,
+ Cursor cWayPoints, File target) throws IOException {
FileWriter fw = new FileWriter(target);
fw.write(XML_HEADER + "\n");
fw.write(TAG_GPX + "\n");
@@ -48,7 +52,8 @@ public static void writeGpxFile(String trackName, Cursor cTrackPoints, Cursor cW
fw.close();
}
- private static void writeTrackPoints(String trackName, FileWriter fw, Cursor c) throws IOException {
+ private static void writeTrackPoints(String trackName, FileWriter fw,
+ Cursor c) throws IOException {
fw.write("\t" + "<trk>" + "\n");
fw.write("\t\t" + "<name>" + trackName + "</name>" + "\n");
fw.write("\t\t" + "<trkseg>" + "\n");
@@ -56,13 +61,22 @@ private static void writeTrackPoints(String trackName, FileWriter fw, Cursor c)
c.moveToNext();
while (!c.isAfterLast()) {
StringBuffer out = new StringBuffer();
- out.append("\t\t\t" + "<trkpt lat=\"" + c.getDouble(c.getColumnIndex("LATITUDE")) + "\" " + "lon=\""
- + c.getDouble(c.getColumnIndex("LONGITUDE")) + "\">" + "\n");
- out.append("\t\t\t\t" + "<ele>" + c.getDouble(c.getColumnIndex("ALTITUDE")) + "</ele>" + "\n");
- out.append("\t\t\t\t" + "<time>"
- + POINT_DATE_FORMATTER.format(new Date(c.getLong(c.getColumnIndex("TIME")))) + "</time>" + "\n");
- out.append("\t\t\t\t" + "<cmt>speed=" + c.getString(c.getColumnIndex("SPEED")) + "</cmt>" + "\n");
- out.append("\t\t\t\t" + "<hdop>" + c.getString(c.getColumnIndex("ACCURACY")) + "</hdop>" + "\n");
+ out.append("\t\t\t" + "<trkpt lat=\""
+ + c.getDouble(c.getColumnIndex("LATITUDE")) + "\" "
+ + "lon=\"" + c.getDouble(c.getColumnIndex("LONGITUDE"))
+ + "\">" + "\n");
+ out.append("\t\t\t\t" + "<ele>"
+ + c.getDouble(c.getColumnIndex("ALTITUDE")) + "</ele>"
+ + "\n");
+ out.append("\t\t\t\t"
+ + "<time>"
+ + POINT_DATE_FORMATTER.format(new Date(c.getLong(c
+ .getColumnIndex("TIME")))) + "</time>" + "\n");
+ out.append("\t\t\t\t" + "<cmt>speed="
+ + c.getString(c.getColumnIndex("SPEED")) + "</cmt>" + "\n");
+ out.append("\t\t\t\t" + "<hdop>"
+ + c.getString(c.getColumnIndex("ACCURACY")) + "</hdop>"
+ + "\n");
out.append("\t\t\t" + "</trkpt>" + "\n");
fw.write(out.toString());
@@ -74,18 +88,29 @@ private static void writeTrackPoints(String trackName, FileWriter fw, Cursor c)
fw.write("\t" + "</trk>" + "\n");
}
- private static void writeWayPoints(FileWriter fw, Cursor c) throws IOException {
+ private static void writeWayPoints(FileWriter fw, Cursor c)
+ throws IOException {
c.moveToNext();
while (!c.isAfterLast()) {
StringBuffer out = new StringBuffer();
- out.append("\t" + "<wpt lat=\"" + c.getDouble(c.getColumnIndex("LATITUDE")) + "\" " + "lon=\""
- + c.getDouble(c.getColumnIndex("LONGITUDE")) + "\">" + "\n");
- out.append("\t\t" + "<ele>" + c.getDouble(c.getColumnIndex("ALTITUDE")) + "</ele>" + "\n");
- out.append("\t\t" + "<time>" + POINT_DATE_FORMATTER.format(new Date(c.getLong(c.getColumnIndex("TIME"))))
- + "</time>" + "\n");
- out.append("\t\t" + "<name>" + c.getString(c.getColumnIndex("NAME")) + "</name>" + "\n");
- out.append("\t\t" + "<cmt>speed=" + c.getString(c.getColumnIndex("SPEED")) + "</cmt>" + "\n");
- out.append("\t\t" + "<hdop>" + c.getString(c.getColumnIndex("ACCURACY")) + "</hdop>" + "\n");
+ out.append("\t" + "<wpt lat=\""
+ + c.getDouble(c.getColumnIndex("LATITUDE")) + "\" "
+ + "lon=\"" + c.getDouble(c.getColumnIndex("LONGITUDE"))
+ + "\">" + "\n");
+ out.append("\t\t" + "<ele>"
+ + c.getDouble(c.getColumnIndex("ALTITUDE")) + "</ele>"
+ + "\n");
+ out.append("\t\t"
+ + "<time>"
+ + POINT_DATE_FORMATTER.format(new Date(c.getLong(c
+ .getColumnIndex("TIME")))) + "</time>" + "\n");
+ out.append("\t\t" + "<name>"
+ + c.getString(c.getColumnIndex("NAME")) + "</name>" + "\n");
+ out.append("\t\t" + "<cmt>speed="
+ + c.getString(c.getColumnIndex("SPEED")) + "</cmt>" + "\n");
+ out.append("\t\t" + "<hdop>"
+ + c.getString(c.getColumnIndex("ACCURACY")) + "</hdop>"
+ + "\n");
out.append("\t" + "</wpt>" + "\n");
fw.write(out.toString());
View
43 src/biz/bokhorst/Preferences.java
@@ -1,22 +1,23 @@
package biz.bokhorst;
/*
- Copyright 2011 Marcel Bokhorst
+ Copyright 2011, 2012 Marcel Bokhorst
+ All Rights Reserved
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
import java.util.ArrayList;
import java.util.List;
@@ -63,9 +64,10 @@ public void onCreate(Bundle savedInstanceState) {
Preference p = this.getPreferenceScreen().findPreference("TrackName");
p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- ListPreference lp = (ListPreference) Preferences.this.getPreferenceScreen().findPreference(
- "TrackNameList");
+ public boolean onPreferenceChange(Preference preference,
+ Object newValue) {
+ ListPreference lp = (ListPreference) Preferences.this
+ .getPreferenceScreen().findPreference("TrackNameList");
SharedPreferences.Editor editor = lp.getEditor();
editor.putString("TrackNameList", (String) newValue);
editor.commit();
@@ -75,12 +77,15 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
});
// Track name list
- ListPreference lp = (ListPreference) this.getPreferenceScreen().findPreference("TrackNameList");
+ ListPreference lp = (ListPreference) this.getPreferenceScreen()
+ .findPreference("TrackNameList");
setTrackNameList(lp);
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- Preference p = Preferences.this.getPreferenceScreen().findPreference("TrackName");
+ public boolean onPreferenceChange(Preference preference,
+ Object newValue) {
+ Preference p = Preferences.this.getPreferenceScreen()
+ .findPreference("TrackName");
SharedPreferences.Editor editor = p.getEditor();
editor.putString("TrackName", (String) newValue);
editor.commit();
View
BIN  src/org/xmlrpc/android/Base64Coder.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/IXMLRPCSerializer.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/MethodCall.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/Tag.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/XMLRPCClient.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/XMLRPCCommon.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/XMLRPCException.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/XMLRPCFault.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/XMLRPCSerializable.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/XMLRPCSerializer.class
Binary file not shown
View
BIN  src/org/xmlrpc/android/XMLRPCServer.class
Binary file not shown
View
2  wp/bpt.php
@@ -3,7 +3,7 @@
Plugin Name: BackPackTrack
Plugin URI: http://blog.bokhorst.biz/5283/computers-en-internet/backpacktrack-for-android/
Description: BackPackTrack XML-RPC methods
-Version: 0.3
+Version: 0.4
Author: Marcel Bokhorst
Author URI: http://blog.bokhorst.biz/about/
*/
View
9 wp/readme.txt
@@ -3,8 +3,8 @@ Contributors: Marcel Bokhorst, M66B
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=AJSBB7DGNA3MJ&lc=US&item_name=BackPackTrack%20for%20Android&item_number=Marcel%20Bokhorst&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted
Tags: android, gpx, post, posts, maps, google, google maps, routes, tracks, geocode, geotag
Requires at least: 3.1
-Tested up to: 3.2
-Stable tag: 0.3
+Tested up to: 3.3.1
+Stable tag: 0.4
WordPress plugin and open source Android application to track and display your journeys
@@ -100,6 +100,11 @@ You can report issues [here](https://github.com/M66B/BackPackTrack/issues "githu
== Changelog ==
+= 0.4 =
+* Improvement: Android: acquiring partial wake lock
+* Improvement: Android: more source code documentation
+* Improvement: Android: list newest waypoint first
+
= 0.3 =
* Improvement: added option to write GPX file to external storage
Please sign in to comment.
Something went wrong with that request. Please try again.