it.tidalwave.ui.android.widget.DisplayableArrayAdapter Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - Android - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* 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.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it/mobile
* SCM: https://java.net/hg/bluebill-mobile~android-src
*
**********************************************************************************************************************/
package it.tidalwave.ui.android.widget;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.util.List;
import it.tidalwave.util.As;
import it.tidalwave.role.Displayable;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import static it.tidalwave.role.Displayable.Displayable;
/***********************************************************************************************************************
*
* @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);
}
((TextView)view).setText((displayable != null) ? displayable.getDisplayName() : "???");
}
return view;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy