[Systeminfo]update Systeminfo(tizen_2.1)
[samples/web/Systeminfo.git] / js / main.js
1 /*
2  *      Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  *      Licensed under the Flora License, Version 1.0 (the "License");
5  *      you may not use this file except in compliance with the License.
6  *      You may obtain a copy of the License at
7  *
8  *              http://floralicense.org/license
9  *
10  *      Unless required by applicable law or agreed to in writing, software
11  *      distributed under the License is distributed on an "AS IS" BASIS,
12  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *      See the License for the specific language governing permissions and
14  *      limitations under the License.
15  */
16
17 var gInfoTitle = "", gInfo = "", gBatteryListener;
18
19 $(document).delegate("#main", "pageinit", function() {
20         $("#main .ui-btn-back").bind("vclick", function() {
21                 tizen.application.getCurrentApplication().exit();
22                 return false;
23         });
24         $("#storage-info").bind("vclick", function() {
25                 getSystemProperty("STORAGE", onStorageSuccess);
26                 return false;
27         });
28         $("#battery-info").bind("vclick", function() {
29                 getSystemProperty("BATTERY", onBatterySuccess);
30                 return false;
31         });
32         $("#cpu-info").bind("vclick", function() {
33                 getSystemProperty("CPU", onCpuInfoSuccess);
34                 return false;
35         });
36         $("#display-info").bind("vclick", function() {
37                 getSystemProperty("DISPLAY", onDisplaySuccess);
38                 return false;
39         });
40
41         $("#orientation-info").bind("vclick", function() {
42                 getSystemProperty("DEVICE_ORIENTATION", onOrientationSuccess);
43                 return false;
44         });
45 });
46
47 $(document).delegate("#info", "pageinit", function() {
48         $("#info").bind("pagebeforeshow", function() {
49                 $("#info-title").html(gInfoTitle);
50                 $("#info-list").html(gInfo).trigger("create").listview("refresh");
51         });
52 });
53
54 function onError(e) {
55         alert("Error: " + e.message);
56 }
57
58 function make2lineListItem(title, value) {
59         return '<li class="ui-li-has-multiline ui-li-text-ellipsis">'
60                         + title
61                         + '<span class="ui-li-text-sub">'
62                         + value
63                         + '</span></li>';
64 }
65
66 function make1lineListItem(value) {
67         return '<li>' + value + '</li>';
68 }
69
70 function makeDividerListItem(value) {
71         return '<li data-role="list-divider">' + value + '</li>';
72 }
73
74 function onStorageSuccess(storages) {
75         gInfoTitle = "STORAGES(" + storages.length + ")";
76         gInfo = "";
77         for (var i = 0; i < storages.length; i++) {
78                 gInfo += makeDividerListItem("Storage " + (i + 1))
79                                 + make2lineListItem("Type", storages[i].type)
80                                 + make2lineListItem("Capacity", Math.floor(storages[i].capacity / 1000000) + " MB")
81                                 + make2lineListItem("Available capacity", Math.floor(storages[i].availableCapacity / 1000000) + " MB")
82                                 + make2lineListItem("Removable", (storages[i].isRemoveable == true ? "Yes" : "No"));
83         }
84
85         $.mobile.changePage("#info");
86 }
87
88 function onBatterySuccess(battery) {
89         gInfoTitle = "BATTERY";
90         gInfo = make2lineListItem("Level", battery.level)
91                         + make2lineListItem("Charging", (battery.isCharging == true ? "Yes" : "No"));
92
93         $.mobile.changePage("#info");
94 }
95
96 function onCpuInfoSuccess(cpu) {
97         gInfoTitle = "CPU";
98         gInfo = make2lineListItem("Load", cpu.load);
99
100         $.mobile.changePage("#info");
101 }
102
103 function onDisplaySuccess(display) {
104         gInfoTitle = "DISPLAY";
105         gInfo = makeDividerListItem("Resolution")
106                         + make2lineListItem("Width", display.resolutionWidth)
107                         + make2lineListItem("Height", display.resolutionHeight)
108                         + makeDividerListItem("Dots per inch")
109                         + make2lineListItem("Horizontal", display.dotsPerInchWidth)
110                         + make2lineListItem("Vertical", display.dotsPerInchHeight)
111                         + makeDividerListItem("Physical size")
112                         + make2lineListItem("Width", display.physicalWidth)
113                         + make2lineListItem("Height", display.physicalHeight)
114                         + makeDividerListItem("Brightness")
115                         + make1lineListItem(display.brightness);
116
117         $.mobile.changePage("#info");
118 }
119
120 function onDeviceSuccess(device) {
121         gInfoTitle = "DEVICE";
122         gInfo = make2lineListItem("IMEI", device.imei)
123                         + make2lineListItem("Model", device.model)
124                         + make2lineListItem("Version", device.version)
125                         + make2lineListItem("Vendor", device.vendor);
126
127         $.mobile.changePage("#info");
128 }
129
130 function onOrientationSuccess(orientation) {
131         gInfoTitle = "DEVICE ORIENTATION";
132         gInfo = make2lineListItem("Status", orientation.status);
133
134         $.mobile.changePage("#info");
135 }
136
137 function getSystemProperty(property, onSuccess) {
138         try {
139                 tizen.systeminfo.getPropertyValue(property, onSuccess, onError);
140         } catch (e) {
141                 alert("Exception: " + e.message);
142         }
143 }