it.tidalwave.bluebill.mobile.android.taxonomy.browser.PickTaxonActivity 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: PickTaxonActivity.java,v 7e4367efde27 2010/08/08 11:03:43 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.browser;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.bluebill.taxonomy.Taxonomy.Type;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.util.CommonOptionsMenuController;
/***********************************************************************************************************************
*
* This activity allows to pick a Taxon (actually a species). It offers the user the capability of choosing where to
* start browsing from (in the range from Order to Species, bounds included).
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class PickTaxonActivity extends Activity
{
private static final String CLASS = PickTaxonActivity.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
private ListView liRecentTaxa;
private TextView tvTaxonomy;
private TextView tvTaxonLanguages;
private final AndroidPickTaxonController controller = new AndroidPickTaxonController(this);
private final CommonOptionsMenuController commonOptionsMenuController = new CommonOptionsMenuController(this);
private final TaxonomyFooterController taxonomyFooterController = new TaxonomyFooterController();
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
private final OnClickListener taxonomyBrowserStarter = new OnClickListener()
{
public void onClick (final @Nonnull View view)
{
controller.startBrowsingByType((Type)view.getTag());
}
};
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public void onCreate (final @Nonnull Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.pick_taxon_activity);
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);
btOrder.setTag(Type.ORDER);
btFamily.setTag(Type.FAMILY);
btGenus.setTag(Type.GENUS);
btSpecies.setTag(Type.SPECIES);
btOrder.setOnClickListener(taxonomyBrowserStarter);
btFamily.setOnClickListener(taxonomyBrowserStarter);
btGenus.setOnClickListener(taxonomyBrowserStarter);
btSpecies.setOnClickListener(taxonomyBrowserStarter);
liRecentTaxa = (ListView)findViewById(R.id.liRecentTaxa);
tvTaxonomy = (TextView)findViewById(R.id.tvTaxonomy);
tvTaxonLanguages = (TextView)findViewById(R.id.tvPrimaryLanguage);
liRecentTaxa.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick (final @Nonnull AdapterView> av,
final @Nonnull View view,
final @Nonnegative int position,
final long id)
{
controller.pickHistoricTaxon(position);
}
});
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
protected void onResume()
{
super.onResume();
controller.bindTaxa(); // e.g. we changed the primary taxon locale - notifyDataSetChanged() is not enough
// as we need to resort them
updateHeaderAndFooter();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public boolean onCreateOptionsMenu (final @Nonnull Menu menu)
{
getMenuInflater().inflate(R.menu.pick_taxon_options_menu, menu);
getMenuInflater().inflate(R.menu.common_options_menu, menu);
return true;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
public boolean onOptionsItemSelected (final @Nonnull MenuItem item)
{
switch (item.getItemId())
{
case R.id.clearTaxonHistory:
controller.clearTaxonHistory();
return true;
default:
return commonOptionsMenuController.onOptionsItemSelected(item);
}
}
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
public void updateList()
{
liRecentTaxa.setAdapter(controller.getTaxonHistoryAdapter());
}
/*******************************************************************************************************************
*
* Propagates the result back.
*
******************************************************************************************************************/
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
logger.warning("onActivityResult(%d, %d, %s)", requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
setResult(resultCode, data);
finish();
}
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
private void updateHeaderAndFooter()
{
tvTaxonomy.setText(taxonomyFooterController.getTaxonomyDisplayName());
tvTaxonLanguages.setText(taxonomyFooterController.getTaxonLanguages());
}
}