Skip to content

Commit

Permalink
Update SdlService for 5.1 in JavaEE app (#1640)
Browse files Browse the repository at this point in the history
* Update SdlService for 5.1 in JavaEE app

* remove unused import

Co-authored-by: Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com>
  • Loading branch information
Robert Henigan and Henigan authored Mar 22, 2021
1 parent ab0bb87 commit c480dd4
Showing 1 changed file with 62 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@

package com.smartdevicelink;

import android.util.Log;
import com.smartdevicelink.managers.AlertCompletionListener;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.SdlManager;
import com.smartdevicelink.managers.SdlManagerListener;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
import com.smartdevicelink.managers.lifecycle.LifecycleConfigurationUpdate;
import com.smartdevicelink.managers.screen.AlertView;
import com.smartdevicelink.managers.screen.choiceset.ChoiceCell;
import com.smartdevicelink.managers.screen.choiceset.ChoiceSet;
import com.smartdevicelink.managers.screen.choiceset.ChoiceSetSelectionListener;
Expand All @@ -47,10 +48,9 @@
import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCNotification;
import com.smartdevicelink.proxy.TTSChunkFactory;
import com.smartdevicelink.proxy.rpc.Alert;
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
import com.smartdevicelink.proxy.rpc.Speak;
import com.smartdevicelink.proxy.rpc.TTSChunk;
import com.smartdevicelink.proxy.rpc.enums.*;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.transport.BaseTransportConfig;
Expand Down Expand Up @@ -94,7 +94,7 @@ public SdlService(BaseTransportConfig config, SdlServiceCallback callback) {
}

public void start() {
DebugTool.logInfo("SdlService start() ");
DebugTool.logInfo(TAG, "SdlService start() ");
if (sdlManager != null) {
sdlManager.start();
}
Expand All @@ -112,7 +112,7 @@ private void buildSdlManager(BaseTransportConfig transport) {
// Build flavors are selected by the "build variants" tab typically located in the bottom left of Android Studio
// Typically in your app, you will only set one of these.
if (sdlManager == null) {
DebugTool.logInfo("Creating SDL Manager");
DebugTool.logInfo(TAG, "Creating SDL Manager");

//FIXME add the transport type
// The app type to be used
Expand All @@ -124,12 +124,12 @@ private void buildSdlManager(BaseTransportConfig transport) {
SdlManagerListener listener = new SdlManagerListener() {
@Override
public void onStart(SdlManager sdlManager) {
DebugTool.logInfo("SdlManager onStart");
DebugTool.logInfo(TAG, "SdlManager onStart");
}

@Override
public void onDestroy(SdlManager sdlManager) {
DebugTool.logInfo("SdlManager onDestroy ");
DebugTool.logInfo(TAG, "SdlManager onDestroy ");
SdlService.this.sdlManager = null;
if (SdlService.this.callback != null) {
SdlService.this.callback.onEnd();
Expand All @@ -141,20 +141,40 @@ public void onError(SdlManager sdlManager, String info, Exception e) {
}

@Override
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
String appName;
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
boolean isNeedUpdate = false;
String appName = APP_NAME;
String ttsName = APP_NAME;
switch (language) {
case ES_MX:
isNeedUpdate = true;
ttsName = APP_NAME_ES;
break;
case FR_CA:
isNeedUpdate = true;
ttsName = APP_NAME_FR;
break;
default:
break;
}
switch (hmiLanguage) {
case ES_MX:
isNeedUpdate = true;
appName = APP_NAME_ES;
break;
case FR_CA:
isNeedUpdate = true;
appName = APP_NAME_FR;
break;
default:
return null;
break;
}
if (isNeedUpdate) {
Vector<TTSChunk> chunks = new Vector<>(Collections.singletonList(new TTSChunk(ttsName, SpeechCapabilities.TEXT)));
return new LifecycleConfigurationUpdate(appName, null, chunks, null);
} else {
return null;
}

return new LifecycleConfigurationUpdate(appName, null, TTSChunkFactory.createSimpleTTSChunks(appName), null);
}

@Override
Expand Down Expand Up @@ -204,14 +224,14 @@ private void setVoiceCommands() {
VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() {
@Override
public void onVoiceCommandSelected() {
Log.i(TAG, "Voice Command 1 triggered");
DebugTool.logInfo(TAG, "Voice Command 1 triggered");
}
});

VoiceCommand voiceCommand2 = new VoiceCommand(list2, new VoiceCommandSelectionListener() {
@Override
public void onVoiceCommandSelected() {
Log.i(TAG, "Voice Command 2 triggered");
DebugTool.logInfo(TAG, "Voice Command 2 triggered");
}
});

Expand All @@ -229,51 +249,51 @@ private void sendMenus() {
// some voice commands
List<String> voice2 = Collections.singletonList("Cell two");

MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() {
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", "Secondary Text", "Tertiary Text", livio, livio, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
DebugTool.logInfo(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
showTest();
}
});

MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() {
MenuCell mainCell2 = new MenuCell("Test Cell 2", "Secondary Text", null, null, null, voice2, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
DebugTool.logInfo(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
}
});

// SUB MENU

MenuCell subCell1 = new MenuCell("SubCell 1", null, null, new MenuSelectionListener() {
MenuCell subCell1 = new MenuCell("SubCell 1", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
DebugTool.logInfo(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
}
});

MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
MenuCell subCell2 = new MenuCell("SubCell 2", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
DebugTool.logInfo(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
}
});

// sub menu parent cell
MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, Arrays.asList(subCell1, subCell2));
MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, null, MenuLayout.LIST, null, null, Arrays.asList(subCell1, subCell2));

MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
showPerformInteraction();
}
});

MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, null,null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Clearing Menu. Source: " + trigger.toString());
DebugTool.logInfo(TAG, "Clearing Menu. Source: " + trigger.toString());
// Clear this thing
sdlManager.getScreenManager().setMenu(Collections.<MenuCell>emptyList());
showAlert("Menu Cleared");
Expand All @@ -288,7 +308,8 @@ public void onTriggered(TriggerSource trigger) {
* Will speak a sample welcome message
*/
private void performWelcomeSpeak() {
sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(WELCOME_SPEAK)));
List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(WELCOME_SPEAK, SpeechCapabilities.TEXT));
sdlManager.sendRPC(new Speak(chunks));
}

