2 New, 4 Updated patches.
[webos-internals:modifications.git] / top-bar / top-bar-battery-percent-and-icon-white-red-teal.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 6fdbb39..c7f8fc7 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 @@ -1567,10 +1567,36 @@ closePbapAlert: function() {
6         }       
7  },
8  
9 +/* Format battery level percent */
10 +getBatteryLevelPercent: function(percent, color, image, charging) {    
11 +       if (color) {
12 +               if (charging == 1)
13 +                       bColor = '#00FFCC'; //teal
14 +               else if (percent >= 13) 
15 +                       bColor = '#FFFFFF'; //white
16 +               else if(percent <= 12)
17 +                       bColor = '#FF0000'; //red
18 +               else 
19 +                       bColor = 'white';
20 +               
21 +               if (image != undefined)
22 +                       var fPercent = '<span style="color: ' + bColor + ';">' + percent + unescape('%') + '</span>';
23 +               else 
24 +                       var fPercent = '<span style="position: relative; bottom: 2px; color: ' + bColor + ';">' + percent + unescape('%') + '</span>';
25 +       }
26 +       else {
27 +               var fPercent = percent + unescape('%');
28 +       }
29 +       return fPercent;
30 +},
31 +
32  /*
33   * Handle power and charging notifications
34   */
35  handlePowerNotifications: function(payload) {
36 +       // user definable setting
37 +       var batteryLevelImage = 2;      // 2 displays the image on left and numerical percentage on right
38 +       var batteryLevelColor = 1; // Set to 0 for white, 1 for color
39         
40         Mojo.Log.info("SystemUI Power Payload "+ Object.toJSON(payload));
41         if(!this.powerdServiceUp) {
42 @@ -1590,7 +1616,15 @@ handlePowerNotifications: function(payload) {
43                         // Show the battery level if not charging
44                         if (!this.isCharging) {
45                                 Mojo.Log.info("SystemUI- Is Charging "+ this.isCharging + " Battery level "+ i);
46 +                               if (batteryLevelImage == 0) {
47                                 $('power').className = 'battery-' + i;
48 +                               } else if(batteryLevelImage == 1) {
49 +                                       $('power').className = 'battery-percent';
50 +                                       $('power').innerHTML = this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 0);
51 +                               } else if(batteryLevelImage == 2) {
52 +                                       $('power').className = 'battery-percentimage';
53 +                                       $('power').innerHTML = '<img src="images/battery-' + i + '.png" />' + this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor);
54 +                               }
55                                 
56                                 //Show Banner Message if the Battery level is below 20%
57                                 var batteryalert = $L("#{percent_ui}% battery remaining").interpolate(payload); 
58 @@ -1622,10 +1656,23 @@ handlePowerNotifications: function(payload) {
59                         }
60                         else {
61                                 Mojo.Log.info("SystemUI- Is Charging "+ this.isCharging );
62 -                               if(payload.percent_ui == 100)
63 +                               if (batteryLevelImage == 0) {
64 +                                       if (payload.percent_ui == 100)                          
65                                         $('power').className = 'battery-charged';
66                                 else
67                                         $('power').className = 'battery-charging-' + i;
68 +                               } else if (batteryLevelImage == 1) {
69 +                                       $('power').className = 'battery-percent';
70 +                                       $('power').innerHTML = this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
71 +                               } else if(batteryLevelImage == 2) {
72 +                                       if (payload.percent_ui == 100) {
73 +                                               $('power').className = 'battery-percentimage-charged';
74 +                                               $('power').innerHTML = '<img src="images/battery-charged.png" />' + this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
75 +                                       } else {
76 +                                               $('power').className = 'battery-percentimage';
77 +                                               $('power').innerHTML = '<img src="images/battery-charging-' + i + '.png" />' + this.getBatteryLevelPercent(payload.percent_ui, batteryLevelColor, true, 1);
78 +                                       }
79 +                               }
80                                         
81                         }
82                         
83 @@ -1662,10 +1709,23 @@ handlePowerNotifications: function(payload) {
84                                                 
85                 if (this.isCharging) {
86                         Mojo.Log.info("SystemUI- Charger Notification "+ this.isCharging + " Last battery level "+ this.lastBatteryLevel);
87 -                       if(this.batteryLevel == 100)
88 +                       if (batteryLevelImage == 0) {
89 +                               if (this.batteryLevel == 100)
90                                 $('power').className = 'battery-charged';
91                         else
92                                 $('power').className = 'battery-charging-' + this.lastBatteryLevel;
93 +                       } else if(batteryLevelImage == 1) {
94 +                               $('power').className = 'battery-percent';
95 +                               $('power').innerHTML = this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
96 +                       } else if(batteryLevelImage == 2) {
97 +                               if (this.batteryLevel == 100) {
98 +                                       $('power').className = 'battery-percentimage-charged';
99 +                                       $('power').innerHTML = '<img src="images/battery-charged.png" />' + this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
100 +                               } else {
101 +                                       $('power').className = 'battery-percentimage';
102 +                                       $('power').innerHTML = '<img src="images/battery-charging-' + this.lastBatteryLevel + '.png" />' + this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true, 1);
103 +                               }
104 +                       }                               
105                                                 
106                         var stageController = Mojo.Controller.getAppController().getStageProxy("LowBatteryAlert");
107                         if (stageController) {
108 @@ -1686,7 +1746,17 @@ handlePowerNotifications: function(payload) {
109                 else {
110                         this.chargingBannerShown = false;                       
111                         Mojo.Log.info("SystemUI- Charger Notification "+ this.isCharging + " Last battery level "+ this.lastBatteryLevel);
112 +                       if (batteryLevelImage == 0) {
113                         $('power').className = 'battery-' + this.lastBatteryLevel;      
114 +                       }
115 +                       else if (batteryLevelImage == 1) {
116 +                               $('power').className = 'battery-percent';
117 +                               $('power').innerHTML = this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor, true);
118 +                       }
119 +                       else if(batteryLevelImage == 2) {
120 +                               $('power').className = 'battery-percentimage';
121 +                               $('power').innerHTML = '<img src="images/battery-' + this.lastBatteryLevel + '.png" />' + this.getBatteryLevelPercent(this.batteryLevel, batteryLevelColor);
122 +                       }                               
123                         Mojo.Controller.getAppController().removeBanner('chargingAlert');               
124                 }       
125         }
126 diff --git a/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css b/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
127 index 0917ee7..a6862a2 100644
128 --- a/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
129 +++ b/usr/lib/luna/system/luna-systemui/stylesheets/systemui.css
130 @@ -136,6 +136,22 @@ body.palm-default {
131         margin-left: 2px;
132         width: 17px;            
133  }
134 +
135 +/* Begin: Battery Percent / Image w/ Percent */
136 +#power.battery-percent {
137 +       width: 38px;
138 +       background-color: black;
139 +}
140 +#power.battery-percentimage {
141 +       width: 49px;
142 +       background-color: black;
143 +}
144 +#power.battery-percentimage-charged {
145 +       width: 49px;
146 +       background-color: black;
147 +}
148 +/* End: Battery Percent / Image w/ Percent */
149 +
150  #power.error {
151         background: url(../images/battery-error.png) center center no-repeat;
152  }