package com.openxc.enabler.preferences;

import android.content.Context;
import android.util.Log;

import com.openxc.enabler.R;
import com.openxc.sinks.MockedLocationSink;

/**
 * Enable or disable overwriting native GPS measurements with those from the
 * vehicle.
 *
 * @see MockedLocationSink#setOverwritingStatus
 */
public class GpsOverwritePreferenceManager extends VehiclePreferenceManager {
    private final static String TAG = "GpsOverwritePreferenceManager";
    private MockedLocationSink mMockedLocationSink;

    public GpsOverwritePreferenceManager(Context context) {
        super(context);
    }

    public void close() {
        super.close();
        if(getVehicleManager() != null){
            mMockedLocationSink.stop();
            mMockedLocationSink = null;
        }
    }

    protected PreferenceListener createPreferenceListener(){
        return new PreferenceListener() {
            private int[] WATCHED_PREFERENCE_KEY_IDS = {
                R.string.gps_overwrite_checkbox_key,
            };

            protected int[] getWatchedPreferenceKeyIds() {
                return WATCHED_PREFERENCE_KEY_IDS;
            }

            public void readStoredPreferences() {
                setNativeGpsOverwriteStatus(getPreferences().getBoolean(
                            getString(R.string.gps_overwrite_checkbox_key), false));
            }
        };
    }

    private void setNativeGpsOverwriteStatus(boolean enabled) {
        Log.i(TAG, "Setting native GPS overwriting to " + enabled);
        if(mMockedLocationSink == null) {
            mMockedLocationSink = new MockedLocationSink(getContext(),
                    getVehicleManager());
        }
        mMockedLocationSink.setOverwritingStatus(enabled);
    }
}

@@ -143,32 +143,31 @@
 nxc.
-sinks.MockedLocationSink
+VehicleLocationProvider
 ;%0A%0A/
@@ -269,30 +269,31 @@
  * @see 
-Mocked
+Vehicle
 Location
 Sink#set
@@ -284,20 +284,24 @@
 Location
-Sink
+Provider
 #setOver
@@ -479,30 +479,31 @@
 private 
-Mocked
+Vehicle
 Location
 Sink mMo
@@ -498,32 +498,41 @@
 tion
-Sink mMockedLocationSink
+Provider mVehicleLocationProvider
 ;%0A%0A 
@@ -720,38 +720,39 @@
            m
-Mocked
+Vehicle
 Location
 Sink.stop();
@@ -739,20 +739,24 @@
 Location
-Sink
+Provider
 .stop();
@@ -765,38 +765,39 @@
            m
-Mocked
+Vehicle
 Location
 Sink = null;
@@ -780,28 +780,32 @@
 icleLocation
-Sink
+Provider
  = null;%0A   
@@ -1556,30 +1556,31 @@
     if(m
-Mocked
+Vehicle
 Location
 Sink == 
@@ -1571,20 +1571,24 @@
 Location
-Sink
+Provider
  == null
@@ -1600,38 +1600,39 @@
            m
-Mocked
+Vehicle
 Location
 Sink = new M
@@ -1623,37 +1623,46 @@
 tion
-Sink = new MockedLocationSink
+Provider = new VehicleLocationProvider
 (get
@@ -1737,22 +1737,23 @@
    m
-Mocked
+Vehicle
 Location
 Sink
@@ -1752,12 +1752,16 @@
 tion
-Sink
+Provider
 .set

Use new class name for VehicleLocationProvider in Enabler.