// Path: blelibrary/src/main/java/com/github/captain_miao/android/ble/constant/BleScanState.java
// public enum BleScanState {
// 
//     SCAN_TIMEOUT(-2, "SCAN_SUCCESS_TIME_OUT"),
//     BLUETOOTH_OFF(-1, "BLUETOOTH_OFF"),
//     SCAN_SUCCESS(0, "SCAN_SUCCESS"),
//     SCAN_FAILED_ALREADY_STARTED(1, "SCAN_FAILED_ALREADY_STARTED"),
//     SCAN_FAILED_APPLICATION_REGISTRATION_FAILED(2, "SCAN_FAILED_APPLICATION_REGISTRATION_FAILED"),
//     SCAN_FAILED_INTERNAL_ERROR(3, "SCAN_FAILED_INTERNAL_ERROR"),
//     SCAN_FAILED_FEATURE_UNSUPPORTED(4, "SCAN_FAILED_FEATURE_UNSUPPORTED"),
//     SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES(5, "SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES");
// 
// 
//     BleScanState(int code, String message) {
//         this.code = code;
//         this.message = message;
//     }
// 
//     private int code;
//     private String message;
// 
//     public int getCode() {
//         return code;
//     }
// 
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public static BleScanState newInstance(int code) {
//         switch (code) {
//             case -2:
//                 return BleScanState.SCAN_TIMEOUT;
//             case -1:
//                 return BleScanState.BLUETOOTH_OFF;
// 
//             case 1:
//                 return BleScanState.SCAN_FAILED_ALREADY_STARTED;
//             case 2:
//                 return BleScanState.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED;
//             case 3:
//                 return BleScanState.SCAN_FAILED_INTERNAL_ERROR;
//             case 4:
//                 return BleScanState.SCAN_FAILED_FEATURE_UNSUPPORTED;
//             case 5:
//                 return BleScanState.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES;
//             default:
//                 return BleScanState.SCAN_SUCCESS;
//         }
//     }
// }
// 
// Path: blelibrary/src/main/java/com/github/captain_miao/android/ble/utils/BleLog.java
// public class BleLog {
// 	private static boolean isPrintLog = true;
// 
// 	private BleLog() {}
// 
// 	public static boolean isPrintLog() {
// 		return isPrintLog;
// 	}
// 
// 	public static void setPrintLog(boolean isPrintLog) {
// 		BleLog.isPrintLog = isPrintLog;
// 	}
// 
// 	public static void v(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.v(tag, msg);
// 		}
// 	}
// 
// 	public static void d(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.d(tag, msg);
// 		}
// 	}
// 
// 	public static void i(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.i(tag, msg);
// 		}
// 	}
// 
// 	public static void w(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.w(tag, msg);
// 		}
// 	}
// 
// 	public static void e(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.e(tag, msg);
// 		}
// 	}
// }


import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.os.Build;
import com.github.captain_miao.android.ble.constant.BleScanState;
import com.github.captain_miao.android.ble.utils.BleLog;
import java.util.List;
package com.github.captain_miao.android.ble;




/**
 * @author YanLu
 * @since 15/9/14
 *
 * Android5.0 above scan bluetooth
 */

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class LollipopBleScanner extends BaseBleScanner {
    private final static String TAG = LollipopBleScanner.class.getName();


    private BluetoothLeScanner mBluetoothScanner = null;
    private BluetoothAdapter mBluetoothAdapter = null;
    private SimpleScanCallback mScanCallback = null;

    public LollipopBleScanner(SimpleScanCallback callback) {
        mScanCallback = callback;
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter != null) {
            mBluetoothScanner = mBluetoothAdapter.getBluetoothLeScanner();
        }
    }

    @SuppressWarnings(value = {"deprecation"})
    @Override
    public void onStartBleScan(long timeoutMillis) {
        long delay = timeoutMillis == 0 ? defaultTimeout : timeoutMillis;
        if (mBluetoothScanner != null && mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
            try {
                mBluetoothScanner.startScan(scanCallback);
                isScanning = true;
            } catch (Exception e){
                isScanning = false;
                BleLog.e(TAG, e.toString());
            }
            timeoutHandler.postDelayed(timeoutRunnable, delay);
        } else {
// Path: blelibrary/src/main/java/com/github/captain_miao/android/ble/constant/BleScanState.java
// public enum BleScanState {
// 
//     SCAN_TIMEOUT(-2, "SCAN_SUCCESS_TIME_OUT"),
//     BLUETOOTH_OFF(-1, "BLUETOOTH_OFF"),
//     SCAN_SUCCESS(0, "SCAN_SUCCESS"),
//     SCAN_FAILED_ALREADY_STARTED(1, "SCAN_FAILED_ALREADY_STARTED"),
//     SCAN_FAILED_APPLICATION_REGISTRATION_FAILED(2, "SCAN_FAILED_APPLICATION_REGISTRATION_FAILED"),
//     SCAN_FAILED_INTERNAL_ERROR(3, "SCAN_FAILED_INTERNAL_ERROR"),
//     SCAN_FAILED_FEATURE_UNSUPPORTED(4, "SCAN_FAILED_FEATURE_UNSUPPORTED"),
//     SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES(5, "SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES");
// 
// 
//     BleScanState(int code, String message) {
//         this.code = code;
//         this.message = message;
//     }
// 
//     private int code;
//     private String message;
// 
//     public int getCode() {
//         return code;
//     }
// 
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public static BleScanState newInstance(int code) {
//         switch (code) {
//             case -2:
//                 return BleScanState.SCAN_TIMEOUT;
//             case -1:
//                 return BleScanState.BLUETOOTH_OFF;
// 
//             case 1:
//                 return BleScanState.SCAN_FAILED_ALREADY_STARTED;
//             case 2:
//                 return BleScanState.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED;
//             case 3:
//                 return BleScanState.SCAN_FAILED_INTERNAL_ERROR;
//             case 4:
//                 return BleScanState.SCAN_FAILED_FEATURE_UNSUPPORTED;
//             case 5:
//                 return BleScanState.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES;
//             default:
//                 return BleScanState.SCAN_SUCCESS;
//         }
//     }
// }
// 
// Path: blelibrary/src/main/java/com/github/captain_miao/android/ble/utils/BleLog.java
// public class BleLog {
// 	private static boolean isPrintLog = true;
// 
// 	private BleLog() {}
// 
// 	public static boolean isPrintLog() {
// 		return isPrintLog;
// 	}
// 
// 	public static void setPrintLog(boolean isPrintLog) {
// 		BleLog.isPrintLog = isPrintLog;
// 	}
// 
// 	public static void v(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.v(tag, msg);
// 		}
// 	}
// 
// 	public static void d(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.d(tag, msg);
// 		}
// 	}
// 
// 	public static void i(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.i(tag, msg);
// 		}
// 	}
// 
// 	public static void w(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.w(tag, msg);
// 		}
// 	}
// 
// 	public static void e(String tag, String msg) {
// 		if (isPrintLog) {
// 			Log.e(tag, msg);
// 		}
// 	}
// }


// Path: blelibrary/src/main/java/com/github/captain_miao/android/ble/LollipopBleScanner.java
import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.os.Build;
import com.github.captain_miao.android.ble.constant.BleScanState;
import com.github.captain_miao.android.ble.utils.BleLog;
import java.util.List;

package com.github.captain_miao.android.ble;




/**
 * @author YanLu
 * @since 15/9/14
 *
 * Android5.0 above scan bluetooth
 */

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class LollipopBleScanner extends BaseBleScanner {
    private final static String TAG = LollipopBleScanner.class.getName();


    private BluetoothLeScanner mBluetoothScanner = null;
    private BluetoothAdapter mBluetoothAdapter = null;
    private SimpleScanCallback mScanCallback = null;

    public LollipopBleScanner(SimpleScanCallback callback) {
        mScanCallback = callback;
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter != null) {
            mBluetoothScanner = mBluetoothAdapter.getBluetoothLeScanner();
        }
    }

    @SuppressWarnings(value = {"deprecation"})
    @Override
    public void onStartBleScan(long timeoutMillis) {
        long delay = timeoutMillis == 0 ? defaultTimeout : timeoutMillis;
        if (mBluetoothScanner != null && mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
            try {
                mBluetoothScanner.startScan(scanCallback);
                isScanning = true;
            } catch (Exception e){
                isScanning = false;
                BleLog.e(TAG, e.toString());
            }
            timeoutHandler.postDelayed(timeoutRunnable, delay);
        } else {
            mScanCallback.onBleScanFailed(BleScanState.BLUETOOTH_OFF);