mirror of
https://github.com/flyandi/mazda-custom-application-sdk
synced 2024-12-24 04:02:54 -06:00
232 lines
5.4 KiB
JavaScript
232 lines
5.4 KiB
JavaScript
|
/**
|
||
|
* Custom Applications SDK for Mazda Connect Infotainment System
|
||
|
*
|
||
|
* A mini framework that allows to write custom applications for the Mazda Connect Infotainment System
|
||
|
* that includes an easy to use abstraction layer to the JCI system.
|
||
|
*
|
||
|
* Written by Andreas Schwarz (http://github.com/flyandi/mazda-custom-applications-sdk)
|
||
|
* Copyright (c) 2016. All rights reserved.
|
||
|
*
|
||
|
* WARNING: The installation of this application requires modifications to your Mazda Connect system.
|
||
|
* If you don't feel comfortable performing these changes, please do not attempt to install this. You might
|
||
|
* be ending up with an unusuable system that requires reset by your Dealer. You were warned!
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the
|
||
|
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||
|
* License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License along with this program.
|
||
|
* If not, see http://www.gnu.org/licenses/
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Multicontroller Example Applicatiom
|
||
|
*
|
||
|
* This is a tutorial example application showing and testing the built-in Multicontroller context
|
||
|
* aware methods.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
|
||
|
CustomApplicationsHandler.register("app.multicontroller", new CustomApplication({
|
||
|
|
||
|
/**
|
||
|
* (require)
|
||
|
*
|
||
|
* An object array that defines resources to be loaded such as javascript's, css's, images, etc
|
||
|
*
|
||
|
* All resources are relative to the applications root path
|
||
|
*/
|
||
|
|
||
|
require: {
|
||
|
|
||
|
/**
|
||
|
* (js) defines javascript includes
|
||
|
*/
|
||
|
|
||
|
js: [],
|
||
|
|
||
|
/**
|
||
|
* (css) defines css includes
|
||
|
*/
|
||
|
|
||
|
css: ['app.css'],
|
||
|
|
||
|
/**
|
||
|
* (images) defines images that are being preloaded
|
||
|
*
|
||
|
* Images are assigned to an id
|
||
|
*/
|
||
|
|
||
|
images: {},
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* (settings)
|
||
|
*
|
||
|
* An object that defines application settings
|
||
|
*/
|
||
|
|
||
|
settings: {
|
||
|
|
||
|
/**
|
||
|
* (terminateOnLost)
|
||
|
*
|
||
|
* If set to 'true' this will remove the stateless life cycle and always
|
||
|
* recreate the application once the focus is lost. Otherwise by default
|
||
|
* the inital created state will stay alive across the systems runtime.
|
||
|
*
|
||
|
* Default is false or not set
|
||
|
* /
|
||
|
|
||
|
// terminateOnLost: false,
|
||
|
|
||
|
/**
|
||
|
* (title) The title of the application in the Application menu
|
||
|
*/
|
||
|
|
||
|
title: 'Multicontroller Demo',
|
||
|
|
||
|
/**
|
||
|
* (statusbar) Defines if the statusbar should be shown
|
||
|
*/
|
||
|
|
||
|
statusbar: true,
|
||
|
|
||
|
/**
|
||
|
* (statusbarIcon) defines the status bar icon
|
||
|
*
|
||
|
* Set to true to display the default icon app.png or set a string to display
|
||
|
* a fully custom icon.
|
||
|
*
|
||
|
* Icons need to be 37x37
|
||
|
*/
|
||
|
|
||
|
statusbarIcon: true,
|
||
|
|
||
|
/**
|
||
|
* (statusbarTitle) overrides the statusbar title, otherwise title is used
|
||
|
*/
|
||
|
|
||
|
statusbarTitle: false,
|
||
|
|
||
|
|
||
|
/**
|
||
|
* (hasLeftButton) indicates if the UI left button / return button should be shown
|
||
|
*/
|
||
|
|
||
|
hasLeftButton: false,
|
||
|
|
||
|
/**
|
||
|
* (hasMenuCaret) indicates if the menu item should be displayed with an caret
|
||
|
*/
|
||
|
|
||
|
hasMenuCaret: false,
|
||
|
|
||
|
/**
|
||
|
* (hasRightArc) indicates if the standard right car should be displayed
|
||
|
*/
|
||
|
|
||
|
hasRightArc: true,
|
||
|
|
||
|
},
|
||
|
|
||
|
|
||
|
|
||
|
/***
|
||
|
*** User Interface Life Cycles
|
||
|
***/
|
||
|
|
||
|
/**
|
||
|
* (created)
|
||
|
*
|
||
|
* Executed when the application gets initialized
|
||
|
*
|
||
|
* Add any content that will be static here
|
||
|
*/
|
||
|
|
||
|
created: function() {
|
||
|
|
||
|
// let's build our interface
|
||
|
|
||
|
// 1) create our context aware sections
|
||
|
this.createSections();
|
||
|
|
||
|
// 2) create our statusbar
|
||
|
this.statusBar = $("<div/>").addClass("status").appendTo(this.canvas);
|
||
|
|
||
|
},
|
||
|
|
||
|
/***
|
||
|
*** Events
|
||
|
***/
|
||
|
|
||
|
/**
|
||
|
* (event) onControllerEvent
|
||
|
*
|
||
|
* Called when a new (multi)controller event is available
|
||
|
*/
|
||
|
|
||
|
onControllerEvent: function(eventId) {
|
||
|
|
||
|
// We only get not processed values from the multicontroller here
|
||
|
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* (event) onContextEvent
|
||
|
*
|
||
|
* Called when the context of an element was changed
|
||
|
*/
|
||
|
|
||
|
onContextEvent: function(eventId, context, element) {
|
||
|
|
||
|
// We only get not processed values from the multicontroller here
|
||
|
|
||
|
},
|
||
|
|
||
|
|
||
|
/***
|
||
|
*** Applicaton specific methods
|
||
|
***/
|
||
|
|
||
|
/**
|
||
|
* (createSections)
|
||
|
*
|
||
|
* This method registers all the sections we want to display
|
||
|
*/
|
||
|
|
||
|
createSections: function() {
|
||
|
|
||
|
// random data for testing
|
||
|
[
|
||
|
|
||
|
{top: 20, left: 20, title: "Panel 1"},
|
||
|
{top: 250, left:250, title: "Panel 2"}
|
||
|
|
||
|
].forEach(function(item) {
|
||
|
|
||
|
/**
|
||
|
* addContext is our main method to make anything a context aware item and expects either
|
||
|
* a JQUERY or DOM element.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
this.addContext($("<div/>").addClass("section").css(item).append(item.title).appendTo(this.canvas), function(event, element) {
|
||
|
|
||
|
});
|
||
|
|
||
|
}.bind(this));
|
||
|
|
||
|
|
||
|
},
|
||
|
|
||
|
|
||
|
}));
|