mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-09 07:01:33 +02:00
Basically moved code out of ControlCenter to a separate class. Also provides change events when the device list has changed, or changes to the device state have occurred.
40 lines
1.6 KiB
Java
40 lines
1.6 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
|
|
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) {
|
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
if (!prefs.getBoolean("general_autoconnectonbluetooth", false)) {
|
|
return;
|
|
}
|
|
|
|
GBApplication.deviceService().connect();
|
|
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
|
|
GBApplication.deviceService().quit();
|
|
|
|
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent);
|
|
}
|
|
}
|
|
}
|
|
}
|