OpenSeizureDetector / Android_Pebble_SD

The main OpenSeizureDetector Android App, that is published on the Android Play Store.
http://openseizuredetector.org.uk
GNU General Public License v3.0
9 stars 14 forks source link

Crash in ExportActivity when using comma as decimal separator #185

Closed jones139 closed 5 months ago

jones139 commented 6 months ago

Thank you @aroonpro and @pmithrandir for reporting

***** DEVICE INFO Brand: OPPO Device: OP4F39L1 Model: CPH2195 Manufacturer: OPPO Product: CPH2195EEA SDK: 33 Release: 13

***** APP INFO Version: 4.2.7 Installed On: 2023-11-18 15:11:30 Updated On: 2024-04-20 04:02:16 Current Date: 2024-05-02 22:57:53

***** ERROR LOG java.lang.NumberFormatException: For input string: "2,0" at jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054) at jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110) at java.lang.Double.parseDouble(Double.java:660) at uk.org.openseizuredetector.ExportDataActivity.onClick(ExportDataActivity.java:201) at android.view.View.performClick(View.java:7558) at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1218) at android.view.View.performClickInternal(View.java:7534) at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) at android.view.View$PerformClick.run(View.java:29672) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:240) at android.os.Looper.loop(Looper.java:351) at android.app.ActivityThread.main(ActivityThread.java:8377) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

jones139 commented 6 months ago

See also #183

jones139 commented 6 months ago

I think something along these lines, based on https://codingstrain.com/java-double-parse-string-with-comma/

NumberFormat format = NumberFormat.getInstance(Locale.ITALY); Number number = format.parse(numStr); double doubleNum = number.doubleValue();

Just need to find the way of finding our actual locale in Android.

Maybe Locale current = getResources().getConfiguration().getLocales().get(0) (from https://stackoverflow.com/questions/14389349/android-get-current-locale-not-default)

pmithrandir commented 6 months ago

https://stackoverflow.com/questions/8188137/decimal-point-or-decimal-comma-in-android

they suggest to use:

char separatorChar = DecimalFormatSymbols.getInstance().getDecimalSeparator();
AroonPro commented 6 months ago

Already found and included in @AroonPro/Android_Pebble_SD/v5.0.0_upstream

Only to say that the decision to important what where and when is @jones139 . Like said in the v5 thread.

AroonPro commented 6 months ago

Constants. GLOBAL_CONSANTS. char CURRENT_USER_DECIMAL_CHARACTER = DecimalFormatSymbols.getInstance().getDecimalSeparator();

Osdutil:

/*

}

ExportActivity: mDuration = OsdUtil.parseToDouble(mDurationTxt.getText().toString());

jones139 commented 6 months ago

Thanks, I'll pull your code into v4.2 because this one needs fixing. Then I'm going to say V4.2 is stable enough to publish so we only have two versions to maintain rather than three!

jones139 commented 6 months ago

I have implemented a version of ParseToDouble into OsdUils as suggested by @AroonPro. My version is slightly different because I have used NumberFormat to do the parsing as recommended by the Oracle java documentation.

It seems to work in both English and French, so I think it fixes this issue.