View Javadoc

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.util.List;
22  
23  import sk.baka.ambient.R;
24  import sk.baka.ambient.activity.main.AbstractListController;
25  import sk.baka.ambient.views.gesturelist.GesturesListView;
26  import android.view.View;
27  import android.widget.TextView;
28  
29  /***
30   * Shows an immutable list of strings.
31   * 
32   * @author Martin Vysny
33   */
34  public class StringListController extends AbstractListController {
35  	/***
36  	 * Creates new controller.
37  	 * 
38  	 * @param listViewId
39  	 *            the list view id.
40  	 * @param mainActivity
41  	 *            owning activity.
42  	 */
43  	public StringListController(final int listViewId,
44  			final SearchActivity mainActivity) {
45  		super(listViewId, listViewId, mainActivity);
46  	}
47  
48  	private List<String> content = null;
49  
50  	/***
51  	 * Sets the content and updates the list view.
52  	 * 
53  	 * @param content
54  	 *            the content.
55  	 */
56  	public void setContent(final List<String> content) {
57  		this.content = content;
58  		update(null);
59  	}
60  
61  	@Override
62  	protected void recomputeListItems() {
63  		listView.getModel().getModel().clear();
64  		listView.getModel().getModel().addAll(content);
65  	}
66  
67  	public void itemActivated(int index, Object model) {
68  		((SearchActivity) mainActivity).stringItemClicked((String) model);
69  	}
70  
71  	public void update(GesturesListView listView, View itemView, int index,
72  			Object model) {
73  		final boolean highlighted = listView.getHighlight().contains(index);
74  		final int bgColor;
75  		if (highlighted) {
76  			bgColor = highlightColor;
77  		} else {
78  			bgColor = 0;
79  		}
80  		itemView.setBackgroundColor(bgColor);
81  		final TextView text = (TextView) itemView
82  				.findViewById(R.id.playlist_item_text);
83  		text.setText((String) model);
84  	}
85  }