Merge pull request #2269 from Philoul/Steampunk_Bug

Steampunk bug
This commit is contained in:
Milos Kozak 2019-12-12 08:46:39 +01:00 committed by GitHub
commit ca2259e093
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 15 deletions

View file

@ -25,12 +25,22 @@ public class SafeParse {
} }
public static Long stringToLong(String input) { public static Long stringToLong(String input) {
Long result = 0L; Long result = 0L;
input = input.replace(",", "."); input = input.replace(",", ".");
try { try {
result = Long.parseLong(input); result = Long.parseLong(input);
} catch (Exception e) { } catch (Exception e) {
} }
return result; return result;
}
public static Float stringToFloat(String input) {
Float result = 0f;
input = input.replace(",", ".");
try {
result = Float.valueOf(input);
} catch (Exception e) {
}
return result;
} }
} }

View file

@ -10,7 +10,7 @@ import android.view.animation.RotateAnimation;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interaction.menus.MainMenuActivity; import info.nightscout.androidaps.interaction.menus.MainMenuActivity;
import info.nightscout.androidaps.interaction.utils.SafeParse;
/** /**
* Created by andrew-warrington on 01/12/2017. * Created by andrew-warrington on 01/12/2017.
*/ */
@ -124,34 +124,34 @@ public class Steampunk extends BaseWatchFace {
float deltaIsNegative = 1f; //by default go clockwise float deltaIsNegative = 1f; //by default go clockwise
if (!rawData.sAvgDelta.equals("--")) { //if a legitimate delta value is received, then... 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 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 //ensure the delta gauge is the right units and granularity
if (!rawData.sUnits.equals("-")) { if (!rawData.sUnits.equals("-")) {
if (rawData.sUnits.equals("mmol")) { if (rawData.sUnits.equals("mmol")) {
if (sharedPrefs.getString("delta_granularity", "2").equals("1")) { //low if (sharedPrefs.getString("delta_granularity", "2").equals("1")) { //low
mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_10); 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 if (sharedPrefs.getString("delta_granularity", "2").equals("2")) { //medium
mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_05); 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 if (sharedPrefs.getString("delta_granularity", "2").equals("3")) { //high
mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_03); 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 { } else {
if (sharedPrefs.getString("delta_granularity", "2").equals("1")) { //low if (sharedPrefs.getString("delta_granularity", "2").equals("1")) { //low
mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_20); 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 if (sharedPrefs.getString("delta_granularity", "2").equals("2")) { //medium
mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_10); 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 if (sharedPrefs.getString("delta_granularity", "2").equals("3")) { //high
mLinearLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_5); 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);
} }
} }
} }