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

it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound.AndroidObservationSoundNodeRenderer 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: AndroidObservationSoundNodeRenderer.java,v 5db84108423b 2010/07/15 19:24:40 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound;

import android.content.Context;
import android.view.ViewGroup;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.SoundObservationNode;
import javax.annotation.Nonnull;
import java.util.Date;
import java.text.DateFormat;
import it.tidalwave.util.As;
import it.tidalwave.util.AsException;
import it.tidalwave.util.Displayable;
import it.tidalwave.util.Identifiable;
import it.tidalwave.mobile.media.Media;
import android.text.Html;
import android.view.View;
import android.widget.TextView;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.AndroidMediaNodeRenderer;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.observation.Observation;
import static it.tidalwave.util.Displayable.Displayable;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class AndroidObservationSoundNodeRenderer extends AndroidMediaNodeRenderer
  {
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public AndroidObservationSoundNodeRenderer (final @Nonnull Context context)
      {
        super(context, R.layout.sound_browser_row);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override @Nonnull
    public View getView (final @Nonnull SoundObservationNode node, final @Nonnull ViewGroup viewGroup)
      throws Exception
      {
        final View view = super.getView(node, viewGroup);
        final TextView tvLabel = (TextView)view.findViewById(R.id.tvLabel);
        final TextView tvLocationAndDate = (TextView)view.findViewById(R.id.tvLocationAndDate);
        final TextView tvAuthor = (TextView)view.findViewById(R.id.tvAuthor);
        final TextView tvRights = (TextView)view.findViewById(R.id.tvRights);
        final TextView tvDuration = (TextView)view.findViewById(R.id.tvDuration);

        final Observation observation = node.getObservation();
        final Media media = observation.as(Media.class);
        final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
        final As author = observation.findObservers().result();
        final As source = observation.getSource();
        final As location =  observation.getLocation();
        final Date date = observation.getDate();
        final String callType = observation.as(Displayable.class).getDisplayName();

        String observationId = "";

        try
          {
            observationId = observation.as(Identifiable.class).getId().stringValue();
            observationId = observationId.replaceAll(".*/", "");
          }
        catch (AsException e)
          {
            // no id, never mind
          }

        tvLabel.setText(Html.fromHtml(String.format("%s", callType)));
        tvLocationAndDate.setText(location.as(Displayable).getDisplayName() + " " + df.format(date));
        tvAuthor.setText(author.as(Displayable).getDisplayName() + ", " + source.as(Displayable).getDisplayName() + " " + observationId);
        renderLicense(tvRights, media);
        tvDuration.setText(formatDuration(media.get(Media.DURATION)));

        return view;
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy