// Path: core/src/main/java/com/novoda/location/Constants.java
// public interface Constants {
// 	
//     boolean USE_GPS = true;
//     boolean REFRESH_DATA_ON_LOCATION_CHANGED = true;
//     boolean ENABLE_PASSIVE_UPDATES = false;
//     
//     int UPDATES_MAX_DISTANCE = 100;
//     long UPDATES_MAX_TIME = 5 * 60 * 1000;
// 	
//     long DEFAULT_INTERVAL_PASSIVE = 15 * 60 * 1000;
// 	int DEFAULT_DISTANCE_PASSIVE = 300;
//     
//     String ACTIVE_LOCATION_UPDATE_ACTION = "com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION";
//     String ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION = "com.novoda.location.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION";
//     String ACTIVE_LOCATION_UPDATE_PROVIDER_ENABLED_ACTION = "com.novoda.location.ACTIVE_LOCATION_UPDATE_PROVIDER_ENABLED_ACTION";
//     
// }
// 
// Path: core/src/main/java/com/novoda/location/LocatorSettings.java
// public class LocatorSettings {
// 
//     private final String packageName;
//     private final String updateAction;
// 
//     private boolean useGps = Constants.USE_GPS;
//     private boolean updateOnLocationChange = Constants.REFRESH_DATA_ON_LOCATION_CHANGED;
//     private long updatesInterval = Constants.UPDATES_MAX_TIME;
//     private int updatesDistance = Constants.UPDATES_MAX_DISTANCE;
//     private long passiveUpdatesInterval = Constants.DEFAULT_INTERVAL_PASSIVE;
//     private int passiveUpdatesDistance = Constants.DEFAULT_DISTANCE_PASSIVE;
//     private boolean enablePassiveUpdates = Constants.ENABLE_PASSIVE_UPDATES;
// 
//     public LocatorSettings(String packageName, String updateAction) {
//         this.packageName = packageName;
//         this.updateAction = updateAction;
//     }
//     
//     public String getPackageName() {
//         return packageName;
//     }
// 
//     public String getUpdateAction() {
//         return updateAction;
//     }
//     
//     public boolean shouldUseGps() {
//         return useGps;
//     }
// 
//     public void setUseGps(boolean useGps) {
//         this.useGps = useGps;
//     }
// 
//     public boolean shouldUpdateLocation() {
//         return updateOnLocationChange;
//     }
// 
//     public void setUpdateOnLocationChange(boolean updateOnLocationChange) {
//         this.updateOnLocationChange = updateOnLocationChange;
//     }
// 
//     public boolean shouldEnablePassiveUpdates() {
//         return enablePassiveUpdates;
//     }
// 
//     public void setEnablePassiveUpdates(boolean enablePassiveUpdates) {
//         this.enablePassiveUpdates = enablePassiveUpdates;
//     }
// 
//     public long getUpdatesInterval() {
//         return updatesInterval;
//     }
// 
//     public void setUpdatesInterval(long updatesInterval) {
//         this.updatesInterval = updatesInterval;
//     }
// 
//     public int getUpdatesDistance() {
//         return updatesDistance;
//     }
// 
//     public void setUpdatesDistance(int updatesDistance) {
//         this.updatesDistance = updatesDistance;
//     }
// 
//     public long getPassiveUpdatesInterval() {
//         return passiveUpdatesInterval;
//     }
// 
//     public void setPassiveUpdatesInterval(long passiveUpdatesInterval) {
//         this.passiveUpdatesInterval = passiveUpdatesInterval;
//     }
// 
//     public int getPassiveUpdatesDistance() {
//         return passiveUpdatesDistance;
//     }
// 
//     public void setPassiveUpdatesDistance(int passiveUpdatesDistance) {
//         this.passiveUpdatesDistance = passiveUpdatesDistance;
//     }
// 
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.novoda.location.Constants;
import com.novoda.location.LocatorSettings;
/**
 * Copyright 2011 Novoda Ltd.
 *
 * 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.
 * 
 * Sections copyright Matthias Kaeppler 2009-2011 based on Ignition-Support.
 */
package com.novoda.location.provider.store;



public class SharedPreferenceSettingsDao implements SettingsDao {
    
    private static final String SHARED_PREFERENCE_FILE = "novocation_prefs";
    private static final String SP_KEY_RUN_ONCE = "sp_key_run_once";
    private static final String SP_KEY_PASSIVE_LOCATION_CHANGES = "sp_key_follow_location_changes";
    private static final String SP_KEY_PASSIVE_LOCATION_UPDATES_DISTANCE_DIFF = "sp_passive_location_updates_distance_diff";
    private static final String SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL = "sp_key_passive_location_updates_interval";
    
    @Override
    public void persistSettingsToPreferences(Context context, LocatorSettings settings) {
        Editor editor = getSharedPrefs(context).edit();
        editor.putBoolean(SP_KEY_PASSIVE_LOCATION_CHANGES, settings.shouldEnablePassiveUpdates());
        editor.putInt(SP_KEY_PASSIVE_LOCATION_UPDATES_DISTANCE_DIFF, settings.getPassiveUpdatesDistance());
        editor.putLong(SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL, settings.getPassiveUpdatesInterval());
        editor.putBoolean(SP_KEY_RUN_ONCE, true);
        editor.commit();
    }

	@Override
    public long getPassiveLocationInterval(Context context) {
        return getSharedPrefs(context).getLong(SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL, Constants.UPDATES_MAX_TIME);
    }

    @Override
    public int getPassiveLocationDistance(Context context) {
// Path: core/src/main/java/com/novoda/location/Constants.java
// public interface Constants {
// 	
//     boolean USE_GPS = true;
//     boolean REFRESH_DATA_ON_LOCATION_CHANGED = true;
//     boolean ENABLE_PASSIVE_UPDATES = false;
//     
//     int UPDATES_MAX_DISTANCE = 100;
//     long UPDATES_MAX_TIME = 5 * 60 * 1000;
// 	
//     long DEFAULT_INTERVAL_PASSIVE = 15 * 60 * 1000;
// 	int DEFAULT_DISTANCE_PASSIVE = 300;
//     
//     String ACTIVE_LOCATION_UPDATE_ACTION = "com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION";
//     String ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION = "com.novoda.location.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION";
//     String ACTIVE_LOCATION_UPDATE_PROVIDER_ENABLED_ACTION = "com.novoda.location.ACTIVE_LOCATION_UPDATE_PROVIDER_ENABLED_ACTION";
//     
// }
// 
// Path: core/src/main/java/com/novoda/location/LocatorSettings.java
// public class LocatorSettings {
// 
//     private final String packageName;
//     private final String updateAction;
// 
//     private boolean useGps = Constants.USE_GPS;
//     private boolean updateOnLocationChange = Constants.REFRESH_DATA_ON_LOCATION_CHANGED;
//     private long updatesInterval = Constants.UPDATES_MAX_TIME;
//     private int updatesDistance = Constants.UPDATES_MAX_DISTANCE;
//     private long passiveUpdatesInterval = Constants.DEFAULT_INTERVAL_PASSIVE;
//     private int passiveUpdatesDistance = Constants.DEFAULT_DISTANCE_PASSIVE;
//     private boolean enablePassiveUpdates = Constants.ENABLE_PASSIVE_UPDATES;
// 
//     public LocatorSettings(String packageName, String updateAction) {
//         this.packageName = packageName;
//         this.updateAction = updateAction;
//     }
//     
//     public String getPackageName() {
//         return packageName;
//     }
// 
//     public String getUpdateAction() {
//         return updateAction;
//     }
//     
//     public boolean shouldUseGps() {
//         return useGps;
//     }
// 
//     public void setUseGps(boolean useGps) {
//         this.useGps = useGps;
//     }
// 
//     public boolean shouldUpdateLocation() {
//         return updateOnLocationChange;
//     }
// 
//     public void setUpdateOnLocationChange(boolean updateOnLocationChange) {
//         this.updateOnLocationChange = updateOnLocationChange;
//     }
// 
//     public boolean shouldEnablePassiveUpdates() {
//         return enablePassiveUpdates;
//     }
// 
//     public void setEnablePassiveUpdates(boolean enablePassiveUpdates) {
//         this.enablePassiveUpdates = enablePassiveUpdates;
//     }
// 
//     public long getUpdatesInterval() {
//         return updatesInterval;
//     }
// 
//     public void setUpdatesInterval(long updatesInterval) {
//         this.updatesInterval = updatesInterval;
//     }
// 
//     public int getUpdatesDistance() {
//         return updatesDistance;
//     }
// 
//     public void setUpdatesDistance(int updatesDistance) {
//         this.updatesDistance = updatesDistance;
//     }
// 
//     public long getPassiveUpdatesInterval() {
//         return passiveUpdatesInterval;
//     }
// 
//     public void setPassiveUpdatesInterval(long passiveUpdatesInterval) {
//         this.passiveUpdatesInterval = passiveUpdatesInterval;
//     }
// 
//     public int getPassiveUpdatesDistance() {
//         return passiveUpdatesDistance;
//     }
// 
//     public void setPassiveUpdatesDistance(int passiveUpdatesDistance) {
//         this.passiveUpdatesDistance = passiveUpdatesDistance;
//     }
// 
// }


// Path: core/src/main/java/com/novoda/location/provider/store/SharedPreferenceSettingsDao.java
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.novoda.location.Constants;
import com.novoda.location.LocatorSettings;

/**
 * Copyright 2011 Novoda Ltd.
 *
 * 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.
 * 
 * Sections copyright Matthias Kaeppler 2009-2011 based on Ignition-Support.
 */
package com.novoda.location.provider.store;



public class SharedPreferenceSettingsDao implements SettingsDao {
    
    private static final String SHARED_PREFERENCE_FILE = "novocation_prefs";
    private static final String SP_KEY_RUN_ONCE = "sp_key_run_once";
    private static final String SP_KEY_PASSIVE_LOCATION_CHANGES = "sp_key_follow_location_changes";
    private static final String SP_KEY_PASSIVE_LOCATION_UPDATES_DISTANCE_DIFF = "sp_passive_location_updates_distance_diff";
    private static final String SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL = "sp_key_passive_location_updates_interval";
    
    @Override
    public void persistSettingsToPreferences(Context context, LocatorSettings settings) {
        Editor editor = getSharedPrefs(context).edit();
        editor.putBoolean(SP_KEY_PASSIVE_LOCATION_CHANGES, settings.shouldEnablePassiveUpdates());
        editor.putInt(SP_KEY_PASSIVE_LOCATION_UPDATES_DISTANCE_DIFF, settings.getPassiveUpdatesDistance());
        editor.putLong(SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL, settings.getPassiveUpdatesInterval());
        editor.putBoolean(SP_KEY_RUN_ONCE, true);
        editor.commit();
    }

	@Override
    public long getPassiveLocationInterval(Context context) {
        return getSharedPrefs(context).getLong(SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL, Constants.UPDATES_MAX_TIME);
    }

    @Override
    public int getPassiveLocationDistance(Context context) {
        return getSharedPrefs(context).getInt(SP_KEY_PASSIVE_LOCATION_UPDATES_DISTANCE_DIFF, Constants.UPDATES_MAX_DISTANCE);