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 326c1c50be98 2010/06/26 22:17:07 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound;

import android.widget.AdapterView;
import javax.annotation.Nonnull;
import java.io.IOException;
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.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.MediaController;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.TaxonFactSheetAbstractActivity;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.TaxonFactSheetContainerActivity;
import org.openide.util.NbBundle;

/***********************************************************************************************************************
 *
 * @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 TaxonSoundFactSheetAndroidController controller;

    private MediaController mediaController;

    private ListView list;

    private ProgressDialog dialog;

//    private Button btPlay;
//
//    private Button btDownload;

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

        try
          {
            final String preparingData = NbBundle.getMessage(TaxonFactSheetContainerActivity.class, "preparingData");
            dialog = ProgressDialog.show(this, "", preparingData, true);
            controller = new TaxonSoundFactSheetAndroidController(this, taxon);
            list = (ListView)findViewById(R.id.list);
//            btPlay = (Button)findViewById(R.id.btPlay);
//            btDownload = (Button)findViewById(R.id.btDownload);
            list.setAdapter(controller.getSoundsAdapter());
            registerForContextMenu(list);
            mediaController = new MediaController(this);
            mediaController.setAnchorView(list);
            controller.initialize();

//            btPlay.setEnabled(false);
//            btDownload.setEnabled(false);
//
//            btPlay.setOnClickListener(new View.OnClickListener()
//              {
//                public void onClick (final @Nonnull View view)
//                  {
//                    controller.playMedia(list.getSelectedItemPosition());
//                  }
//              });
//            btDownload.setOnClickListener(new View.OnClickListener()
//              {
//                public void onClick (final @Nonnull View view)
//                  {
//                    controller.downloadMedia(list.getSelectedItemPosition());
//                  }
//              });

//            list.setOnItemClickListener(new AdapterView.OnItemClickListener()
//              {
//                public void onItemClick (final @Nonnull AdapterView av,
//                                         final @Nonnull View view,
//                                         final int index,
//                                         final long id)
//                  {
//                      System.err.println("ONITEMCLICK " + index);
////                      list.getAdapter().
//                      list.setItemChecked(index, true);
//                  }
//              });

//            list.setOnItemSelectedListener(new OnItemSelectedListener()
//              {
//                public void onItemSelected (final @Nonnull AdapterView adapterView,
//                                            final @Nonnull View view,
//                                            final int index,
//                                            final long id)
//                  {
//                    btPlay.setEnabled(controller.isPlayable(index));
//                    btDownload.setEnabled(controller.isDownloadable(index));
//                  }
//
//                public void onNothingSelected (final @Nonnull AdapterView adapterView)
//                  {
//                    btPlay.setEnabled(false);
//                    btDownload.setEnabled(false);
//                  }
//            });
          }
        catch (IOException e)
          {
            logger.warning("While setting up %s", e);
            logger.throwing("onCreate()", CLASS, e);
          }
      }

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

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    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);
        menu.findItem(R.id.downloadMedia).setEnabled(controller.isDownloadable(info.position));
        menu.findItem(R.id.refreshMedia).setEnabled(controller.isRefreshable(info.position));
        menu.findItem(R.id.playMedia).setEnabled(controller.isPlayable(info.position));
        menu.findItem(R.id.goToPage).setEnabled(controller.hasWebPage(info.position));
        menu.findItem(R.id.deleteMedia).setEnabled(controller.isDeletable(info.position));
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public boolean onContextItemSelected (final @Nonnull MenuItem item)
      {
        final AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();

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

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

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

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

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

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

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void openWebPage (final @Nonnull String url)
      {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void notifyDataLoaded()
      {
        list.post(new Runnable()
          {
            public void run()
              {
                list.setAdapter(controller.getSoundsAdapter());
                dialog.dismiss();
              }
          });
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void notify (final @Nonnull String message)
      {
        list.post(new Runnable()
          {
            public void run()
              {
                getCommonUITasks().showTemporaryMessage(message);
              }
          });
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy