Example #1
0
        window.setTimeout(function () {
            if (!_devPowered) {
                if (errorCallback) {
                    errorCallback(new WebAPIError(
                            errorcode.SERVICE_NOT_AVAILABLE_ERR));
                }
                return;
            }

            if (!_data.historyDevs[address]) {
                if (errorCallback) {
                    errorCallback(new WebAPIError(errorcode.NOT_FOUND_ERR));
                }
                return;
            }

            event.trigger("bt-service-state-update", [address, false]);
            _data.historyDevs[address].__defineGetter__("isBonded", function () {
                return false;
            });
            event.trigger("bt-device-bonded-changed", [address, false]);
            if (successCallback) {
                successCallback();
            }
        }, 1);
Example #2
0
            it("updates the current position info and doesn't call again after the watch is cleared", function () {
                geolocation.addWatch(s, e, [0]);

                event.trigger("PositionInfoUpdatedEvent", [newpos], true);

                expect(s).toHaveBeenCalled();

                var s_args = s.mostRecentCall.args[0];
                expect(s_args.latitude).toEqual(jasmine.any(Number));
                expect(s_args.longitude).toEqual(jasmine.any(Number));
                expect(s_args.altitude).toEqual(jasmine.any(Number));
                expect(s_args.accuracy).toEqual(jasmine.any(Number));
                expect(s_args.altitudeAccuracy).toEqual(jasmine.any(Number));
                expect(s_args.heading).toEqual(jasmine.any(Number));
                expect(s_args.speed).toEqual(jasmine.any(Number));

                expect(e).not.toHaveBeenCalled();

                s.reset();
                e.reset();

                geolocation.clearWatch(null, null, [0]);

                newpos = movePositionABit(newpos);

                event.trigger("PositionInfoUpdatedEvent", [newpos], true);

                expect(s).not.toHaveBeenCalled();
                expect(e).not.toHaveBeenCalled();

            });
Example #3
0
    setInfo: function (e) {
        var triggerDeviceMotion = false,
            triggerDeviceOrientation = false;

        if (e.x !== undefined && e.y !== undefined && e.z !== undefined) {
            _motion = {
                acceleration: new Acceleration(e.x, e.y, e.z),
                accelerationIncludingGravity: new Acceleration(e.x, e.y, e.z),
                rotationRate: new Rotation(0, 0, 0),
                orientation: new Rotation(e.alpha, e.beta, e.gamma),
                timestamp: new Date().getTime()
            };
            triggerDeviceMotion = true;
            triggerDeviceOrientation = true;
        }
        else {
            _motion = {
                acceleration: new Acceleration(0, 0, 0),
                accelerationIncludingGravity: new Acceleration(0, 0, -9.81),
                rotationRate: new Rotation(0, 0, 0),
                orientation: new Rotation(0, 0, 0),
                timestamp: new Date().getTime()
            };
        }

        if (triggerDeviceMotion) {
            event.trigger("DeviceMotionEvent", [_motion]);
        }

        if (triggerDeviceOrientation) {
            event.trigger("DeviceOrientationEvent", [_motion]);
        }

        event.trigger("AccelerometerInfoChangedEvent", [_motion]);
    },
Example #4
0
        event.on("NetworkRequest", function (networkType, domainName) {
            var type = networkType.toLowerCase(), name, idBearer,
                evNetworkOpened       = "NO_" + networkType + "_" + domainName,
                evNetworkDisconnected = "ND_" + networkType + "_" + domainName;

            if (!$("#bearer-" + type + "-radio1").prop("checked")) {
                event.trigger(evNetworkOpened, [false]);
                event.trigger(evNetworkDisconnected);

                return;
            }

            name = domainName.replace(/\./, "");
            idBearer = type + '-' + name;

            if ($("#bearer-row-" + idBearer).length <= 0) {
                $("#bearer-" + type).append("<tr id='bearer-row-" + idBearer + "'>" +
                     "<td>&nbsp<lable class='ui-text-label'>" + domainName + "</label></td>" +
                     "<td><button id='bearer-btn-" + idBearer + "'>X</button>&nbsp&nbsp</td>" +
                     "</tr>");

                $("#bearer-btn-" + idBearer).click(function () {
                    _bearerRelease(type, idBearer, evNetworkDisconnected);
                });

                $("#bearer-" + type + " tr:even").css("background-color", "white");
                $("#bearer-" + type + " tr:odd").css("background-color", "whitesmoke");
            }

            event.trigger(evNetworkOpened, [true]);
        });
Example #5
0
function _endCall(callEndReason) {
    if (_data.autoAcceptTimerId) {
        var path = _RECORDING_PATH + _record.serviceId + ".mp3";

        _record.recording.push(path);
        db.saveObject(_RECORDING_KEY, path);

        clearTimeout(_data.autoAcceptTimerId);
        _data.autoAcceptTimerId = null;
    }

    _record.duration = _data.conversationStartTime ? ((new Date()) - _data.conversationStartTime) : 0;
    _data.conversationStartTime = null;
    
    _record.endReason = callEndReason;

    if (_data.status === _status.PLACED) {
        _record.direction = "missed-new";
    }

    event.trigger("CallRecorded", [_record]);
    event.trigger("CallInProgress", [false]);

    _data.status = _status.IDLE;
    _transferStatus();
    _record = {};

    _conversationSeconds = 0;
    window.clearInterval(_conversationTimer);
    jQuery("#call-status").hide();
    jQuery("#remote-call-status").hide();

    jQuery("#status-text").hide();
    jQuery("#remote-status-text").hide();
}
Example #6
0
 it("only passed the baton once", function () {
     var baton = new MockBaton();
     server.deviceBatteryLevelChange({}, {}, baton);
     event.trigger("DeviceBatteryLevelChanged", [], true);
     event.trigger("DeviceBatteryLevelChanged", [], true);
     expect(baton.pass).toHaveBeenCalled();
 });
Example #7
0
 it("only passes the baton once", function () {
     var baton = new MockBaton();
     menu.onSelect({}, {}, baton);
     event.trigger("MenuItemSelected", [1], true);
     event.trigger("MenuItemSelected", [2], true);
     expect(baton.pass.callCount).toBe(1);
 });
Example #8
0
 it("only passes the baton once", function () {
     var baton = new MockBaton();
     sysEvent.onCoverageChange({}, {}, baton);
     event.trigger("CoverageChange", [], true);
     event.trigger("CoverageChange", [], true);
     expect(baton.pass.callCount).toBe(1);
 });
Example #9
0
function flightModeChangedCB(value) {
    var networkSettings = {};
    if (value === true) {
        networkSettings['wifiSetting'] = deviceSettings.retrieve("WIFI_NETWORK.status");
        networkSettings['cellularSetting'] = deviceSettings.retrieve("CELLULAR_NETWORK.status");
        //networkSettings['bluetoothSetting'] = deviceSettings.retrieve("CELLULAR_NETWORK.status");
        //networkSettings['nfcSetting'] = deviceSettings.retrieve("CELLULAR_NETWORK.status");
        db.saveObject(DBNETWORKSETTING_KEY, networkSettings);

        deviceSettings.persist("CELLULAR_NETWORK.status", false);
        deviceSettings.persist("WIFI_NETWORK.status", false);
        event.trigger("nfc-power-setting", [false]);
        event.trigger("bt-power-setting", [false]);

        document.getElementById("device-settings-WIFI_NETWORK-status").checked = false;
        document.getElementById("device-settings-CELLULAR_NETWORK-status").checked = false;
        $("#device-settings-CELLULAR_NETWORK-status").parent().append("<span id='config_flight_mode_notice' style='color:#555555;'>  (Disabled for Flight Mode)</span>");
        document.getElementById("device-settings-CELLULAR_NETWORK-status").disabled = true;

    } else {
        networkSettings = db.retrieveObject(DBNETWORKSETTING_KEY)||{"wifiSetting": true, "cellularSetting": true};
        deviceSettings.persist("WIFI_NETWORK.status", networkSettings['wifiSetting']);
        deviceSettings.persist("CELLULAR_NETWORK.status", networkSettings['cellularSetting']);
        document.getElementById("device-settings-WIFI_NETWORK-status").checked = networkSettings['wifiSetting'];
        document.getElementById("device-settings-CELLULAR_NETWORK-status").checked = networkSettings['cellularSetting'];
        $("#config_flight_mode_notice").remove();
        document.getElementById("device-settings-CELLULAR_NETWORK-status").disabled = false;
    }
}
Example #10
0
 utils.forEach(_data.historyDevs, function (dev) {
     event.trigger("bt-service-state-update", [dev.address, false]);
     dev.__defineGetter__("isBonded", function () {
         return false;
     });
     event.trigger("bt-device-bonded-changed", [dev.address, false]);
     jQuery("#service-transfer-textarea-" + dev.address.replace(/:/g, "")).val("");
     jQuery("#service-receive-textarea-" + dev.address.replace(/:/g, "")).html("");
 });
