@@ -59,7 +59,10 @@ public class ChoiceSet {
5959 ChoiceSetCanceledListener canceledListener ;
6060
6161 // defaults
62- private final Integer defaultTimeout = 10 ;
62+ private static final int TIMEOUT_DEFAULT = 0 ;
63+ private static final int TIMEOUT_MIN = 5 ;
64+ private static final int TIMEOUT_MAX = 100 ;
65+ private static Integer defaultTimeout = 10 ;
6366 private final ChoiceSetLayout defaultLayout = ChoiceSetLayout .CHOICE_SET_LAYOUT_LIST ;
6467
6568 /**
@@ -79,10 +82,10 @@ public ChoiceSet(@NonNull String title, @NonNull List<ChoiceCell> choices, @NonN
7982 setTitle (title );
8083 setChoiceSetSelectionListener (listener );
8184 setChoices (choices );
85+ setTimeout (TIMEOUT_DEFAULT );
8286
8387 // defaults
8488 setLayout (defaultLayout );
85- setTimeout (defaultTimeout );
8689
8790 // things to do
8891 checkChoiceSetParameters ();
@@ -301,21 +304,43 @@ public void setLayout(ChoiceSetLayout layout) {
301304 * @return The Timeout
302305 */
303306 public Integer getTimeout () {
307+ if (timeout == TIMEOUT_DEFAULT ) {
308+ timeout = getDefaultTimeout ();
309+ } else if (timeout < TIMEOUT_MIN ) {
310+ return TIMEOUT_MIN ;
311+ } else if (timeout > TIMEOUT_MAX ) {
312+ return TIMEOUT_MAX ;
313+ }
304314 return timeout ;
305315 }
306316
307317 /**
308- * @param timeout - Maps to PerformInteraction.timeout. This applies only to a manual selection
309- * (not a voice selection, which has its timeout handled by the system). Defaults to `defaultTimeout` .
310- * <strong>This is set to seconds if using the screen manager.</strong>
318+ * Maps to PerformInteraction.timeout. Timeout in seconds. Defaults to 0, which will use `defaultTimeout`.
319+ * If this is set below the minimum, it will be capped at 5 seconds. Minimum 5 seconds, maximum 100 seconds .
320+ * If this is set above the maximum, it will be capped at 100 seconds.
311321 */
312322 public void setTimeout (Integer timeout ) {
313- if (timeout == null ) {
314- this .timeout = defaultTimeout ;
315- } else {
316323 this .timeout = timeout ;
324+ }
325+
326+ public int getDefaultTimeout () {
327+ if (defaultTimeout < TIMEOUT_MIN ) {
328+ return TIMEOUT_MIN ;
329+ } else if (defaultTimeout > TIMEOUT_MAX ) {
330+ return TIMEOUT_MAX ;
317331 }
318- checkChoiceSetParameters ();
332+ return defaultTimeout ;
333+ }
334+
335+ /**
336+ * Set this to change the default timeout for all ChoiceSets. If a timeout is not set on an individual
337+ * ChoiceSet object (or if it is set to 0), then it will use this timeout instead. See `timeout`
338+ * for more details. If this is not set by you, it will default to 10 seconds. The minimum is
339+ * 5 seconds, the maximum is 100 seconds. If this is set below the minimum, it will be capped
340+ * at 3 seconds. If this is set above the maximum, it will be capped at 10 seconds.
341+ */
342+ public void setDefaultTimeout (int defaultTimeout ) {
343+ this .defaultTimeout = defaultTimeout ;
319344 }
320345
321346 /**
@@ -388,11 +413,6 @@ private void checkChoiceSetParameters() {
388413 DebugTool .logWarning (TAG , "Attempted to create a choice set with a title of " + getTitle ().length () + " length. Only 500 characters are supported." );
389414 }
390415 }
391- if (getTimeout () != null ) {
392- if (getTimeout () < 5 || getTimeout () > 100 ) {
393- DebugTool .logWarning (TAG , "Attempted to create a choice set with a " + getTimeout () + " second timeout; Only 5 - 100 seconds is valid" );
394- }
395- }
396416 if (getChoices () != null ) {
397417 if (getChoices ().size () == 0 || getChoices ().size () > 100 ) {
398418 DebugTool .logWarning (TAG , "Attempted to create a choice set with " + getChoices ().size () + " choices; Only 1 - 100 choices are valid" );
0 commit comments