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

it.tidalwave.bluebill.mobile.android.taxonomy.factsheet.TaxonFactSheetActivitySupport 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;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.taxonomy.TaxonIntentHelper;
import it.tidalwave.bluebill.mobile.android.util.CommonOptionsMenuController;
import it.tidalwave.bluebill.mobile.android.util.CommonOptionsMenuControllerProvider;
import it.tidalwave.netbeans.util.Locator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/***********************************************************************************************************************
 *
 * @stereotype Activity
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Slf4j @RequiredArgsConstructor
public abstract class TaxonFactSheetActivitySupport extends Activity
  {
    private final int layoutId;
  
    private final int viewId;
  
    @CheckForNull
    private Taxon taxon;
    
    protected AndroidTaxonFactSheetViewSupport view;
    
    private final CommonOptionsMenuController commonOptionsMenuController = Locator.find(CommonOptionsMenuControllerProvider.class).createCommonOptionsMenuController(this);  

   /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public void onCreate (final @Nonnull Bundle savedInstanceState)
      {
        log.info("onCreate()");
        super.onCreate(savedInstanceState);
        setContentView(layoutId);
        view = (AndroidTaxonFactSheetViewSupport)findViewById(viewId);
        initializeView();
        view.initWidgets();
        
        final ListView lvList = view.getLvList();
        
        if (lvList != null) // some subclasses might not use it   
          {
            registerForContextMenu(lvList);
            log.debug(">>>> registered for context menu: {}", lvList);
          }

        try
          {
            taxon = TaxonIntentHelper.getTaxon(getIntent());
          }
        catch (NotFoundException e)
          {
            throw new RuntimeException("Can't find taxon", e); 
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public void onResume()
      {
        log.info("onResume()");
        super.onResume();

        try
          {
            view.getController().initialize(taxon);
          }
        catch (Exception e)
          {
            log.warn("While initializing controller {}", e);
            // FIXME: diags
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @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);
      }
    
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public void onCreateContextMenu (final @Nonnull ContextMenu menu,
                                     final @Nonnull View view,
                                     final @Nonnull ContextMenuInfo menuInfo)
      {
//        android:icon="@android:drawable/ic_media_play"  FIXME ICONS
//        android:icon="@android:drawable/ic_menu_delete"
        this.view.getListAdapter().onCreateContextMenu(menu, view, menuInfo);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public boolean onContextItemSelected (final @Nonnull MenuItem item)
      {
        return view.getListAdapter().onContextItemSelected(item);
      }

    protected void initializeView()
      {
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy