From 5b36b312ceaad5f3fceb464273171cc8e8972859 Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 11 Dec 2019 23:57:42 +0100 Subject: [PATCH 1/2] Correction bug Steampunk (detailed delta with , and not .) --- .../interaction/utils/SafeParse.java | 23 +++++++++++++------ .../androidaps/watchfaces/Steampunk.java | 16 ++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java index 0d654567b0..d34f502efa 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java @@ -25,12 +25,21 @@ public class SafeParse { } public static Long stringToLong(String input) { - Long result = 0L; - input = input.replace(",", "."); - try { - result = Long.parseLong(input); - } catch (Exception e) { - } - return result; + Long result = 0L; + input = input.replace(",", "."); + try { + result = Long.parseLong(input); + } catch (Exception e) { + } + return result; + } + public static Float stringToFloat(String input) { + Float result = 0f; + input = input.replace(",", "."); + try { + result = Float.valueOf(input); + } catch (Exception e) { + } + return result; } } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java index a600290a04..8842d4b531 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java @@ -10,7 +10,7 @@ import android.view.animation.RotateAnimation; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interaction.menus.MainMenuActivity; - +import info.nightscout.androidaps.interaction.utils.SafeParse; /** * Created by andrew-warrington on 01/12/2017. */ @@ -124,34 +124,34 @@ public class Steampunk extends BaseWatchFace { float deltaIsNegative = 1f; //by default go clockwise if (!rawData.sAvgDelta.equals("--")) { //if a legitimate delta value is received, then... if (rawData.sAvgDelta.substring(0,1).equals("-")) deltaIsNegative = -1f; //if the delta is negative, go counter-clockwise - + Float AbssAvgDelta = SafeParse.stringToFloat(rawData.sAvgDelta.substring(1)) ; //get rid of the sign so it can be converted to float. //ensure the delta gauge is the right units and granularity if (!rawData.sUnits.equals("-")) { if (rawData.sUnits.equals("mmol")) { if (sharedPrefs.getString("delta_granularity", "2").equals("1")) { //low mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_10); - deltaRotationAngle = (Float.valueOf(rawData.sAvgDelta.substring(1)) * 30f); //get rid of the sign so it can be converted to float. + deltaRotationAngle = (AbssAvgDelta * 30f); } if (sharedPrefs.getString("delta_granularity", "2").equals("2")) { //medium mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_05); - deltaRotationAngle = (Float.valueOf(rawData.sAvgDelta.substring(1)) * 60f); //get rid of the sign so it can be converted to float. + deltaRotationAngle = (AbssAvgDelta * 60f); } if (sharedPrefs.getString("delta_granularity", "2").equals("3")) { //high mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_03); - deltaRotationAngle = (Float.valueOf(rawData.sAvgDelta.substring(1)) * 100f); //get rid of the sign so it can be converted to float. + deltaRotationAngle = (AbssAvgDelta * 100f); } } else { if (sharedPrefs.getString("delta_granularity", "2").equals("1")) { //low mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_20); - deltaRotationAngle = (Float.valueOf(rawData.sAvgDelta.substring(1)) * 1.5f); //get rid of the sign so it can be converted to float. + deltaRotationAngle = (AbssAvgDelta * 1.5f); } if (sharedPrefs.getString("delta_granularity", "2").equals("2")) { //medium mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_10); - deltaRotationAngle = (Float.valueOf(rawData.sAvgDelta.substring(1)) * 3f); //get rid of the sign so it can be converted to float. + deltaRotationAngle = (AbssAvgDelta * 3f); } if (sharedPrefs.getString("delta_granularity", "2").equals("3")) { //high mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_5); - deltaRotationAngle = (Float.valueOf(rawData.sAvgDelta.substring(1)) * 6f); //get rid of the sign so it can be converted to float. + deltaRotationAngle = (AbssAvgDelta * 6f); } } } From b9a9fe3a0a6dea6349256576a9300970153703ad Mon Sep 17 00:00:00 2001 From: Philoul Date: Thu, 12 Dec 2019 00:28:08 +0100 Subject: [PATCH 2/2] No modif Code tabulation --- .../androidaps/interaction/utils/SafeParse.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java index d34f502efa..81ef482194 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SafeParse.java @@ -33,13 +33,14 @@ public class SafeParse { } return result; } - public static Float stringToFloat(String input) { - Float result = 0f; - input = input.replace(",", "."); - try { - result = Float.valueOf(input); - } catch (Exception e) { - } - return result; + + public static Float stringToFloat(String input) { + Float result = 0f; + input = input.replace(",", "."); + try { + result = Float.valueOf(input); + } catch (Exception e) { + } + return result; } }