Renamed more-icons-per-row-5x4-flare576
[webos-internals:adamrmcd-modifications.git] / luna / battery-percent-and-icon.patch
1 diff --git a/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js b/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
2 index ee479ac..c2447db 100644
3 --- a/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
4 +++ b/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
5 @@ -1430,10 +1430,49 @@ closePbapAlert: function() {
6         }       
7  },
8  
9 +/* Format battery level percent
10 + * We use this function instead of just a variable because
11 + * sometimes this.batteryLevel is used, and sometimes
12 + * payload.percent_ui is
13 + */
14 +getBatteryLevelPercent: function(percent, color, image, charging) {    
15 +       if (color) {
16 +               if (charging == 1)
17 +                       bColor = '#33CCFF';
18 +               else if (percent >= 70) 
19 +                       bColor = '#33FF33';
20 +               else if(percent <= 69 && percent >= 45) 
21 +                       bColor = '#FFFF33';
22 +               else if(percent <= 44 && percent >= 20)
23 +                       bColor = '#FFCC00';
24 +               else if(percent <= 19)
25 +                       bColor = '#FF0000';
26 +               else 
27 +                       bColor = 'white';
28 +               
29 +               // Use span to set color
30 +               if (image != undefined)
31 +                       var fPercent = '<span style="color: ' + bColor + ';">' + percent + unescape('%') + '</span>';
32 +               else 
33 +                       var fPercent = '<span style="position: relative; bottom: 2px; color: ' + bColor + ';">' + percent + unescape('%') + '</span>';
34 +       }
35 +       else {
36 +               var fPercent = percent + unescape('%');
37 +       }
38 +       return fPercent;
39 +},
40 +
41 +
42  /*
43   * Handle power and charging notifications
44   */
45  handlePowerNotifications: function(payload) {
46 +       // Replace this with a user definable setting
47 +       var batteryLevelImage = 2;      // 0 displays image (factory default)
48 +                                       // 1 displays numerical percentage
49 +                                       // 2 displays the image on left and numerical percentage on right (default)
50 +               
51 +       var batteryLevelColor = 1; // Set to 0 for white, 1 for color
52         
53         Mojo.Log.info("SystemUI Power Payload "+ Object.toJSON(payload));
54         if(!this.powerdServiceUp) {
55 @@ -1453,7 +1492,15 @@ handlePowerNotifications: function(payload) {
56                         // Show the battery level if not charging
57                         if (!this.isCharging) {
58                                 Mojo.Log.info("SystemUI- Is Charging "+ this.isCharging + " Battery level "+ i);
59 +                               if (batteryLevelImage == 0) {
60                                 $('power').className = 'battery-' + i;
61 +                               } else if(batteryLevelImage == 1) {
62 +                                       $('power').className = 'battery-percent';
63 +                                       $('power').innerHTML = this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 0);
64 +                               } else if(batteryLevelImage == 2) {
65 +                                       $('power').className = 'battery-percentimage';
66 +                                       $('power').innerHTML = '<img src="images/battery-' + i + '.png" />' + this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor);
67 +                               }
68                                 
69                                 //Show Banner Message if the Battery level is below 20%
70                                 var batteryalert = $L("#{percent_ui}% battery remaining").interpolate(payload); 
71 @@ -1482,10 +1529,23 @@ handlePowerNotifications: function(payload) {
72                         }
73                         else {
74                                 Mojo.Log.info("SystemUI- Is Charging "+ this.isCharging );
75 -                               if(payload.percent_ui == 100)
76 +                               if (batteryLevelImage == 0) {
77 +                                       if (payload.percent_ui == 100)
78                                         $('power').className = 'battery-charged';
79                                 else
80                                         $('power').className = 'battery-charging-' + i;
81 +                               } else if (batteryLevelImage == 1) {
82 +                                       $('power').className = 'battery-percent';
83 +                                       $('power').innerHTML = this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
84 +                               } else if(batteryLevelImage == 2) {
85 +                                       if (payload.percent_ui == 100) {
86 +                                               $('power').className = 'battery-percentimage-charged';
87 +                                               $('power').innerHTML = '<img src="images/battery-charged.png" />' + this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
88 +                                       } else {
89 +                                               $('power').className = 'battery-percentimage';
90 +                                               $('power').innerHTML = '<img src="images/battery-charging-' + i + '.png" />' + this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
91 +                                       }
92 +                               }
93                                         
94                         }
95                         
96 @@ -1522,10 +1582,23 @@ handlePowerNotifications: function(payload) {
97                                                 
98                 if (this.isCharging) {
99                         Mojo.Log.info("SystemUI- Charger Notification "+ this.isCharging + " Last battery level "+ this.lastBatteryLevel);
100 -                       if(this.batteryLevel == 100)
101 +                       if (batteryLevelImage == 0) {
102 +                               if (this.batteryLevel == 100)
103                                 $('power').className = 'battery-charged';
104                         else
105                                 $('power').className = 'battery-charging-' + this.lastBatteryLevel;
106 +                       } else if(batteryLevelImage == 1) {
107 +                               $('power').className = 'battery-percent';
108 +                               $('power').innerHTML = this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
109 +                       } else if(batteryLevelImage == 2) {
110 +                               if (this.batteryLevel == 100) {
111 +                                       $('power').className = 'battery-percentimage-charged';
112 +                                       $('power').innerHTML = '<img src="images/battery-charged.png" />' + this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
113 +                               } else {
114 +                                       $('power').className = 'battery-percentimage';
115 +                                       $('power').innerHTML = '<img src="images/battery-charging-' + this.lastBatteryLevel + '.png" />' + this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
116 +                               }
117 +                       }
118                                                 
119                         var stageController = Mojo.Controller.getAppController().getStageProxy("LowBatteryAlert");
120                         if (stageController) {
121 @@ -1546,7 +1619,17 @@ handlePowerNotifications: function(payload) {
122                 else {
123                         this.chargingBannerShown = false;                       
124                         Mojo.Log.info("SystemUI- Charger Notification "+ this.isCharging + " Last battery level "+ this.lastBatteryLevel);
125 +                       if (batteryLevelImage == 0) {
126                         $('power').className = 'battery-' + this.lastBatteryLevel;      
127 +                       }
128 +                       else if (batteryLevelImage == 1) {
129 +                               $('power').className = 'battery-percent';
130 +                               $('power').innerHTML = this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true);
131 +                       }
132 +                       else if(batteryLevelImage == 2) {
133 +                               $('power').className = 'battery-percentimage';
134 +                               $('power').innerHTML = '<img src="images/battery-' + this.lastBatteryLevel + '.png" />' + this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor);
135 +                       }       
136                         Mojo.Controller.getAppController().removeBanner('chargingAlert');               
137                 }       
138         }
139 diff --git a/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css b/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
140 index 58b22e8..b23eab5 100644
141 --- a/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
142 +++ b/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
143 @@ -136,6 +136,22 @@ body.palm-default {
144         margin-left: 2px;
145         width: 17px;            
146  }
147 +
148 +/* Begin: Battery Percent / Image w/ Percent */
149 +#power.battery-percent {
150 +       width: 38px;
151 +       background-color: black;
152 +}
153 +#power.battery-percentimage {
154 +       width: 49px;
155 +       background-color: black;
156 +}
157 +#power.battery-percentimage-charged {
158 +       width: 49px;
159 +       background-color: black;
160 +}
161 +/* End: Battery Percent / Image w/ Percent */
162 +
163  #power.error {
164         background: url(../images/battery-error.png) center center no-repeat;
165  }