it.tidalwave.bluebill.mobile.android.observation.CountAndGenderActivity 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.observation;
import javax.annotation.Nonnull;
import java.util.Arrays;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.ui.FlowController.Condition;
import it.tidalwave.bluebill.taxonomy.mobile.Taxon;
import it.tidalwave.bluebill.mobile.observation.ui.CountAndGenderViewController;
import it.tidalwave.bluebill.mobile.observation.ui.spi.DefaultCountAndGenderViewController;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import it.tidalwave.mobile.android.ui.AndroidFlowController;
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.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* This activity allows to add an ObservationItem to the current Observation.
*
* @stereotype View
* @stereotype Activity
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@Slf4j
public class CountAndGenderActivity extends Activity
{
public static final Class CountAndGenderActivity = CountAndGenderActivity.class;
/** This condition means that the activity asked for adding more species to the current Observation. */
public static final Condition ADD_MORE = new Condition()
{
public boolean compute (final @Nonnull Object... args)
{
return Arrays.asList(args).contains(CountAndGenderViewController.ADD_MORE__);
}
};
private final AndroidFlowController controlFlow = AndroidFlowController.forActivity(this);
private final CommonOptionsMenuController commonOptionsMenuController = Locator.find(CommonOptionsMenuControllerProvider.class).createCommonOptionsMenuController(this);
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public void onCreate (final @Nonnull Bundle savedInstanceState)
{
log.info("onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.view_count_and_gender);
final AndroidCountAndGenderView view = (AndroidCountAndGenderView)findViewById(R.id.viewCountAndGender);
final CountAndGenderViewController controller = new DefaultCountAndGenderViewController(view, controlFlow);
view.initialize(controller);
try
{
final Taxon taxon = TaxonIntentHelper.getTaxon(getIntent());
controller.initialize(taxon); // initialized here since we don't want to reset data when the form is recalled
}
catch (NotFoundException e)
{
throw new RuntimeException(e);
}
}
/*******************************************************************************************************************
*
* Propagates the result back.
*
******************************************************************************************************************/
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
log.info("onActivityResult({}, {}, {})", new Object[] { requestCode, resultCode, data });
if (resultCode == RESULT_OK)
{
setResult(resultCode, data);
finish();
}
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@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);
}
}