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

it.tidalwave.bluebill.mobile.android.observation.AddObservationControlFlow 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 it.tidalwave.util.logging.Logger;
import it.tidalwave.mobile.android.ui.AndroidFlowController;
import it.tidalwave.bluebill.mobile.observation.ui.ObservationsViewController;
import android.app.Activity;
import android.content.Intent;
import static it.tidalwave.bluebill.mobile.android.location.LocationPickerActivity.LocationPickerActivity;
import static it.tidalwave.bluebill.mobile.android.taxonomy.browser.TaxonPickerActivity.TaxonPickerActivity;
import static it.tidalwave.bluebill.mobile.android.taxonomy.browser.SpeciesBrowserActivity.SpeciesBrowserActivity;
import static it.tidalwave.bluebill.mobile.android.observation.CountAndGenderActivity.CountAndGenderActivity;
import static it.tidalwave.bluebill.mobile.android.observation.CountAndGenderActivity.ADD_MORE;

/***********************************************************************************************************************
 *
 * The {@link ControlFlow} for the process of adding an {@link it.tidalwave.observation.Observation}.
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
public class AddObservationControlFlow extends AndroidFlowController
  {
    private static final String CLASS = AddObservationControlFlow.class.getName();
    private static final Logger logger = Logger.getLogger(CLASS);

    public AddObservationControlFlow()
      {
        startFrom(TaxonPickerActivity);
        when(TaxonPickerActivity).completes().thenForwardTo(CountAndGenderActivity);
        when(SpeciesBrowserActivity).completes().thenForwardTo(CountAndGenderActivity);
        when(CountAndGenderActivity).completesWith(ADD_MORE).thenForwardTo(TaxonPickerActivity);
        when(CountAndGenderActivity).completesWithout(ADD_MORE).thenForwardTo(LocationPickerActivity);
      }
    
    public static void onActivityResult (final @Nonnull ObservationsViewController controller, 
                                         final int requestCode, 
                                         final int resultCode,
                                         final Intent data) 
      {
        logger.info("onActivityResult(%d, %d, %s)", requestCode, resultCode, data);
        
        if (requestCode == AndroidFlowController.findRequestCode(AddObservationControlFlow.class)) 
          {
            switch (resultCode)
              {
                case Activity.RESULT_OK:
                    controller.commitNewObservation();
                    break;

                case Activity.RESULT_CANCELED:
                    controller.cancelNewObservation();
                    break;
              }
          }
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy