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

it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound.TaxonSoundFactSheetActivity 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: TaxonSoundFactSheetActivity.java,v 20575c7536b3 2010/07/15 18:52:42 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound;

import javax.annotation.Nonnull;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.mobile.android.media.MediaControllerAdapter;
import it.tidalwave.mobile.media.MediaPlayer.Controller;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.sound.TaxonSoundFactSheetUI;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.MediaController;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.TaxonFactSheetAbstractActivity;
import it.tidalwave.bluebill.observation.Observation;
import it.tidalwave.mobile.media.Media;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class TaxonSoundFactSheetActivity extends TaxonFactSheetAbstractActivity implements TaxonSoundFactSheetUI
  {
    private static final String CLASS = TaxonSoundFactSheetActivity.class.getName();
    private static final Logger logger = Logger.getLogger(CLASS);

    private MediaController mediaController;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public TaxonSoundFactSheetActivity()
      {
        super(R.layout.taxon_sound_fact_sheet);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public void onCreate (final @Nonnull Bundle savedInstanceState)
      {
        super.onCreate(savedInstanceState);

        mediaController = new MediaController(this);
        mediaController.setAnchorView(list);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() // TODO: pull up
          {
            public void onItemClick (final @Nonnull AdapterView av,
                                     final @Nonnull View view,
                                     final int index,
                                     final long id)
              {
                final Media media = controller.getMedia(index);
                controller.getDefaultAction(media).run(controller, media);
              }
          });
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    protected void onPause()
      {
        super.onPause();
        controller.disposePlayer(); // TODO: pull up
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void notifyPlayMedia (final @Nonnull Controller controller)
      {
        mediaController.setMediaPlayer(new MediaControllerAdapter(controller));
        mediaController.show(0);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public void onCreateContextMenu (final @Nonnull ContextMenu menu,
                                     final @Nonnull View view,
                                     final @Nonnull ContextMenuInfo menuInfo)
      {
        final AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
        getMenuInflater().inflate(R.menu.media_context_menu, menu);
        final Observation observation = controller.getObservation(info.position);
        menu.findItem(R.id.downloadMedia).setEnabled(controller.isDownloadable(observation.as(Media.class)));
        menu.findItem(R.id.refreshMedia).setEnabled(controller.isRefreshable(observation.as(Media.class)));
        menu.findItem(R.id.playMedia).setEnabled(controller.isPlayable(observation.as(Media.class)));
        menu.findItem(R.id.deleteMedia).setEnabled(controller.isDeletable(observation.as(Media.class)));
        menu.findItem(R.id.goToPage).setEnabled(controller.hasWebPage(observation));
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public boolean onContextItemSelected (final @Nonnull MenuItem item)
      {
        final AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
        final Observation observation = controller.getObservation(info.position);
        final Media media = controller.getMedia(info.position);

        switch (item.getItemId())
          {
            case R.id.downloadMedia:
                controller.downloadMedia(media);
                return true;

            case R.id.refreshMedia:
                controller.refreshMedia(media);
                return true;

            case R.id.playMedia:
                controller.playMedia(media);
                return true;

            case R.id.deleteMedia:
                controller.deleteMedia(media);
                return true;

            case R.id.goToPage:
                controller.goToPage(observation);
                return true;

            default:
                return super.onOptionsItemSelected(item);
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    protected TaxonSoundFactSheetAndroidController createController()
      {
        return new TaxonSoundFactSheetAndroidController(this, taxon, factSheetProvider);
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy