Compare commits
No commits in common. "eb8dc8384653b74c82d0665c48b4711530067e8c" and "c2787d179abc0a18c865ecf057793ae9e97781f9" have entirely different histories.
eb8dc83846
...
c2787d179a
|
|
@ -26,8 +26,8 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,9 +51,5 @@ dependencies {
|
||||||
// optional - Guava support for Room, including Optional and ListenableFuture
|
// optional - Guava support for Room, including Optional and ListenableFuture
|
||||||
implementation("androidx.room:room-guava:$room_version")
|
implementation("androidx.room:room-guava:$room_version")
|
||||||
|
|
||||||
implementation("io.jenetics:jpx:3.1.0")
|
|
||||||
// https://mvnrepository.com/artifact/org.codehaus.woodstox/woodstox-core-asl
|
|
||||||
implementation("org.codehaus.woodstox:woodstox-core-asl:4.4.1")
|
|
||||||
implementation("com.github.pengrad:java-telegram-bot-api:7.9.1")
|
implementation("com.github.pengrad:java-telegram-bot-api:7.9.1")
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
@ -114,18 +114,6 @@ public class LocationLoggingService extends Service implements LocationListener
|
||||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
|
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
public Location getLastKnownLocation(){
|
|
||||||
LocationManager locationManager = (LocationManager) getSystemService(Service.LOCATION_SERVICE);
|
|
||||||
return locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendLastKnownLocationToTelegram(){
|
|
||||||
Location lastKnownLocation = getLastKnownLocation();
|
|
||||||
this.lastLocation = lastKnownLocation;
|
|
||||||
sendLocationToTelegram(lastKnownLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
Log.d(TAG, "Service has been destroyed.");
|
Log.d(TAG, "Service has been destroyed.");
|
||||||
|
|
@ -176,17 +164,17 @@ public class LocationLoggingService extends Service implements LocationListener
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastLocation = newLocation;
|
|
||||||
sendLocationToTelegram(lastLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendLocationToTelegram(Location location) {
|
|
||||||
if(!internetAvailable)
|
if(!internetAvailable)
|
||||||
{
|
{
|
||||||
Log.i(TAG, "Internet is not available.");
|
Log.i(TAG, "Internet is not available.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastLocation = newLocation;
|
||||||
|
sendLocationToTelegram(lastLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendLocationToTelegram(Location location){
|
||||||
String botToken = getResources().getString(R.string.telegramToken);
|
String botToken = getResources().getString(R.string.telegramToken);
|
||||||
String telegramChat = getResources().getString(R.string.telegramChat);
|
String telegramChat = getResources().getString(R.string.telegramChat);
|
||||||
TelegramBot bot = new TelegramBot(botToken);
|
TelegramBot bot = new TelegramBot(botToken);
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,4 @@ public class LocationLoggingServiceBinder extends Binder {
|
||||||
public List<LocationEntity> allLocations(){
|
public List<LocationEntity> allLocations(){
|
||||||
return this.service.allLocations();
|
return this.service.allLocations();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLastKnownLocationToTelegram(){
|
|
||||||
this.service.sendLastKnownLocationToTelegram();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import android.location.LocationListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.activity.EdgeToEdge;
|
import androidx.activity.EdgeToEdge;
|
||||||
|
|
@ -19,30 +18,13 @@ import androidx.core.graphics.Insets;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.core.view.WindowInsetsCompat;
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PipedInputStream;
|
|
||||||
import java.io.PipedOutputStream;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import io.jenetics.jpx.GPX;
|
|
||||||
import io.jenetics.jpx.WayPoint;
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements LocationListener, ServiceConnection {
|
public class MainActivity extends AppCompatActivity implements LocationListener, ServiceConnection {
|
||||||
private final String TAG = MainActivity.class.getName();
|
private final String TAG = MainActivity.class.getName();
|
||||||
private Button exportButton;
|
|
||||||
private Button sendTelegramButton;
|
|
||||||
private WriteToFile writeToFile;
|
|
||||||
private static boolean includeComments = false;
|
|
||||||
private static Double accuracyThreshold = 2.0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
writeToFile = new WriteToFile(this,"application/gpx");
|
|
||||||
|
|
||||||
Intent serviceIntent = new Intent(this, LocationLoggingService.class);
|
Intent serviceIntent = new Intent(this, LocationLoggingService.class);
|
||||||
startForegroundService(serviceIntent);
|
startForegroundService(serviceIntent);
|
||||||
|
|
||||||
|
|
@ -53,9 +35,6 @@ public class MainActivity extends AppCompatActivity implements LocationListener,
|
||||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||||
return insets;
|
return insets;
|
||||||
});
|
});
|
||||||
|
|
||||||
exportButton = findViewById(R.id.buttonExport);
|
|
||||||
sendTelegramButton = findViewById(R.id.buttonSendTelegram);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -90,95 +69,6 @@ public class MainActivity extends AppCompatActivity implements LocationListener,
|
||||||
|
|
||||||
LocationLoggingServiceBinder binder = (LocationLoggingServiceBinder) iBinder;
|
LocationLoggingServiceBinder binder = (LocationLoggingServiceBinder) iBinder;
|
||||||
binder.subscribeToLocationUpdates(this);
|
binder.subscribeToLocationUpdates(this);
|
||||||
|
|
||||||
if(sendTelegramButton != null){
|
|
||||||
sendTelegramButton.setOnClickListener(v -> {
|
|
||||||
binder.sendLastKnownLocationToTelegram();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(exportButton != null){
|
|
||||||
exportButton.setOnClickListener(v -> {
|
|
||||||
Log.d(TAG, "Export button clicked.");
|
|
||||||
new Thread(() -> {
|
|
||||||
GPX gpx = GPX.builder().addTrack(track -> track.addSegment(segment -> {
|
|
||||||
for(LocationEntity location : binder.allLocations()){
|
|
||||||
WayPoint wayPoint = locationToWayPoint(location);
|
|
||||||
if(wayPoint != null) {
|
|
||||||
segment.addPoint(wayPoint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})).build();
|
|
||||||
Log.d(TAG, "Built GPX.");
|
|
||||||
|
|
||||||
writeToFile.write("output.gpx", outputStream -> {
|
|
||||||
try {
|
|
||||||
GPX.Writer.of(GPX.Writer.Indent.SPACE4).write(gpx, outputStream);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Failed to write.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).start();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static WayPoint locationToWayPoint(LocationEntity location) {
|
|
||||||
if(accuracyThreshold != null)
|
|
||||||
{
|
|
||||||
if(location.accuracy == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.accuracy > accuracyThreshold) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WayPoint.Builder builder = WayPoint.builder()
|
|
||||||
.lat(location.latitude)
|
|
||||||
.lon(location.longitude)
|
|
||||||
.time(location.unixTime);
|
|
||||||
|
|
||||||
if(location.speed != null){
|
|
||||||
builder.speed(location.speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.bearing != null){
|
|
||||||
builder.course(location.bearing);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.altitude != null){
|
|
||||||
builder.ele(location.altitude);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(includeComments) {
|
|
||||||
StringBuilder commentBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
if (location.isMock) {
|
|
||||||
commentBuilder.append("Location is mock.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location.accuracy != null) {
|
|
||||||
commentBuilder.append(String.format("Accuracy is expected to be within %s meters.\n", location.accuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location.altitudeAccuracy != null) {
|
|
||||||
commentBuilder.append(String.format("Altitude accuracy is expected to be within %s meters.\n", location.altitudeAccuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location.bearingAccuracy != null) {
|
|
||||||
commentBuilder.append(String.format("Bearing accuracy is expected to be within %s degrees.\n", location.bearingAccuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location.speedAccuracy != null) {
|
|
||||||
commentBuilder.append(String.format("Speed accuracy is expected to be within %s meters per second.\n", location.speedAccuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.cmt(commentBuilder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -18,21 +18,4 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/buttonExport"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textViewMain"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
android:text="Export"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
<Button
|
|
||||||
android:id="@+id/buttonSendTelegram"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/buttonExport"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
android:text="Send to telegram" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
Reference in a new issue