it.tidalwave.bluebill.mobile.android.taxonomy.TaxonomyAdapter Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* $Id: TaxonomyAdapter.java,v 3cadcf8b23fe 2010/06/11 12:26:37 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nonnegative;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.bluebill.taxonomy.Taxon;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonomyPreferences;
import it.tidalwave.bluebill.mobile.android.R;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class TaxonomyAdapter extends BaseAdapter implements Filterable
{
private static final String CLASS = TaxonomyAdapter.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
@Nonnull
private final LayoutInflater layoutInflater;
@Nonnull
private final TaxonomyPreferences preferences;
private final TaxonWidgetFilter filter;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public TaxonomyAdapter (final @Nonnull Context context,
final @Nonnull TaxonomyPreferences preferences,
final @Nonnull List taxa)
{
this.layoutInflater = LayoutInflater.from(context);
this.preferences = preferences;
this.filter = new TaxonWidgetFilter(taxa, this);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override @Nonnegative
public int getCount()
{
return filter.getCount();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Taxon getItem (final @Nonnegative int index)
{
return filter.getItem(index);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public long getItemId (final @Nonnegative int id)
{
return id;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override @Nonnull
public Filter getFilter()
{
return filter;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public View getView (final @Nonnegative int index,
@CheckForNull View view,
final @Nonnull ViewGroup vg)
{
// logger.warning("getView(%d, %s, %s)", index, view, vg);
TextView textView;
if (view == null)
{
view = layoutInflater.inflate(R.layout.taxon_browser_row, null);
textView = (TextView)view.findViewById(R.id.text);
view.setTag(textView);
}
else
{
textView = (TextView)view.getTag();
}
textView.setText(preferences.formatAsHtml(getItem(index)));
return view;
}
}