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 package sk.baka.ambient.activity.main;
19
20 import java.util.List;
21
22 import sk.baka.ambient.AmbientApplication;
23 import sk.baka.ambient.R;
24 import sk.baka.ambient.collection.TrackMetadataBean;
25 import sk.baka.ambient.commons.Interval;
26 import sk.baka.ambient.views.gesturelist.GesturesListView;
27 import sk.baka.ambient.views.gesturelist.IGestureListViewListener;
28 import sk.baka.ambient.views.gesturelist.ModelHolder;
29 import sk.baka.ambient.views.gesturelist.TrackListClipboardObject;
30 import android.app.Activity;
31
32 /***
33 * The items in this controller are rendered as a list and can be selected.
34 *
35 * @author Martin Vysny
36 */
37 public abstract class AbstractListController extends AbstractController
38 implements IGestureListViewListener {
39
40 /***
41 * The list instance.
42 */
43 public GesturesListView listView;
44
45 /***
46 * Creates new controller.
47 *
48 * @param mainViewId
49 * the view whose visibility is controlled.
50 * @param listViewId
51 * the id of the {@link GesturesListView}
52 * @param mainActivity
53 * the main activity instance.
54 */
55 protected AbstractListController(final int mainViewId, int listViewId,
56 Activity mainActivity) {
57 super(mainViewId, mainActivity);
58 final GesturesListView pv = ((GesturesListView) mainView
59 .findViewById(listViewId));
60 pv.listener = this;
61 this.listView = pv;
62 }
63
64 /***
65 * The color of highlighted items in the list.
66 */
67 protected final int highlightColor = mainActivity.getResources().getColor(
68 R.color.highlight);
69
70 /***
71 * Recomputes the {@link GesturesListView#getModel() model}. You don't have
72 * to call the {@link ModelHolder#notifyModified()} - it is called
73 * automatically after the method finishes.
74 */
75 protected abstract void recomputeListItems();
76
77 public void highlightChanged(Interval highlight) {
78
79 }
80
81 /***
82 * Overrides default functionality - the {@link #recomputeListItems()} is
83 * invoked and the list view contents are updated.
84 */
85 @Override
86 public void update(final Interval target) {
87 recomputeListItems();
88 listView.getModel().highlight(target == null ? Interval.EMPTY : target);
89 listView.getModel().notifyModified();
90 }
91
92 public boolean canComputeItems() {
93 return false;
94 }
95
96 public boolean isReadOnly() {
97 return true;
98 }
99
100 public List<TrackMetadataBean> computeTracks(Interval highlight) {
101 throw new UnsupportedOperationException("computeTracks");
102 }
103
104 public void dropItems(List<TrackMetadataBean> tracks, int x, int y,
105 int index) {
106 throw new UnsupportedOperationException("dropItems");
107 }
108
109 public Interval moveItems(Interval highlight, int delta) {
110 throw new UnsupportedOperationException("moveItems");
111 }
112
113 public Interval moveItemsByOne(Interval highlight, boolean down) {
114 throw new UnsupportedOperationException("moveItemsByOne");
115 }
116
117 public String getHint(Interval highlight) {
118 throw new UnsupportedOperationException("getHint");
119 }
120
121 public boolean isComputeTracksLong(Interval interval) {
122 throw new UnsupportedOperationException("isComputeTracksLong");
123 }
124
125 public boolean isComputeTracksOnlineOp(Interval interval) {
126 throw new UnsupportedOperationException("isComputeTracksOnlineOp");
127 }
128
129 public void removeItems(Interval remove) {
130 throw new UnsupportedOperationException("removeItems");
131 }
132
133 public boolean canHighlight() {
134 return true;
135 }
136
137 public void setClipboard(TrackListClipboardObject clipboard) {
138 AmbientApplication.getInstance().setClipboard(clipboard);
139 }
140
141 public Object getClipboard() {
142 return AmbientApplication.getInstance().getClipboard();
143 }
144
145 @Override
146 public void destroy() {
147 listView = null;
148 super.destroy();
149 }
150
151 @Override
152 protected void performZoom(boolean zoom) {
153 listView.zoom(zoom);
154 }
155 }