From 6cf4342574b18ef988c00d135ebff5f326736630 Mon Sep 17 00:00:00 2001 From: androidnaut Date: Fri, 16 Oct 2015 12:13:39 -0500 Subject: [PATCH 1/2] Update BatteryDrawer.java The battery life indicator is a circle within a circle. The inner circle currently has its radius set to the battery life percentage of the radius of the overall circle. Thus, when battery life is at 50%, the radius or diameter of the smaller circle is 50% of the radius or diameter of the overall circle. This is not an accurate representation of battery life. Instead, the AREA of the circles should represent the battery percentage left. Remember pi r-squared is the area of a circle, so if square the radius of the large circle, multiply by the battery percentage, and then take the square root of that, we'll have a smaller circle which area is proportional to the larger circle according to the percentage battery life left. This is a much more accurate indication of battery life. --- .../com/androidexperiments/meter/drawers/BatteryDrawer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java b/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java index 7f06b57..f5c37ea 100644 --- a/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java +++ b/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java @@ -180,7 +180,7 @@ public void draw(Canvas c){ int fgCircleColor = interpolateColor(color_foreground_decharge, color_foreground_charging, (float) lerp(_colorTransitionToCharged)); fgCircleColor = interpolateColor(fgCircleColor, color_foreground_critical, (float) lerp(_colorTransitionToCritical)); paint.setColor(fgCircleColor); - c.drawCircle((float)(x+c.getWidth()*pos.getX()),(float)(y+c.getWidth()*pos.getY()), _circleSize*batteryPct, paint); + c.drawCircle((float)(x+c.getWidth()*pos.getX()),(float)(y+c.getWidth()*pos.getY()), Math.sqrt(_circleSize*_circleSize*batteryPct), paint); // Text String label1 = "Battery " + Integer.toString(Math.round(batteryPct*100)) + "%"; From 468b155e3f688da46c90b1846ca1ff3f444d96ff Mon Sep 17 00:00:00 2001 From: androidnaut Date: Fri, 23 Oct 2015 17:01:54 -0500 Subject: [PATCH 2/2] Update BatteryDrawer.java Oops -- forgot to cast my edited 3rd argument to float. Fixed. Works great on N6 running 5.1.1 and more accurately represents remaining battery life. --- .../com/androidexperiments/meter/drawers/BatteryDrawer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java b/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java index f5c37ea..c21d897 100644 --- a/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java +++ b/app/src/main/java/com/androidexperiments/meter/drawers/BatteryDrawer.java @@ -180,7 +180,7 @@ public void draw(Canvas c){ int fgCircleColor = interpolateColor(color_foreground_decharge, color_foreground_charging, (float) lerp(_colorTransitionToCharged)); fgCircleColor = interpolateColor(fgCircleColor, color_foreground_critical, (float) lerp(_colorTransitionToCritical)); paint.setColor(fgCircleColor); - c.drawCircle((float)(x+c.getWidth()*pos.getX()),(float)(y+c.getWidth()*pos.getY()), Math.sqrt(_circleSize*_circleSize*batteryPct), paint); + c.drawCircle((float)(x+c.getWidth()*pos.getX()),(float)(y+c.getWidth()*pos.getY()), (float) Math.sqrt(_circleSize*_circleSize*batteryPct), paint); // Text String label1 = "Battery " + Integer.toString(Math.round(batteryPct*100)) + "%";