Compare commits
No commits in common. "1b7e725026d5f48b29af9233a448a58e02dffc32" and "1a647885904d7847c439a4e8c752a3533b647fca" have entirely different histories.
1b7e725026
...
1a64788590
|
|
@ -1,10 +0,0 @@
|
||||||
package com.proculite.logmylocation;
|
|
||||||
|
|
||||||
import androidx.room.Dao;
|
|
||||||
import androidx.room.Insert;
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
public interface LocationDao {
|
|
||||||
@Insert
|
|
||||||
void insert(LocationEntity location);
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
package com.proculite.logmylocation;
|
|
||||||
|
|
||||||
import androidx.room.Database;
|
|
||||||
import androidx.room.RoomDatabase;
|
|
||||||
|
|
||||||
@Database(entities = {LocationEntity.class}, version = 2)
|
|
||||||
public abstract class LocationDatabase extends RoomDatabase {
|
|
||||||
public abstract LocationDao locationDao();
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
package com.proculite.logmylocation;
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo;
|
|
||||||
import androidx.room.Entity;
|
|
||||||
import androidx.room.PrimaryKey;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class LocationEntity {
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
public long id;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "accuracy")
|
|
||||||
public Float accuracy;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "altitude")
|
|
||||||
public Double altitude;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "altitude_accuracy")
|
|
||||||
public Float altitudeAccuracy;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "msl_altitude")
|
|
||||||
public Double mslAltitude;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "msl_altitude_accuracy")
|
|
||||||
public Float mslAltitudeAccuracy;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "bearing")
|
|
||||||
public Float bearing;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "latitude")
|
|
||||||
public double latitude;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "longitude")
|
|
||||||
public double longitude;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "speed")
|
|
||||||
public Float speed;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "speed_accuracy")
|
|
||||||
public Float speedAccuracy;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "unix_time")
|
|
||||||
public long unixTime;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "is_mock")
|
|
||||||
public boolean isMock;
|
|
||||||
}
|
|
||||||
|
|
@ -7,19 +7,16 @@ import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.location.LocationProvider;
|
import android.location.LocationProvider;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.location.LocationManagerCompat;
|
import androidx.core.location.LocationManagerCompat;
|
||||||
import androidx.room.Room;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LocationLoggingService extends Service implements LocationListener {
|
public class LocationLoggingService extends Service implements LocationListener {
|
||||||
private final String TAG = LocationLoggingService.class.getName();
|
private final String TAG = LocationLoggingService.class.getName();
|
||||||
private LocationDao locationDao;
|
|
||||||
|
|
||||||
public LocationLoggingService() {
|
public LocationLoggingService() {
|
||||||
}
|
}
|
||||||
|
|
@ -33,13 +30,6 @@ public class LocationLoggingService extends Service implements LocationListener
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
Log.d(TAG, "Service started.");
|
Log.d(TAG, "Service started.");
|
||||||
|
|
||||||
LocationDatabase database = Room
|
|
||||||
.databaseBuilder(getApplicationContext(), LocationDatabase.class, "location")
|
|
||||||
.fallbackToDestructiveMigration()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
locationDao = database.locationDao();
|
|
||||||
|
|
||||||
subscribeToLocationUpdates(this);
|
subscribeToLocationUpdates(this);
|
||||||
|
|
||||||
return super.onStartCommand(intent, flags, startId);
|
return super.onStartCommand(intent, flags, startId);
|
||||||
|
|
@ -66,72 +56,12 @@ public class LocationLoggingService extends Service implements LocationListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(@NonNull Location location) {
|
public void onLocationChanged(@NonNull Location location) {
|
||||||
new Thread(()->{
|
|
||||||
Log.d(TAG, String.format(
|
Log.d(TAG, String.format(
|
||||||
"New location. Latitude: %s Longitude: %s Altitude: %s",
|
"New location. Latitude: %s Longitude: %s Altitude: %s",
|
||||||
location.getLatitude(),
|
location.getLatitude(),
|
||||||
location.getLongitude(),
|
location.getLongitude(),
|
||||||
location.getAltitude())
|
location.getAltitude())
|
||||||
);
|
);
|
||||||
|
|
||||||
if(locationDao == null)
|
|
||||||
{
|
|
||||||
Log.w(TAG, "Location DAO is null, could not write new location.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationEntity locationEntity = new LocationEntity();
|
|
||||||
|
|
||||||
locationEntity.latitude = location.getLatitude();
|
|
||||||
locationEntity.longitude = location.getLongitude();
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
||||||
locationEntity.isMock = location.isMock();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.hasAccuracy())
|
|
||||||
{
|
|
||||||
locationEntity.accuracy = location.getAccuracy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.hasAltitude())
|
|
||||||
{
|
|
||||||
locationEntity.altitude = location.getAltitude();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.hasBearing())
|
|
||||||
{
|
|
||||||
locationEntity.bearing = location.getBearing();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.hasSpeed())
|
|
||||||
{
|
|
||||||
locationEntity.speed = location.getSpeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.hasSpeedAccuracy())
|
|
||||||
{
|
|
||||||
locationEntity.speedAccuracy = location.getSpeedAccuracyMetersPerSecond();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.hasVerticalAccuracy())
|
|
||||||
{
|
|
||||||
locationEntity.altitudeAccuracy = location.getVerticalAccuracyMeters();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
||||||
if(location.hasMslAltitude())
|
|
||||||
{
|
|
||||||
locationEntity.mslAltitude = location.getMslAltitudeMeters();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.hasMslAltitudeAccuracy())
|
|
||||||
{
|
|
||||||
locationEntity.mslAltitudeAccuracy = location.getMslAltitudeAccuracyMeters();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
locationDao.insert(locationEntity);
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue