Check gps for recording

This commit is contained in:
Victor Shcherb 2015-06-10 16:50:55 +02:00
parent bbc097725c
commit ece6d236ab
7 changed files with 53 additions and 17 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="gps_network_not_enabled">Location service is not enabled. Do you want to turn it on?</string>
<string name="disable_recording_once_app_killed">Run in background</string> <string name="disable_recording_once_app_killed">Run in background</string>
<string name="disable_recording_once_app_killed_descrp">Unless checked, GPX recording will stop when the app is killed (via recent apps). Upon app restart, the recording will resume (see notification in the top bar about the OsmAnd Sleep mode process).</string> <string name="disable_recording_once_app_killed_descrp">Unless checked, GPX recording will stop when the app is killed (via recent apps). Upon app restart, the recording will resume (see notification in the top bar about the OsmAnd Sleep mode process).</string>
<string name="shared_string_import2osmand">Import to OsmAnd</string> <string name="shared_string_import2osmand">Import to OsmAnd</string>

View file

@ -17,7 +17,10 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.router.RouteSegmentResult; import net.osmand.router.RouteSegmentResult;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.hardware.GeomagneticField; import android.hardware.GeomagneticField;
import android.hardware.Sensor; import android.hardware.Sensor;
import android.hardware.SensorEvent; import android.hardware.SensorEvent;
@ -31,6 +34,7 @@ import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
public class OsmAndLocationProvider implements SensorEventListener { public class OsmAndLocationProvider implements SensorEventListener {
@ -871,6 +875,37 @@ public class OsmAndLocationProvider implements SensorEventListener {
return true; return true;
} }
public boolean checkGPSEnabled(final Context context) {
LocationManager lm = (LocationManager)app.getSystemService(Context.LOCATION_SERVICE);
boolean gpsenabled = false;
boolean networkenabled = false;
try {
gpsenabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch(Exception ex) {}
try {
networkenabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch(Exception ex) {}
if(!gpsenabled && !networkenabled) {
// notify user
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setMessage(context.getResources().getString(R.string.gps_network_not_enabled));
dialog.setPositiveButton(context.getResources().getString(R.string.shared_string_settings), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivity(myIntent);
}
});
dialog.setNegativeButton(context.getString(R.string.shared_string_cancel), null);
dialog.show();
return false;
}
return true;
}
} }

View file

@ -668,6 +668,7 @@ public class OsmandApplication extends Application {
return 0; return 0;
} }
} }
public void startNavigationService(int intent) { public void startNavigationService(int intent) {
final Intent serviceIntent = new Intent(this, NavigationService.class); final Intent serviceIntent = new Intent(this, NavigationService.class);

View file

@ -18,6 +18,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.osmo.OsMoGroupsActivity;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
@ -258,7 +259,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
if(item == R.string.save_current_track){ if(item == R.string.save_current_track){
saveCurrentTrack(); saveCurrentTrack();
} else if(item == R.string.gpx_monitoring_start) { } else if(item == R.string.gpx_monitoring_start) {
startGPXMonitoring(map); if (app.getLocationProvider().checkGPSEnabled(map)) {
startGPXMonitoring(map);
}
} else if(item == R.string.gpx_monitoring_stop) { } else if(item == R.string.gpx_monitoring_stop) {
stopRecording(); stopRecording();
} else if(item == R.string.gpx_start_new_segment) { } else if(item == R.string.gpx_start_new_segment) {

View file

@ -178,7 +178,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
public static void updateCurrentTrack(View v, final Activity ctx, OsmandApplication app) { public static void updateCurrentTrack(View v, final Activity ctx, final OsmandApplication app) {
if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) {
return; return;
} }
@ -199,7 +199,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (isRecording) { if (isRecording) {
plugin.stopRecording(); plugin.stopRecording();
} else { } else {
plugin.startGPXMonitoring(ctx); if (app.getLocationProvider().checkGPSEnabled(ctx)) {
plugin.startGPXMonitoring(ctx);
}
} }
} }
}); });

View file

@ -221,12 +221,14 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) { if(isChecked) {
if (osMoPlugin != null && osMoPlugin.getTracker() != null){ if (app.getLocationProvider().checkGPSEnabled(OsMoGroupsActivity.this)) {
osMoPlugin.getTracker().enableTracker(); if (osMoPlugin != null && osMoPlugin.getTracker() != null) {
osMoPlugin.getTracker().enableTracker();
}
app.startNavigationService(NavigationService.USED_BY_LIVE);
// interval setting not needed here, handled centrally in app.startNavigationService
// app.getSettings().SERVICE_OFF_INTERVAL.set(0);
} }
app.startNavigationService(NavigationService.USED_BY_LIVE);
//interval setting not needed here, handled centrally in app.startNavigationService
//app.getSettings().SERVICE_OFF_INTERVAL.set(0);
} else { } else {
if (osMoPlugin != null && osMoPlugin.getTracker() != null){ if (osMoPlugin != null && osMoPlugin.getTracker() != null){
osMoPlugin.getTracker().disableTracker(); osMoPlugin.getTracker().disableTracker();

View file

@ -4,20 +4,11 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PublicKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAPublicKeySpec;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import javax.crypto.Cipher;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;