1 /*global ThemeEngine, loadScript, template, changeCssBgImageColor, ThemeKeyColorSelected, ThemeKeyColor, Speech, Settings */
7 * Array of applications that will be rendered to the top bar panel.
8 * @property topBarAplicationsModel
13 var topBarAplicationsModel = [];
16 * Array of applications that would not fit the top bar panel.
17 * @property extraAppsModel
21 var extraAppsModel = [];
26 * The callback to be invoked when the application was not launched successfully.
30 * @param err {Any} An error message.
32 function onError(err) {
35 alert("An error occured while launching the application: " + err.message);
39 * Returns the application object by application id from topBarAplicationsModel.
43 * @param id {String} Application ID.
44 * @return {Object} Object representing basic application's information.
46 function getAppByID(id) {
49 for (j = 0; j < topBarAplicationsModel.length; ++j) {
50 if (id === topBarAplicationsModel[j].id) {
51 return topBarAplicationsModel[j];
54 for (i = 0; i < extraAppsModel.length; ++i) {
55 if (id === extraAppsModel[i].id) {
56 return extraAppsModel[i];
64 * Returns the application object by application name from topBarAplicationsModel.
66 * @method getAppByName
68 * @param appName {String} Application name.
69 * @return {Object} Object representing basic application's information.
71 function getAppByName(appName) {
73 for (var j = 0; j < topBarAplicationsModel.length; ++j) {
74 if (appName.toString().trim().toLowerCase() === topBarAplicationsModel[j].appName.toString().trim().toLowerCase()) {
75 return topBarAplicationsModel[j];
78 for (var i = 0; i < extraAppsModel.length; ++i) {
79 if (appName.toString().trim().toLowerCase() === extraAppsModel[i].appName.toString().trim().toLowerCase()) {
80 return extraAppsModel[i];
88 * The callback to be invoked when the application was launched successfully.
90 * @method onAppInfoSuccess
93 function onLaunchSuccess() {
95 console.log("App launched succesfully...");
102 * Launches an application with the given application ID.
104 * @method launchApplication
106 * @param id {String} Application ID.
108 function launchApplication(id) {
110 if (id === "http://com.intel.tizen/settings") {
111 if (typeof Settings === 'undefined') {
112 loadScript('./css/car/components/settings/js/settings.js', function(path, status) {
113 if (status === "ok") {
123 var app = getAppByID(id);
125 if (app.installed && !app.running) {
126 appToHide = tizen.application.getCurrentApplication();
127 tizen.application.launch(app.id, onLaunchSuccess, onError);
128 } else if (app.running) {
129 console.log("Application is running!");
132 console.log("Application is not installed!");
133 alert("Application is not installed!");
140 * Represents top bar UI control element that is used to navigate between predefined set of applications. Applications displayed in this list must have
141 * [application ID](https://developer.tizen.org/dev-guide/2.2.1/org.tizen.web.device.apireference/tizen/application.html#::Application::ApplicationId)
142 * starting with `intelPoC` prefix (e.g. `html5POC04.HomeScreen`). Use following snippet to include component in your `index.html` file:
144 * <script type='text/javascript' src='./css/car/components/topBarIcons/topBarIcons.js'></script>
145 * <link rel="stylesheet" href="./css/car/components/topBarIcons/topBarIcons.css" />
147 * and following code to initialize:
149 * $("#topBarIcons").topBarIconsPlugin('init');
156 * Name of the application that is used to highlight only the icon of currently running application.
157 * @property runningAppName
164 * Initializes the element and gets the list of installed application.
167 * @param appName {String} Name of running application.
170 TopBarIcons.initLaunchingAppsByVoiceRecognition();
171 TopBarIcons.runningAppName = typeof(tizen.application.getCurrentApplication) === 'undefined' ? "" : tizen.application.getCurrentApplication().appInfo.id;
174 this.addClass("topBarIcons");
176 if (typeof ThemeEngine !== 'undefined') {
177 ThemeEngine.addStatusListener(function(themeId) {
178 TopBarIcons.renderApps();
181 console.error("ThemeEngine API is not available.");
184 TopBarIcons._getApps();
187 _getApps: function() {
189 if (typeof(tizen.application.getAppsInfo) !== 'undefined') {
190 tizen.application.getAppsInfo(TopBarIcons.onAppInfoSuccess, function(err) {
191 // Workaround due to https://bugs.tizen.org/jira/browse/TIVI-2018
192 window.setTimeout(function() {
193 TopBarIcons._getApps();
200 console.error(exc.message);
206 * The callback to be invoked when the installed application list is retrieved. Compares list of installed applications to predefined list and sets installed and running properties, that are used when launching an application.
207 * Calls render application icons function.
208 * @method onAppInfoSuccess
209 * @param list {Array} Array of installed application.
211 onAppInfoSuccess: function(list) {
217 var homeScreenApp = {};
219 for (i = 0; i < list.length; i++) {
221 var subName = app.name.substr(7);
222 subName = subName.replace(/\./g, "").replace(/\ /g, "");
223 if (app.name.indexOf('Modello') >= 0) {
227 style: "background-image: url('icons/" + subName + "_icon.png');",
228 iconPath: app.iconPath,
229 css: "app_" + app.id.replace(/\./g, "_").replace(/\ /g, "_"),
231 running: TopBarIcons.runningAppName === app.id
234 if (app.name === "ModelloHomescreen") {
235 homeScreenApp = newApp;
237 //app filter to block adding some apps into topbar
238 if (app.name === 'ModelloAMBSimulator') {
239 extraAppsModel.push(newApp);
240 } else if (modelData.length < 7) {
241 modelData.push(newApp);
247 modelData.sort(function(x, y) {
248 return x.appName > y.appName ? 1 : -1;
251 modelData.unshift(homeScreenApp);
252 while (modelData.length < 8) {
257 id: "http://com.intel.tizen/settings",
263 var equals = modelData.length === topBarAplicationsModel.length;
266 for (j = 0; j < modelData.length; j++) {
267 equals = modelData[j].id === topBarAplicationsModel[j].id ? equals : false;
268 equals = modelData[j].appName === topBarAplicationsModel[j].appName ? equals : false;
269 equals = modelData[j].css === topBarAplicationsModel[j].css ? equals : false;
270 equals = modelData[j].iconPath === topBarAplicationsModel[j].iconPath ? equals : false;
275 topBarAplicationsModel = modelData;
276 if (appListLenght !== list.length) {
277 loadScript('./css/car/components/jsViews/jsrender.js', function(path, status) {
278 if (status === "ok") {
279 loadScript('./css/car/components/jsViews/template.js', function(path, status) {
280 if (status === "ok") {
281 TopBarIcons.renderApps();
283 // jsRender adds additional properties so we need to store it once again for comparsion in next round
284 topBarAplicationsModel = modelData;
292 console.error(exc.message);
297 * Renders the array of predefined applications into the panel utilizing template mechanism.
300 * @param caption {String} Caption text.
302 renderApps: function() {
303 $(".topBarIcons").empty();
305 template.compile(topBarAplicationsModel, "./css/car/components/topBarIcons/templates/topBarIconsDelegate.html", ".topBarIcons", function() {
307 for (j = 0; j < topBarAplicationsModel.length; ++j) {
308 if (topBarAplicationsModel[j].running) {
309 changeCssBgImageColor("." + topBarAplicationsModel[j].css, ThemeKeyColorSelected);
311 changeCssBgImageColor("." + topBarAplicationsModel[j].css, ThemeKeyColor);
316 initLaunchingAppsByVoiceRecognition: function() {
317 if (typeof(Speech) !== 'undefined') {
318 Speech.addVoiceRecognitionListener({
319 onapplicationlaunch: function(appName) {
320 // check if app is in foreground
321 //if (!document. webkitHidden) {
322 launchApplication(getAppByName(appName).id);
327 console.warn("Speech API is not available.");
333 * jQuery extension method for class {{#crossLink "TopBarIcons"}}{{/crossLink}} plugin.
334 * @param method {Object|jQuery selector} Identificator (name) of method or jQuery selector.
335 * @method topBarIconsPlugin
337 * @return Result of called method.
339 $.fn.topBarIconsPlugin = function(method) {
340 // Method calling logic
341 if (TopBarIcons[method]) {
342 return TopBarIcons[method].apply(this, Array.prototype.slice.call(arguments, 1));
343 } else if (typeof method === 'object' || !method) {
344 return TopBarIcons.init.apply(this, arguments);
346 $.error('Method ' + method + ' does not exist on jQuery.boxCaptionPlugin');