Skip to content
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
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms
# github: [labexp]
liberapay: OSMTracker
4 changes: 2 additions & 2 deletions app/src/main/java/net/osmtracker/OSMTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static final class Preferences {
public final static String VAL_UI_ORIENTATION_LANDSCAPE = "landscape";
public final static String VAL_UI_ORIENTATION = VAL_UI_ORIENTATION_NONE;

public final static String VAL_UI_MAP_TILE_MAPNIK = "MAPNIK";
public final static String VAL_UI_MAP_TILE_MAPNIK = "Mapnik";

//default values for repository settings
public final static String VAL_GITHUB_USERNAME = "labexp";
Expand Down Expand Up @@ -187,4 +187,4 @@ public static final class Preferences {
public static final class Devices {
public static final String NEXUS_S = "Nexus S";
}
}
}
116 changes: 115 additions & 1 deletion app/src/main/java/net/osmtracker/activity/DisplayTrackMap.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.osmtracker.activity;

import android.app.Activity;
import android.content.ContentValues;
import android.content.ContentUris;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -12,18 +13,24 @@
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.widget.ImageView;

import androidx.preference.PreferenceManager;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.db.DataHelper;
import net.osmtracker.db.TrackContentProvider;
import net.osmtracker.overlay.WayPointsOverlay;
import net.osmtracker.overlay.Polylines;
import net.osmtracker.service.gps.GPSLoggerConnectionListener;
import net.osmtracker.service.gps.GPSLoggerServiceConnection;
import net.osmtracker.service.gps.GPSLogger;

