Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,786,479 Members 37,583 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Advanced Parameters code optimization

Tip us?
 
ubdu
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 5
Join Date: Oct 2012
Question [Q] Advanced Parameters code optimization

Hi, I finally achieved what I was trying to do, but I'm wondering if there's a better way to write it all out.

It's just a basic battery progress bar color changer in Advanced Parameters.

If the battery is charging, the color is blue.
If the battery is discharging, and is less than or equal to 25% then the color is red.
If the battery is discharging, and is between 26% and 50% (inclusive) then the color is yellow.
If the battery is discharging, and is greater than 51% then the color is green.

My code:
Code:
$#BSTATN#=2?[cl]0000FF[/cl]$
$#BSTATN#!=2&&#BLEVN#<=25?[cl]FF0000[/cl]$
$#BSTATN#!=2&&#BLEVN#>25&&#BLEVN#<=50?[cl]FFFF00[/cl]$
$#BSTATN#!=2&&#BLEVN#>50?[cl]00FF00[/cl]$
Is there a more concise or better way to get my results? I'm trying to learn to expand my scope. Thanks in advance.
 
ubdu
Old
(Last edited by ubdu; 19th April 2014 at 07:38 PM.) Reason: making it easier to read
#2  
Junior Member - OP
Thanks Meter 0
Posts: 5
Join Date: Oct 2012
Quote:
Originally Posted by ubdu View Post
Hi, I finally achieved what I was trying to do, but I'm wondering if there's a better way to write it all out.

It's just a basic battery progress bar color changer in Advanced Parameters.

If the battery is charging, the color is blue.
If the battery is discharging, and is less than or equal to 25% then the color is red.
If the battery is discharging, and is between 26% and 50% (inclusive) then the color is yellow.
If the battery is discharging, and is greater than 51% then the color is green.

My code:
Code:
$#BSTATN#=2?[cl]0000FF[/cl]$
$#BSTATN#!=2&&#BLEVN#<=25?[cl]FF0000[/cl]$
$#BSTATN#!=2&&#BLEVN#>25&&#BLEVN#<=50?[cl]FFFF00[/cl]$
$#BSTATN#!=2&&#BLEVN#>50?[cl]00FF00[/cl]$
Is there a more concise or better way to get my results? I'm trying to learn to expand my scope. Thanks in advance.
I'm going to answer myself with:

Code:
[cl]$#BSTATN#=2?0000FF$
$#BSTATN#!=2&&#BLEVN#<=25?FF0000$
$#BSTATN#!=2&&#BLEVN#>25&&#BLEVN#<=50?FFFF00$
$#BSTATN#!=2&&#BLEVN#>50?00FF00$[/cl]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes