Skip to content

Commit c480dd4

Browse files
Robert HeniganHenigan
andauthored
Update SdlService for 5.1 in JavaEE app (#1640)
* Update SdlService for 5.1 in JavaEE app * remove unused import Co-authored-by: Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com>
1 parent ab0bb87 commit c480dd4

1 file changed

Lines changed: 62 additions & 34 deletions

File tree

javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232

3333
package com.smartdevicelink;
3434

35-
import android.util.Log;
35+
import com.smartdevicelink.managers.AlertCompletionListener;
3636
import com.smartdevicelink.managers.CompletionListener;
3737
import com.smartdevicelink.managers.SdlManager;
3838
import com.smartdevicelink.managers.SdlManagerListener;
3939
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
4040
import com.smartdevicelink.managers.lifecycle.LifecycleConfigurationUpdate;
41+
import com.smartdevicelink.managers.screen.AlertView;
4142
import com.smartdevicelink.managers.screen.choiceset.ChoiceCell;
4243
import com.smartdevicelink.managers.screen.choiceset.ChoiceSet;
4344
import com.smartdevicelink.managers.screen.choiceset.ChoiceSetSelectionListener;
@@ -47,10 +48,9 @@
4748
import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener;
4849
import com.smartdevicelink.protocol.enums.FunctionID;
4950
import com.smartdevicelink.proxy.RPCNotification;
50-
import com.smartdevicelink.proxy.TTSChunkFactory;
51-
import com.smartdevicelink.proxy.rpc.Alert;
5251
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
5352
import com.smartdevicelink.proxy.rpc.Speak;
53+
import com.smartdevicelink.proxy.rpc.TTSChunk;
5454
import com.smartdevicelink.proxy.rpc.enums.*;
5555
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
5656
import com.smartdevicelink.transport.BaseTransportConfig;
@@ -94,7 +94,7 @@ public SdlService(BaseTransportConfig config, SdlServiceCallback callback) {
9494
}
9595

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

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

130130
@Override
131131
public void onDestroy(SdlManager sdlManager) {
132-
DebugTool.logInfo("SdlManager onDestroy ");
132+
DebugTool.logInfo(TAG, "SdlManager onDestroy ");
133133
SdlService.this.sdlManager = null;
134134
if (SdlService.this.callback != null) {
135135
SdlService.this.callback.onEnd();
@@ -141,20 +141,40 @@ public void onError(SdlManager sdlManager, String info, Exception e) {
141141
}
142142

143143
@Override
144-
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
145-
String appName;
144+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
145+
boolean isNeedUpdate = false;
146+
String appName = APP_NAME;
147+
String ttsName = APP_NAME;
146148
switch (language) {
147149
case ES_MX:
150+
isNeedUpdate = true;
151+
ttsName = APP_NAME_ES;
152+
break;
153+
case FR_CA:
154+
isNeedUpdate = true;
155+
ttsName = APP_NAME_FR;
156+
break;
157+
default:
158+
break;
159+
}
160+
switch (hmiLanguage) {
161+
case ES_MX:
162+
isNeedUpdate = true;
148163
appName = APP_NAME_ES;
149164
break;
150165
case FR_CA:
166+
isNeedUpdate = true;
151167
appName = APP_NAME_FR;
152168
break;
153169
default:
154-
return null;
170+
break;
171+
}
172+
if (isNeedUpdate) {
173+
Vector<TTSChunk> chunks = new Vector<>(Collections.singletonList(new TTSChunk(ttsName, SpeechCapabilities.TEXT)));
174+
return new LifecycleConfigurationUpdate(appName, null, chunks, null);
175+
} else {
176+
return null;
155177
}
156-
157-
return new LifecycleConfigurationUpdate(appName, null, TTSChunkFactory.createSimpleTTSChunks(appName), null);
158178
}
159179

160180
@Override
@@ -204,14 +224,14 @@ private void setVoiceCommands() {
204224
VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() {
205225
@Override
206226
public void onVoiceCommandSelected() {
207-
Log.i(TAG, "Voice Command 1 triggered");
227+
DebugTool.logInfo(TAG, "Voice Command 1 triggered");
208228
}
209229
});
210230

211231
VoiceCommand voiceCommand2 = new VoiceCommand(list2, new VoiceCommandSelectionListener() {
212232
@Override
213233
public void onVoiceCommandSelected() {
214-
Log.i(TAG, "Voice Command 2 triggered");
234+
DebugTool.logInfo(TAG, "Voice Command 2 triggered");
215235
}
216236
});
217237

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

232-
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() {
252+
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", "Secondary Text", "Tertiary Text", livio, livio, null, new MenuSelectionListener() {
233253
@Override
234254
public void onTriggered(TriggerSource trigger) {
235-
Log.i(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
255+
DebugTool.logInfo(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
236256
showTest();
237257
}
238258
});
239259

240-
MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() {
260+
MenuCell mainCell2 = new MenuCell("Test Cell 2", "Secondary Text", null, null, null, voice2, new MenuSelectionListener() {
241261
@Override
242262
public void onTriggered(TriggerSource trigger) {
243-
Log.i(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
263+
DebugTool.logInfo(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
244264
}
245265
});
246266

247267
// SUB MENU
248268

249-
MenuCell subCell1 = new MenuCell("SubCell 1", null, null, new MenuSelectionListener() {
269+
MenuCell subCell1 = new MenuCell("SubCell 1", null, null, null, null, null, new MenuSelectionListener() {
250270
@Override
251271
public void onTriggered(TriggerSource trigger) {
252-
Log.i(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
272+
DebugTool.logInfo(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
253273
}
254274
});
255275

256-
MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
276+
MenuCell subCell2 = new MenuCell("SubCell 2", null, null, null, null, null, new MenuSelectionListener() {
257277
@Override
258278
public void onTriggered(TriggerSource trigger) {
259-
Log.i(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
279+
DebugTool.logInfo(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
260280
}
261281
});
262282

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

266-
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
286+
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, null, null, null, new MenuSelectionListener() {
267287
@Override
268288
public void onTriggered(TriggerSource trigger) {
269289
showPerformInteraction();
270290
}
271291
});
272292

273-
MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
293+
MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, null,null, null, new MenuSelectionListener() {
274294
@Override
275295
public void onTriggered(TriggerSource trigger) {
276-
Log.i(TAG, "Clearing Menu. Source: " + trigger.toString());
296+
DebugTool.logInfo(TAG, "Clearing Menu. Source: " + trigger.toString());
277297
// Clear this thing
278298
sdlManager.getScreenManager().setMenu(Collections.<MenuCell>emptyList());
279299
showAlert("Menu Cleared");
@@ -288,7 +308,8 @@ public void onTriggered(TriggerSource trigger) {
288308
* Will speak a sample welcome message
289309
*/
290310
private void performWelcomeSpeak() {
291-
sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(WELCOME_SPEAK)));
311+
List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(WELCOME_SPEAK, SpeechCapabilities.TEXT));
312+
sdlManager.sendRPC(new Speak(chunks));
292313
}
293314

294315
/**
@@ -305,7 +326,7 @@ private void performWelcomeShow() {
305326
@Override
306327
public void onComplete(boolean success) {
307328
if (success) {
308-
Log.i(TAG, "welcome show successful");
329+
DebugTool.logInfo(TAG, "welcome show successful");
309330
}
310331
}
311332
});
@@ -320,14 +341,21 @@ private void showTest() {
320341
sdlManager.getScreenManager().setTextField2("");
321342
sdlManager.getScreenManager().commit(null);
322343

323-
sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME)));
344+
List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(TEST_COMMAND_NAME, SpeechCapabilities.TEXT));
345+
sdlManager.sendRPC(new Speak(chunks));
324346
}
325347

326348
private void showAlert(String text) {
327-
Alert alert = new Alert();
328-
alert.setAlertText1(text);
329-
alert.setDuration(5000);
330-
sdlManager.sendRPC(alert);
349+
AlertView.Builder builder = new AlertView.Builder();
350+
builder.setText(text);
351+
builder.setTimeout(5);
352+
AlertView alertView = builder.build();
353+
sdlManager.getScreenManager().presentAlert(alertView, new AlertCompletionListener() {
354+
@Override
355+
public void onComplete(boolean success, Integer tryAgainTime) {
356+
DebugTool.logInfo(TAG, "Alert presented: "+ success);
357+
}
358+
});
331359
}
332360

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

355383
@Override
356384
public void onError(String error) {
357-
Log.e(TAG, "There was an error showing the perform interaction: " + error);
385+
DebugTool.logError(TAG, "There was an error showing the perform interaction: " + error);
358386
}
359387
});
360388
sdlManager.getScreenManager().presentChoiceSet(choiceSet, InteractionMode.MANUAL_ONLY);

0 commit comments

Comments
 (0)