import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
Expand All @@ -50,7 +57,9 @@
* @author Viesturs Zarins
*
*/
public class DisplayTrackMap extends Activity {
public class DisplayTrackMap extends Activity
implements GPSLoggerConnectionListener
{

private static final String TAG = DisplayTrackMap.class.getSimpleName();

Expand Down Expand Up @@ -146,6 +155,11 @@ public class DisplayTrackMap extends Activity {
*/
private boolean zoomedToTrackAlready = false;

/**
* Are we currently tracking?
*/
private boolean isTracking;

/**
* the last position we know
*/
Expand Down Expand Up @@ -173,6 +187,88 @@ public class DisplayTrackMap extends Activity {
*/
private SharedPreferences prefs = null;

private ImageView startStopButton = null;

private GPSLogger gpsLogger;

private GPSLoggerServiceConnection gpsLoggerConnection;

private synchronized GPSLoggerServiceConnection getGpsLoggerConnection() {
if(gpsLoggerConnection == null)
gpsLoggerConnection = new GPSLoggerServiceConnection(this);
return gpsLoggerConnection;
}

private synchronized void unbindGpsLoggerConnection() {
if(gpsLoggerConnection != null) {
unbindService(gpsLoggerConnection);
gpsLoggerConnection=null;
}
}

@Override
public long getCurrentTrackId() {
return currentTrackId;
}

@Override
public void setGpsLogger(GPSLogger l) {
gpsLogger = l;
if(l == null)
isTracking = false;
updateTrackingIcon();
}

@Override
public GPSLogger getGpsLogger() {
return gpsLogger;
}

private boolean isTracking() {
if(gpsLogger != null &&
gpsLogger.isTracking())
isTracking = true;
return isTracking;
}

private void updateTrackingIcon() {
if(startStopButton != null)
startStopButton.setImageResource(isTracking() ?
R.drawable.started :
R.drawable.stopped);
}

private void toggleStartStop() {
DataHelper dataHelper = new DataHelper(this);
boolean forceTracking = false;
if(isTracking()) {
// currently tracking => stop it
Intent intent = new Intent(OSMTracker.INTENT_STOP_TRACKING);
intent.setPackage(getPackageName());
sendBroadcast(intent);

isTracking = false;
dataHelper.stopTracking(currentTrackId);
} else {
// currently not tracking => start it
Intent intent = new Intent(this, GPSLogger.class);
intent.putExtra(TrackContentProvider.Schema.COL_TRACK_ID, currentTrackId);
startService(intent);
bindService(intent, getGpsLoggerConnection(), 0);

// update DB, copied from TrackManager
ContentValues values = new ContentValues();
values.put(TrackContentProvider.Schema.COL_ACTIVE,
TrackContentProvider.Schema.VAL_TRACK_ACTIVE);
getContentResolver().update(TrackContentProvider.CONTENT_URI_TRACK, values,
TrackContentProvider.Schema.COL_ID + " = ?",
new String[] {Long.toString(currentTrackId)});

isTracking = true;
}
updateTrackingIcon();
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -183,6 +279,9 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.displaytrackmap);

currentTrackId = getIntent().getExtras().getLong(TrackContentProvider.Schema.COL_TRACK_ID);
long activeTrackId =
DataHelper.getActiveTrackId(getContentResolver());
isTracking = currentTrackId == activeTrackId;
setTitle(getTitle() + ": #" + currentTrackId);

// Initialize OSM view
Expand Down Expand Up @@ -232,8 +331,23 @@ public void onChange(boolean selfChange) {
osmViewController.animateTo(currentPosition,CENTER_DEFAULT_ZOOM_LEVEL, ANIMATION_DURATION_MS);
}
});
startStopButton =
(ImageView)findViewById(R.id.displaytrackmap_imgStartStop);
if(activeTrackId == currentTrackId ||
activeTrackId == TrackManager.TRACK_ID_NO_TRACK) {
updateTrackingIcon();
startStopButton.setOnClickListener(view -> toggleStartStop());
} else {
startStopButton.setVisibility(View.INVISIBLE);
}
}

@Override
public void onDestroy() {
super.onDestroy();
unbindGpsLoggerConnection();
}

/**
* Sets the map tile provider according to the user's demands in the settings.
*/
Expand Down
65 changes: 38 additions & 27 deletions app/src/main/java/net/osmtracker/activity/TrackLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import net.osmtracker.listener.PressureListener;
import net.osmtracker.listener.SensorListener;
import net.osmtracker.receiver.MediaButtonReceiver;
import net.osmtracker.service.gps.GPSLoggerConnectionListener;
import net.osmtracker.service.gps.GPSLogger;
import net.osmtracker.service.gps.GPSLoggerServiceConnection;
import net.osmtracker.util.CustomLayoutsUtils;
Expand All @@ -67,7 +68,8 @@
* @author Nicolas Guillaumin
*
*/
public class TrackLogger extends Activity {
public class TrackLogger extends Activity
implements GPSLoggerConnectionListener {

private static final String TAG = TrackLogger.class.getSimpleName();

Expand Down Expand Up @@ -332,35 +334,38 @@ protected void onResume() {
OSMTracker.Preferences.VAL_GPS_CHECKSTARTUP)) {
checkGPSProvider();
}

// Register GPS status update for upper controls
((GpsStatusRecord) findViewById(R.id.gpsStatus)).requestLocationUpdates(true);

// Start GPS Logger service
startService(gpsLoggerServiceIntent);

// Bind to GPS service.
// We can't use BIND_AUTO_CREATE here, because when we'll ubound
// later, we want to keep the service alive in background
bindService(gpsLoggerServiceIntent, gpsLoggerConnection, 0);
if(currentTrackId ==
DataHelper.getActiveTrackId(getContentResolver())) {
// Register GPS status update for upper controls
((GpsStatusRecord) findViewById(R.id.gpsStatus)).requestLocationUpdates(true);

// Start GPS Logger service
startService(gpsLoggerServiceIntent);

// Bind to GPS service.
// We can't use BIND_AUTO_CREATE here, because when we'll ubound
// later, we want to keep the service alive in background
bindService(gpsLoggerServiceIntent, gpsLoggerConnection, 0);

// connect the sensor listener
sensorListener.register(this);
// connect the sensor listener
sensorListener.register(this);

// connect the pressure listener
pressureListener.register(this, prefs.getBoolean(OSMTracker.Preferences.KEY_USE_BAROMETER,OSMTracker.Preferences.VAL_USE_BAROMETER));
// connect the pressure listener
pressureListener.register(this, prefs.getBoolean(OSMTracker.Preferences.KEY_USE_BAROMETER,OSMTracker.Preferences.VAL_USE_BAROMETER));

setEnabledActionButtons(buttonsEnabled);
if(!buttonsEnabled){
Toast.makeText(this, R.string.tracklogger_waiting_gps, Toast.LENGTH_LONG).show();
}
setEnabledActionButtons(buttonsEnabled);
if(!buttonsEnabled){
Toast.makeText(this, R.string.tracklogger_waiting_gps, Toast.LENGTH_LONG).show();
}

mAudioManager.registerMediaButtonEventReceiver(mediaButtonReceiver);

//save the layout file name if it change, in tags array
String layoutName = CustomLayoutsUtils.getCurrentLayoutName(getApplicationContext());
layoutNameTags.add(layoutName);
mAudioManager.registerMediaButtonEventReceiver(mediaButtonReceiver);

//save the layout file name if it change, in tags array
String layoutName = CustomLayoutsUtils.getCurrentLayoutName(getApplicationContext());
layoutNameTags.add(layoutName);
} else {
((GpsStatusRecord) findViewById(R.id.gpsStatus)).showStopped();
}
super.onResume();
}

Expand Down Expand Up @@ -396,8 +401,14 @@ protected void onPause() {
if (gpsLogger != null) {
if (!gpsLogger.isTracking()) {
Log.v(TAG, "Service is not tracking, trying to stopService()");
unbindService(gpsLoggerConnection);
stopService(gpsLoggerServiceIntent);
try {
unbindService(gpsLoggerConnection);
} catch(Exception e) {
}
try {
stopService(gpsLoggerServiceIntent);
} catch(Exception e) {
}
} else {
unbindService(gpsLoggerConnection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class TrackManager extends AppCompatActivity
private static final String PREV_VISIBLE = "prev_visible";

/** Constant used if no track is active (-1)*/
private static final long TRACK_ID_NO_TRACK = -1;
public static final long TRACK_ID_NO_TRACK = -1;

// The active track being recorded, if any, or {TRACK_ID_NO_TRACK};
// value is updated in {@link #onResume()}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/net/osmtracker/layout/GpsStatusRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public void requestLocationUpdates(boolean request) {
}
}

public void showStopped() {
TextView tvAccuracy = findViewById(R.id.gpsstatus_record_tvAccuracy);
tvAccuracy.setText(R.string.various_stopped);
}

private GnssStatus.Callback mStatusCallback = new GnssStatus.Callback() {
@Override
public void onSatelliteStatusChanged(GnssStatus status) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.osmtracker.service.gps;

import android.view.View;
import android.content.Intent;
import android.app.Activity;

public interface GPSLoggerConnectionListener {
void setGpsLogger(GPSLogger l);

long getCurrentTrackId();

default void setEnabledActionButtons(boolean enabled) { }

GPSLogger getGpsLogger();

/* Stuff supplied by Activity / AppCompatActivity */
String getPackageName();

void sendBroadcast(Intent intent);

<T extends View> T findViewById (int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.activity.TrackLogger;
import net.osmtracker.layout.GpsStatusRecord;
import net.osmtracker.db.TrackContentProvider;

Expand All @@ -20,11 +19,11 @@
public class GPSLoggerServiceConnection implements ServiceConnection {

/**
* Reference to TrackLogger activity
* Reference to client activity
*/
private TrackLogger activity;
private GPSLoggerConnectionListener activity;

public GPSLoggerServiceConnection(TrackLogger tl) {
public GPSLoggerServiceConnection(GPSLoggerConnectionListener tl) {
activity = tl;
}

Expand Down
Binary file added app/src/main/res/drawable-mdpi/started.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/stopped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading