Сравнить коммиты
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
1b0559c98a | ||
|
|
2e0e7ea453 | ||
|
|
ac6d677ff4 | ||
|
|
cbfe90757d | ||
|
|
a9f4390ae4 | ||
|
|
8a938701c8 | ||
|
|
2319834c5b | ||
|
|
1b93619e64 | ||
|
|
2a36e1aa6d | ||
|
|
64687b26c2 | ||
|
|
dcb60ab75e | ||
|
|
0b4c4cccc6 | ||
|
|
ef5bfff70a | ||
|
|
855efc7acb | ||
|
|
0ae47e65d4 | ||
|
|
e8d5e5c99b | ||
|
|
c3980780d8 | ||
|
|
3c11216334 | ||
|
|
bcde8388d6 | ||
|
|
7f18915514 | ||
|
|
42ad669fca |
+16
-11
@@ -1,16 +1,16 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 27
|
compileSdkVersion 28
|
||||||
buildToolsVersion '27.0.3'
|
buildToolsVersion '28.0.2'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.traccar.client"
|
applicationId "org.traccar.client"
|
||||||
buildConfigField "boolean", "HIDDEN_APP", "false"
|
buildConfigField "boolean", "HIDDEN_APP", "false"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 27
|
targetSdkVersion 28
|
||||||
versionCode 47
|
versionCode 52
|
||||||
versionName '5.10'
|
versionName '5.15'
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
@@ -26,15 +26,20 @@ android {
|
|||||||
buildConfigField "boolean", "HIDDEN_APP", "true"
|
buildConfigField "boolean", "HIDDEN_APP", "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions {
|
||||||
|
unitTests {
|
||||||
|
includeAndroidResources = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.android.support:design:27.1.0'
|
implementation 'com.android.support:design:28.0.0-rc02'
|
||||||
compile 'com.mapzen.android:lost:3.0.4'
|
testImplementation 'junit:junit:4.12'
|
||||||
testCompile 'junit:junit:4.12'
|
testImplementation 'org.robolectric:robolectric:3.8'
|
||||||
testCompile 'org.robolectric:robolectric:3.6.1'
|
googleImplementation 'com.google.firebase:firebase-core:16.0.3'
|
||||||
googleCompile 'com.google.firebase:firebase-core:11.8.0'
|
googleImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
|
||||||
googleCompile 'com.crashlytics.sdk.android:crashlytics:2.9.1'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Google")) {
|
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Google")) {
|
||||||
|
|||||||
@@ -9,15 +9,21 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:name=".MainApplication">
|
android:name=".MainApplication">
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="google_analytics_adid_collection_enabled"
|
||||||
|
android:value="false" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:launchMode="singleTask" />
|
android:launchMode="singleTask" />
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public static final int DATABASE_VERSION = 2;
|
public static final int DATABASE_VERSION = 3;
|
||||||
public static final String DATABASE_NAME = "traccar.db";
|
public static final String DATABASE_NAME = "traccar.db";
|
||||||
|
|
||||||
public interface DatabaseHandler<T> {
|
public interface DatabaseHandler<T> {
|
||||||
@@ -80,7 +80,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
"speed REAL," +
|
"speed REAL," +
|
||||||
"course REAL," +
|
"course REAL," +
|
||||||
"accuracy REAL," +
|
"accuracy REAL," +
|
||||||
"battery REAL)");
|
"battery REAL," +
|
||||||
|
"mock INTEGER)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,6 +90,11 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS position;");
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
|
||||||
public void insertPosition(Position position) {
|
public void insertPosition(Position position) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put("deviceId", position.getDeviceId());
|
values.put("deviceId", position.getDeviceId());
|
||||||
@@ -100,6 +106,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
values.put("course", position.getCourse());
|
values.put("course", position.getCourse());
|
||||||
values.put("accuracy", position.getAccuracy());
|
values.put("accuracy", position.getAccuracy());
|
||||||
values.put("battery", position.getBattery());
|
values.put("battery", position.getBattery());
|
||||||
|
values.put("mock", position.getMock() ? 1 : 0);
|
||||||
|
|
||||||
db.insertOrThrow("position", null, values);
|
db.insertOrThrow("position", null, values);
|
||||||
}
|
}
|
||||||
@@ -133,6 +140,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
position.setCourse(cursor.getDouble(cursor.getColumnIndex("course")));
|
position.setCourse(cursor.getDouble(cursor.getColumnIndex("course")));
|
||||||
position.setAccuracy(cursor.getDouble(cursor.getColumnIndex("accuracy")));
|
position.setAccuracy(cursor.getDouble(cursor.getColumnIndex("accuracy")));
|
||||||
position.setBattery(cursor.getDouble(cursor.getColumnIndex("battery")));
|
position.setBattery(cursor.getDouble(cursor.getColumnIndex("battery")));
|
||||||
|
position.setMock(cursor.getInt(cursor.getColumnIndex("mock")) > 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 Anton Tananaev (anton@traccar.org)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.traccar.client;
|
|
||||||
|
|
||||||
public final class DistanceCalculator {
|
|
||||||
|
|
||||||
private static final double EQUATORIAL_EARTH_RADIUS = 6378.1370;
|
|
||||||
private static final double DEG_TO_RAD = Math.PI / 180;
|
|
||||||
|
|
||||||
public static double distance(double lat1, double lon1, double lat2, double lon2) {
|
|
||||||
double dlong = (lon2 - lon1) * DEG_TO_RAD;
|
|
||||||
double dlat = (lat2 - lat1) * DEG_TO_RAD;
|
|
||||||
double a = Math.pow(Math.sin(dlat / 2), 2)
|
|
||||||
+ Math.cos(lat1 * DEG_TO_RAD) * Math.cos(lat2 * DEG_TO_RAD) * Math.pow(Math.sin(dlong / 2), 2);
|
|
||||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
||||||
double d = EQUATORIAL_EARTH_RADIUS * c;
|
|
||||||
return d * 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015 - 2017 Anton Tananaev (anton.tananaev@gmail.com)
|
* Copyright 2015 - 2018 Anton Tananaev (anton.tananaev@gmail.com)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,6 +17,7 @@ package org.traccar.client;
|
|||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -37,6 +38,9 @@ public class Position {
|
|||||||
accuracy = location.getAccuracy();
|
accuracy = location.getAccuracy();
|
||||||
}
|
}
|
||||||
this.battery = battery;
|
this.battery = battery;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
|
this.mock = location.isFromMockProvider();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
@@ -139,4 +143,14 @@ public class Position {
|
|||||||
this.battery = battery;
|
this.battery = battery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean mock;
|
||||||
|
|
||||||
|
public boolean getMock() {
|
||||||
|
return mock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMock(boolean mock) {
|
||||||
|
this.mock = mock;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,16 +21,15 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.location.LocationListener;
|
||||||
|
import android.location.LocationManager;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.mapzen.android.lost.api.LocationListener;
|
public class PositionProvider implements LocationListener {
|
||||||
import com.mapzen.android.lost.api.LocationRequest;
|
|
||||||
import com.mapzen.android.lost.api.LocationServices;
|
|
||||||
import com.mapzen.android.lost.api.LostApiClient;
|
|
||||||
|
|
||||||
public class PositionProvider implements LostApiClient.ConnectionCallbacks, LocationListener {
|
|
||||||
|
|
||||||
private static final String TAG = PositionProvider.class.getSimpleName();
|
private static final String TAG = PositionProvider.class.getSimpleName();
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ public class PositionProvider implements LostApiClient.ConnectionCallbacks, Loca
|
|||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private SharedPreferences preferences;
|
private SharedPreferences preferences;
|
||||||
private LostApiClient apiClient;
|
private LocationManager locationManager;
|
||||||
|
|
||||||
private String deviceId;
|
private String deviceId;
|
||||||
private long interval;
|
private long interval;
|
||||||
@@ -53,12 +52,12 @@ public class PositionProvider implements LostApiClient.ConnectionCallbacks, Loca
|
|||||||
|
|
||||||
private Location lastLocation;
|
private Location lastLocation;
|
||||||
|
|
||||||
private boolean started;
|
|
||||||
|
|
||||||
public PositionProvider(Context context, PositionListener listener) {
|
public PositionProvider(Context context, PositionListener listener) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
||||||
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
deviceId = preferences.getString(MainFragment.KEY_DEVICE, "undefined");
|
deviceId = preferences.getString(MainFragment.KEY_DEVICE, "undefined");
|
||||||
@@ -67,33 +66,25 @@ public class PositionProvider implements LostApiClient.ConnectionCallbacks, Loca
|
|||||||
angle = Integer.parseInt(preferences.getString(MainFragment.KEY_ANGLE, "0"));
|
angle = Integer.parseInt(preferences.getString(MainFragment.KEY_ANGLE, "0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
public void startUpdates() {
|
public void startUpdates() {
|
||||||
started = true;
|
try {
|
||||||
apiClient = new LostApiClient.Builder(context).addConnectionCallbacks(this).build();
|
locationManager.requestLocationUpdates(
|
||||||
apiClient.connect();
|
getProvider(preferences.getString(MainFragment.KEY_ACCURACY, "medium")),
|
||||||
|
distance > 0 || angle > 0 ? MINIMUM_INTERVAL : interval, 0, this);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPriority(String accuracy) {
|
public static String getProvider(String accuracy) {
|
||||||
switch (accuracy) {
|
switch (accuracy) {
|
||||||
case "high":
|
case "high":
|
||||||
return LocationRequest.PRIORITY_HIGH_ACCURACY;
|
return LocationManager.GPS_PROVIDER;
|
||||||
case "low":
|
case "low":
|
||||||
return LocationRequest.PRIORITY_LOW_POWER;
|
return LocationManager.PASSIVE_PROVIDER;
|
||||||
default:
|
default:
|
||||||
return LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
|
return LocationManager.NETWORK_PROVIDER;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
@Override
|
|
||||||
public void onConnected() {
|
|
||||||
if (started) {
|
|
||||||
LocationRequest request = LocationRequest.create()
|
|
||||||
.setPriority(getPriority(preferences.getString(MainFragment.KEY_ACCURACY, "medium")))
|
|
||||||
.setInterval(distance > 0 || angle > 0 ? MINIMUM_INTERVAL : interval);
|
|
||||||
LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, request, this);
|
|
||||||
} else {
|
|
||||||
apiClient.disconnect();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +92,7 @@ public class PositionProvider implements LostApiClient.ConnectionCallbacks, Loca
|
|||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
if (location != null && (lastLocation == null
|
if (location != null && (lastLocation == null
|
||||||
|| location.getTime() - lastLocation.getTime() >= interval
|
|| location.getTime() - lastLocation.getTime() >= interval
|
||||||
|| distance > 0 && DistanceCalculator.distance(location.getLatitude(), location.getLongitude(), lastLocation.getLatitude(), lastLocation.getLongitude()) >= distance
|
|| distance > 0 && location.distanceTo(lastLocation) >= distance
|
||||||
|| angle > 0 && Math.abs(location.getBearing() - lastLocation.getBearing()) >= angle)) {
|
|| angle > 0 && Math.abs(location.getBearing() - lastLocation.getBearing()) >= angle)) {
|
||||||
Log.i(TAG, "location new");
|
Log.i(TAG, "location new");
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
@@ -112,16 +103,19 @@ public class PositionProvider implements LostApiClient.ConnectionCallbacks, Loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionSuspended() {
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
Log.i(TAG, "lost client suspended");
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopUpdates() {
|
public void stopUpdates() {
|
||||||
if (apiClient.isConnected()) {
|
locationManager.removeUpdates(this);
|
||||||
LocationServices.FusedLocationApi.removeLocationUpdates(apiClient, this);
|
|
||||||
apiClient.disconnect();
|
|
||||||
}
|
|
||||||
started = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getBatteryLevel(Context context) {
|
public static double getBatteryLevel(Context context) {
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ public class ProtocolFormatter {
|
|||||||
.appendQueryParameter("accuracy", String.valueOf(position.getAccuracy()))
|
.appendQueryParameter("accuracy", String.valueOf(position.getAccuracy()))
|
||||||
.appendQueryParameter("batt", String.valueOf(position.getBattery()));
|
.appendQueryParameter("batt", String.valueOf(position.getBattery()));
|
||||||
|
|
||||||
|
if (position.getMock()) {
|
||||||
|
builder.appendQueryParameter("mock", String.valueOf(position.getMock()));
|
||||||
|
}
|
||||||
|
|
||||||
if (alarm != null) {
|
if (alarm != null) {
|
||||||
builder.appendQueryParameter("alarm", alarm);
|
builder.appendQueryParameter("alarm", alarm);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.traccar.client;
|
package org.traccar.client;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.location.Criteria;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.location.LocationListener;
|
||||||
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Looper;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
@@ -32,10 +38,7 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.mapzen.android.lost.api.LocationServices;
|
public class ShortcutActivity extends AppCompatActivity {
|
||||||
import com.mapzen.android.lost.api.LostApiClient;
|
|
||||||
|
|
||||||
public class ShortcutActivity extends AppCompatActivity implements LostApiClient.ConnectionCallbacks {
|
|
||||||
|
|
||||||
public static final String EXTRA_ACTION = "action";
|
public static final String EXTRA_ACTION = "action";
|
||||||
public static final String ACTION_START = "start";
|
public static final String ACTION_START = "start";
|
||||||
@@ -44,8 +47,6 @@ public class ShortcutActivity extends AppCompatActivity implements LostApiClient
|
|||||||
|
|
||||||
private static final String ALARM_SOS = "sos";
|
private static final String ALARM_SOS = "sos";
|
||||||
|
|
||||||
private LostApiClient apiClient;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -102,20 +103,46 @@ public class ShortcutActivity extends AppCompatActivity implements LostApiClient
|
|||||||
setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
|
setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("MissingPermission")
|
||||||
private void sendAlarm() {
|
private void sendAlarm() {
|
||||||
apiClient = new LostApiClient.Builder(this).addConnectionCallbacks(this).build();
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
apiClient.connect();
|
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
|
String provider = PositionProvider.getProvider(
|
||||||
|
preferences.getString(MainFragment.KEY_ACCURACY, "medium"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Location location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
||||||
|
if (location != null) {
|
||||||
|
sendAlarmLocation(location);
|
||||||
|
} else {
|
||||||
|
locationManager.requestSingleUpdate(provider, new LocationListener() {
|
||||||
|
@Override
|
||||||
|
public void onLocationChanged(Location location) {
|
||||||
|
sendAlarmLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("MissingPermission")
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected() {
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {
|
||||||
|
}
|
||||||
|
}, Looper.myLooper());
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendAlarmLocation(Location location) {
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
Location location = LocationServices.FusedLocationApi.getLastLocation(apiClient);
|
|
||||||
|
|
||||||
if (location != null) {
|
|
||||||
|
|
||||||
Position position = new Position(
|
Position position = new Position(
|
||||||
preferences.getString(MainFragment.KEY_DEVICE, null),
|
preferences.getString(MainFragment.KEY_DEVICE, null),
|
||||||
location, PositionProvider.getBatteryLevel(this));
|
location, PositionProvider.getBatteryLevel(this));
|
||||||
@@ -133,16 +160,6 @@ public class ShortcutActivity extends AppCompatActivity implements LostApiClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
|
||||||
Toast.makeText(this, R.string.status_send_fail, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
apiClient.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectionSuspended() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean executeAction(Intent intent) {
|
private boolean executeAction(Intent intent) {
|
||||||
@@ -168,7 +185,12 @@ public class ShortcutActivity extends AppCompatActivity implements LostApiClient
|
|||||||
Toast.makeText(this, R.string.status_service_destroy, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.status_service_destroy, Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
case ACTION_SOS:
|
case ACTION_SOS:
|
||||||
|
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
|
&& ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||||
sendAlarm();
|
sendAlarm();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, R.string.status_send_fail, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class StatusActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addMessage(String message) {
|
public static void addMessage(String message) {
|
||||||
DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT);
|
DateFormat format = DateFormat.getTimeInstance(DateFormat.MEDIUM);
|
||||||
message = format.format(new Date()) + " - " + message;
|
message = format.format(new Date()) + " - " + message;
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
while (messages.size() > LIMIT) {
|
while (messages.size() > LIMIT) {
|
||||||
|
|||||||
@@ -78,15 +78,18 @@ public class TrackingService extends Service {
|
|||||||
Log.i(TAG, "service create");
|
Log.i(TAG, "service create");
|
||||||
StatusActivity.addMessage(getString(R.string.status_service_create));
|
StatusActivity.addMessage(getString(R.string.status_service_create));
|
||||||
|
|
||||||
|
startForeground(NOTIFICATION_ID, createNotification(this));
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
&& ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
&& ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||||
trackingController = new TrackingController(this);
|
trackingController = new TrackingController(this);
|
||||||
trackingController.start();
|
trackingController.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
startForeground(NOTIFICATION_ID, createNotification(this));
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
ContextCompat.startForegroundService(this, new Intent(this, HideNotificationService.class));
|
ContextCompat.startForegroundService(this, new Intent(this, HideNotificationService.class));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<network-security-config>
|
||||||
|
<base-config cleartextTrafficPermitted="true" />
|
||||||
|
</network-security-config>
|
||||||
+3
-4
@@ -5,9 +5,9 @@ buildscript {
|
|||||||
maven { url 'https://maven.fabric.io/public' }
|
maven { url 'https://maven.fabric.io/public' }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||||
classpath 'com.google.gms:google-services:3.1.1'
|
classpath 'com.google.gms:google-services:4.0.2'
|
||||||
classpath 'io.fabric.tools:gradle:1.25.1'
|
classpath 'io.fabric.tools:gradle:1.25.4'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,6 +15,5 @@ allprojects {
|
|||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
maven { url 'https://maven.fabric.io/public' }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user