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

it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.stillimage.AndroidTaxonStillImageFactSheetView Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * 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.bluebill.mobile.android.taxonomy.factsheet.stillimage;

import android.content.Context;
import android.util.AttributeSet;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import it.tidalwave.role.PlainTextRenderable;
import it.tidalwave.role.ui.PresentationModel;
import it.tidalwave.mobile.media.Media;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.ui.stillimage.DefaultTaxonStillImageFactSheetViewController;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.ui.stillimage.TaxonStillImageFactSheetView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.TextSwitcher;
import android.widget.ViewSwitcher;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.AndroidTaxonFactSheetViewSupport;
import it.tidalwave.ui.android.widget.PresentationModelAdapter;
import it.tidalwave.ui.android.widget.StillImageViewer;
import lombok.extern.slf4j.Slf4j;
import static it.tidalwave.role.PlainTextRenderable.PlainTextRenderable;
import static it.tidalwave.semantic.vocabulary.DublinCoreVocabulary.*;

/***********************************************************************************************************************
 *
 * @stereotype View
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Slf4j
public class AndroidTaxonStillImageFactSheetView extends AndroidTaxonFactSheetViewSupport 
                                                 implements TaxonStillImageFactSheetView
  {
    private Gallery gaThumbnailStrip;

    private StillImageViewer ivFullImage;

    private TextSwitcher tsCaption;

    private TextSwitcher tsSource;

    private TextSwitcher tsLicense;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    private final AdapterView.OnItemSelectedListener itemSelectedListener = new AdapterView.OnItemSelectedListener()
      {
        public void onItemSelected (final @Nonnull AdapterView parent,
                                    final @Nonnull View view,
                                    final @Nonnegative int position,
                                    final long id)
          {
            controller.showImage(position);
          }

        public void onNothingSelected (final @Nonnull AdapterView parent)
          {
          }
      };

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    private final ViewSwitcher.ViewFactory imageViewFactory = new ViewSwitcher.ViewFactory()
      {
        @Nonnull
        public View makeView()
          {
            return LayoutInflater.from(getContext()).inflate(R.layout.component_image_view, null);
          }
      };

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    private final ViewSwitcher.ViewFactory textViewFactory = new ViewSwitcher.ViewFactory()
      {
        @Nonnull
        public View makeView()
          {
            return LayoutInflater.from(getContext()).inflate(R.layout.component_taxon_still_image_label, null);
          }
      };

    public AndroidTaxonStillImageFactSheetView (final @Nonnull Context context, final @Nonnull AttributeSet attrs) 
      {
        super(context, attrs);
      }

    public AndroidTaxonStillImageFactSheetView (final @Nonnull Context context) 
      {
        super(context);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    protected void onAttachedToWindow()
      {
        log.info("onAttachedToWindow()");
        super.onAttachedToWindow();
        gaThumbnailStrip = (Gallery)findViewById(R.id.gaThumbnailStrip);
        ivFullImage = (StillImageViewer)findViewById(R.id.ivFullImage);
        tsCaption = (TextSwitcher)findViewById(R.id.tvCaption);
        tsSource  = (TextSwitcher)findViewById(R.id.tvSource);
        tsLicense = (TextSwitcher)findViewById(R.id.tvLicense);

        gaThumbnailStrip.setOnItemSelectedListener(itemSelectedListener);
        ivFullImage.setFactory(imageViewFactory);
        tsCaption.setFactory(textViewFactory);
        tsSource.setFactory(textViewFactory);
        tsLicense.setFactory(textViewFactory);
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override
    protected DefaultTaxonStillImageFactSheetViewController createController()
      {
        return new AndroidTaxonStillImageFactSheetViewController(this);
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void renderImage (final @Nonnull PresentationModel image)
      {                
        post(new Runnable()
          {
            public void run()
              {
                log.info("renderImage({})", image);
                ivFullImage.setImage(image);

                // FIXME: can't use TextViewRenderable since ts* are TextSwitchers - enhance TextViewRenderable or create TextSwitcherRenderable
                final PlainTextRenderable stringRenderable = image.as(PlainTextRenderable);
                tsCaption.setText(stringRenderable.render("%s", DC_TITLE));
                tsSource.setText(stringRenderable.render("Author: %s (publisher: %s)", Media.AUTHOR, DC_PUBLISHER));    
                tsLicense.setText(stringRenderable.render("%s", Media.RIGHTS));
              }
          });
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override
    public void populate (final @Nonnull PresentationModel stillImagesPM)
      {
        // don't call super 
        post(new Runnable()
          {
            public void run()
              {
                gaThumbnailStrip.setAdapter(listAdapter = new PresentationModelAdapter(getContext(), stillImagesPM));
              }
          });
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy