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

it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.TaxonFactSheetContainerActivity 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: TaxonFactSheetContainerActivity.java,v d6bc9998ab99 2010/07/14 02:01:06 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.factsheet;

import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.video.TaxonVideoFactSheetActivity;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.main.TaxonMainFactSheetActivity;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.openide.util.NbBundle;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.netbeans.util.Locator;
import it.tidalwave.bluebill.taxonomy.Taxon;
import it.tidalwave.bluebill.mobile.observation.ObservationClipboard;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonomyPreferences;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TextView;
import it.tidalwave.bluebill.mobile.android.taxonomy.TaxonIntentHelper;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.name.TaxonNameFactSheetActivity;
import it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.sound.TaxonSoundFactSheetActivity;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.util.CommonOptionsMenuController;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class TaxonFactSheetContainerActivity extends TabActivity
  {
    @CheckForNull
    private Taxon taxon;

    private final CommonOptionsMenuController commonOptionsMenuController = new CommonOptionsMenuController(this);

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

        final TextView textView = (TextView)findViewById(R.id.tvTaxon);

        try
          {
            taxon = TaxonIntentHelper.getTaxon(getIntent());
            Locator.find(ObservationClipboard.class).addToTaxonHistory(taxon);
            textView.setText(Locator.find(TaxonomyPreferences.class).formatAsHtmlSingleLanguageAndScientific(taxon, ""));

            createTab(TaxonMainFactSheetActivity.class,  "facts", R.drawable.ic_tab_fact_sheet_main);
            createTab(TaxonPhotoFactSheetActivity.class, "photo", R.drawable.ic_tab_fact_sheet_photo);
            createTab(TaxonVideoFactSheetActivity.class, "video", R.drawable.ic_tab_fact_sheet_video);
            createTab(TaxonSoundFactSheetActivity.class, "sound", R.drawable.ic_tab_fact_sheet_sound);
            createTab(TaxonNameFactSheetActivity.class,  "name",  R.drawable.ic_tab_fact_sheet_name);

            getTabHost().setCurrentTab(0);
          }
        catch (NotFoundException e)
          {
            textView.setText(e.getMessage());
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    private void createTab (final @Nonnull Class activityClass,
                            final @Nonnull String id,
                            final int iconResourceId)
      throws NotFoundException
      {
        final TabHost tabHost = getTabHost(); 
        final Intent intent = TaxonIntentHelper.intentFor(taxon, activityClass);
        final Resources resources = getResources();
        final String indicator = NbBundle.getMessage(TaxonFactSheetContainerActivity.class, "tab_" + id);
        final TabHost.TabSpec tabSpec = tabHost.newTabSpec(id)
                                               .setIndicator(indicator, resources.getDrawable(iconResourceId))
                                               .setContent(intent);
        tabHost.addTab(tabSpec);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public boolean onCreateOptionsMenu (final @Nonnull Menu menu)
      {
        getMenuInflater().inflate(R.menu.common_options_menu, menu);
        return true;
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public boolean onOptionsItemSelected (final @Nonnull MenuItem item)
      {
        return commonOptionsMenuController.onOptionsItemSelected(item);
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy