Skip to content

Commit 98fc500

Browse files
author
Robert Henigan
authored
Merge pull request #1631 from smartdevicelink/bugfix/issue_1630_fix_choice_set_default_timeout
Bugfix/issue 1630 fix choice set default timeout
2 parents 82c75e7 + abbc455 commit 98fc500

3 files changed

Lines changed: 67 additions & 27 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSetTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,31 @@ public void testSettersAndGetters() {
7979
assertEquals(choiceSet.getTimeout(), defaultTimeout);
8080
assertEquals(choiceSet.getChoices(), choices);
8181
assertEquals(choiceSet.getChoiceSetSelectionListener(), listener);
82+
83+
// Test timeout and default timeout
84+
choiceSet.setDefaultTimeout(20);
85+
assertEquals(choiceSet.getDefaultTimeout(), 20);
86+
choiceSet.setDefaultTimeout(1);
87+
assertEquals(choiceSet.getDefaultTimeout(), 5);
88+
choiceSet.setDefaultTimeout(101);
89+
assertEquals(choiceSet.getDefaultTimeout(), 100);
90+
91+
choiceSet.setTimeout(20);
92+
assertEquals(choiceSet.getTimeout().intValue(), 20);
93+
choiceSet.setTimeout(1);
94+
assertEquals(choiceSet.getTimeout().intValue(), 5);
95+
choiceSet.setTimeout(101);
96+
assertEquals(choiceSet.getTimeout().intValue(), 100);
97+
// Reset default value for other unit test
98+
choiceSet.setDefaultTimeout(10);
8299
}
83100

84101
@Test
85102
public void testConstructors() {
86103

87104
// first constructor was tested in previous method, use the rest here
88105
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);
106+
89107
assertEquals(choiceSet.getTitle(), TestValues.GENERAL_STRING);
90108
assertEquals(choiceSet.getInitialPrompt().get(0).getText(), TestValues.GENERAL_STRING);
91109
assertEquals(choiceSet.getHelpPrompt().get(0).getText(), TestValues.GENERAL_STRING);
@@ -95,6 +113,7 @@ public void testConstructors() {
95113
assertEquals(choiceSet.getChoices(), choices);
96114
assertEquals(choiceSet.getChoiceSetSelectionListener(), listener);
97115

116+
98117
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);
99118
assertEquals(choiceSet2.getTitle(), TestValues.GENERAL_STRING);
100119
assertEquals(choiceSet2.getInitialPrompt(), TestValues.GENERAL_TTSCHUNK_LIST);

base/src/main/java/com/smartdevicelink/managers/screen/AlertView.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
import java.util.List;
4040

4141
public class AlertView implements Cloneable {
42-
43-
private static Integer defaultTimeout = 5;
42+
43+
private static final int TIMEOUT_DEFAULT = 0;
4444
private static final int TIMEOUT_MIN = 3;
4545
private static final int TIMEOUT_MAX = 10;
46+
private static Integer defaultTimeout = 5;
4647
private String text, secondaryText, tertiaryText;
4748
private Integer timeout;
4849
private AlertAudioData audio;
@@ -53,7 +54,6 @@ public class AlertView implements Cloneable {
5354

5455

5556
private AlertView() {
56-
this.timeout = defaultTimeout;
5757
}
5858

5959
public static class Builder {
@@ -62,14 +62,17 @@ public static class Builder {
6262

6363
public Builder() {
6464
alertView = new AlertView();
65+
if (alertView.timeout == null) {
66+
alertView.timeout = TIMEOUT_DEFAULT;
67+
}
6568
}
6669

6770
/**
6871
* The primary line of text for display on the alert. If fewer than three alert lines are available
6972
* on the head unit, the screen manager will automatically concatenate some of the lines together.
7073
*/
7174
public Builder setText(String text) {
72-
this.alertView.text = text;
75+
alertView.text = text;
7376
return this;
7477
}
7578

@@ -165,8 +168,8 @@ public void cancel() {
165168
}
166169

167170
public Integer getTimeout() {
168-
if (timeout == null) {
169-
timeout = defaultTimeout;
171+
if (timeout == TIMEOUT_DEFAULT) {
172+
timeout = getDefaultTimeout();
170173
} else if (timeout < TIMEOUT_MIN) {
171174
return TIMEOUT_MIN;
172175
} else if (timeout > TIMEOUT_MAX) {
@@ -237,17 +240,15 @@ public void setIcon(SdlArtwork icon) {
237240
}
238241

239242
public int getDefaultTimeout() {
243+
if (defaultTimeout < TIMEOUT_MIN) {
244+
return TIMEOUT_MIN;
245+
} else if (defaultTimeout > TIMEOUT_MAX) {
246+
return TIMEOUT_MAX;
247+
}
240248
return defaultTimeout;
241249
}
242250

243251
public void setDefaultTimeout(int defaultTimeout) {
244-
if (defaultTimeout <= TIMEOUT_MIN) {
245-
AlertView.defaultTimeout = TIMEOUT_MIN;
246-
return;
247-
} else if (defaultTimeout >= TIMEOUT_MAX) {
248-
AlertView.defaultTimeout = TIMEOUT_MAX;
249-
return;
250-
}
251252
AlertView.defaultTimeout = defaultTimeout;
252253
}
253254

base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceSet.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)