Example #11
0
    it("only passes the baton once", function () {
        var baton = new MockBaton();

        appEvent.onBackground({}, {}, baton);

        event.trigger("AppRequestBackground", [], true);
        event.trigger("AppRequestBackground", [], true);

        expect(baton.pass.callCount).toBe(1);
    });
Example #12
0
 omnibar.addEventListener("keydown", function (event) {
     if (event.keyCode === '13' || event.keyCode === 13 || event.keyCode === '0' || event.keyCode === 0) { // enter or return
         if (omnibar.value.trim() !== "") {
             if (_currentURL().match(/^file:/) && omnibar.value.match(/^file:/)) { // Use ajax to know whether that file exists
                 xhr = new XMLHttpRequest();
                 xhr.onreadystatechange = function () {
                     if (xhr.readyState === 4) {
                         if (xhr.responseText !== '') {
                             _persist(omnibar.value);
                             _persistRoot(omnibar.value);
                             emulatorBridge.window().location.assign(omnibar.value);
                         } else {
                             alert("File doesn't exist!");
                             return;
                         }
                     }
                 };
                 xhr.open('GET', omnibar.value, true);
                 xhr.send(null);
             } else {
                 //default the protocal if not provided
                 omnibar.value = omnibar.value.indexOf("://") < 0 ? "http://" + omnibar.value : omnibar.value;
                 _persist(omnibar.value);
                 _persistRoot(omnibar.value);
                 emulatorBridge.window().location.assign(omnibar.value);
             }
             _event.trigger("ApplicationLoad", null);
             _addHistory(omnibar.value);
         }
     }
 });
Example #13
0
    frame.onload = function () {
        var bootLoader = document.querySelector("#emulator-booting"),
            id;
        if (bootLoader) {
            document.querySelector("#ui").removeChild(bootLoader);
        }

        event.trigger("TinyHipposLoaded");

        _cleanBody();
        id = window.setInterval(_cleanBody, 20);

        window.setTimeout(function () {
            window.clearInterval(id);
        }, 1200);

        if (ui.registered("omnibar")) {
            //reset the onload function so that when navigating we can destroy
            //the iframe and create a new one so we can reinject the platform by
            //calling post again.
            frame.onload = function () {
                var url = frame.contentWindow.location.href;
                document.getElementById("viewport-container").removeChild(frame);
                event.trigger("FrameHistoryChange", [url]);
                _console.log("-----------------------------------------------------------");
                _console.log("Pay no attention to that man behind the curtain.");
                _console.log("Environment Warning up again (Set main batteries to auto-fire cycle)");
                _post(url);
            };
        }
    };
Example #14
0
 jQuery("#package-update-btn").live("click", function () {
     var path = $("#package-list-select option:selected").val();
     addPackage(path, "update");
     loadPackageList();
     loadInstalledList();
     event.trigger("update-package", [path]);
 });
