// Path: app/src/main/java/hrv/band/app/device/antplus/AntPlusRRDataDevice.java
// public class AntPlusRRDataDevice
//         extends HRVRRIntervalDevice
//         implements AntPluginPcc.IDeviceStateChangeReceiver,
//         AntPluginPcc.IPluginAccessResultReceiver<AntPlusHeartRatePcc>,
//         AntPlusHeartRatePcc.ICalculatedRrIntervalReceiver {
// 
//     private final Activity activity;
//     private AntPlusHeartRatePcc wgtplc;
// 
//     public AntPlusRRDataDevice(Activity activity) {
//         this.activity = activity;
//     }
// 
//     @Override
//     public void onDeviceStateChange(DeviceState deviceState) {
//         if(deviceState == DeviceState.DEAD)
//         {
//             wgtplc = null;
//         }
//     }
// 
//     @Override
//     public void onResultReceived(AntPlusHeartRatePcc antPlusHeartRatePcc, RequestAccessResult requestAccessResult, DeviceState deviceState) {
// 
//         switch(requestAccessResult) {
//             case SUCCESS:
//                 wgtplc = antPlusHeartRatePcc;
//                 notifyDeviceStatusChanged(HRVDeviceStatus.CONNECTED);
//                 break;
//             case USER_CANCELLED:
//             case SEARCH_TIMEOUT:
//             case OTHER_FAILURE:
//                 notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED);
//                 break;
//             default:
//                 notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED);
//         }
//     }
// 
//     @Override
//     public void onNewCalculatedRrInterval(long l, EnumSet<EventFlag> enumSet, BigDecimal bigDecimal, AntPlusHeartRatePcc.RrFlag rrFlag) {
//         double rr = bigDecimal.longValue() / 1000.0;
//         this.rrMeasurements.add(rr);
//         notifyRRIntervalListeners(rr);
//     }
// 
// 
//     @Override
//     public void stopMeasuring() {
//         if(wgtplc != null) {
//             wgtplc.releaseAccess();
//             notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED);
//         }
//     }
// 
//     @Override
//     public List<Double> getRRIntervals() {
//         return rrMeasurements;
//     }
// 
//     @Override
//     public void pauseMeasuring() {
//         stopMeasuring();
//     }
// 
//     @Override
//     public void destroy() {
//         stopMeasuring();
//     }
// 
//     @Override
//     public void connect() {
//         notifyDeviceStatusChanged(HRVDeviceStatus.CONNECTING);
// 
//         //Release the old access
//         if(wgtplc != null) {
//             wgtplc.releaseAccess();
//             wgtplc = null;
//         }
// 
//         final AntPlusRRDataDevice helper = this;
// 
//         //Make access request
//         activity.runOnUiThread(new Runnable() {
//             @Override
//             public void run() {
//                 AntPlusHeartRatePcc.requestAccess(activity, activity.getApplicationContext(), helper, helper);
//             }
//         });
//     }
// 
//     @Override
//     public void tryStartRRIntervalMeasuring() {
//         if(wgtplc == null)
//         {
//             connect();
//         }
//         else {
//             boolean submitted = wgtplc.subscribeCalculatedRrIntervalEvent(this);
// 
//             if(submitted) {
//                 notifyDeviceStartedMeasurement();
//             }
//         }
//     }
// }


import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import hrv.band.app.device.antplus.AntPlusRRDataDevice;
import hrv.band.app.device.msband.MSBandRRIntervalDevice;
package hrv.band.app.device;



/**
 * Copyright (c) 2017
 * Created by Thomas Czogalik on 23.04.2017
 */
public class ConnectionManager {
    private Activity activity;
    private SharedPreferences sharedPreferences;

    private static final String SELECTED_DEVICE_ID = "selected_device_id";

// Path: app/src/main/java/hrv/band/app/device/antplus/AntPlusRRDataDevice.java
// public class AntPlusRRDataDevice
//         extends HRVRRIntervalDevice
//         implements AntPluginPcc.IDeviceStateChangeReceiver,
//         AntPluginPcc.IPluginAccessResultReceiver<AntPlusHeartRatePcc>,
//         AntPlusHeartRatePcc.ICalculatedRrIntervalReceiver {
// 
//     private final Activity activity;
//     private AntPlusHeartRatePcc wgtplc;
// 
//     public AntPlusRRDataDevice(Activity activity) {
//         this.activity = activity;
//     }
// 
//     @Override
//     public void onDeviceStateChange(DeviceState deviceState) {
//         if(deviceState == DeviceState.DEAD)
//         {
//             wgtplc = null;
//         }
//     }
// 
//     @Override
//     public void onResultReceived(AntPlusHeartRatePcc antPlusHeartRatePcc, RequestAccessResult requestAccessResult, DeviceState deviceState) {
// 
//         switch(requestAccessResult) {
//             case SUCCESS:
//                 wgtplc = antPlusHeartRatePcc;
//                 notifyDeviceStatusChanged(HRVDeviceStatus.CONNECTED);
//                 break;
//             case USER_CANCELLED:
//             case SEARCH_TIMEOUT:
//             case OTHER_FAILURE:
//                 notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED);
//                 break;
//             default:
//                 notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED);
//         }
//     }
// 
//     @Override
//     public void onNewCalculatedRrInterval(long l, EnumSet<EventFlag> enumSet, BigDecimal bigDecimal, AntPlusHeartRatePcc.RrFlag rrFlag) {
//         double rr = bigDecimal.longValue() / 1000.0;
//         this.rrMeasurements.add(rr);
//         notifyRRIntervalListeners(rr);
//     }
// 
// 
//     @Override
//     public void stopMeasuring() {
//         if(wgtplc != null) {
//             wgtplc.releaseAccess();
//             notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED);
//         }
//     }
// 
//     @Override
//     public List<Double> getRRIntervals() {
//         return rrMeasurements;
//     }
// 
//     @Override
//     public void pauseMeasuring() {
//         stopMeasuring();
//     }
// 
//     @Override
//     public void destroy() {
//         stopMeasuring();
//     }
// 
//     @Override
//     public void connect() {
//         notifyDeviceStatusChanged(HRVDeviceStatus.CONNECTING);
// 
//         //Release the old access
//         if(wgtplc != null) {
//             wgtplc.releaseAccess();
//             wgtplc = null;
//         }
// 
//         final AntPlusRRDataDevice helper = this;
// 
//         //Make access request
//         activity.runOnUiThread(new Runnable() {
//             @Override
//             public void run() {
//                 AntPlusHeartRatePcc.requestAccess(activity, activity.getApplicationContext(), helper, helper);
//             }
//         });
//     }
// 
//     @Override
//     public void tryStartRRIntervalMeasuring() {
//         if(wgtplc == null)
//         {
//             connect();
//         }
//         else {
//             boolean submitted = wgtplc.subscribeCalculatedRrIntervalEvent(this);
// 
//             if(submitted) {
//                 notifyDeviceStartedMeasurement();
//             }
//         }
//     }
// }


// Path: app/src/main/java/hrv/band/app/device/ConnectionManager.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import hrv.band.app.device.antplus.AntPlusRRDataDevice;
import hrv.band.app.device.msband.MSBandRRIntervalDevice;

package hrv.band.app.device;



/**
 * Copyright (c) 2017
 * Created by Thomas Czogalik on 23.04.2017
 */
public class ConnectionManager {
    private Activity activity;
    private SharedPreferences sharedPreferences;

    private static final String SELECTED_DEVICE_ID = "selected_device_id";

    public ConnectionManager(Activity activity) {