private void calculateCalibration(long difference,float currentMeasure,byte currentIndex){
  if (difference >= MedtronicConstants.TIME_15_MIN_IN_MS && difference < MedtronicConstants.TIME_20_MIN_IN_MS) {
    if (isSensorMeasureInRange(currentIndex,expectedSensorSortNumberForCalibration)) {
      isCalibrating=false;
      calibrationStatus=MedtronicConstants.CALIBRATED;
      calibrationIsigValue=currentMeasure;
      SharedPreferences.Editor editor=settings.edit();
      calibrationFactor=lastGlucometerValue / calibrationIsigValue;
      editor.remove("expectedSensorSortNumberForCalibration0");
      editor.remove("expectedSensorSortNumberForCalibration1");
      editor.putFloat("calibrationFactor",(float)calibrationFactor);
      editor.putInt("calibrationStatus",calibrationStatus);
      editor.commit();
    }
 else {
      if (calibrationStatus != MedtronicConstants.WITHOUT_ANY_CALIBRATION && currentIndex != expectedSensorSortNumber) {
        calibrationStatus=MedtronicConstants.LAST_CALIBRATION_FAILED_USING_PREVIOUS;
        isCalibrating=false;
      }
 else {
        calibrationStatus=MedtronicConstants.WITHOUT_ANY_CALIBRATION;
      }
      SharedPreferences.Editor editor=settings.edit();
      editor.remove("expectedSensorSortNumberForCalibration0");
      editor.remove("expectedSensorSortNumberForCalibration1");
      editor.commit();
    }
  }
 else   if (difference >= MedtronicConstants.TIME_20_MIN_IN_MS) {
    if (isSensorMeasureInRange(currentIndex,expectedSensorSortNumberForCalibration)) {
      calibrationStatus=MedtronicConstants.CALIBRATED_IN_15MIN;
      calibrationIsigValue=currentMeasure;
      SharedPreferences.Editor editor=settings.edit();
      calibrationFactor=lastGlucometerValue / calibrationIsigValue;
      editor.remove("expectedSensorSortNumberForCalibration0");
      editor.remove("expectedSensorSortNumberForCalibration1");
      editor.putFloat("calibrationFactor",(float)calibrationFactor);
      editor.putInt("calibrationStatus",calibrationStatus);
      editor.commit();
    }
 else {
      if (calibrationStatus != MedtronicConstants.WITHOUT_ANY_CALIBRATION)       calibrationStatus=MedtronicConstants.LAST_CALIBRATION_FAILED_USING_PREVIOUS;
 else {
        calibrationStatus=MedtronicConstants.WITHOUT_ANY_CALIBRATION;
      }
      SharedPreferences.Editor editor=settings.edit();
      editor.remove("expectedSensorSortNumberForCalibration0");
      editor.remove("expectedSensorSortNumberForCalibration1");
      editor.commit();
    }
    isCalibrating=false;
  }
 else {
    if (isCalibrating) {
      if (difference < MedtronicConstants.TIME_5_MIN_IN_MS) {
        calibrationStatus=MedtronicConstants.CALIBRATING;
      }
 else       if (difference >= MedtronicConstants.TIME_5_MIN_IN_MS && difference <= MedtronicConstants.TIME_15_MIN_IN_MS)       calibrationStatus=MedtronicConstants.CALIBRATING2;
 else       calibrationStatus=MedtronicConstants.CALIBRATING;
    }
 else {
      if (calibrationStatus != MedtronicConstants.WITHOUT_ANY_CALIBRATION)       calibrationStatus=MedtronicConstants.LAST_CALIBRATION_FAILED_USING_PREVIOUS;
 else {
        calibrationStatus=MedtronicConstants.WITHOUT_ANY_CALIBRATION;
      }
      SharedPreferences.Editor editor=settings.edit();
      editor.remove("expectedSensorSortNumberForCalibration0");
      editor.remove("expectedSensorSortNumberForCalibration1");
      editor.putInt("calibrationStatus",calibrationStatus);
      editor.commit();
    }
  }
}

