This commit is contained in:
Victor Shcherb 2016-04-16 22:02:15 +02:00
parent 60cf701dd6
commit 0570e87207
10 changed files with 19 additions and 73 deletions

View file

@ -574,7 +574,8 @@ public class AppInitializer implements IProgress {
}
}
if(app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get() && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null){
app.startNavigationService(NavigationService.USED_BY_GPX);
int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get() ;
app.startNavigationService(NavigationService.USED_BY_GPX, interval < 30000 ? 0 : interval);
}
}

View file

@ -34,6 +34,7 @@ public class NavigationService extends Service implements LocationListener {
public static int USED_BY_LIVE = 4;
public static int USED_BY_WAKE_UP = 8;
public final static String USAGE_INTENT = "SERVICE_USED_BY";
public final static String USAGE_OFF_INTERVAL = "SERVICE_OFF_INTERVAL";
private NavigationServiceBinder binder = new NavigationServiceBinder();
@ -95,17 +96,6 @@ public class NavigationService extends Service implements LocationListener {
if ((usedBy & usageIntent) > 0) {
usedBy -= usageIntent;
}
if (usedBy == 2) {
//reset SERVICE_OFF_INTERVAL to automatic settings for USED_BY_GPX
if (settings.SAVE_GLOBAL_TRACK_INTERVAL.get() < 30000) {
settings.SERVICE_OFF_INTERVAL.set(0);
} else {
//Use SERVICE_OFF_INTERVAL > 0 to conserve power for longer GPX recording intervals
settings.SERVICE_OFF_INTERVAL.set(settings.SAVE_GLOBAL_TRACK_INTERVAL.get());
}
}
if (usedBy == 0) {
final Intent serviceIntent = new Intent(ctx, NavigationService.class);
ctx.stopService(serviceIntent);
@ -118,10 +108,9 @@ public class NavigationService extends Service implements LocationListener {
final OsmandApplication app = (OsmandApplication) getApplication();
settings = app.getSettings();
usedBy = intent.getIntExtra(USAGE_INTENT, 0);
serviceOffInterval = intent.getIntExtra(USAGE_OFF_INTERVAL, 0);
if ((usedBy & USED_BY_NAVIGATION) != 0) {
serviceOffInterval = 0;
} else {
serviceOffInterval = settings.SERVICE_OFF_INTERVAL.get();
}
// use only gps provider
serviceOffProvider = LocationManager.GPS_PROVIDER;
@ -165,22 +154,6 @@ public class NavigationService extends Service implements LocationListener {
return START_REDELIVER_INTENT;
}
protected void stopService() {
OsMoPlugin osmoPlugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class);
if (osmoPlugin != null) {
if (osmoPlugin.getTracker().isEnabledTracker()) {
osmoPlugin.getTracker().disableTracker();
}
}
OsmandMonitoringPlugin monitoringPlugin =
OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (monitoringPlugin != null) {
monitoringPlugin.stopRecording();
}
NavigationService.this.stopSelf();
}
@Override

View file

@ -727,23 +727,15 @@ public class OsmandApplication extends MultiDexApplication {
}
public void startNavigationService(int intent) {
public void startNavigationService(int intent, int interval) {
final Intent serviceIntent = new Intent(this, NavigationService.class);
serviceIntent.putExtra(NavigationService.USAGE_INTENT, intent);
if (getNavigationService() == null) {
if (intent != NavigationService.USED_BY_GPX) {
//for only-USED_BY_GPX case use pre-configured SERVICE_OFF_INTERVAL
//other cases always use "continuous":
getSettings().SERVICE_OFF_INTERVAL.set(0);
}
startService(serviceIntent);
} else {
//additional cases always use "continuous"
//TODO: fallback to custom USED_BY_GPX interval in case all other sleep mode purposes have been stopped
getSettings().SERVICE_OFF_INTERVAL.set(0);
getNavigationService().addUsageIntent(intent);
getNotificationHelper().showNotification();
serviceIntent.putExtra(NavigationService.USAGE_OFF_INTERVAL, interval);
if (getNavigationService() != null) {
getNavigationService().stopSelf();
}
startService(serviceIntent);
getNotificationHelper().showNotification();
}

View file

@ -2435,13 +2435,6 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public static final String SERVICE_OFF_ENABLED = "service_off_enabled"; //$NON-NLS-1$
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Integer> SERVICE_OFF_INTERVAL = new IntPreference("service_off_interval",
0).makeGlobal();
public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal();

View file

@ -17,7 +17,6 @@ import android.widget.LinearLayout.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import net.osmand.Location;
import net.osmand.ValueHolder;
import net.osmand.plus.ApplicationMode;
@ -367,15 +366,8 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
settings.SAVE_GLOBAL_TRACK_INTERVAL.set(vs.value);
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true);
settings.SAVE_GLOBAL_TRACK_REMEMBER.set(choice.value);
if (settings.SAVE_GLOBAL_TRACK_INTERVAL.get() < 30000) {
settings.SERVICE_OFF_INTERVAL.set(0);
} else {
//Use SERVICE_OFF_INTERVAL > 0 to conserve power for longer GPX recording intervals
settings.SERVICE_OFF_INTERVAL.set(settings.SAVE_GLOBAL_TRACK_INTERVAL.get());
}
app.startNavigationService(NavigationService.USED_BY_GPX);
int interval = settings.SAVE_GLOBAL_TRACK_INTERVAL.get();
app.startNavigationService(NavigationService.USED_BY_GPX, interval < 30000? 0 : interval);
}
};
if(choice.value || map == null) {

View file

@ -63,9 +63,7 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
if (plugin != null && plugin.getTracker() != null) {
plugin.getTracker().enableTracker();
}
getMyApplication().startNavigationService(NavigationService.USED_BY_LIVE);
//interval setting not needed here, handled centrally in app.startNavigationService
//app.getSettings().SERVICE_OFF_INTERVAL.set(0);
getMyApplication().startNavigationService(NavigationService.USED_BY_LIVE, 0);
} else {
if (plugin != null && plugin.getTracker() != null) {
plugin.getTracker().disableTracker();

View file

@ -83,7 +83,7 @@ public class OsMoControlDevice implements OsMoReactor {
}
} else if(data.equals("START_TRACKING")) {
tracker.enableTrackerCmd();
app.startNavigationService(NavigationService.USED_BY_LIVE);
app.startNavigationService(NavigationService.USED_BY_LIVE, 0);
//interval setting not needed here, handled centrally in app.startNavigationService
//app.getSettings().SERVICE_OFF_INTERVAL.set(0);
} else if(data.equals("OSMAND_INFO")) {

View file

@ -292,9 +292,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
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, 0);
}
} else {
if (osMoPlugin != null && osMoPlugin.getTracker() != null) {

View file

@ -116,7 +116,7 @@ public class RoutingHelper {
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_NAVIGATION);
}
} else {
app.startNavigationService(NavigationService.USED_BY_NAVIGATION);
app.startNavigationService(NavigationService.USED_BY_NAVIGATION, 0);
}
}
@ -132,7 +132,7 @@ public class RoutingHelper {
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_NAVIGATION);
}
} else {
app.startNavigationService(NavigationService.USED_BY_NAVIGATION);
app.startNavigationService(NavigationService.USED_BY_NAVIGATION, 0);
}
}

View file

@ -123,7 +123,7 @@ public class MapInfoWidgetsFactory {
} else {
final ValueHolder<Integer> vs = new ValueHolder<Integer>();
vs.value = app.getSettings().SERVICE_OFF_INTERVAL.get();
vs.value = 0;
final AlertDialog[] dlgshow = new AlertDialog[1];
AlertDialog.Builder dlg = new AlertDialog.Builder(map);
dlg.setTitle(app.getString(R.string.enable_sleep_mode));
@ -147,8 +147,7 @@ public class MapInfoWidgetsFactory {
dlg.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
app.getSettings().SERVICE_OFF_INTERVAL.set(vs.value);
app.startNavigationService(NavigationService.USED_BY_WAKE_UP);
app.startNavigationService(NavigationService.USED_BY_WAKE_UP, vs.value);
}
});
dlg.setNegativeButton(R.string.shared_string_cancel, null);