2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license
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.
17 var gMediaSource, gMediaFolders, gMediaItems, gItemId, gFolderId, gMediaType = "ALL";
20 $(document).delegate("#main", "pageinit", function() {
23 $("#main .ui-btn-back").bind("vclick", function() {
24 tizen.application.getCurrentApplication().exit();
28 $("#folder-type-all").bind("vclick", function() {
29 showFolderList("ALL");
30 $("#folder-type-all").css('color','red');
31 $("#folder-type-internal").css('color','black');
32 $("#folder-type-external").css('color','black');
35 $("#folder-type-internal").bind("vclick", function() {
36 showFolderList("INTERNAL");
37 $("#folder-type-all").css('color','black');
38 $("#folder-type-internal").css('color','red');
39 $("#folder-type-external").css('color','black');
42 $("#folder-type-external").bind("vclick", function() {
43 showFolderList("EXTERNAL");
44 $("#folder-type-all").css('color','black');
45 $("#folder-type-internal").css('color','black');
46 $("#folder-type-external").css('color','red');
51 $(document).delegate("#items", "pageinit", function() {
52 $("#items").bind("pagebeforeshow", showItemList);
54 $("#items-list input").bind("change", function() {
55 if ($(this).prop("checked") == true) {
56 gMediaType = $(this).attr("value");
57 getFolderItems(gFolderId, gMediaType);
61 $("#items-list").delegate("li", "vclick", function() {
62 var id = $(this).data("id");
65 $.mobile.changePage("#detail");
71 $(document).delegate("#detail", "pageinit", function() {
72 $("#detail").bind("pagebeforeshow", showMediaDetail);
75 function makeListItem(id, mainText, subText) {
76 return '<li class="ui-li-has-multiline ui-li-text-ellipsis"'
77 + (id == null ? '' : ' data-id="'+ id +'"')
80 + '<span class="ui-li-text-sub">'
85 function getFolders (storageType) {
87 gMediaSource = tizen.content;
88 gMediaSource.getDirectories(onGetFoldersSuccess, onGetFoldersError);
90 alert("getLocalMediaSource exc:" + exc.message);
93 function onGetFoldersSuccess(folders) {
94 $("#folder-list").delegate("li", "vclick", function() {
95 var id = $(this).data("id");
97 getFolderItems(Number(id), gMediaType);
102 gMediaFolders = folders;
103 showFolderList(storageType);
106 function onGetFoldersError(err) {
107 alert("GetFolders failed:" + err.message);
113 function showFolderList(storageType) {
115 if(flagInit == false){
116 getFolders(storageType);
120 for (var i = 0; i < gMediaFolders.length; i++) {
121 if (storageType == "ALL" || storageType == gMediaFolders[i].storageType) {
122 str += makeListItem(i, gMediaFolders[i].title, gMediaFolders[i].folderURI);
125 $("#folder-list>li[data-id]").remove();
126 $("#folder-list").append(str).trigger("create").listview("refresh");
131 function showItemList() {
133 var title = gMediaFolders[gFolderId].title;
135 $("#items-title").html(gFolderId == null ? "All" : title.toString().toUpperCase());
137 for (var i = 0; i < gMediaItems.length; i++) {
138 str += makeListItem(i, gMediaItems[i].title,
139 gMediaItems[i].type + " Rating: " + gMediaItems[i].rating);
142 $("#items-list>li[data-id]").remove();
143 $("#items-list").append(str).trigger("create").listview("refresh");
146 function getFolderItems(folderId, mediaType) {
147 function onFindItemsSuccess(items) {
149 gFolderId = folderId;
150 gMediaType = mediaType;
152 if($.mobile.activePage.attr("id") == "items") {
155 $.mobile.changePage("#items");
159 function onFindItemsError(err) {
160 alert("getFolderItems findItems failed: " + err.message);
164 gMediaSource.find(onFindItemsSuccess, onFindItemsError,
165 folderId == null ? null : gMediaFolders[folderId].id,
166 mediaType == "ALL" ? null : new tizen.AttributeFilter("type", "EXACTLY", mediaType),
167 new tizen.SortMode("title", "ASC"));
169 //alert("findItems exc:" + exc.message);
173 function makeCommonPropertiesListItems(item) {
174 return makeListItem(null, "Title", item.title)
175 + makeListItem(null, "Size", item.size + " Bytes")
176 + makeListItem(null, "Type", item.type)
177 + makeListItem(null, "Identifier", item.id)
178 + makeListItem(null, "Item URI", item.contentURI)
179 + makeListItem(null, "MIME type", item.mimeType)
180 + makeListItem(null, "Release date", item.releaseDate)
181 + makeListItem(null, "Modified date", item.modifiedDate)
182 + makeListItem(null, "Description", item.description)
183 + makeListItem(null, "Rating", item.rating);
186 function showMediaDetail() {
187 var str, item = gMediaItems[gItemId];
189 if (item.type == "IMAGE") {
190 str = makeCommonPropertiesListItems(item)
191 + makeListItem(null, "Width", item.width)
192 + makeListItem(null, "Height", item.height)
193 + makeListItem(null, "Latitude", item.geolocation.latitude)
194 + makeListItem(null, "Longitude", item.geolocation.longitude);
195 } else if (item.type == "VIDEO") {
196 str = makeCommonPropertiesListItems(item)
197 + makeListItem(null, "Width", item.width)
198 + makeListItem(null, "Height", item.height)
199 + makeListItem(null, "Album", item.album)
200 + makeListItem(null, "Artist", item.artists[0])
201 + makeListItem(null, "Duration", item.duration + " Milliseconds");
202 } else if (item.type == "AUDIO") {
203 str = makeCommonPropertiesListItems(item)
204 + makeListItem(null, "Album", item.album)
205 + makeListItem(null, "Artist", item.artists[0])
206 + makeListItem(null, "Composer", item.composers[0])
207 + makeListItem(null, "Genre", item.genres[0])
208 + makeListItem(null, "Copyright", item.copyright)
209 + makeListItem(null, "Bitrate", item.bitrate + " Bps")
210 + makeListItem(null, "Track number", item.trackNumber)
211 + makeListItem(null, "Duration", item.duration + " Milliseconds");
213 str = makeCommonPropertiesListItems(item);
216 $("#media-details").html(str).trigger("create").listview("refresh");