
it.tidalwave.bluebill.mobile.android.taxonomy.browser.TaxonPickerActivity Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* 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://kenai.com/hg/bluebill~android-src
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy.browser;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.spi.TaxonFactSheetViewControllerSupport;
import javax.annotation.Nonnull;
import it.tidalwave.util.logging.Logger;
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.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
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.Button;
import android.widget.ListView;
import android.widget.TextView;
import it.tidalwave.ui.android.view.Bindings;
import it.tidalwave.ui.android.widget.PresentationModelAdapter;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.util.CommonOptionsMenuController;
import static org.openide.util.NbBundle.*;
/***********************************************************************************************************************
*
* 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).
*
* @stereotype View
* @stereotype Activity
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class TaxonPickerActivity extends Activity implements TaxonPickerView
{
private static final String CLASS = TaxonPickerActivity.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
public static final Class TaxonPickerActivity = TaxonPickerActivity.class;
private static final Class _ = TaxonFactSheetViewControllerSupport.class; // FIXME:
private ListView liRecentTaxa;
private TextView tvTaxonomy;
private TextView tvTaxonLanguages;
private final TaxonPickerViewController controller = new AndroidTaxonPickerViewController(this);
private PresentationModelAdapter adapter;
private ProgressDialog progressDialog;
private final CommonOptionsMenuController commonOptionsMenuController = new CommonOptionsMenuController(this);
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void populate (final @Nonnull PresentationModel taxaPM)
{
runOnUiThread(new Runnable()
{
public void run()
{
adapter = new PresentationModelAdapter(TaxonPickerActivity.this, taxaPM);
Bindings.bind(liRecentTaxa, adapter);
if (progressDialog != null)
{
progressDialog.dismiss();
progressDialog = null;
}
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void showTaxonomyName (final @Nonnull String taxonomyName)
{
runOnUiThread(new Runnable()
{
public void run()
{
tvTaxonomy.setText(taxonomyName);
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
public void showTaxonomyLanguages (final @Nonnull String taxonomyLanguages)
{
runOnUiThread(new Runnable()
{
public void run()
{
tvTaxonLanguages.setText(taxonomyLanguages);
}
});
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public void onCreate (final @Nonnull Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_taxon_picker);
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);
liRecentTaxa = (ListView)findViewById(R.id.liRecentTaxa);
tvTaxonomy = (TextView)findViewById(R.id.tvTaxonomy);
tvTaxonLanguages = (TextView)findViewById(R.id.tvPrimaryLanguage);
Bindings.bind(btOrder, controller.getBrowseByRankAction(Rank.ORDER));
Bindings.bind(btFamily, controller.getBrowseByRankAction(Rank.FAMILY));
Bindings.bind(btGenus, controller.getBrowseByRankAction(Rank.GENUS));
Bindings.bind(btSpecies, controller.getBrowseByRankAction(Rank.SPECIES));
registerForContextMenu(liRecentTaxa);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
protected void onResume()
{
super.onResume();
final String preparingData = getMessage(_, "preparingData");
progressDialog = ProgressDialog.show(this, "", preparingData, true);
new Thread()
{
@Override
public void run()
{
// always reinitialize, even if you have previously loaded data, because e.g. we changed the primary
// taxon locale, or the taxonomy, etc...
controller.initialize();
}
}.start();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@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;
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public boolean onOptionsItemSelected (final @Nonnull MenuItem item)
{
switch (item.getItemId())
{
case R.id.clearTaxonHistory:
controller.clearTaxonHistory();
return true;
default:
return commonOptionsMenuController.onOptionsItemSelected(item);
}
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public void onCreateContextMenu (final @Nonnull ContextMenu menu,
final @Nonnull View view,
final @Nonnull ContextMenuInfo menuInfo)
{
adapter.onCreateContextMenu(menu, view, menuInfo);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public boolean onContextItemSelected (final @Nonnull MenuItem item)
{
return adapter.onContextItemSelected(item);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
* 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();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy