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

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

import android.util.AttributeSet;
import android.content.Context;
import android.widget.LinearLayout;
import javax.annotation.Nonnull;
import it.tidalwave.role.ui.PresentationModel;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon.Rank;
import it.tidalwave.bluebill.mobile.taxonomy.ui.TaxonPickerView;
import it.tidalwave.bluebill.mobile.taxonomy.ui.TaxonPickerViewController;
import android.app.ProgressDialog;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import it.tidalwave.ui.android.view.AndroidBindings;
import it.tidalwave.ui.android.widget.PresentationModelAdapter;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.util.ui.UserNotification;
import static lombok.AccessLevel.*;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/***********************************************************************************************************************
 *
 * @stereotype View
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Slf4j
public class AndroidTaxonPickerView extends LinearLayout implements TaxonPickerView
  {
    @Getter(PACKAGE)
    private ListView liRecentTaxa;

    private TextView tvTaxonomy;

    private TextView tvTaxonLanguages;

    @Getter(PACKAGE)
    private PresentationModelAdapter adapter;
    
    private ProgressDialog progressDialog;
    
    /*******************************************************************************************************************
     *
     * 
     ******************************************************************************************************************/
    public AndroidTaxonPickerView (final @Nonnull Context context, final @Nonnull AttributeSet attrs) 
      {
        super(context, attrs);
      }

    /*******************************************************************************************************************
     *
     * 
     ******************************************************************************************************************/
    public AndroidTaxonPickerView (final @Nonnull Context context) 
      {
        super(context);
      }
    
    /*******************************************************************************************************************
     *
     * 
     ******************************************************************************************************************/
    public void initialize (final @Nonnull TaxonPickerViewController controller)
      {
        log.info("initialize({})", controller);
        
        liRecentTaxa = (ListView)findViewById(R.id.liRecentTaxa);
        tvTaxonomy = (TextView)findViewById(R.id.tvTaxonomy);
        tvTaxonLanguages = (TextView)findViewById(R.id.tvPrimaryLanguage);
        
        final Button btOrder = (Button)findViewById(R.id.btOrder);
        final Button btFamily = (Button)findViewById(R.id.btFamily);
        final Button btGenus = (Button)findViewById(R.id.btGenus);
        final Button btSpecies = (Button)findViewById(R.id.btSpecies);
        
        AndroidBindings.bind(btOrder, controller.getBrowseByRankAction(Rank.ORDER)); 
        AndroidBindings.bind(btFamily, controller.getBrowseByRankAction(Rank.FAMILY)); 
        AndroidBindings.bind(btGenus, controller.getBrowseByRankAction(Rank.GENUS)); 
        AndroidBindings.bind(btSpecies, controller.getBrowseByRankAction(Rank.SPECIES)); 
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void populate (final @Nonnull PresentationModel taxaPM)
      {
        post(new Runnable() 
          {
            public void run() 
              {
                log.info("populate({})", taxaPM);
                AndroidBindings.bind(liRecentTaxa, adapter = new PresentationModelAdapter(getContext(), taxaPM));                
              }
          });
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void showTaxonomyName (final @Nonnull String taxonomyName) 
      {
        post(new Runnable() 
          {
            public void run() 
              {
                log.info("showTaxonomyName({})", taxonomyName);
                tvTaxonomy.setText(taxonomyName);
              }
          });
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void showTaxonomyLanguages (final @Nonnull String taxonomyLanguages) 
      {
        post(new Runnable() 
          {
            public void run() 
              {
                log.info("showTaxonomyLanguages({})", taxonomyLanguages);
                tvTaxonLanguages.setText(taxonomyLanguages);
              }
          });
      }
    
    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void lock (final @Nonnull UserNotification notification) 
      {
        post(new Runnable() 
          {
            public void run() 
              {
                log.info("lock({})", notification);
                progressDialog = ProgressDialog.show(getContext(), notification.getCaption(), notification.getText(), true);  
              }
          });
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    public void unlock() 
      {
        post(new Runnable() 
          {
            public void run() 
              {
                log.info("unlock()");

                if (progressDialog != null)
                  {
                    progressDialog.dismiss();
                    progressDialog = null;
                  }
              }
          });
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy