40 lines
1.5 KiB
Java
40 lines
1.5 KiB
Java
|
package info.nightscout.androidaps.receivers;
|
||
|
|
||
|
import android.content.BroadcastReceiver;
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.net.ConnectivityManager;
|
||
|
import android.net.NetworkInfo;
|
||
|
import android.net.wifi.SupplicantState;
|
||
|
import android.net.wifi.WifiInfo;
|
||
|
import android.net.wifi.WifiManager;
|
||
|
import android.os.BatteryManager;
|
||
|
import android.os.PowerManager;
|
||
|
import android.support.annotation.Nullable;
|
||
|
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
import info.nightscout.androidaps.MainApp;
|
||
|
import info.nightscout.androidaps.events.EventChargingState;
|
||
|
import info.nightscout.androidaps.events.EventNetworkChange;
|
||
|
|
||
|
public class ChargingStateReceiver extends BroadcastReceiver {
|
||
|
private static Logger log = LoggerFactory.getLogger(ChargingStateReceiver.class);
|
||
|
|
||
|
@Override
|
||
|
public void onReceive(Context context, Intent intent) {
|
||
|
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
||
|
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
|
||
|
status == BatteryManager.BATTERY_STATUS_FULL;
|
||
|
|
||
|
int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||
|
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
|
||
|
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
|
||
|
|
||
|
EventChargingState event = new EventChargingState(isCharging, usbCharge || acCharge);
|
||
|
if (event != null)
|
||
|
MainApp.bus().post(event);
|
||
|
}
|
||
|
|
||
|
}
|