1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package sk.baka.ambient.activity.search;
20
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.xml.sax.SAXException;
25
26 import sk.baka.ambient.activity.main.StaticPlaylistController;
27 import sk.baka.ambient.collection.TrackMetadataBean;
28 import sk.baka.ambient.library.LibraryUtils;
29
30 import com.es.skreemr.SkreemRSearch;
31 import com.es.skreemr.SkreemRSong;
32
33 /***
34 * Performs SkreemR search.
35 *
36 * @author Martin Vysny
37 */
38 public final class SkreemrEngine implements ISearchEngine {
39
40 private StaticPlaylistController controller = null;
41 private SearchActivity owner = null;
42 private int listViewId;
43
44 public boolean canSearchOffline() {
45 return false;
46 }
47
48 public void init(SearchActivity owner, final int listViewId) {
49 this.owner = owner;
50 this.listViewId = listViewId;
51 }
52
53 public List<? extends Object> performSearch(String query)
54 throws IOException, SAXException {
55 final List<SkreemRSong> result = new SkreemRSearch().search(query, 1);
56 if (Thread.currentThread().isInterrupted()) {
57 return null;
58 }
59 final List<TrackMetadataBean> tracks = LibraryUtils.toTrackBean(result);
60 return tracks;
61 }
62
63 @SuppressWarnings("unchecked")
64 public void update(List<? extends Object> model) {
65 if (controller == null) {
66 controller = new StaticPlaylistController(listViewId, listViewId,
67 owner, (List<TrackMetadataBean>) model, false);
68 } else {
69 controller.setTracks((List<TrackMetadataBean>) model);
70 }
71 }
72
73 public void passivate() {
74 controller = null;
75 }
76
77 public SearchType getType() {
78 return SearchType.SkreemR;
79 }
80
81 public boolean canPerformSearch() {
82 return true;
83 }
84 }