Add support to disable/enable Homescreen animation
[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     var checkAnimationConfig = function() {
88         var animation = Configuration.get("animationEnabled");
89         if (animation === undefined || animation) {
90             $(".rollRight").css("-webkit-animation-play-state", "running");
91             $(".rollLeft").css("-webkit-animation-play-state", "running");
92             $(".liveBg").css("-webkit-animation-play-state", "running");
93         } else {
94             $(".rollRight").css("-webkit-animation-play-state", "paused");
95             $(".rollLeft").css("-webkit-animation-play-state", "paused");
96             $(".liveBg").css("-webkit-animation-play-state", "paused");
97         }
98     };
99
100     /* fixed webkit animation bugs */
101     window.setTimeout(function() {
102         checkAnimationConfig();
103         Configuration.addUpdateListener(function() {
104             checkAnimationConfig();
105         });
106     }, 1000);
107     /* end fixed webkit animation bugs */
108 };
109
110 $(function() {
111     "use strict";
112     // debug mode - window.setTimeout("init()", 20000);
113     init();
114 });
115
116 /**
117  * Store state of audio plugin before application closing.
118  * @method window.onbeforeunload
119  * @static
120  **/
121 window.onbeforeunload = function() {
122     "use strict";
123     $('#audioPlayer').audioAPI('setStatusAll');
124 };
125
126 /**
127  * Provides inicialization of application content and starts animation.
128  * @class intelIVI.main
129  * @static
130  **/
131 window.intelIVI.main = (window.intelIVI.main || {
132
133     /**
134      * Calls initialization of content.
135      * @method init
136      **/
137
138     init: function() {
139         "use strict";
140         var viewPort = window.intelIVI.corpus.init();
141         document.body.appendChild(viewPort);
142         window.intelIVI.utility.startAnimation(1);
143     },
144     /**
145      * Provides reloading of content.
146      * @method counterEnd
147      **/
148
149     counterEnd: function() {
150         "use strict";
151         window.location.reload();
152     }
153 });
154
155 function untouchable(param) {
156     "use strict";
157
158     setTimeout(function() {
159         animationOngoing = false;
160     }, param);
161 }
162
163 /**
164  * Provides initialization of animated application components.
165  * @class intelIVI.utility
166  * @static
167  **/
168 window.intelIVI.utility = (window.intelIVI.utility || {
169     /**
170      * Starts initial animations on Homescreen.
171      * @method startAnimation
172      **/
173
174     startAnimation: function(index) {
175         "use strict";
176         $('#wrapper .step' + (index - 2)).css('opacity', '0');
177         $('#wrapper .step' + index).css('opacity', '0.4');
178         if (index === 10) {
179             $('#indicator').addClass('showI');
180             window.intelIVI.utility.showContent(1);
181             return;
182         }
183         var time = 40;
184         setTimeout(function() {
185             index++;
186             window.intelIVI.utility.startAnimation(index);
187         }, time);
188     },
189     /**
190      * Shows animated content pies one by one.
191      * @method showContent
192      **/
193
194     showContent: function(index) {
195         "use strict";
196         $('#content_ul .sector' + index).css('opacity', '1');
197         if (index === 4) {
198             $('#bottomPanel').addClass('showBP');
199             $('#dateTime').addClass('showDT');
200             $('#topBarIcons').addClass('showTBI');
201         }
202         if (index === 8) {
203             $('#wrapper .step9').css('opacity', '0.4');
204             $('#wrapper .step9').addClass('liveBg');
205             return;
206         }
207         setTimeout(function() {
208             index++;
209             window.intelIVI.utility.showContent(index);
210         }, 80);
211     }
212 });
213
214 /**
215  * Provides initialization of pie.
216  * @class intelIVI.corpus
217  * @static
218  **/
219 window.intelIVI.corpus = (window.intelIVI.corpus || {
220     /**
221      * Create HTML elements of pie.
222      * @method init
223      **/
224     init: function() {
225         "use strict";
226         var i;
227         for (i = 1; i < 10; i++) {
228             var viewPortBg = document.createElement('div');
229             viewPortBg.className = "backGround step" + i;
230             /*global wrapper*/
231             wrapper.appendChild(viewPortBg);
232         }
233         /* global viewPort*/
234         wrapper.appendChild(viewPort);
235         return wrapper;
236     }
237 });