Android Open Source - field-data-app Bio Sample Fragment






From Project

Back to project page field-data-app.

License

The source code is released under:

MIT License

If you think the Android project field-data-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package nz.cri.gns.springs.fragments;
//w w w .  jav a  2  s . c om
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nz.cri.gns.springs.R;
import nz.cri.gns.springs.SpringsApplication;
import nz.cri.gns.springs.db.ChecklistItem;
import nz.cri.gns.springs.util.UiUtil;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Screen where the user completes checklists and entry of measurements
 * of a sample collected from a geothermal feature.
 * @author duncanw
 *
 */
public class BioSampleFragment extends BioSampleActivityFragment implements OnFocusChangeListener, TextWatcher,  CompoundButton.OnCheckedChangeListener {
  
  private View rootView;
  private boolean sampleUpdatedSinceLastSave = false;
  
  private Map<String, ChecklistItem> checklistItemMap;
  
  public static final String BIO_CHECKLIST_NAME = "bio-sample";
  
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
      
      rootView = inflater.inflate(R.layout.fragment_bio_data, container, false);
      
      Button saveButton = (Button) rootView.findViewById(R.id.save_bio_sample_button);
      saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              updateSampleFromInput();
            Toast.makeText(SpringsApplication.getAppContext(), "Update saved", Toast.LENGTH_LONG).show();             
            }
        });
      
      setInputFromSample();      
      UiUtil.addEditTextListener(this, this, rootView);
      
      setChecklistState();
      UiUtil.addCheckBoxListener(this, rootView);
      
      return rootView;
    }
    
  @Override
  public void onFocusChange(View v, boolean hasFocus) {
    if (sampleUpdatedSinceLastSave) {
      updateSampleFromInput();
    }
  }
  
    public void updateSampleFromInput() {
      
      currentSample.setTemperature(UiUtil.getNumericInput(rootView, R.id.sample_temperature_input));
      currentSample.setPh(UiUtil.getNumericInput(rootView, R.id.ph_input));
      currentSample.setOrp(UiUtil.getNumericInput(rootView, R.id.orp_input));
    currentSample.setConductivity(UiUtil.getNumericInput(rootView, R.id.conductivity_input));
    currentSample.setTds(UiUtil.getNumericInput(rootView, R.id.tds_input));
    currentSample.setDo(UiUtil.getNumericInput(rootView, R.id.do_input));
    currentSample.setTurbidity(UiUtil.getNumericInput(rootView,  R.id.turbidity_input));
    currentSample.setDnaVolume(UiUtil.getNumericInput(rootView,  R.id.dna_input));
    currentSample.setFerrousIronAbs(UiUtil.getNumericInput(rootView, R.id.ferrous_iron_input));
    currentSample.setGasVolume(UiUtil.getNumericInput(rootView,  R.id.gas_volume_input));

      currentSample.setComments(((EditText) rootView.findViewById(R.id.sample_comments_input)).getText().toString());
      currentSample.setSoilCollected(((CheckBox) rootView.findViewById(R.id.soil_collected_checkbox)).isChecked());
      currentSample.setWaterColumnCollected(((CheckBox) rootView.findViewById(R.id.water_column_collected_checkbox)).isChecked());
      currentSample.setSettledAt4C(((CheckBox) rootView.findViewById(R.id.settled_checkbox)).isChecked());
      
      getHelper().getBiologicalSampleDao().update(currentSample);
      sampleUpdatedSinceLastSave = false;
    }
    
    
    
    public void setInputFromSample() {
      
      if (currentSample.getTemperature()!= null) {
        ((EditText) rootView.findViewById(R.id.sample_temperature_input)).setText(String.valueOf(currentSample.getTemperature()));
      }
      
      if (currentSample.getPh()!= null) {
        ((EditText) rootView.findViewById(R.id.ph_input)).setText(String.valueOf(currentSample.getPh()));
      }
      
      if (currentSample.getOrp()!= null) {
        ((EditText) rootView.findViewById(R.id.orp_input)).setText(String.valueOf(currentSample.getOrp()));
      }
      
      if (currentSample.getConductivity()!= null) {
        ((EditText) rootView.findViewById(R.id.conductivity_input)).setText(String.valueOf(currentSample.getConductivity()));
      }
      
      if (currentSample.getTds()!= null) {
        ((EditText) rootView.findViewById(R.id.tds_input)).setText(String.valueOf(currentSample.getTds()));
      }      
      
      if (currentSample.getDo()!= null) {
        ((EditText) rootView.findViewById(R.id.do_input)).setText(String.valueOf(currentSample.getDo()));
      }
      
      if (currentSample.getTurbidity()!= null) {
        ((EditText) rootView.findViewById(R.id.turbidity_input)).setText(String.valueOf(currentSample.getTurbidity()));
      }
      
      if (currentSample.getDnaVolume() != null) {
        ((EditText) rootView.findViewById(R.id.dna_input)).setText(String.valueOf(currentSample.getDnaVolume()));
      }
      
      if (currentSample.getFerrousIronAbs() != null) {
        ((EditText) rootView.findViewById(R.id.ferrous_iron_input)).setText(String.valueOf(currentSample.getFerrousIronAbs()));
      }
      
      if (currentSample.getGasVolume() != null) {
        ((EditText) rootView.findViewById(R.id.gas_volume_input)).setText(String.valueOf(currentSample.getGasVolume()));
      }
      
      if (currentSample.getComments() != null) {
        ((EditText) rootView.findViewById(R.id.sample_comments_input)).setText(String.valueOf(currentSample.getComments()));
      }
      
      if (currentSample.getSoilCollected() != null) {
        ((CheckBox) rootView.findViewById(R.id.soil_collected_checkbox)).setChecked(currentSample.getSoilCollected());
      }
      
      if (currentSample.getWaterColumnCollected() != null) {
        ((CheckBox) rootView.findViewById(R.id.water_column_collected_checkbox)).setChecked(currentSample.getWaterColumnCollected());
      }
      
      if (currentSample.getSettledAt4C() != null) {
        ((CheckBox) rootView.findViewById(R.id.settled_checkbox)).setChecked(currentSample.getSettledAt4C());
      }      

    }
    
  @Override
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    
    if (buttonView.getId() == R.id.soil_collected_checkbox) {
      updateSampleFromInput();
      
    } else if (buttonView.getId() == R.id.water_column_collected_checkbox) {
      updateSampleFromInput();
      
    } else if (buttonView.getId() == R.id.settled_checkbox) {
      updateSampleFromInput();      
      
    } else {
      // Checklist checkbox toggled
      String itemName = buttonView.getTag().toString();
      ChecklistItem item = checklistItemMap.get(itemName);
      if (item == null) {
        item = new ChecklistItem();
        item.setChecklistName(BIO_CHECKLIST_NAME);
        item.setItemName(itemName);
        item.setObjectId(currentSample.getId());
        item.setItemValue(isChecked);
        getHelper().getChecklistItemDao().create(item);
        checklistItemMap.put(itemName, item);
        
      } else {
        item.setItemValue(isChecked);
        getHelper().getChecklistItemDao().update(item);
      }
    }
  }
    
    public void setChecklistState() {
      
      checklistItemMap = new HashMap<String, ChecklistItem>();
      List<ChecklistItem> checklistItems =  ChecklistItem.getBy(BIO_CHECKLIST_NAME, currentSample.getId(), getHelper());
      for (ChecklistItem item : checklistItems) {
        View view = rootView.findViewWithTag(item.getItemName());
        if (view != null) {
          checklistItemMap.put(item.getItemName(), item);
          ((CheckBox)view).setChecked(item.getItemValue());
        }
      }
    }
  
  @Override
  public void afterTextChanged(Editable s) {
    sampleUpdatedSinceLastSave = true;
  }
  
  @Override
  public void beforeTextChanged(CharSequence s, int start, int count,
      int after) {
    
  }

  @Override
  public void onTextChanged(CharSequence s, int start, int before, int count) {
    
  }

            

}