Example #15
0
function _loadApplication() {
    var omnibar = _omnibar(),
            xhr;
    if (omnibar.value.trim() !== "") {
        if (_currentURL().match(/^file:/) && omnibar.value.match(/^file:/)) { // Use ajax to know whether that file exists
            xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.responseText !== '') {
                        _persist(omnibar.value);
                        _persistRoot(omnibar.value);
                        emulatorBridge.window().location.assign(omnibar.value);
                    } else {
                        alert("File doesn't exist!");
                        return;
                    }
                }
            };
            xhr.open('GET', omnibar.value, true);
            xhr.send(null);
        } else {
            omnibar.value = omnibar.value.indexOf("://") < 0 ? "http://" + omnibar.value : omnibar.value;
            _persist(omnibar.value);
            _persistRoot(omnibar.value);
            emulatorBridge.window().location.assign(omnibar.value);
        }
        _addHistory(omnibar.value);
    }
    _event.trigger("ApplicationLoad", null);
}
Example #16
0
    jQuery(sendSelector.join(",")).bind("click", function () {
        var appId = this.id.replace("-send", ""),
            key = jQuery("#" + appId + "-key").val(),
            value = jQuery("#" + appId + "-value").val(),
            data, remotePort, errorHtml,
            messagePortName = jQuery("#" + appId + "-local-port").val(),
            certificate = _db[appId].certificate;

        if ((key.length === 0) || (value.length === 0))
            return;

        data = [{
            key: key,
            value: value
        }];
        remotePort = {
            appId: appId,
            messagePortName: messagePortName,
            isTrusted: false
        };
        jQuery("#" + appId + "-key").val("");
        jQuery("#" + appId + "-value").val("");

        if (!certificate && _messagePortGlobal.localMessagePorts[messagePortName]) {
            errorHtml = 'Access Denied: "' + messagePortName + '" is a trusted port ' +
                'and the target application is signed with the different certification ' +
                'from this application.';
            jQuery("#" + appId + "-access").html(errorHtml);
            jQuery("#" + appId + "-access").show();
            return;
        }

        event.trigger("LocalMessagePortReceived", [data, remotePort, false]);
    });
Example #17
0
    setPreferenceForKey: function (preference, key) {
        utils.validateNumberOfArguments(1, 2, arguments.length);
        utils.validateArgumentType(key, "string");

        var msg = "",
            prefix = platform.getPersistencePrefix();

        if (app.isPreferenceReadOnly(key)) {
            msg += "Cannot modify a read only preference. Preference key: " + key;
        }
        else {
            if (preference === null) {
                msg += "deleting preference " + key;
                db.remove(key, prefix);
            }
            else {
                msg += "setting preference " + key + " == " + preference;
                utils.validateArgumentType(preference, "string");
                db.save(key, preference, prefix);
            }
        }

        _console.log(msg);
        event.trigger("StorageUpdatedEvent");
    },
Example #18
0
    unregisterService: function (successCallback, errorCallback) {
        var appId, appService;

        if (!_security.all && !_security.unregisterService) {
            throw new WebAPIException(errorcode.SECURITY_ERR);
        }
        if ((successCallback && !(new TypeCoerce(t.SuccessCallback)).match(successCallback)) ||
            (errorCallback && !(new TypeCoerce(t.ErrorCallback)).match(errorCallback))) {
            throw new WebAPIException(errorcode.TYPE_MISMATCH_ERR);
        }

        appId = _getCurrentApplicationId();
        appService = _data.service[appId];
        if (!appService || !appService.isRegistered) {
            if (errorCallback) {
                window.setTimeout(function () {
                    errorCallback(new WebAPIError(errorcode.UNKNOWN_ERR));
                }, 1);
            }
            return;
        }

        delete _data.service[appId];
        event.trigger("PushRequest", ["UNREGISTER", appId]);
    },
Example #19
0
    registerService: function (appControl, successCallback, errorCallback) {
        var appId, appService;

        if (!_security.all && !_security.registerService) {
            throw new WebAPIException(errorcode.SECURITY_ERR);
        }
        if (!(new TypeCoerce(t.ApplicationControl)).match(appControl) ||
            !(new TypeCoerce(t.PushRegisterSuccessCallback)).match(successCallback) ||
            (errorCallback && !(new TypeCoerce(t.ErrorCallback)).match(errorCallback))) {
            throw new WebAPIException(errorcode.TYPE_MISMATCH_ERR);
        }

        appId = _getCurrentApplicationId();
        appService = {
            appId:          appId,
            registrationId: null,
            appControl:     appControl,
            isRegistered:   false
        };
        _data.service[appId] = appService;

        event.trigger("PushRequest", ["REGISTER", appService], true);

        if (appService.registrationId !== null) {
            appService.isRegistered = true;
            successCallback(appService.registrationId);
        } else if (errorCallback) {
            window.setTimeout(function () {
                errorCallback(new WebAPIError(errorcode.UNKNOWN_ERR));
            }, 1);
        }
    },
