Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Fix battery charging or discharging on android player mini-hack
Browse files Browse the repository at this point in the history
Must check to see how it is charging.
  • Loading branch information
jamesmontemagno committed Dec 2, 2014
1 parent 22e23ed commit 285f8b9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions XamarinAndroidPlayer/AndroidPlayerMiniHack/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,26 @@ protected override void OnCreate (Bundle bundle)

batterylevel.Text = string.Format("Current Charge: {0}%", Math.Floor (level * 100D / scale));


// Are we charging / charged?
// Are we charging / charged? works on phones, not emulators must check how.
int status = battery.GetIntExtra(BatteryManager.ExtraStatus, -1);
var isCharging = status == (int)BatteryStatus.Charging || status == (int)BatteryStatus.Full;

batterystatus.Text = "Status: " + (isCharging ? "charging" : "discharging");
// How are we charging?
var chargePlug = battery.GetIntExtra(BatteryManager.ExtraPlugged, -1);
var usbCharge = chargePlug == (int)BatteryPlugged.Usb;
var acCharge = chargePlug == (int)BatteryPlugged.Ac;
var wirelessCharge = chargePlug == (int)BatteryPlugged.Wireless;

isCharging = (usbCharge || acCharge || wirelessCharge);
if(!isCharging){
batterystatus.Text = "Status: discharging";
} else if(usbCharge){
batterystatus.Text = "Status: charging via usb";
} else if(acCharge){
batterystatus.Text = "Status: charging via ac";
} else if(wirelessCharge){
batterystatus.Text = "Status: charging via wireless";
}
};

recyclerView = FindViewById<RecyclerView> (Resource.Id.recycler_view);
Expand Down

0 comments on commit 285f8b9

Please sign in to comment.