1 /*global ThemeKeyColor, Settings, loadScript */
4 * @module HomescreenApplication
7 * Retrieves list of installed apps from [Tizen Application API](https://developer.tizen.org/dev-guide/2.2.0/org.tizen.web.device.apireference/tizen/application.html)
8 * and manages displaing it in app grid view. Class also provides launching of installed app by clicking on app representation in grid view.
13 * Global variable which holds the list component in the UI
19 * Global variable which holds the identifier of the application information event listener
20 * @property listenerID
24 var listenerID = null;
26 * Global variable which holds the current index of last element in appList
34 * Provides hiding installed app grid afted click out of app cells.
40 $("#homeScrAppGridView").live("click", function() {
46 * Provide logging of app launch success.
47 * @method onLaunchSuccess
50 function onLaunchSuccess() {
52 console.log("App launched...");
56 * Provide logging of app launch error.
58 * @param err {string} Error message.
61 function onError(err) {
63 console.error(err.message);
67 * Provide launch of application.
68 * @method onFrameClick
69 * @param appData {object} Contains Object of specific app.
72 function onFrameClick(appData) {
77 var scriptCallback = function(path, status) {
78 if (status === "ok") {
83 for (i = 0; i < appList.length; ++i) {
84 if (appList[i].id === appData.id) {
85 if (appData.id === "http://com.intel.tizen/intelPocSettings") {
86 if (typeof Settings === 'undefined') {
87 loadScript('./css/car/components/settings/js/settings.js', scriptCallback);
92 tizen.application.launch(appData.id, onLaunchSuccess, onError);
98 console.error(exc.message);
103 * Create app grid view based on appList.
104 * @method insertAppFrame
105 * @param appFrame {object} Contains Object of specific app from appList property.
108 function insertAppFrame(appFrame) {
110 var rootDiv = $("<div></div>").addClass("homeScrAppGridFrame boxShadow3").data("app-data", appFrame).click(function() {
111 onFrameClick($(this).data("app-data"));
114 var innerDiv = $("<div></div>").addClass("homeScrAppGridImg").appendTo(rootDiv);
115 $("<img />").data("src", appFrame.iconPath).appendTo(innerDiv);
116 var textDiv = $("<div />").addClass("homeScrAppGridText").appendTo(rootDiv);
117 $("<div />").addClass("homeScrAppGridTitle fontColorNormal fontSizeSmaller fontWeightBold").text(appFrame.appName).appendTo(textDiv);
118 $("<div />").addClass("homeScrAppGridCategory").text(appFrame.appName).appendTo(textDiv);
120 $('#homeScrAppGridView').append(rootDiv);
122 var img = new Image();
123 var ctx = document.createElement('canvas').getContext('2d');
125 img.onload = function() {
126 var w = ctx.canvas.width = img.width;
127 var h = ctx.canvas.height = img.height;
129 // Change icon only in case of Intel POC apps
130 if (appFrame.appName.indexOf("Modello") >= 0) {
131 ctx.fillStyle = ThemeKeyColor;
132 ctx.fillRect(0, 0, w, h);
133 ctx.globalCompositeOperation = 'destination-in';
135 ctx.drawImage(img, 0, 0);
137 $("div.homeScrAppGridImg img").each(function() {
138 if ($(this).data("src") === appFrame.iconPath) {
139 $(this)[0].src = ctx.canvas.toDataURL();
144 img.onerror = img.onabort = function() {
145 $("div.homeScrAppGridImg img").each(function() {
146 if ($(this).data("src") === appFrame.iconPath) {
147 $(this).attr("src", "./css/images/default_icon.png");
152 img.src = appFrame.iconPath;
155 appList.push(appFrame);
158 var evalInstalledApps = null;
161 * Callback method for getting and resorting appList array for Homescreen app using.
162 * @method onAppInfoSuccess
163 * @param list {array} Contains Objects of apps from evalInstalledApps listener.
166 function onAppInfoSuccess(list) {
171 var applications = [];
174 id: "http://com.intel.tizen/intelPocSettings",
177 iconPath: "./css/car/components/settings/icon.png"
180 list.sort(function(x, y) {
181 return x.appName > y.appName ? 1 : -1;
184 for (i = 0; i < list.length; i++) {
190 style: "background-image: url('file://" + app.iconPath + "');",
191 iconPath: app.iconPath,
192 css: "app_" + app.id.replace(/\./g, "_").replace(/\ /g, "_"),
195 applications.push(newApp);
197 var equals = applications.length === appList.length;
200 for (var j = 0; j < applications.length; j++) {
201 equals = applications[j].id === appList[j].id ? equals : false;
202 equals = applications[j].appName === appList[j].appName ? equals : false;
203 equals = applications[j].css === appList[j].css ? equals : false;
204 equals = applications[j].iconPath === appList[j].iconPath ? equals : false;
210 $('#homeScrAppGridView .homeScrAppGridFrame').remove();
212 for (i = 0; i < applications.length; i++) {
213 insertAppFrame(applications[i]);
217 console.log(exc.message);
219 //Workaround due to https://bugs.tizen.org/jira/browse/TIVI-2018
220 window.setTimeout(function() {
224 if (null === listenerID) {
225 listenerID = tizen.application.addAppInfoEventListener({
226 oninstalled: function(appInfo) {
227 console.log('The application ' + appInfo.name + ' is installed');
230 onupdated: function(appInfo) {
231 console.log('The application ' + appInfo.name + ' is updated');
234 onuninstalled: function(appid) {
235 console.log('The application ' + appid + ' is uninstalled');
244 * Listener for installed apps events.
245 * @method evalInstalledApps
248 evalInstalledApps = function() {
250 if (typeof tizen !== 'undefined') {
252 // get the installed applications list
253 tizen.application.getAppsInfo(onAppInfoSuccess, function(err) {
254 // Workaround due to https://bugs.tizen.org/jira/browse/TIVI-2018
255 window.setTimeout(function() {
262 console.error(exc.message);