Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update Example apps for 1.3
  • Loading branch information
renonick87 committed Mar 22, 2021
commit 29f5ac3840e7aaf641bb04b7d95b67d189388226
53 changes: 49 additions & 4 deletions examples/js/hello-sdl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@
this._logPermissions();

// wait for the FULL state for more functionality
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL && this._prevHmiLevel !== SDL.rpc.enums.HMILevel.HMI_FULL) {
const screenManager = this._sdlManager.getScreenManager();
const isRpcAllowed = (rpc) => {
if (!this._permissionManager) {
this._permissionManager = this._sdlManager.getPermissionManager();
}
return this._permissionManager &&
this._permissionManager.isRpcAllowed(rpc);
};
Expand Down Expand Up @@ -167,6 +170,23 @@
this._isButtonSubscriptionRequested = true;
}

const choices = [
new SDL.manager.screen.choiceset.ChoiceCell('First Choice Cell'),
new SDL.manager.screen.choiceset.ChoiceCell('Second Choice Cell'),
];
await screenManager.preloadChoices(choices);

const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet('choice', screenManager.getPreloadedChoices(), new SDL.manager.screen.choiceset.ChoiceSetSelectionListener()
.setOnChoiceSelected((choiceCell, triggerSource, rowIndex) => {
console.log(choiceCell, triggerSource, rowIndex);
resolve();
})
.setOnError((error) => {
resolve();
}));

screenManager.presentChoiceSet(choiceSet);

const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
.setFilePath(this._filePath);

Expand Down Expand Up @@ -206,11 +226,36 @@
await this._sleep();
}

// tear down the app
await this._sdlManager.sendRpcResolve(new SDL.rpc.messages.UnregisterAppInterface());
const alertState = new SDL.manager.screen.utils.SoftButtonState('EXIT', 'exit app', null);
const alertState2 = new SDL.manager.screen.utils.SoftButtonState('DISMISS', 'dismiss alert', null);

const alertView = new SDL.manager.screen.utils.AlertView()
.setText('Exit the Application?')
.setTimeout(3000)
.setSoftButtons([
new SDL.manager.screen.utils.SoftButtonObject('Exit', [alertState], 'EXIT', async (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
// tear down the app
await this._sdlManager.sendRpcResolve(new SDL.rpc.messages.UnregisterAppInterface());

this._sdlManager.dispose();
}
}),
new SDL.manager.screen.utils.SoftButtonObject('Dismiss', [alertState2], 'DISMISS', (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
console.log('Alert button pressed!');
}
}),
]);

const alertCompletionListener = new SDL.manager.screen.utils.AlertCompletionListener()
.setOnComplete((success, tryAgainTime) => {
console.log(`Alert presented ${(success) ? 'successfully' : 'unsuccessfully'}`);
});

this._sdlManager.dispose();
screenManager.presentAlert(alertView, alertCompletionListener);
}
this._prevHmiLevel = hmiLevel;
}

async _sleep (timeout = 1000) {
Expand Down
55 changes: 51 additions & 4 deletions examples/node/hello-sdl-tcp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ class AppClient {
this._logPermissions();

// wait for the FULL state for more functionality
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL && this._prevHmiLevel !== SDL.rpc.enums.HMILevel.HMI_FULL) {
const screenManager = this._sdlManager.getScreenManager();
const isRpcAllowed = (rpc) => {
if (!this._permissionManager) {
this._permissionManager = this._sdlManager.getPermissionManager();
}
return this._permissionManager &&
this._permissionManager.isRpcAllowed(rpc);
};
Expand Down Expand Up @@ -162,6 +165,25 @@ class AppClient {
this._isButtonSubscriptionRequested = true;
}

const choices = [
new SDL.manager.screen.choiceset.ChoiceCell('First Choice Cell'),
new SDL.manager.screen.choiceset.ChoiceCell('Second Choice Cell'),
];
await screenManager.preloadChoices(choices);

await new Promise ((resolve) => {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet('choice', choices, new SDL.manager.screen.choiceset.ChoiceSetSelectionListener()
.setOnChoiceSelected((choiceCell, triggerSource, rowIndex) => {
console.log(choiceCell, triggerSource, rowIndex);
resolve();
})
.setOnError((error) => {
resolve();
}));

screenManager.presentChoiceSet(choiceSet);
});

const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
.setFilePath(this._filePath);

Expand Down Expand Up @@ -201,11 +223,36 @@ class AppClient {
await this._sleep();
}

// tear down the app
await this._sdlManager.sendRpcResolve(new SDL.rpc.messages.UnregisterAppInterface());
const alertState = new SDL.manager.screen.utils.SoftButtonState('EXIT', 'exit app', null);
const alertState2 = new SDL.manager.screen.utils.SoftButtonState('DISMISS', 'dismiss alert', null);

const alertView = new SDL.manager.screen.utils.AlertView()
.setText('Exit the Application?')
.setTimeout(3000)
.setSoftButtons([
new SDL.manager.screen.utils.SoftButtonObject('Exit', [alertState], 'EXIT', async (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
// tear down the app
await this._sdlManager.sendRpcResolve(new SDL.rpc.messages.UnregisterAppInterface());

this._sdlManager.dispose();
}
}),
new SDL.manager.screen.utils.SoftButtonObject('Dismiss', [alertState2], 'DISMISS', (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
console.log('Alert button pressed!');
}
}),
]);

const alertCompletionListener = new SDL.manager.screen.utils.AlertCompletionListener()
.setOnComplete((success, tryAgainTime) => {
console.log(`Alert presented ${(success) ? 'successfully' : 'unsuccessfully'}`);
});

this._sdlManager.dispose();
screenManager.presentAlert(alertView, alertCompletionListener);
}
this._prevHmiLevel = hmiLevel;
}

_onButtonListener (buttonName, onButton) {
Expand Down
54 changes: 53 additions & 1 deletion examples/node/hello-sdl/AppClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,20 @@ class AppClient {
this._logPermissions();

// wait for the FULL state for more functionality
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL && this._prevHmiLevel !== SDL.rpc.enums.HMILevel.HMI_FULL) {
this._hmiFull = true;
this._checkReadyState();
}
this._prevHmiLevel = hmiLevel;
}

async _checkReadyState () {
if (this._managersReady && this._hmiFull) {
const screenManager = this._sdlManager.getScreenManager();
const isRpcAllowed = (rpc) => {
if (!this._permissionManager) {
this._permissionManager = this._sdlManager.getPermissionManager();
}
return this._permissionManager &&
this._permissionManager.isRpcAllowed(rpc);
};
Expand Down Expand Up @@ -180,6 +184,25 @@ class AppClient {
screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration()
.setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA));

const choices = [
new SDL.manager.screen.choiceset.ChoiceCell('First Choice Cell'),
new SDL.manager.screen.choiceset.ChoiceCell('Second Choice Cell'),
];
await screenManager.preloadChoices(choices);

await new Promise ((resolve) => {
const choiceSet = new SDL.manager.screen.choiceset.ChoiceSet('choice', choices, new SDL.manager.screen.choiceset.ChoiceSetSelectionListener()
.setOnChoiceSelected((choiceCell, triggerSource, rowIndex) => {
console.log(choiceCell, triggerSource, rowIndex);
resolve();
})
.setOnError((error) => {
resolve();
}));

screenManager.presentChoiceSet(choiceSet);
});

const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
.setFilePath(this._filePath);

Expand Down Expand Up @@ -209,6 +232,35 @@ class AppClient {
await this._sleep(2000);
softButtonObjects[0].transitionToNextState();
await this._sleep(2000);

const alertState = new SDL.manager.screen.utils.SoftButtonState('EXIT', 'exit app', null);
const alertState2 = new SDL.manager.screen.utils.SoftButtonState('DISMISS', 'dismiss alert', null);

const alertView = new SDL.manager.screen.utils.AlertView()
.setText('Exit the Application?')
.setTimeout(3000)
.setSoftButtons([
new SDL.manager.screen.utils.SoftButtonObject('Exit', [alertState], 'EXIT', async (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
// tear down the app
await this._sdlManager.sendRpcResolve(new SDL.rpc.messages.UnregisterAppInterface());

this._sdlManager.dispose();
}
}),
new SDL.manager.screen.utils.SoftButtonObject('Dismiss', [alertState2], 'DISMISS', (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
console.log('Alert button pressed!');
}
}),
]);

const alertCompletionListener = new SDL.manager.screen.utils.AlertCompletionListener()
.setOnComplete((success, tryAgainTime) => {
console.log(`Alert presented ${(success) ? 'successfully' : 'unsuccessfully'}`);
});

