diff options
author | Julian Kast <julian@livio.com> | 2021-03-11 08:58:32 -0500 |
---|---|---|
committer | Julian Kast <julian@livio.com> | 2021-03-11 08:58:32 -0500 |
commit | 18910d7cf5fa5f9d4e9915e2cd8b27e2415bef19 (patch) | |
tree | d099a2c2eacca48295339419ceab18bf820e0348 | |
parent | c60d308e11e2879ee674a59dd19e73f0535f821f (diff) | |
download | sdl_android-18910d7cf5fa5f9d4e9915e2cd8b27e2415bef19.tar.gz |
Add default timeout to ChoiceSet and refactor timeout. Added unit test
2 files changed, 36 insertions, 14 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java index 4eeb04927..f78e4c894 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java @@ -86,6 +86,7 @@ public class ChoiceSetTests { // first constructor was tested in previous method, use the rest here ChoiceSet choiceSet = new ChoiceSet(TestValues.GENERAL_STRING, layout, TestValues.GENERAL_INTEGER, TestValues.GENERAL_STRING, TestValues.GENERAL_STRING, TestValues.GENERAL_STRING, TestValues.GENERAL_VRHELPITEM_LIST, TestValues.GENERAL_KEYBOARDPROPERTIES, choices, listener); + choiceSet.setDefaultTimeout(5); assertEquals(choiceSet.getTitle(), TestValues.GENERAL_STRING); assertEquals(choiceSet.getInitialPrompt().get(0).getText(), TestValues.GENERAL_STRING); assertEquals(choiceSet.getHelpPrompt().get(0).getText(), TestValues.GENERAL_STRING); @@ -94,6 +95,7 @@ public class ChoiceSetTests { assertEquals(choiceSet.getTimeout(), TestValues.GENERAL_INTEGER); assertEquals(choiceSet.getChoices(), choices); assertEquals(choiceSet.getChoiceSetSelectionListener(), listener); + assertEquals(choiceSet.getDefaultTimeout(), 5); ChoiceSet choiceSet2 = new ChoiceSet(TestValues.GENERAL_STRING, layout, TestValues.GENERAL_INTEGER, TestValues.GENERAL_TTSCHUNK_LIST, TestValues.GENERAL_TTSCHUNK_LIST, TestValues.GENERAL_TTSCHUNK_LIST, TestValues.GENERAL_VRHELPITEM_LIST, TestValues.GENERAL_KEYBOARDPROPERTIES, choices, listener); assertEquals(choiceSet2.getTitle(), TestValues.GENERAL_STRING); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java index b8d7412ee..de5e18955 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java @@ -59,7 +59,9 @@ public class ChoiceSet { ChoiceSetCanceledListener canceledListener; // defaults - private final Integer defaultTimeout = 10; + private static Integer defaultTimeout = 10; + private static final int TIMEOUT_MIN = 5; + private static final int TIMEOUT_MAX = 100; private final ChoiceSetLayout defaultLayout = ChoiceSetLayout.CHOICE_SET_LAYOUT_LIST; /** @@ -82,7 +84,6 @@ public class ChoiceSet { // defaults setLayout(defaultLayout); - setTimeout(defaultTimeout); // things to do checkChoiceSetParameters(); @@ -301,21 +302,45 @@ public class ChoiceSet { * @return The Timeout */ public Integer getTimeout() { + if (timeout == null) { + timeout = defaultTimeout; + } else if (timeout < TIMEOUT_MIN) { + return TIMEOUT_MIN; + } else if (timeout > TIMEOUT_MAX) { + return TIMEOUT_MAX; + } return timeout; } /** - * @param timeout - Maps to PerformInteraction.timeout. This applies only to a manual selection - * (not a voice selection, which has its timeout handled by the system). Defaults to `defaultTimeout`. - * <strong>This is set to seconds if using the screen manager.</strong> + * Maps to PerformInteraction.timeout. Timeout in seconds. Defaults to 0, which will use `defaultTimeout`. + * If this is set below the minimum, it will be capped at 5 seconds. Minimum 5 seconds, maximum 100 seconds. + * If this is set above the maximum, it will be capped at 100 seconds. */ public void setTimeout(Integer timeout) { - if (timeout == null) { - this.timeout = defaultTimeout; - } else { this.timeout = timeout; + } + + public int getDefaultTimeout() { + return defaultTimeout; + } + + /** + * Set this to change the default timeout for all ChoiceSets. If a timeout is not set on an individual + * ChoiceSet object (or if it is set to 0), then it will use this timeout instead. See `timeout` + * for more details. If this is not set by you, it will default to 10 seconds. The minimum is + * 5 seconds, the maximum is 100 seconds. If this is set below the minimum, it will be capped + * at 3 seconds. If this is set above the maximum, it will be capped at 10 seconds. + */ + public void setDefaultTimeout(int defaultTimeout) { + if (defaultTimeout <= TIMEOUT_MIN) { + this.defaultTimeout = TIMEOUT_MIN; + return; + } else if (defaultTimeout >= TIMEOUT_MAX) { + this.defaultTimeout = TIMEOUT_MAX; + return; } - checkChoiceSetParameters(); + this.defaultTimeout = defaultTimeout; } /** @@ -388,11 +413,6 @@ public class ChoiceSet { DebugTool.logWarning(TAG, "Attempted to create a choice set with a title of " + getTitle().length() + " length. Only 500 characters are supported."); } } - if (getTimeout() != null) { - if (getTimeout() < 5 || getTimeout() > 100) { - DebugTool.logWarning(TAG, "Attempted to create a choice set with a " + getTimeout() + " second timeout; Only 5 - 100 seconds is valid"); - } - } if (getChoices() != null) { if (getChoices().size() == 0 || getChoices().size() > 100) { DebugTool.logWarning(TAG, "Attempted to create a choice set with " + getChoices().size() + " choices; Only 1 - 100 choices are valid"); |