Example #20
0
 _video.addEventListener("ended", function () {
     event.trigger("MultimediaVideoStateChanged", [_STATES.COMPLETED], true);
     if (_loopCount > 1) {
         _self.open(_currentVideoFile);
         _self.play(_loopCount--);
     }
 }, false);
Example #21
0
 jQuery(this).parent().next().toggle("blind", {}, 300, function () {
     if (isOpen) {
         pNode.removeClass("ui-box-open");
     }
     event.trigger("ApplicationState", [pNode]);
     uiBoxToggleEngaged = false;
 });
Example #22
0
    event.on("vehicle-set-request", function (property, value) {
        var status = true, enums, showValue;

        for (var item in value) {
            var enterID = property + "-" + item + "-set";
            var showID = property + "-" + item + "-show";
            var enterContainer = jQuery("#vehicle-container #" + enterID);
            var showContainer = jQuery("#vehicle-container #" + showID);

            if (Object.prototype.toString.call(value[item]) === '[object Array]') {
                enterContainer.val(value[item].join(","));
            }
            else {
                enterContainer.val(value[item].toString());
            }
            if (showContainer) {
                enums = vehiclePanelEngine.getPropertyConstant(property, item);
                showValue = value[item];
                if (enums) {
                    showValue = enums["val" + value[item]];
                }
                showContainer.html(showValue);
            }
        }

        event.trigger("vehicle-set-response", [status]);
    });
Example #23
0
/**
 * receive sending message from current application and show content
 * @param remoteMessagePort
 * @param data
 * @param localMessagePort
 * @private
 */
function _receiveMessage(remoteMessagePort, data, localMessagePort) {
    var htmlTemplate, header, footer, html = '', i, appId, messagePortName, selector,
        remotePort;

    appId = remoteMessagePort.appId;
    messagePortName = remoteMessagePort.messagePortName;

    selector = "#" + appId + "-receiving ." + messagePortName.replace(/\s+/g, "");

    header = '<table class="preferences-table" style="border-bottom: 1px dashed #DCDCDC; width: 100%;">';
    htmlTemplate = '<tr><td><label class="ui-text-label">Key:</label></td><td>#Key</td></tr>' +
        '<tr><td><label class="ui-text-label">Value:</label></td><td>#Value</td></tr>';
    footer = '</table>';

    for (i = 0; i < data.length; i++) {
        html += header +
            htmlTemplate.replace("#Key", data[i].key).replace("#Value", data[i].value) +
            footer;
    }

    jQuery(selector).html(html);

    if (!localMessagePort) return;

    remotePort = {
        appId: appId,
        messagePortName: localMessagePort.messagePortName,
        isTrusted: localMessagePort.isTrusted
    };

    event.trigger("LocalMessagePortReceived", [_db[appId]["reply"], remotePort, true]);
}
Example #24
0
 jQuery("#nfc-power").bind("change", function () {
     var status;
     status = jQuery("#nfc-power").val() === "On" ? true : false;
     if (status)
         jQuery("#nfc").show();
     event.trigger("nfc-power-setting", [status]);
 });
Example #25
0
    event.on("vehicle-subscribe-request", function (property, isRegister, zone) {
        if (isRegister) {
            _vehicleGlobalVars.registerListeners[property] = true;
            return;
        }

        var value, status, time, history,
            propertyObj = {};

        if (_vehicleGlobalVars.vehicleCache.supported.indexOf(property) === -1) {
            propertyObj.val = null;
            propertyObj.supported = false;
            propertyObj.type = property;
        }
        else {
            history = _vehicleGlobalVars.history;
            time = _vehicleGlobalVars.timeCurrent;

            value = history[time][property];
            value.time = time;
            status = true;

            propertyObj.val = value;
            propertyObj.supported = status;
            propertyObj.type = property;
        }

        event.trigger("vehicle-subscribe-response", [propertyObj]);
    });