Java Source Code List

nz.cri.gns.springs.GpsLocation.java
nz.cri.gns.springs.SpringsApplication.java
nz.cri.gns.springs.activity.BioSampleActivity.java
nz.cri.gns.springs.activity.EditBiologicalSamplesActivity.java
nz.cri.gns.springs.activity.MainMenuActivity.java
nz.cri.gns.springs.activity.ManageBioSamplesActivity.java
nz.cri.gns.springs.activity.SettingsActivity.java
nz.cri.gns.springs.db.BiologicalSampleTest.java
nz.cri.gns.springs.db.BiologicalSample.java
nz.cri.gns.springs.db.ChecklistItem.java
nz.cri.gns.springs.db.Configuration.java
nz.cri.gns.springs.db.FeatureTest.java
nz.cri.gns.springs.db.Feature.java
nz.cri.gns.springs.db.PersistentObject.java
nz.cri.gns.springs.db.SpringsDbHelper.java
nz.cri.gns.springs.db.SurveyImage.java
nz.cri.gns.springs.db.SurveyTest.java
nz.cri.gns.springs.db.Survey.java
nz.cri.gns.springs.fragments.AppearanceFragment.java
nz.cri.gns.springs.fragments.BioSampleActivityFragment.java
nz.cri.gns.springs.fragments.BioSampleFragment.java
nz.cri.gns.springs.fragments.ChooseImageFragment.java
nz.cri.gns.springs.fragments.ExportSamplesFragment.java
nz.cri.gns.springs.fragments.FeatureIdFragment.java
nz.cri.gns.springs.fragments.ImageColourPickerFragment.java
nz.cri.gns.springs.fragments.ImageFragment.java
nz.cri.gns.springs.fragments.SpringsDialogFragment.java
nz.cri.gns.springs.fragments.SpringsFragment.java
nz.cri.gns.springs.util.CustomExceptionHandler.java
nz.cri.gns.springs.util.DataStatistics.java
nz.cri.gns.springs.util.DateTimePickerDialog.java
nz.cri.gns.springs.util.UiUtil.java
nz.cri.gns.springs.util.Util.java