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).
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_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>

View file

@ -17,7 +17,10 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.router.RouteSegmentResult;
import net.osmand.util.MapUtils;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.hardware.GeomagneticField;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
@ -31,6 +34,7 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
public class OsmAndLocationProvider implements SensorEventListener {
@ -873,4 +877,35 @@ public class OsmAndLocationProvider implements SensorEventListener {
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

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

View file

@ -18,6 +18,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.osmo.OsMoGroupsActivity;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
@ -258,7 +259,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
if(item == R.string.save_current_track){
saveCurrentTrack();
} else if(item == R.string.gpx_monitoring_start) {
if (app.getLocationProvider().checkGPSEnabled(map)) {
startGPXMonitoring(map);
}
} else if(item == R.string.gpx_monitoring_stop) {
stopRecording();
} 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) {
return;
}
@ -199,9 +199,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (isRecording) {
plugin.stopRecording();
} else {
if (app.getLocationProvider().checkGPSEnabled(ctx)) {
plugin.startGPXMonitoring(ctx);
}
}
}
});
SavingTrackHelper sth = app.getSavingTrackHelper();
ImageButton save = ((ImageButton) v.findViewById(R.id.show_on_map));

View file

@ -221,12 +221,14 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
if (app.getLocationProvider().checkGPSEnabled(OsMoGroupsActivity.this)) {
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);
}
} else {
if (osMoPlugin != null && osMoPlugin.getTracker() != null){
osMoPlugin.getTracker().disableTracker();

View file

@ -4,20 +4,11 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
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.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.crypto.Cipher;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;