Example #26
0
function _saveVehicleData () {
    var configurationContainer = jQuery("#vehicle-container #vehicle-configuration-show *[id$='-set']"),
        currentConfigContainer = jQuery("#vehicle-container #vehicle-configuration-types"),
        settingContainer = jQuery("#vehicle-container #vehicle-setting-show  *[id$='-set']"),
        autoContainer = jQuery("#vehicle-container #vehicle-running-show  *[id$='-set']"),
        supportedContainer = jQuery("#vehicle-container #vehicle-supported-hide  *[id$='-supported']:checked"),
        supported = [], currentConfig, configuration = [], setting = [], autoRunning = [],
        history = {}, itemKey, format, delTime, time, zone, source;

    supportedContainer.each(function (index, item) {
        supported.push(item.value);
    });

    currentConfig = currentConfigContainer.val().replace("configuration", "");

    configurationContainer.each(function (index, item) {
        itemKey = item.id.replace("-set", "");
        history[itemKey] = item.value;

        configuration.push(item.value);
    });

    settingContainer.each(function (index, item) {
        itemKey = item.id.replace("-set", "");
        history[itemKey] = item.value;

        setting.push(item.value);
    });

    autoContainer.each(function (index, item) {
        var value;

        value = item.value;
        if (item.id.indexOf("TripMeter") > -1) {
            value = item.value.split(",");
        }

        itemKey = item.id.replace("-set", "");
        history[itemKey] = value;

        autoRunning.push(value);
    });

    _vehicleGlobalVars.timeHistoryArray.push(_vehicleGlobalVars.timeCurrent);
    if (_vehicleGlobalVars.timeHistoryArray.length > _vehicleGlobalVars.timeHistoryLimit) {
        delTime = _vehicleGlobalVars.timeHistoryArray.shift();
        delete _vehicleGlobalVars.history[delTime];
    }

    time = _vehicleGlobalVars.timeCurrent;
    source = "";
    zone = 0;

    format = _formatHistory(history, time, zone, source);
    _vehicleGlobalVars.history[_vehicleGlobalVars.timeCurrent] = format;
    event.trigger("vehicle-cache-refresh", [supported, format]);

    vehiclePanelEngine.saveData(supported, currentConfig, configuration, setting, autoRunning);
}
Example #27
0
 it("calls refresh on FileSystemInitialized", function () {
     spyOn(cache, "refresh");
     spyOn(fs, "mkdir").andCallFake(function (path, success, error) {
         success();
     });
     event.trigger("FileSystemInitialized", null, true);
     expect(cache.refresh).toHaveBeenCalled();
 });
Example #28
0
 it("only passes the baton once", function () {
     var baton = new MockBaton();
     sms.onReceive({}, {}, baton);
     event.trigger("MessageReceived", [{
         type: "sms",
         time: new Date(),
         from: "Westley",
         body: "AAARRRRRRRHHHHHHHAGGGGGGGGAAAA!!!!"
     }], true);
     event.trigger("MessageReceived", [{
         type: "sms",
         time: new Date(),
         from: "Inigo Montoya",
         body: "Do you hear that Fezzik? That is the sound of ultimate suffering. My heart made that sound when the six-fingered man killed my father. The Man in Black makes it now."
     }], true);
     expect(baton.pass.callCount).toBe(1);
 });
Example #29
0
 function updateIsNear(isDetectTag, isAttached) {
     _data.isDetectTag = isDetectTag;
     _data.isNear = isAttached;
     if (!_data.isNear) {
         _data.connectedState = false;
         event.trigger("nfc-connectedState-changed", [false]);
     }
 }
Example #30
0
 afterEach(function () {
     domNode = null;
     videoNode = null;
     s.verifyAndRestore();
     //HACK: this is to clear the state of video player between tests
     video.onStateChange = null;
     event.trigger("MultimediaVideoStateChanged", [null], true);
 });