2015-05-30 21:40:42 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
2015-03-17 21:41:58 +01:00
|
|
|
|
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2015-03-27 10:56:08 +01:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2015-03-17 21:41:58 +01:00
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
2016-04-25 23:18:55 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2015-05-30 21:40:42 +02:00
|
|
|
|
2015-03-17 21:41:58 +01:00
|
|
|
public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
|
|
|
|
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
|
|
|
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
|
2015-03-22 12:46:28 +01:00
|
|
|
|
|
|
|
Intent refreshIntent = new Intent(ControlCenter.ACTION_REFRESH_DEVICELIST);
|
2015-03-29 23:43:05 +02:00
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
2015-03-22 12:46:28 +01:00
|
|
|
|
2016-04-25 23:18:55 +02:00
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
if (!prefs.getBoolean("general_autoconnectonbluetooth", false)) {
|
2015-03-17 21:41:58 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-03-21 18:18:07 +01:00
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().connect();
|
2015-03-17 22:03:54 +01:00
|
|
|
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().quit();
|
2015-03-17 22:03:54 +01:00
|
|
|
|
2015-12-07 23:33:32 +01:00
|
|
|
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
2015-03-27 10:56:08 +01:00
|
|
|
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent);
|
2015-03-17 21:41:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|