Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/***********************************************************************************************************************
*
* 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: DisplayableArrayAdapter.java,v f41afde5ae70 2010/06/08 14:47:38 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.mobile.android.ui;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.util.List;
import it.tidalwave.util.As;
import it.tidalwave.util.Displayable;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class DisplayableArrayAdapter extends ArrayAdapter
{
public DisplayableArrayAdapter (final @Nonnull Context context,
final int resource,
final int textViewResourceId,
final @Nonnull List objects)
{
super(context, resource, textViewResourceId, objects);
}
public DisplayableArrayAdapter (final @Nonnull Context context,
final int textViewResourceId,
final @Nonnull List objects)
{
super(context, textViewResourceId, objects);
}
public DisplayableArrayAdapter (final @Nonnull Context context,
final int resource,
final int textViewResourceId,
final @Nonnull T[] objects)
{
super(context, resource, textViewResourceId, objects);
}
public DisplayableArrayAdapter (final @Nonnull Context context,
final int textViewResourceId,
final @Nonnull T[] objects)
{
super(context, textViewResourceId, objects);
}
public DisplayableArrayAdapter (final @Nonnull Context context,
final int resource,
final int textViewResourceId)
{
super(context, resource, textViewResourceId);
}
public DisplayableArrayAdapter (final @Nonnull Context context,
final int textViewResourceId)
{
super(context, textViewResourceId);
}
@Override @Nonnull
public View getView (final @Nonnegative int position,
final @Nonnull View convertView,
final @Nonnull ViewGroup parent)
{
return fixedView(position, super.getView(position, convertView, parent));
}
@Override
public View getDropDownView (int position, View convertView, ViewGroup parent)
{
return fixedView(position, super.getDropDownView(position, convertView, parent));
}
// @Override TODO
// public void sort(Comparator super T> comparator)
// {
// super.sort(comparator);
// }
@Nonnull
private View fixedView (final @Nonnegative int position,
final @Nonnull View view)
{
if (view instanceof TextView)
{
final Object item = getItem(position);
Displayable displayable = null;
if (item instanceof Displayable)
{
displayable = (Displayable)item;
}
else if (item instanceof As)
{
displayable = ((As)item).as(Displayable.class);
}
((TextView)view).setText((displayable != null) ? displayable.getDisplayName() : "???");
}
return view;
}
}