All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.NodesAdapter 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: NodesAdapter.java,v e317d74b96ee 2010/07/15 13:17:28 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.factsheet;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.util.List;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.Node;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.TextNode;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.HeaderNode;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound.AndroidObservationSoundNodeRenderer;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.video.AndroidMovieNodeRenderer;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.SoundObservationNode;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.StaticImageNode;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.VideoNode;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class NodesAdapter extends BaseAdapter
  {
    private final AndroidTextNodeRenderer textNodeRenderer;
    private final AndroidHeaderNodeRenderer headerNodeRenderer;
    private final AndroidStaticImageRenderer staticImageRenderer;
    private final AndroidObservationSoundNodeRenderer observationSoundNodeRenderer;
    private final AndroidMovieNodeRenderer movieNodeRenderer;

    @Nonnull
    private final List renderables;

    public NodesAdapter (final @Nonnull Context context, final @Nonnull List nodes)
      {
        this.renderables = nodes;
        this.textNodeRenderer = new AndroidTextNodeRenderer(context);
        this.headerNodeRenderer = new AndroidHeaderNodeRenderer(context);
        this.staticImageRenderer = new AndroidStaticImageRenderer(context);
        this.observationSoundNodeRenderer = new AndroidObservationSoundNodeRenderer(context); 
        this.movieNodeRenderer = new AndroidMovieNodeRenderer(context);
      }

    @Nonnegative
    public int getCount()
      {
        return renderables.size();
      }

    @Nonnull
    public Node getItem (final @Nonnegative int index)
      {
        return renderables.get(index);
      }

    public long getItemId (final int id)
      {
        return id;
      }

    @Nonnull
    public View getView (final @Nonnegative int index,
                         final @Nonnull View convertView,
                         final @Nonnull ViewGroup parent)
      {
        final Node node = getItem(index);

        try
          {
            if (node instanceof HeaderNode) // FIXME: search in the Lookup of Node
              {
                return headerNodeRenderer.getView((HeaderNode)node, parent);
              }
            else if (node instanceof TextNode)
              {
                return textNodeRenderer.getView((TextNode)node, parent);
              }
            else if (node instanceof StaticImageNode)
              {
                return staticImageRenderer.getView((StaticImageNode)node, parent);
              }
            else if (node instanceof SoundObservationNode)
              {
                return observationSoundNodeRenderer.getView((SoundObservationNode)node, parent);
              }
            else if (node instanceof VideoNode)
              {
                return movieNodeRenderer.getView((VideoNode)node, parent);
              }
          }
        catch (Exception e)
          {
            throw new RuntimeException(e);
          }

        throw new RuntimeException(" " + node);
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy