Сравнить коммиты
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
5ac0610bd5 | ||
|
|
b109de92c4 | ||
|
|
be0d556ed6 | ||
|
|
1861d9ca34 | ||
|
|
c0cc6e8e55 | ||
|
|
1cc3a2d9d1 | ||
|
|
9263b4e08b |
+15
-4
@@ -7,16 +7,16 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 3
|
||||
targetSdkVersion 22
|
||||
versionCode 24
|
||||
versionName "3.4"
|
||||
versionCode 25
|
||||
versionName "3.5"
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
release {
|
||||
storeFile file('../../android.keystore')
|
||||
keyAlias "tananaev"
|
||||
storePassword System.console().readLine("Enter store password: ")
|
||||
keyPassword System.console().readLine("Enter key password: ")
|
||||
storePassword ""
|
||||
keyPassword ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,3 +32,14 @@ dependencies {
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile "org.robolectric:robolectric:3.0"
|
||||
}
|
||||
|
||||
task requestPasswords << {
|
||||
android.signingConfigs.release.storePassword = new String(System.console().readPassword("\nStore password: "))
|
||||
android.signingConfigs.release.keyPassword = new String(System.console().readPassword("Key password: "))
|
||||
}
|
||||
|
||||
tasks.whenTaskAdded { theTask ->
|
||||
if (theTask.name.equals("packageRelease")) {
|
||||
theTask.dependsOn "requestPasswords"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,6 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
initPreferences();
|
||||
|
||||
// DELME
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_PROVIDER, null).equals("mixed")) {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putString(KEY_PROVIDER, LocationManager.GPS_PROVIDER).commit();
|
||||
}
|
||||
|
||||
if (getPreferenceScreen().getSharedPreferences().getBoolean(KEY_STATUS, false)) {
|
||||
setPreferencesEnabled(false);
|
||||
startService(new Intent(this, TrackingService.class));
|
||||
@@ -139,11 +134,13 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
|
||||
String KEY_SHOWN_PORT_DIALOG = "portDialogHasBeenShown";
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (!preferences.getString(KEY_PORT, "5055").equals("5055")) {
|
||||
if (!firstLaunch) {
|
||||
if (!preferences.contains(KEY_SHOWN_PORT_DIALOG)) {
|
||||
showDialog(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
preferences.edit().putBoolean(KEY_SHOWN_PORT_DIALOG, true).commit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
|
||||
*
|
||||
* 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.GpsStatus;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
public class MixedPositionProvider extends PositionProvider implements LocationListener, GpsStatus.Listener {
|
||||
|
||||
private static int FIX_TIMEOUT = 30 * 1000;
|
||||
|
||||
private LocationListener backupListener;
|
||||
private long lastFixTime;
|
||||
|
||||
public MixedPositionProvider(Context context, PositionListener listener) {
|
||||
super(context, listener);
|
||||
}
|
||||
|
||||
public void startUpdates() {
|
||||
lastFixTime = System.currentTimeMillis();
|
||||
locationManager.addGpsStatusListener(this);
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, period, 0, this);
|
||||
}
|
||||
|
||||
public void stopUpdates() {
|
||||
locationManager.removeUpdates(this);
|
||||
locationManager.removeGpsStatusListener(this);
|
||||
stopBackupProvider();
|
||||
}
|
||||
|
||||
private void startBackupProvider() {
|
||||
Log.i(TAG, "backup provider start");
|
||||
if (backupListener == null) {
|
||||
|
||||
backupListener = new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
Log.i(TAG, "backup provider location");
|
||||
updateLocation(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String s, int i, Bundle bundle) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String s) {
|
||||
}
|
||||
};
|
||||
|
||||
locationManager.requestLocationUpdates(
|
||||
LocationManager.NETWORK_PROVIDER, period, 0, backupListener);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopBackupProvider() {
|
||||
Log.i(TAG, "backup provider stop");
|
||||
if (backupListener != null) {
|
||||
locationManager.removeUpdates(backupListener);
|
||||
backupListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
Log.i(TAG, "provider location");
|
||||
stopBackupProvider();
|
||||
lastFixTime = System.currentTimeMillis();
|
||||
updateLocation(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
Log.i(TAG, "provider enabled");
|
||||
stopBackupProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
Log.i(TAG, "provider disabled");
|
||||
startBackupProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGpsStatusChanged(int event) {
|
||||
if (backupListener == null && System.currentTimeMillis() - (lastFixTime + period) > FIX_TIMEOUT) {
|
||||
startBackupProvider();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,17 +21,15 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class PositionProvider implements LocationListener {
|
||||
public abstract class PositionProvider {
|
||||
|
||||
private static final String TAG = PositionProvider.class.getSimpleName();
|
||||
protected static final String TAG = PositionProvider.class.getSimpleName();
|
||||
|
||||
public interface PositionListener {
|
||||
void onPositionUpdate(Position position);
|
||||
@@ -41,11 +39,13 @@ public class PositionProvider implements LocationListener {
|
||||
|
||||
private final Context context;
|
||||
private final SharedPreferences preferences;
|
||||
private final LocationManager locationManager;
|
||||
protected final LocationManager locationManager;
|
||||
|
||||
private String deviceId;
|
||||
private String type;
|
||||
private final long period;
|
||||
protected String type;
|
||||
protected final long period;
|
||||
|
||||
private long lastUpdateTime;
|
||||
|
||||
public PositionProvider(Context context, PositionListener listener) {
|
||||
this.context = context;
|
||||
@@ -58,49 +58,24 @@ public class PositionProvider implements LocationListener {
|
||||
period = Integer.parseInt(preferences.getString(MainActivity.KEY_INTERVAL, null)) * 1000;
|
||||
|
||||
type = preferences.getString(MainActivity.KEY_PROVIDER, null);
|
||||
if (!type.equals(LocationManager.NETWORK_PROVIDER)) {
|
||||
type = LocationManager.GPS_PROVIDER;
|
||||
}
|
||||
}
|
||||
|
||||
public void startUpdates() {
|
||||
locationManager.requestLocationUpdates(type, period, 0, this);
|
||||
}
|
||||
public abstract void startUpdates();
|
||||
|
||||
public void stopUpdates() {
|
||||
locationManager.removeUpdates(this);
|
||||
}
|
||||
public abstract void stopUpdates();
|
||||
|
||||
private long lastTime;
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if (location != null && location.getTime() != lastTime) {
|
||||
protected void updateLocation(Location location) {
|
||||
if (location != null && location.getTime() != lastUpdateTime) {
|
||||
Log.i(TAG, "location new");
|
||||
lastTime = location.getTime();
|
||||
lastUpdateTime = location.getTime();
|
||||
listener.onPositionUpdate(new Position(deviceId, location, getBatteryLevel()));
|
||||
} else {
|
||||
Log.i(TAG, location != null ? "location old" : "location nil");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
Log.i(TAG, "provider status");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
Log.i(TAG, "provider enabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
Log.i(TAG, "provider disabled");
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.ECLAIR)
|
||||
public double getBatteryLevel() {
|
||||
private double getBatteryLevel() {
|
||||
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR) {
|
||||
Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ProtocolFormatter {
|
||||
.appendQueryParameter("timestamp", String.valueOf(position.getTime().getTime() / 1000))
|
||||
.appendQueryParameter("lat", String.valueOf(position.getLatitude()))
|
||||
.appendQueryParameter("lon", String.valueOf(position.getLongitude()))
|
||||
.appendQueryParameter("speed", String.valueOf(position.getSpeed() * 1.943844))
|
||||
.appendQueryParameter("speed", String.valueOf(position.getSpeed()))
|
||||
.appendQueryParameter("bearing", String.valueOf(position.getCourse()))
|
||||
.appendQueryParameter("altitude", String.valueOf(position.getAltitude()))
|
||||
.appendQueryParameter("batt", String.valueOf(position.getBattery()));
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
|
||||
*
|
||||
* 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class SimplePositionProvider extends PositionProvider implements LocationListener {
|
||||
|
||||
public SimplePositionProvider(Context context, PositionListener listener) {
|
||||
super(context, listener);
|
||||
if (!type.equals(LocationManager.NETWORK_PROVIDER)) {
|
||||
type = LocationManager.GPS_PROVIDER;
|
||||
}
|
||||
}
|
||||
|
||||
public void startUpdates() {
|
||||
locationManager.requestLocationUpdates(type, period, 0, this);
|
||||
}
|
||||
|
||||
public void stopUpdates() {
|
||||
locationManager.removeUpdates(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
updateLocation(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,11 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
||||
this.context = context;
|
||||
handler = new Handler();
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
positionProvider = new PositionProvider(context, this);
|
||||
if (preferences.getString(MainActivity.KEY_PROVIDER, null).equals("mixed")) {
|
||||
positionProvider = new MixedPositionProvider(context, this);
|
||||
} else {
|
||||
positionProvider = new SimplePositionProvider(context, this);
|
||||
}
|
||||
databaseHelper = new DatabaseHelper(context);
|
||||
networkManager = new NetworkManager(context, this);
|
||||
isOnline = networkManager.isOnline();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>GPS</item>
|
||||
<item>Mobilní síť</item>
|
||||
<item>Obojí</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Popředí služba</string>
|
||||
<string name="settings_foreground_summary">Zvýšit prioritu služba</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>GPS udbyder</item>
|
||||
<item>Netværks udbyder</item>
|
||||
<item>Mixet udbyder</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Forgrunden tjeneste</string>
|
||||
<string name="settings_foreground_summary">Øg tjeneste prioritet</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>GPS</item>
|
||||
<item>Netzwerk</item>
|
||||
<item>Gemischt</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Vordergrund service</string>
|
||||
<string name="settings_foreground_summary">Erhöhen service priorität</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>Proveedor GPS</item>
|
||||
<item>Proveedor de red</item>
|
||||
<item>Proveedor mixto</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Servicio de primer plano</string>
|
||||
<string name="settings_foreground_summary">Aumentar prioridad de servicio</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>Mode GPS uniquement</item>
|
||||
<item>Mode cellulaire uniquement</item>
|
||||
<item>Mode hybride</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Un service de premier plan</string>
|
||||
<string name="settings_foreground_summary">Augmenter la priorité de service</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>GPS-lokalisering</item>
|
||||
<item>Nettverkslokalisering</item>
|
||||
<item>Blandet lokalisering</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Forgrunnen tjeneste</string>
|
||||
<string name="settings_foreground_summary">Øk tjeneste prioritet</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>Provedor GPS</item>
|
||||
<item>Provedor Rede</item>
|
||||
<item>Provedor Misto</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Serviço primeiro plano</string>
|
||||
<string name="settings_foreground_summary">Aumentar a prioridade de serviço</string>
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>GPS провайдер</item>
|
||||
<item>Сетевой провайдер</item>
|
||||
<item>Смешанный провайдер</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Приотитетный сервис</string>
|
||||
<string name="settings_foreground_title">Приоритетный сервис</string>
|
||||
<string name="settings_foreground_summary">Увеличить приоритет сервиса</string>
|
||||
|
||||
<string name="menu_status">Состояние</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>GPS provajder</item>
|
||||
<item>Provajder Mreže</item>
|
||||
<item>Oba zajedno provajdera</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Prvi plan servis</string>
|
||||
<string name="settings_foreground_summary">Povecanje usluga prioritet</string>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string-array name="settings_provider_names">
|
||||
<item>GPS provider</item>
|
||||
<item>Network provider</item>
|
||||
<item>Mixed provider</item>
|
||||
</string-array>
|
||||
<string name="settings_foreground_title">Foreground service</string>
|
||||
<string name="settings_foreground_summary">Increase service priority</string>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<string-array name="settings_provider_values" translatable="false">
|
||||
<item>gps</item>
|
||||
<item>network</item>
|
||||
<item>mixed</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
Ссылка в новой задаче
Block a user