screenManager.presentAlert(alertView, alertCompletionListener);
}
}

Expand Down
40 changes: 24 additions & 16 deletions examples/webengine/hello-sdl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -358,25 +358,33 @@
});

document.getElementById("alertButton").addEventListener("click", function(){
const alert = new SDL.rpc.messages.Alert();
alert.setAlertText1("Test Alert")
.setDuration(5000);

const btn1 = new SDL.rpc.structs.SoftButton();
btn1.setSystemAction(SDL.rpc.enums.SystemAction.DEFAULT_ACTION)
.setType(SDL.rpc.enums.SoftButtonType.SBT_TEXT)
.setText("ReRoute")
.setSoftButtonID(5502);
const alertView = new SDL.manager.screen.utils.AlertView();
alertView.setText("Test Alert")
.setTimeout(5000);

const alertState = new SDL.manager.screen.utils.SoftButtonState('REROUTE', 'reroute', null)
.setSystemAction(SDL.rpc.enums.SystemAction.DEFAULT_ACTION);
const btn1 = new SDL.manager.screen.utils.SoftButtonObject('ReRoute', [alertState], 'REROUTE', async (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
// Handle OnButtonPress
}
});

const btn2 = new SDL.rpc.structs.SoftButton();
btn2.setSystemAction(SDL.rpc.enums.SystemAction.DEFAULT_ACTION)
.setType(SDL.rpc.enums.SoftButtonType.SBT_TEXT)
.setText("Close")
.setSoftButtonID(5503);
const alertState2 = new SDL.manager.screen.utils.SoftButtonState('CLOSE', 'close', null)
.setSystemAction(SDL.rpc.enums.SystemAction.DEFAULT_ACTION);
const btn2 = new SDL.manager.screen.utils.SoftButtonObject('Close', [alertState2], 'CLOSE', async (id, rpc) => {
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
// Handle OnButtonPress
}
});

alert.setSoftButtons([btn1, btn2])
alertView.setSoftButtons([btn1, btn2])

app.sendRpcRequest(alert);
const alertCompletionListener = new SDL.manager.screen.utils.AlertCompletionListener()
.setOnComplete((success, tryAgainTime) => {
// Handle Alert presented
})
app._sdlManager.getScreenManager().presentAlert(alertView, alertCompletionListener);
});

document.getElementById("unregButton").addEventListener("click", async function(){
Expand Down
15 changes: 5 additions & 10 deletions lib/js/src/manager/screen/choiceset/_ChoiceSetManagerBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,24 @@ class _ChoiceSetManagerBase extends _SubManagerBase {
* @param {ChoiceCell[]} choices - A list of ChoiceCell objects that will be part of a choice set later
* @returns {Promise} - A promise that resolves to a Boolean of whether the operation is a success
*/
async preloadChoices (choices = null) {
preloadChoices (choices = null) {
if (this._getState() === _SubManagerBase.ERROR) {
console.warn('ChoiceSetManager: Choice Manager In Error State');
return false;
return Promise.resolve(false);
}

const choicesToUpload = this._getChoicesToBeUploadedWithArray(choices);

this._removeChoicesFromChoices(this._preloadedChoices, choicesToUpload);
this._removeChoicesFromChoices(this._pendingPreloadChoices, choicesToUpload);

if (choicesToUpload.length === 0) {
return true;
return Promise.resolve(true);
}
this._updateIdsOnChoices(choicesToUpload);

// Add the preload cells to the pending preload choices
this._pendingPreloadChoices = this._pendingPreloadChoices.concat(choicesToUpload);

if (this._fileManager === null) {
console.error('ChoiceSetManager: File Manager was null in preload choice operation');
return false;
return Promise.resolve(false);
}

return new Promise(resolve => {
const preloadChoicesOperation = new _PreloadChoicesOperation(this._lifecycleManager, this._fileManager,
this._displayName, this._defaultMainWindowCapability, this._isVrOptional, choicesToUpload, success => {
Expand Down Expand Up @@ -320,6 +314,7 @@ class _ChoiceSetManagerBase extends _SubManagerBase {
}

if (uniqueChoiceCells.length !== choices.length) {
console.log(uniqueChoiceCells, choices);
console.error('Attempted to create a choice set with a duplicate cell. Cell must have a unique value other than its primary text. The choice set will not be set.');
return false;
}
Expand Down