From 8e5ad15c343ae120b0414e1c31ba76b264e060e8 Mon Sep 17 00:00:00 2001 From: jens Date: Sun, 5 Dec 2021 17:24:47 +0100 Subject: [PATCH] Rework --- .../ActivityManageTriggerDevicePosition.java | 17 +++++++---------- .../activity_manage_trigger_device_position.xml | 9 ++++++++- app/src/main/res/values/strings.xml | 4 +++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/ActivityManageTriggerDevicePosition.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerDevicePosition.java index 42634bfa..b0a6b628 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageTriggerDevicePosition.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerDevicePosition.java @@ -28,8 +28,6 @@ public class ActivityManageTriggerDevicePosition extends Activity boolean editMode = false; - boolean messageDisplayed = false; - float desiredAzimuth, desiredPitch, desiredRoll, desiredAzimuthTolerance, desiredPitchTolerance, desiredRollTolerance; public void updateFields(float azimuth, float pitch, float roll) @@ -38,7 +36,7 @@ public class ActivityManageTriggerDevicePosition extends Activity currentPitch.setText(Float.toString(pitch)); currentRoll.setText(Float.toString(roll)); - if(checkInputs()) + if(checkInputs(false)) { desiredAzimuth = Float.parseFloat(etDesiredAzimuth.getText().toString()); desiredAzimuthTolerance = Float.parseFloat(etDesiredAzimuthTolerance.getText().toString()); @@ -107,9 +105,9 @@ public class ActivityManageTriggerDevicePosition extends Activity // etDesiredAzimuth.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)}); // etDesiredPitch.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)}); // etDesiredRoll.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)}); - etDesiredAzimuthTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 359)}); - etDesiredPitchTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 359)}); - etDesiredRollTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 359)}); + etDesiredAzimuthTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 180)}); + etDesiredPitchTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 180)}); + etDesiredRollTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 180)}); if(getIntent().hasExtra(vectorFieldName)) { @@ -144,7 +142,7 @@ public class ActivityManageTriggerDevicePosition extends Activity @Override public void onClick(View v) { - if(!checkInputs()) + if(!checkInputs(true)) { Toast.makeText(ActivityManageTriggerDevicePosition.this, getResources().getString(R.string.enterValidNumbersIntoAllFields), Toast.LENGTH_LONG).show(); } @@ -167,7 +165,7 @@ public class ActivityManageTriggerDevicePosition extends Activity }); } - boolean checkInputs() + boolean checkInputs(boolean showMessages) { if( !StringUtils.isEmpty(etDesiredAzimuth.getText().toString()) && Miscellaneous.isNumeric(etDesiredAzimuth.getText().toString()) @@ -192,7 +190,7 @@ public class ActivityManageTriggerDevicePosition extends Activity return false; } - if(!messageDisplayed) + if(showMessages) { float dat = Float.parseFloat(etDesiredAzimuthTolerance.getText().toString()); float dpt = Float.parseFloat(etDesiredPitchTolerance.getText().toString()); @@ -204,7 +202,6 @@ public class ActivityManageTriggerDevicePosition extends Activity */ if (Math.abs(dat) >= 180 && Math.abs(dpt) >= 180 && Math.abs(drt) >= 180) { - messageDisplayed = true; Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.toleranceOf180OnlyAllowedIn2Fields), ActivityManageTriggerDevicePosition.this).show(); return false; } diff --git a/app/src/main/res/layout/activity_manage_trigger_device_position.xml b/app/src/main/res/layout/activity_manage_trigger_device_position.xml index 98a927b1..4d82753d 100644 --- a/app/src/main/res/layout/activity_manage_trigger_device_position.xml +++ b/app/src/main/res/layout/activity_manage_trigger_device_position.xml @@ -97,13 +97,14 @@ android:layout_height="wrap_content" /> @@ -146,6 +147,8 @@ @@ -178,6 +181,8 @@ @@ -210,6 +215,8 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5c0a5d59..925c4d3f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -714,7 +714,7 @@ This feature is confirmed to work up until Android 8.0. From some higher version upwards it ceases to work, but due to a lack of physical devices I cannot tell which one that is. On Android 11 it definitely ain\'t working anymore. If you have a version in between please let me know if it\'s working or not. Notice Device position (Gyroscope) - Tolerance + Tolerance\n(0-180) Azimuth: Pitch: Roll: @@ -723,4 +723,6 @@ Would currently apply? the device is in a certain position A tolerance of 180 is allowed for 2 tolerance fields only, not all 3. Otherwise the trigger would ALWAYS apply. + unknown + Position \ No newline at end of file