/**
Expand All @@ -305,7 +326,7 @@ private void performWelcomeShow() {
@Override
public void onComplete(boolean success) {
if (success) {
Log.i(TAG, "welcome show successful");
DebugTool.logInfo(TAG, "welcome show successful");
}
}
});
Expand All @@ -320,14 +341,21 @@ private void showTest() {
sdlManager.getScreenManager().setTextField2("");
sdlManager.getScreenManager().commit(null);

sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME)));
List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(TEST_COMMAND_NAME, SpeechCapabilities.TEXT));
sdlManager.sendRPC(new Speak(chunks));
}

private void showAlert(String text) {
Alert alert = new Alert();
alert.setAlertText1(text);
alert.setDuration(5000);
sdlManager.sendRPC(alert);
AlertView.Builder builder = new AlertView.Builder();
builder.setText(text);
builder.setTimeout(5);
AlertView alertView = builder.build();
sdlManager.getScreenManager().presentAlert(alertView, new AlertCompletionListener() {
@Override
public void onComplete(boolean success, Integer tryAgainTime) {
DebugTool.logInfo(TAG, "Alert presented: "+ success);
}
});
}

public interface SdlServiceCallback {
Expand All @@ -354,7 +382,7 @@ public void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource,

@Override
public void onError(String error) {
Log.e(TAG, "There was an error showing the perform interaction: " + error);
DebugTool.logError(TAG, "There was an error showing the perform interaction: " + error);
}
});
sdlManager.getScreenManager().presentChoiceSet(choiceSet, InteractionMode.MANUAL_ONLY);
Expand Down

0 comments on commit c480dd4

Please sign in to comment.