Skip to content

Commit

Permalink
Improved parsing of reference pressure values
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Aug 16, 2023
1 parent 3aa5f43 commit 2340f2f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/de/blau/android/dialogs/BarometerCalibration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.blau.android.dialogs;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
Expand Down Expand Up @@ -30,6 +33,8 @@ public class BarometerCalibration extends ImmersiveDialogFragment {

private static final String TAG = "fragment_calibration_form";

private static final Pattern FLOAT_PATTERN = Pattern.compile("[^0-9]*([0-9]+[.][0-9]*)[^0-9]*");

/**
* Display a dialog allowing barometer calibration
*
Expand Down Expand Up @@ -93,7 +98,12 @@ public AppCompatDialog onCreateDialog(Bundle savedInstanceState) {
intent.putExtra(TrackerService.CALIBRATE_HEIGHT_KEY, Integer.parseInt(calibrationValue));
break;
case 1: // reference pressure
intent.putExtra(TrackerService.CALIBRATE_P0_KEY, Float.parseFloat(calibrationValue.substring(0, calibrationValue.length() - 2).trim()));
Matcher matcher = FLOAT_PATTERN.matcher(calibrationValue);
if (matcher.find()) {
intent.putExtra(TrackerService.CALIBRATE_P0_KEY, Float.parseFloat(matcher.group(1)));
} else {
throw new NumberFormatException(calibrationValue);
}
break;
default: // GNSS
// this is the default
Expand Down

0 comments on commit 2340f2f

Please sign in to comment.