private void calculateCalibration ( long difference , float currentMeasure , byte currentIndex ) { if ( difference >= MedtronicConstants . TIME_15_MIN_IN_MS && difference < MedtronicConstants . TIME_20_MIN_IN_MS ) { if ( isSensorMeasureInRange ( currentIndex , expectedSensorSortNumberForCalibration ) ) { isCalibrating = false ; calibrationStatus = MedtronicConstants . CALIBRATED ; calibrationIsigValue = currentMeasure ; SharedPreferences . Editor editor = settings . edit ( ) ; calibrationFactor = lastGlucometerValue / calibrationIsigValue ; editor . remove ( "expectedSensorSortNumberForCalibration0" ) ; editor . remove ( "expectedSensorSortNumberForCalibration1" ) ; editor . putFloat ( "calibrationFactor" , ( float ) calibrationFactor ) ; editor . putInt ( "calibrationStatus" , calibrationStatus ) ; editor . commit ( ) ; } else { if ( calibrationStatus != MedtronicConstants . WITHOUT_ANY_CALIBRATION && currentIndex != expectedSensorSortNumber ) { calibrationStatus = MedtronicConstants . LAST_CALIBRATION_FAILED_USING_PREVIOUS ; isCalibrating = false ; } else { calibrationStatus = MedtronicConstants . WITHOUT_ANY_CALIBRATION ; } SharedPreferences . Editor editor = settings . edit ( ) ; editor . remove ( "expectedSensorSortNumberForCalibration0" ) ; editor . remove ( "expectedSensorSortNumberForCalibration1" ) ; editor . commit ( ) ; } } else if ( difference >= MedtronicConstants . TIME_20_MIN_IN_MS ) { if ( isSensorMeasureInRange ( currentIndex , expectedSensorSortNumberForCalibration ) ) { calibrationStatus = MedtronicConstants . CALIBRATED_IN_15MIN ; calibrationIsigValue = currentMeasure ; SharedPreferences . Editor editor = settings . edit ( ) ; calibrationFactor = lastGlucometerValue / calibrationIsigValue ; editor . remove ( "expectedSensorSortNumberForCalibration0" ) ; editor . remove ( "expectedSensorSortNumberForCalibration1" ) ; editor . putFloat ( "calibrationFactor" , ( float ) calibrationFactor ) ; editor . putInt ( "calibrationStatus" , calibrationStatus ) ; editor . commit ( ) ; } else { if ( calibrationStatus != MedtronicConstants . WITHOUT_ANY_CALIBRATION ) calibrationStatus = MedtronicConstants . LAST_CALIBRATION_FAILED_USING_PREVIOUS ; else { calibrationStatus = MedtronicConstants . WITHOUT_ANY_CALIBRATION ; } SharedPreferences . Editor editor = settings . edit ( ) ; editor . remove ( "expectedSensorSortNumberForCalibration0" ) ; editor . remove ( "expectedSensorSortNumberForCalibration1" ) ; editor . commit ( ) ; } isCalibrating = false ; } else { if ( isCalibrating ) { if ( difference < MedtronicConstants . TIME_5_MIN_IN_MS ) { calibrationStatus = MedtronicConstants . CALIBRATING ; } else if ( difference >= MedtronicConstants . TIME_5_MIN_IN_MS && difference <= MedtronicConstants . TIME_15_MIN_IN_MS ) calibrationStatus = MedtronicConstants . CALIBRATING2 ; else calibrationStatus = MedtronicConstants . CALIBRATING ; } else { if ( calibrationStatus != MedtronicConstants . WITHOUT_ANY_CALIBRATION ) calibrationStatus = MedtronicConstants . LAST_CALIBRATION_FAILED_USING_PREVIOUS ; else { calibrationStatus = MedtronicConstants . WITHOUT_ANY_CALIBRATION ; } SharedPreferences . Editor editor = settings . edit ( ) ; editor . remove ( "expectedSensorSortNumberForCalibration0" ) ; editor . remove ( "expectedSensorSortNumberForCalibration1" ) ; editor . putInt ( "calibrationStatus" , calibrationStatus ) ; editor . commit ( ) ; } } }
this method checks if a calibration is valid .
