updates and additions
[webos-internals:modifications.git] / top-bar / top-bar-battery-percent-as-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 6d0a87a..5c9dd76 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 @@ -1962,10 +1962,38 @@ closePbapAlert: function() {
6         }       
7  },
8  
9 +getBatteryLevelPercent: function(percent, color, image, charging) {    
10 +       if (color) {
11 +               if (charging == 1)
12 +                       bColor = '#33CCFF';
13 +               else if (percent >= 70) 
14 +                       bColor = '#33FF33';
15 +               else if(percent <= 69 && percent >= 45) 
16 +                       bColor = '#FFFF33';
17 +               else if(percent <= 44 && percent >= 20)
18 +                       bColor = '#FFCC00';
19 +               else if(percent <= 19)
20 +                       bColor = '#FF0000';
21 +               else 
22 +                       bColor = 'white';
23 +               
24 +               // Use span to set color
25 +               if (image != undefined)
26 +                       var fPercent = '<span style="color: ' + bColor + ';">' + percent + '</span>';
27 +               else 
28 +                       var fPercent = '<span style="position: relative; bottom: 2px; color: ' + bColor + ';">' + percent + '</span>';
29 +       }
30 +       else {
31 +               var fPercent = percent;
32 +       }
33 +       return fPercent;
34 +},
35  /*
36   * Handle power and charging notifications
37   */
38  handlePowerNotifications: function(payload) {
39 +
40 +       var batteryLevelColor = 1; // Set to 0 for white, 1 for color
41         
42         Mojo.Log.info("SystemUI Power Payload "+ Object.toJSON(payload));
43         if(!this.powerdServiceUp) {
44 @@ -1993,7 +2021,8 @@ handlePowerNotifications: function(payload) {
45                         // Show the battery level if not charging
46                         if (!this.isCharging) {
47                                 Mojo.Log.info("SystemUI- Is Charging "+ this.isCharging + " Battery level "+ i);
48 -                               Mojo.Dom.get('power').className = 'battery-' + i;
49 +                               Mojo.Dom.get('power').className = 'battery-'+ i;
50 +                               Mojo.Dom.get('power').innerHTML = this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor);
51                                 
52                                 //Show Banner Message if the Battery level is below 20%
53                                 var batteryalert = $L("#{percent_ui}% battery remaining").interpolate(payload); 
54 @@ -2027,11 +2056,15 @@ handlePowerNotifications: function(payload) {
55                         }
56                         else {
57                                 Mojo.Log.info("SystemUI- Is Charging "+ this.isCharging );
58 -                               if(payload.percent_ui == 100)
59 +                               if (payload.percent_ui == 100) {
60                                         Mojo.Dom.get('power').className = 'battery-charged';
61 -                               else
62 +                                       Mojo.Dom.get('power').innerHTML = this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
63 +                               } else {                                        
64                                         Mojo.Dom.get('power').className = 'battery-charging-' + i;
65 -                                       
66 +                                       Mojo.Dom.get('power').innerHTML = this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
67 +                               }
68 +                       
69 +                                                               
70                         }
71                         
72                         if(this.batteryLevel > 5 && this.batteryLevel <= 10) {                          
73 @@ -2075,10 +2108,13 @@ handlePowerNotifications: function(payload) {
74                                                 
75                 if (this.isCharging) {
76                         Mojo.Log.info("SystemUI- Charger Notification "+ this.isCharging + " Last battery level "+ this.lastBatteryLevel);
77 -                       if(this.batteryLevel == 100)
78 +                       if (this.batteryLevel == 100) {
79                                 Mojo.Dom.get('power').className = 'battery-charged';
80 -                       else
81 +                               Mojo.Dom.get('power').innerHTML = this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
82 +                       } else {
83                                 Mojo.Dom.get('power').className = 'battery-charging-' + this.lastBatteryLevel;
84 +                               Mojo.Dom.get('power').innerHTML = this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
85 +                       }
86                                                 
87                         var stageController = Mojo.Controller.getAppController().getStageController("LowBatteryAlert");
88                         if (stageController) {
89 @@ -2102,7 +2138,8 @@ handlePowerNotifications: function(payload) {
90                 else {
91                         this.chargingBannerShown = false;                       
92                         Mojo.Log.info("SystemUI- Charger Notification "+ this.isCharging + " Last battery level "+ this.lastBatteryLevel);
93 -                       Mojo.Dom.get('power').className = 'battery-' + this.lastBatteryLevel;   
94 +                       Mojo.Dom.get('power').className = 'battery-' + this.lastBatteryLevel;
95 +                       Mojo.Dom.get('power').innerHTML = this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor);    
96                         Mojo.Controller.getAppController().removeBanner('chargingAlert');       
97                         if (this.batteryLevel < this.minBatThresholdForUpdate) {
98                                 Mojo.Log.info("SystemUI - OTA - Closing All Update Alerts due to battery level dropped below threshold level and charger disconnected.");
99 diff --git a/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css b/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
100 index f3cacab..dc20f4f 100644
101 --- a/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
102 +++ b/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
103 @@ -141,11 +141,29 @@ body.palm-default {
104  }
105  
106  #power {
107 -       margin-left: 2px;
108 -       width: 17px;            
109 +       margin-left: 0px;
110 +       width: 25px;            
111 +}
112 +
113 +/* Begin: Battery Percent / Image w/ Percent */
114 +#power.battery-percent {
115 +       width: 27px; height: 28px; text-align: right;
116 +       font-size: 18px;
117 +}
118 +
119 +#power.battery-percentimage {
120 +       width: 49px;
121 +       background-color: black;
122  }
123  
124 -#power.error { background-image: url(../images/battery-error.png); }
125 +#power.battery-percentimage-charged {
126 +       width: 49px;
127 +       background-color: black;
128 +}
129 +/* End: Battery Percent / Image w/ Percent */
130 +
131 +
132 +/*#power.error { background-image: url(../images/battery-error.png); }
133  #power.battery-0 { background-image: url(../images/battery-0.png); }
134  #power.battery-1 { background-image: url(../images/battery-1.png); }
135  #power.battery-2 { background-image: url(../images/battery-2.png); }
136 @@ -171,7 +189,7 @@ body.palm-default {
137  #power.battery-charging-9 { background-image: url(../images/battery-charging-9.png); }
138  #power.battery-charging-10 { background-image: url(../images/battery-charging-10.png); }
139  #power.battery-charging-11 { background-image: url(../images/battery-charging-11.png); }
140 -#power.battery-charged { background-image: url(../images/battery-charged.png); }
141 +#power.battery-charged { background-image: url(../images/battery-charged.png); }*/
142  
143  #rssi {
144         width: 19px;