b0580620134072160a3a9745078f6d313d63f9a9
[profile/ivi/Modello_Homescreen.git] / js / main.js
1 /*global Bootstrap, evalInstalledApps, appList:true, wrapper, viewPort */
2
3 /**
4  * Home screen application is launched after system is completely booted up and provides access to available applications as well as to selected information from
5  * car CAN bus (via {{#crossLink "Bootstrap/carIndicator:property"}}{{/crossLink}} object). Hover and click on elements in images below to navigate to components of Home screen application.
6  *
7  * <img id="Image-Maps_1201312180420487" src="../assets/img/homescreen.png" usemap="#Image-Maps_1201312180420487" border="0" width="649" height="1152" alt="" />
8  *   <map id="_Image-Maps_1201312180420487" name="Image-Maps_1201312180420487">
9  *     <area shape="rect" coords="0,0,573,78" href="../classes/topbaricons.html" alt="top bar icons" title="Top bar icons" />
10  *     <area shape="rect" coords="0,77,644,132" href="../classes/clock.html" alt="clock" title="Clock"    />
11  *     <area shape="rect" coords="0,994,644,1147" href="../classes/bottompanel.html" alt="bottom panel" title="Bottom panel" />
12  *     <area shape="rect" coords="0,159,644,961" href="../classes/actionCatcher.html" alt="Action catcher" title="Action catcher" />
13  *     <area shape="rect" coords="573,1,644,76" href="../modules/Settings.html" alt="Settings" title="Settings"    />
14  *   </map>
15  * @module HomescreenApplication
16  * @main HomescreenApplication
17  **/
18
19 /**
20  * Provides inicialization of application and startup animations.
21  * @class main
22  * @static
23  **/
24
25 var isPc = true,
26     audioVolumeService,
27     audioObj;
28
29 var bootstrap;
30
31 if (typeof tizen !== 'undefined') {
32     isPc = false;
33 }
34 //main
35 if (!window.intelIVI) {
36     window.intelIVI = {};
37 }
38 var animationOngoing = false;
39
40 /**
41  * Initialize plugins, register events for Homescreen app.
42  * @method init
43  * @static
44  **/
45 var init = function() {
46     "use strict";
47
48     setPieAppIDs();
49
50     bootstrap = new Bootstrap(function(status) {
51         $('#dateTime').ClockPlugin('init', 60);
52         $('#dateTime').ClockPlugin('startTimer');
53
54         $('#bottomPanel').bottomPanel('init', true);
55         $("#topBarIcons").topBarIconsPlugin('init', 'dashboard');
56
57         evalInstalledApps();
58         window.intelIVI.main.init();
59
60         bootstrap.carIndicator.addListener({
61             onBatteryStatusChanged: function(newValue) {
62                 var newBatteryStatus = newValue.toString() + "%";
63                 $('#batteryStatus').html(newBatteryStatus);
64                 var newBatteryRange = "~" + Math.round(((newValue / 100) * bootstrap.carIndicator.status.fullBatteryRange)).toString() + " MI";
65                 $('#batteryRange').html(newBatteryRange);
66             },
67             onOutsideTempChanged: function(newValue) {
68                 $("#weatherStatus").html(newValue + "°C");
69             },
70             onInsideTempChanged: function(newValue) {
71                 $("#fanStatus").html(newValue + "°C");
72             },
73             onSpeedChanged: function(newValue) {
74                 $("#homeScrSpeed").html(newValue);
75             },
76             onFullBatteryRange: function() {
77
78             }
79         });
80         bootstrap.themeEngine.addStatusListener(function() {
81             appList = [];
82             evalInstalledApps();
83         });
84
85     });
86
87     /* fixed webkit animation bugs */
88     window.setTimeout(function() {
89         window.setInterval(function() {
90             $("#innerRing").removeClass("rollLeft");
91             $("#outerRing").removeClass("rollRight");
92             window.setTimeout(function() {
93                 $("#innerRing").addClass("rollLeft");
94                 $("#outerRing").addClass("rollRight");
95             }, 50);
96
97         }, 10000);
98    }, 1000);
99     window.setTimeout(function() {
100         window.setInterval(function() {
101           $('#wrapper .step9').removeClass('liveBg');
102             window.setTimeout(function() {
103                 $('#wrapper .step9').addClass('liveBg');
104             }, 50);
105
106         }, 7000);
107     }, 500);
108     /* end fixed webkit animation bugs */
109 };
110
111 $(function() {
112     "use strict";
113     // debug mode - window.setTimeout("init()", 20000);
114     init();
115 });
116
117 /**
118  * Store state of audio plugin before application closing.
119  * @method window.onbeforeunload
120  * @static
121  **/
122 window.onbeforeunload = function() {
123     "use strict";
124     $('#audioPlayer').audioAPI('setStatusAll');
125 };
126
127 /**
128  * Provides inicialization of application content and starts animation.
129  * @class intelIVI.main
130  * @static
131  **/
132 window.intelIVI.main = (window.intelIVI.main || {
133
134     /**
135      * Calls initialization of content.
136      * @method init
137      **/
138
139     init: function() {
140         "use strict";
141         var viewPort = window.intelIVI.corpus.init();
142         document.body.appendChild(viewPort);
143         window.intelIVI.utility.startAnimation(1);
144     },
145     /**
146      * Provides reloading of content.
147      * @method counterEnd
148      **/
149
150     counterEnd: function() {
151         "use strict";
152         window.location.reload();
153     }
154 });
155
156 function untouchable(param) {
157     "use strict";
158
159     setTimeout(function() {
160         animationOngoing = false;
161     }, param);
162 }
163
164 /**
165  * Provides initialization of animated application components.
166  * @class intelIVI.utility
167  * @static
168  **/
169 window.intelIVI.utility = (window.intelIVI.utility || {
170     /**
171      * Starts initial animations on Homescreen.
172      * @method startAnimation
173      **/
174
175     startAnimation: function(index) {
176         "use strict";
177         $('#wrapper .step' + (index - 2)).css('opacity', '0');
178         $('#wrapper .step' + index).css('opacity', '0.4');
179         if (index === 10) {
180             $('#indicator').addClass('showI');
181             window.intelIVI.utility.showContent(1);
182             return;
183         }
184         var time = 40;
185         setTimeout(function() {
186             index++;
187             window.intelIVI.utility.startAnimation(index);
188         }, time);
189     },
190     /**
191      * Shows animated content pies one by one.
192      * @method showContent
193      **/
194
195     showContent: function(index) {
196         "use strict";
197         $('#content_ul .sector' + index).css('opacity', '1');
198         if (index === 4) {
199             $('#bottomPanel').addClass('showBP');
200             $('#dateTime').addClass('showDT');
201             $('#topBarIcons').addClass('showTBI');
202         }
203         if (index === 8) {
204             $('#wrapper .step9').css('opacity', '0.4');
205             $('#wrapper .step9').addClass('liveBg');
206             return;
207         }
208         setTimeout(function() {
209             index++;
210             window.intelIVI.utility.showContent(index);
211         }, 80);
212     }
213 });
214
215 /**
216  * Provides initialization of pie.
217  * @class intelIVI.corpus
218  * @static
219  **/
220 window.intelIVI.corpus = (window.intelIVI.corpus || {
221     /**
222      * Create HTML elements of pie.
223      * @method init
224      **/
225     init: function() {
226         "use strict";
227         var i;
228         for (i = 1; i < 10; i++) {
229             var viewPortBg = document.createElement('div');
230             viewPortBg.className = "backGround step" + i;
231             /*global wrapper*/
232             wrapper.appendChild(viewPortBg);
233         }
234         /* global viewPort*/
235         wrapper.appendChild(viewPort);
236         return wrapper;
237     }
238 });