start implement background service

git-svn-id: https://osmand.googlecode.com/svn/trunk@358 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-07-16 09:21:42 +00:00
parent 7a17a41a39
commit 6ab761ec8c
7 changed files with 38 additions and 7 deletions

View file

@ -30,6 +30,9 @@
<activity android:name=".activities.search.SearchStreet2ByNameActivity"></activity>
<activity android:name=".activities.search.SearchBuildingByNameActivity"></activity>
<activity android:name=".activities.EditPOIFilterActivity"></activity>
<service android:process="@string/process_navigation_service" android:label="@string/process_navigation_service" android:name=".NavigationService">
<intent-filter><action android:name="com.osmand.NavigationService"></action></intent-filter>
</service>
</application>
<uses-sdk android:minSdkVersion="3"/>

View file

@ -3,11 +3,11 @@
<string name="network_provider">Сеть</string>
<string name="gps_provider">GPS</string>
<string name="int_min">мин.</string>
<string name="background_service_int_descr">Выберите интервал позиционирования для фонового сервиса</string>
<string name="background_service_int_descr">Выберите интервал позиционирования для сервиса</string>
<string name="background_service_int">Интервал позиционирования</string>
<string name="background_service_provider_descr">Выберите источник позиционирования для фонового сервиса</string>
<string name="background_service_provider_descr">Выберите источник позиционирования для сервиса</string>
<string name="background_service_provider">Источник позиционирования</string>
<string name="background_router_service_descr">Включить фоновый сервис для позиционирования через долгий период времени</string>
<string name="background_router_service_descr">Включить фоновый сервис для обновления через долгий период времени</string>
<string name="background_router_service">Сервис навигации</string>
<string name="off_router_service_no_gps_available">Сервис маршрутизации OsmAnd включен, отключив позиционирование, он перестает вести по маршруту.</string>
<string name="routing_settings_descr">Изменить настройки маршрутизации</string>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="process_navigation_service">Osmand navigation service</string>
<string name="network_provider">Network</string>
<string name="gps_provider">GPS</string>
<string name="int_min">min.</string>

View file

@ -56,8 +56,8 @@ public class NavigationService extends Service implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// TODO check that MapActivity is not foreground
if(location != null){
if(location != null && !OsmandSettings.getMapActivityEnabled(this)){
// TODO update voice navigation
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getTime());
}

View file

@ -533,6 +533,19 @@ public class OsmandSettings {
return prefs.edit().putBoolean(VOICE_MUTE, mute).commit();
}
// for background service
public static final String MAP_ACTIVITY_ENABLED = "map_activity_enabled"; //$NON-NLS-1$
public static final boolean MAP_ACTIVITY_ENABLED_DEF = false;
public static boolean getMapActivityEnabled(Context ctx) {
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.getBoolean(MAP_ACTIVITY_ENABLED, MAP_ACTIVITY_ENABLED_DEF);
}
public static boolean setMapActivityEnabled(Context ctx, boolean en) {
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.edit().putBoolean(MAP_ACTIVITY_ENABLED, en).commit();
}
// this value string is synchronized with settings_pref.xml preference name
public static final String SERVICE_OFF_ENABLED = "service_off_enabled"; //$NON-NLS-1$
public static final boolean SERVICE_OFF_ENABLED_DEF = false;

View file

@ -574,6 +574,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
wakeLock.release();
wakeLock = null;
}
OsmandSettings.setMapActivityEnabled(this, false);
}
@Override
@ -661,6 +662,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
mapView.getSourceTileSize(), mapView.getRotate(), true);
}
}
OsmandSettings.setMapActivityEnabled(this, true);
checkExternalStorage();
showAndHideMapPosition();
}

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Set;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -25,6 +26,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;
import com.osmand.NavigationService;
import com.osmand.OsmandSettings;
import com.osmand.PoiFiltersHelper;
import com.osmand.ProgressDialogImplementation;
@ -183,7 +185,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
saveTrackInterval.setEntryValues(new String[]{"1", "2", "5", "15", "30", "60", "300"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
saveTrackInterval.setValue(OsmandSettings.getSavingTrackInterval(this)+""); //$NON-NLS-1$
String[] ints = new String[]{"1", "2", "5", "8", "10", "15", "20", "25", "30", "40", "60", }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$
String[] ints = new String[]{"1", "2", "5", "8", "10", "15", "20", "25", "30", "40", "45", "60", "90" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$
String[] intDescriptions = new String[ints.length];
for(int i=0; i<intDescriptions.length; i++){
intDescriptions[i] = ints[i] + " " + getString(R.string.int_min); //$NON-NLS-1$
@ -332,7 +334,17 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
edit.putString(OsmandSettings.SERVICE_OFF_PROVIDER, (String) newValue);
edit.commit();
} else if (preference == routeServiceEnabled) {
// TODO !!!
Intent serviceIntent = new Intent(this, NavigationService.class);
if ((Boolean) newValue) {
ComponentName name = startService(serviceIntent);
if (name == null) {
routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(this));
}
} else {
if(!stopService(serviceIntent)){
routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(this));
}
}
} else if (preference == routerPreference) {
RouteService s = null;
for(RouteService r : RouteService.values()){