forked from upstream-mirrors/OpenTracks
Cleanup.
This commit is contained in:
@@ -60,6 +60,7 @@ import de.dennisguse.opentracks.util.ActivityUtils;
|
|||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
import de.dennisguse.opentracks.util.ListItemUtils;
|
import de.dennisguse.opentracks.util.ListItemUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
import de.dennisguse.opentracks.util.ServiceUtils;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
import de.dennisguse.opentracks.util.TrackUtils;
|
import de.dennisguse.opentracks.util.TrackUtils;
|
||||||
@@ -382,7 +383,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
boolean isGpsStarted = TrackRecordingServiceConnection.isRecordingServiceRunning(this);
|
boolean isGpsStarted = ServiceUtils.isTrackRecordingServiceRunning(this);
|
||||||
boolean isRecording = PreferencesUtils.isRecording(recordingTrackId);
|
boolean isRecording = PreferencesUtils.isRecording(recordingTrackId);
|
||||||
updateMenuItems(isGpsStarted, isRecording);
|
updateMenuItems(isGpsStarted, isRecording);
|
||||||
|
|
||||||
@@ -402,7 +403,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
startGps = !TrackRecordingServiceConnection.isRecordingServiceRunning(this);
|
startGps = !ServiceUtils.isTrackRecordingServiceRunning(this);
|
||||||
|
|
||||||
// Show toast
|
// Show toast
|
||||||
Toast toast = Toast.makeText(this, startGps ? R.string.gps_starting : R.string.gps_stopping, Toast.LENGTH_SHORT);
|
Toast toast = Toast.makeText(this, startGps ? R.string.gps_starting : R.string.gps_stopping, Toast.LENGTH_SHORT);
|
||||||
|
|||||||
+3
-30
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks.services;
|
package de.dennisguse.opentracks.services;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -29,14 +28,13 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.BuildConfig;
|
import de.dennisguse.opentracks.BuildConfig;
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.TrackEditActivity;
|
import de.dennisguse.opentracks.TrackEditActivity;
|
||||||
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
import de.dennisguse.opentracks.util.ServiceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the track recording service.
|
* Wrapper for the track recording service.
|
||||||
@@ -154,7 +152,7 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!startIfNeeded && !isRecordingServiceRunning(context)) {
|
if (!startIfNeeded && !ServiceUtils.isTrackRecordingServiceRunning(context)) {
|
||||||
Log.d(TAG, "Service is not started. Not binding it.");
|
Log.d(TAG, "Service is not started. Not binding it.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -169,31 +167,6 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death
|
|||||||
context.bindService(new Intent(context, TrackRecordingService.class), this, flags);
|
context.bindService(new Intent(context, TrackRecordingService.class), this, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the recording service is running.
|
|
||||||
*
|
|
||||||
* @param context the current context
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static boolean isRecordingServiceRunning(Context context) {
|
|
||||||
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
if (activityManager == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO This approach is deprecated as of API level 26 and should be replaced.
|
|
||||||
List<ActivityManager.RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
|
|
||||||
|
|
||||||
for (ActivityManager.RunningServiceInfo serviceInfo : services) {
|
|
||||||
ComponentName componentName = serviceInfo.service;
|
|
||||||
String serviceName = componentName.getClassName();
|
|
||||||
if (TrackRecordingService.class.getName().equals(serviceName)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resumes the track recording service connection.
|
* Resumes the track recording service connection.
|
||||||
*
|
*
|
||||||
@@ -201,7 +174,7 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death
|
|||||||
*/
|
*/
|
||||||
public void startConnection(@NonNull Context context) {
|
public void startConnection(@NonNull Context context) {
|
||||||
bindIfStarted();
|
bindIfStarted();
|
||||||
if (!isRecordingServiceRunning(context)) {
|
if (!ServiceUtils.isTrackRecordingServiceRunning(context)) {
|
||||||
resetRecordingState(context);
|
resetRecordingState(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package de.dennisguse.opentracks.util;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||||
|
|
||||||
|
public class ServiceUtils {
|
||||||
|
|
||||||
|
private ServiceUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the recording service is running.
|
||||||
|
*
|
||||||
|
* @param context the current context
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static boolean isTrackRecordingServiceRunning(Context context) {
|
||||||
|
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
if (activityManager == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO This approach is deprecated as of API level 26 and should be replaced.
|
||||||
|
List<ActivityManager.RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
|
||||||
|
|
||||||
|
for (ActivityManager.RunningServiceInfo serviceInfo : services) {
|
||||||
|
ComponentName componentName = serviceInfo.service;
|
||||||
|
String serviceName = componentName.getClassName();
|
||||||
|
if (TrackRecordingService.class.getName().equals(serviceName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user