summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrettyWhite <geekman3454@protonmail.com>2019-06-07 10:40:53 -0400
committerBrettyWhite <geekman3454@protonmail.com>2019-06-07 10:40:53 -0400
commitfc9b01d47d37119ec24d45b3f33ac8b2dd66d6ef (patch)
treeffb0d59eb70fd87a3ea13022c026a605df4091cf
parent05c4be27cf9b142bdeb478d92476fee8f3c01d21 (diff)
downloadsdl_android-fc9b01d47d37119ec24d45b3f33ac8b2dd66d6ef.tar.gz
present choice set op
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java54
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java55
2 files changed, 77 insertions, 32 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
index 44be11bac..3bbe2f670 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
@@ -42,6 +42,7 @@ import com.smartdevicelink.managers.screen.choiceset.operations.CheckChoiceVROpt
import com.smartdevicelink.managers.screen.choiceset.operations.CheckChoiceVROptionalOperation;
import com.smartdevicelink.managers.screen.choiceset.operations.DeleteChoicesOperation;
import com.smartdevicelink.managers.screen.choiceset.operations.PreloadChoicesOperation;
+import com.smartdevicelink.managers.screen.choiceset.operations.PresentChoiceSetOperation;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCNotification;
import com.smartdevicelink.proxy.interfaces.ISdl;
@@ -56,6 +57,7 @@ import com.smartdevicelink.proxy.rpc.enums.KeypressMode;
import com.smartdevicelink.proxy.rpc.enums.Language;
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
+import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.util.DebugTool;
@@ -93,7 +95,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
// We will pass operations into this to be completed
private PausableThreadPoolExecutor executor;
private LinkedBlockingQueue<Runnable> operationQueue;
- private boolean pendingPresentOperation;
+ private boolean isPresentOperationPending;
private int nextChoiceId;
private int choiceCellIdMin = 1;
@@ -215,7 +217,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
// If choices are deleted that are already uploaded or pending and are used by a pending presentation, cancel it and send an error
HashSet<ChoiceCell> pendingPresentationChoices = new HashSet<>(pendingPresentationSet.getChoices());
- if (!pendingPresentOperation && (cellsToBeDeleted.retainAll(pendingPresentationChoices) || cellsToBeRemovedFromPending.retainAll(pendingPresentationChoices))){
+ if (!isPresentOperationPending && (cellsToBeDeleted.retainAll(pendingPresentationChoices) || cellsToBeRemovedFromPending.retainAll(pendingPresentationChoices))){
DebugTool.logError("Attempting to delete choice cells while there is a pending presentation operation");
return;
}
@@ -244,7 +246,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
executor.submit(deleteChoicesOperation);
}
- public void presentChoiceSet(final ChoiceSet choiceSet, InteractionMode mode, KeyboardListener listener){
+ public void presentChoiceSet(final ChoiceSet choiceSet, final InteractionMode mode, final KeyboardListener keyboardListener){
if (!isReady()){ return; }
@@ -255,26 +257,62 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
// Perform additional checks against the ChoiceSet
if (!setUpChoiceSet(choiceSet)){ return; }
- if (this.pendingPresentationSet != null){
- // cancel pendingPresentationOperation
+ if (this.pendingPresentationSet != null || isPresentOperationPending){
+ DebugTool.logError("Currently presenting a choice set. Please wait until it is finished");
+ return;
}
this.pendingPresentationSet = choiceSet;
+ isPresentOperationPending = true;
preloadChoices(this.pendingPresentationSet.getChoices(), new CompletionListener() {
@Override
public void onComplete(boolean success) {
if (!success){
choiceSet.getChoiceSetSelectionListener().onError("There was an error pre-loading choice set choices");
+ isPresentOperationPending = false;
return;
}
+ sendChoiceSet(keyboardListener, mode);
}
});
+ }
+
+ private void sendChoiceSet(KeyboardListener keyboardListener, InteractionMode mode){
+
+ findIdsOnChoiceSet(pendingPresentationSet);
+
+ // Pass back the information to the developer
+ ChoiceSetSelectionListener privateChoiceListener = new ChoiceSetSelectionListener() {
+ @Override
+ public void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource, int rowIndex) {
+ if (pendingPresentationSet.getChoiceSetSelectionListener() != null){
+ pendingPresentationSet.getChoiceSetSelectionListener().onChoiceSelected(choiceCell, triggerSource,rowIndex);
+ }
+ pendingPresentationSet = null;
+ isPresentOperationPending = false;
+ }
- findIdsOnChoiceSet(this.pendingPresentationSet);
+ @Override
+ public void onError(String error) {
+ if (pendingPresentationSet.getChoiceSetSelectionListener() != null){
+ pendingPresentationSet.getChoiceSetSelectionListener().onError(error);
+ }
+ pendingPresentationSet = null;
+ isPresentOperationPending = false;
+ }
+ };
+
+ PresentChoiceSetOperation presentOp = null;
- // create presentationChoiceSetOperation
- // add the operation to the queue
+ if (keyboardListener == null){
+ // Non-searchable choice set
+ presentOp = new PresentChoiceSetOperation(internalInterface, pendingPresentationSet, mode, null, null, privateChoiceListener);
+ } else {
+ // Searchable choice set
+ presentOp = new PresentChoiceSetOperation(internalInterface, pendingPresentationSet, mode, keyboardConfiguration, keyboardListener, privateChoiceListener);
+ }
+ executor.submit(presentOp);
}
public void presentKeyboardWithInitialText(String initialText, KeyboardListener listener){
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java
index 0c54e4301..49700ffb0 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java
@@ -35,6 +35,7 @@ package com.smartdevicelink.managers.screen.choiceset.operations;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.screen.choiceset.ChoiceCell;
import com.smartdevicelink.managers.screen.choiceset.ChoiceSet;
+import com.smartdevicelink.managers.screen.choiceset.ChoiceSetSelectionListener;
import com.smartdevicelink.managers.screen.choiceset.KeyboardAutocompleteCompletionListener;
import com.smartdevicelink.managers.screen.choiceset.KeyboardCharacterSetCompletionListener;
import com.smartdevicelink.managers.screen.choiceset.KeyboardListener;
@@ -71,10 +72,10 @@ public class PresentChoiceSetOperation implements Runnable {
private Integer selectedCellRow;
private boolean updatedKeyboardProperties;
private OnRPCNotificationListener keyboardRPCListener;
- private CompletionListener completionListener;
+ private ChoiceSetSelectionListener choiceSetSelectionListener;
public PresentChoiceSetOperation(ISdl internalInterface, ChoiceSet choiceSet, InteractionMode mode,
- KeyboardProperties originalKeyboardProperties, KeyboardListener keyboardListener, CompletionListener completionListener){
+ KeyboardProperties originalKeyboardProperties, KeyboardListener keyboardListener, ChoiceSetSelectionListener choiceSetSelectionListener){
this.internalInterface = new WeakReference<>(internalInterface);
this.keyboardListener = new WeakReference<>(keyboardListener);
this.choiceSet = choiceSet;
@@ -82,7 +83,7 @@ public class PresentChoiceSetOperation implements Runnable {
this.originalKeyboardProperties = originalKeyboardProperties;
this.keyboardProperties = originalKeyboardProperties;
this.selectedCellRow = null;
- this.completionListener = completionListener;
+ this.choiceSetSelectionListener = choiceSetSelectionListener;
}
@Override
@@ -96,6 +97,7 @@ public class PresentChoiceSetOperation implements Runnable {
// Check if we're using a keyboard (searchable) choice set and setup keyboard properties if we need to
if (keyboardListener != null && choiceSet.getCustomKeyboardConfiguration() != null){
keyboardProperties = choiceSet.getCustomKeyboardConfiguration();
+ updatedKeyboardProperties = true;
}
updateKeyboardProperties(new CompletionListener() {
@@ -143,6 +145,10 @@ public class PresentChoiceSetOperation implements Runnable {
public void onResponse(int correlationId, RPCResponse response) {
if (!response.getSuccess()){
DebugTool.logError("Presenting Choice set failed: "+ response.getInfo());
+
+ if (choiceSetSelectionListener != null){
+ choiceSetSelectionListener.onError(response.getInfo());
+ }
finishOperation();
}
@@ -150,6 +156,10 @@ public class PresentChoiceSetOperation implements Runnable {
setSelectedCellWithId(performInteractionResponse.getChoiceID());
selectedTriggerSource = performInteractionResponse.getTriggerSource();
+ if (choiceSetSelectionListener != null){
+ choiceSetSelectionListener.onChoiceSelected(selectedCell, selectedTriggerSource, selectedCellRow);
+ }
+
finishOperation();
}
});
@@ -162,29 +172,24 @@ public class PresentChoiceSetOperation implements Runnable {
private void finishOperation() {
- if (keyboardProperties == null){
- completionListener.onComplete(true);
- }
-
- // We need to reset the keyboard properties
- SetGlobalProperties setGlobalProperties = new SetGlobalProperties();
- setGlobalProperties.setKeyboardProperties(originalKeyboardProperties);
- setGlobalProperties.setOnRPCResponseListener(new OnRPCResponseListener() {
- @Override
- public void onResponse(int correlationId, RPCResponse response) {
- if (response.getSuccess()){
- completionListener.onComplete(true);
- }else{
- DebugTool.logError("Error resetting keyboard properties");
- completionListener.onComplete(false);
+ if (updatedKeyboardProperties) {
+ // We need to reset the keyboard properties
+ SetGlobalProperties setGlobalProperties = new SetGlobalProperties();
+ setGlobalProperties.setKeyboardProperties(originalKeyboardProperties);
+ setGlobalProperties.setOnRPCResponseListener(new OnRPCResponseListener() {
+ @Override
+ public void onResponse(int correlationId, RPCResponse response) {
+ updatedKeyboardProperties = false;
+ DebugTool.logInfo("Successfully reset choice keyboard properties to original config");
}
- }
- });
+ });
- if (internalInterface.get() != null){
- internalInterface.get().sendRPC(setGlobalProperties);
- } else {
- DebugTool.logError("Internal Interface null when finishing choice keyboard reset");
+ if (internalInterface.get() != null) {
+ internalInterface.get().sendRPC(setGlobalProperties);
+ internalInterface.get().removeOnRPCNotificationListener(FunctionID.ON_KEYBOARD_INPUT, keyboardRPCListener);
+ } else {
+ DebugTool.logError("Internal Interface null when finishing choice keyboard reset");
+ }
}
}
@@ -261,6 +266,7 @@ public class PresentChoiceSetOperation implements Runnable {
public void onUpdatedAutoCompleteText(String updatedAutoCompleteText) {
keyboardProperties.setAutoCompleteText(updatedAutoCompleteText);
updateKeyboardProperties(null);
+ updatedKeyboardProperties = true;
}
});
@@ -269,6 +275,7 @@ public class PresentChoiceSetOperation implements Runnable {
public void onUpdatedCharacterSet(List<String> updatedCharacterSet) {
keyboardProperties.setLimitedCharacterList(updatedCharacterSet);
updateKeyboardProperties(null);
+ updatedKeyboardProperties = true;
}
});
} else if (onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_ABORTED) || onKeyboard.getEvent().equals(KeyboardEvent.ENTRY_CANCELLED)){