Merge pull request #187 from OpenSeizureDetector/185-crash-in-exportactivity-when-using-comma-as-decimal-separator
Introduced ParseToDoule function into mUtil as suggested by @AroonPro…
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
OpenSeizureDetector Android App - Change Log
|
||||
============================================
|
||||
V4.2.8 - Fixed crash in export data function when using european style comma based decimal separator.
|
||||
V4.2.7 - BLE2 data source re-start fixed??
|
||||
V4.2.6 - Fixed problem with notifications in Android 13
|
||||
- Improved start-up checks for permissions
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:versionCode="140"
|
||||
android:versionName="4.2.7">
|
||||
android:versionCode="142"
|
||||
android:versionName="4.2.8">
|
||||
<!-- android:allowBackup="false" -->
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
|
||||
|
||||
@@ -35,11 +35,13 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ExportDataActivity extends AppCompatActivity
|
||||
implements View.OnClickListener {
|
||||
@@ -198,8 +200,8 @@ public class ExportDataActivity extends AppCompatActivity
|
||||
if (view == mExportBtn) {
|
||||
mDateTxt.setText(String.format("%02d-%02d-%04d", mDay, mMonth + 1, mYear));
|
||||
mTimeTxt.setText(String.format("%02d:%02d:%02d", mHour, mMinute, 00));
|
||||
mDuration = Double.parseDouble(mDurationTxt.getText().toString());
|
||||
|
||||
mDuration = mUtil.parseToDouble(mDurationTxt.getText().toString());
|
||||
String dateTimeStr = String.format("%04d-%02d-%02dT%02d:%02d:%02dZ", mYear, mMonth + 1, mDay, mHour, mMinute, 00);
|
||||
//mUtil.showToast(dateTimeStr);
|
||||
mEndDate = mUtil.string2date(dateTimeStr);
|
||||
|
||||
@@ -59,6 +59,7 @@ import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -66,6 +67,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -778,4 +780,27 @@ public class OsdUtil {
|
||||
return allOk;
|
||||
}
|
||||
|
||||
public double parseToDouble(String userInput) {
|
||||
/**
|
||||
* Parse a string to a double value, taking localisation into account.
|
||||
* Using NumberFormat as recommended by https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/lang/Double.html#valueOf(java.lang.String)
|
||||
*/
|
||||
double retVal;
|
||||
try {
|
||||
Locale currentLocale;
|
||||
if (android.os.Build.VERSION.SDK_INT < 24) {
|
||||
currentLocale = mContext.getResources().getConfiguration().locale;
|
||||
} else {
|
||||
currentLocale = mContext.getResources().getConfiguration().getLocales().get(0);
|
||||
}
|
||||
NumberFormat nf = NumberFormat.getInstance(currentLocale);
|
||||
retVal = nf.parse(userInput).doubleValue();
|
||||
} catch (ParseException e) {
|
||||
// Handle invalid input (e.g., non-numeric characters)
|
||||
showToast("Invalid input. Please enter a valid numeric value.");
|
||||
retVal = 0.0;
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<string name="app_name">OpenSeizureDetector</string>
|
||||
<string name="changelog">
|
||||
"\n
|
||||
\nV4.2.8 - fixed crash in export data function.
|
||||
\nV4.2.7 - Finally fixed BLE2 data source re-start after dropping connection?
|
||||
\nV4.2.6 - Fixed issues with Android 13 notifications and BLE data source shutdown. Added support for V2.x of Garmin watch app, Added new BLE2 data source, signal strength and battery level graphs.
|
||||
\nV4.2.4 - Fault alarm rather than crash if bluetooth system crashes.
|
||||
|
||||
Reference in New Issue
Block a user