Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
56 changes: 52 additions & 4 deletions examples/js/hello-sdl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,14 @@
this._logPermissions();

// wait for the FULL state for more functionality
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
const prevHmiFull = this._prevHmiLevel !== SDL.rpc.enums.HMILevel.HMI_FULL
this._prevHmiLevel = hmiLevel;
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL && prevHmiFull) {
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 +172,25 @@
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', 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,10 +230,34 @@
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);
}
}

Expand Down
56 changes: 52 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,14 @@ class AppClient {
this._logPermissions();

// wait for the FULL state for more functionality
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
const prevHmiFull = this._prevHmiLevel !== SDL.rpc.enums.HMILevel.HMI_FULL;
this._prevHmiLevel = hmiLevel;
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL && prevHmiFull) {
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 +167,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,10 +225,34 @@ 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);
}
}

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

// wait for the FULL state for more functionality
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
const prevHmiFull = this._prevHmiLevel !== SDL.rpc.enums.HMILevel.HMI_FULL;
this._prevHmiLevel = hmiLevel;
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL && prevHmiFull) {
this._hmiFull = true;
this._checkReadyState();
}
Expand All @@ -125,6 +127,9 @@ class AppClient {
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 +185,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 +233,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
14 changes: 4 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