Skip to content

Commit

Permalink
Merge pull request intel#3 from blackberry-webworks/bb.tablet.sysevent
Browse files Browse the repository at this point in the history
SystemEvent APIs for webworks.tablet + Started Integration Tests
  • Loading branch information
brentlintner committed Aug 17, 2011
2 parents 3b5cda9 + e982835 commit 6ce34ae
Show file tree
Hide file tree
Showing 100 changed files with 616 additions and 54 deletions.
1 change: 0 additions & 1 deletion lib/ripple/platform/webworks.core/2.0.0/server/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ _self = {
notifications.openNotification(constants.NOTIFICATIONS.TYPES.NORMAL, msg);
return {code: 1};
},
event: require('ripple/platform/webworks.handset/2.0.0/server/systemEvent'),
hasPermission: function (args) {
var info = app.getInfo(),
feature = info.features[args.desiredModule];
Expand Down
13 changes: 10 additions & 3 deletions lib/ripple/platform/webworks.handset/2.0.0/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var platform = "ripple/platform/webworks.handset/2.0.0/server/",
core = "ripple/platform/webworks.core/2.0.0/server/";
var utils = require('ripple/utils'),
platform = "ripple/platform/webworks.handset/2.0.0/server/",
core = "ripple/platform/webworks.core/2.0.0/server/",
systemEvent = require(platform + 'systemEvent'),
system = {};

// ugh, thanks to the spec...
system.event = systemEvent;
utils.mixin(require(core + "system"), system);

module.exports = {
blackberry: {
invoke: require(core + "invoke"),
system: require(core + "system"),
system: system,
app: require(platform + "app"),
identity: require(platform + "identity"),
message: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ var event = require('ripple/event'),
event.on("CoverageChange", function () {
var baton = _onCoverageChange;
_onCoverageChange = null;
return baton && baton.pass();
return baton && baton.pass({code: 1});
});

event.on("HardwareKey", function (key) {
var baton = _onHardwareKey["key_" + key];
delete _onHardwareKey["key_" + key];

if (baton) {
baton.pass();
baton.pass({code: 1});
}
else {
event.trigger("HardwareKeyDefault", [key]);
}
});

module.exports = {

onCoverageChange: function (args, post, baton) {
baton.take();
_onCoverageChange = baton;
Expand Down
2 changes: 1 addition & 1 deletion lib/ripple/platform/webworks.handset/2.0.0/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
persistencePrefix: "rim-handset-",

ui: require('ripple/platform/webworks.core/2.0.0/spec/ui'),
device: require('ripple/platform/webworks.core/2.0.0/spec/device'),
device: require('ripple/platform/webworks.handset/2.0.0/spec/device'),
config: require('ripple/platform/webworks.core/2.0.0/spec/config'),
events: require('ripple/platform/webworks.core/2.0.0/spec/events'),

Expand Down
17 changes: 14 additions & 3 deletions lib/ripple/platform/webworks.tablet/2.0.0/client/systemEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var transport = require('ripple/platform/webworks.core/2.0.0/client/transport'),
api = "blackberry/system/event/";

function _poll(evt, handler) {
transport.poll(api + evt, {}, function (data, response) {
if (handler) {
handler(data);
}
return !!handler;
});
}

module.exports = {
deviceBatteryLevelChange: function (handler) {
throw "not implemented";
_poll("deviceBatteryLevelChange", handler);
},

deviceBatteryStateChange: function (handler) {
throw "not implemented";
_poll("deviceBatteryStateChange", handler);
}
};
13 changes: 10 additions & 3 deletions lib/ripple/platform/webworks.tablet/2.0.0/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var platform = "ripple/platform/webworks.tablet/2.0.0/server/",
core = "ripple/platform/webworks.core/2.0.0/server/";
var utils = require('ripple/utils'),
platform = "ripple/platform/webworks.tablet/2.0.0/server/",
core = "ripple/platform/webworks.core/2.0.0/server/",
systemEvent = require(platform + 'systemEvent'),
system = {};

// ugh, thanks to the spec...
system.event = systemEvent;
utils.mixin(require(core + "system"), system);

module.exports = {
blackberry: {
identity: require(platform + "identity"),
app: require(platform + "app"),
system: require(core + "system"),
system: system,
ui: {
dialog: require(platform + "dialog")
}
Expand Down
69 changes: 69 additions & 0 deletions lib/ripple/platform/webworks.tablet/2.0.0/server/systemEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2011 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var event = require('ripple/event'),
_onBatteryStateChange,
_onBatteryLevelChange,
_states = {
UNKNOWN: 0,
FULL: 1,
CHARGING: 2,
UNPLUGGED: 3
},
_battery = {
state: _states.UNKNOWN,
charging: null,
level: null
};

function _getState() {
return _battery.level === 100 ? _states.FULL :
_battery.charging ? _states.CHARGING : _states.UNPLUGGED;
}

function _pass(baton, data) {
if (baton) {
baton.pass({code: 1, data: data});
}
}

event.on("DeviceBatteryStateChanged", function (charging) {
_battery.charging = charging;
_battery.state = _getState();
_pass(_onBatteryStateChange, _battery.state);
});

event.on("DeviceBatteryLevelChanged", function (level) {
level = parseInt(level, 10);

_battery.level = level;
_pass(_onBatteryLevelChange, level);

if (level === 100) {
_battery.state = _getState();
_pass(_onBatteryStateChange, _battery.state);
}
});

module.exports = {
deviceBatteryLevelChange: function (get, post, baton) {
baton.take();
_onBatteryLevelChange = baton;
},
deviceBatteryStateChange: function (get, post, baton) {
baton.take();
_onBatteryStateChange = baton;
}
};
6 changes: 2 additions & 4 deletions lib/ripple/platform/webworks.tablet/2.0.0/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
persistencePrefix: "rim-tablet-",

ui: require('ripple/platform/webworks.core/2.0.0/spec/ui'),
device: require('ripple/platform/webworks.core/2.0.0/spec/device'),
device: require('ripple/platform/webworks.tablet/2.0.0/spec/device'),
config: require('ripple/platform/webworks.core/2.0.0/spec/config'),
events: require('ripple/platform/webworks.core/2.0.0/spec/events'),

Expand Down Expand Up @@ -85,11 +85,9 @@ module.exports = {
},
system: {
path: "webworks.core/2.0.0/client/system",
feature: "blackberry.system",
children: {
event: {
path: "webworks.tablet/2.0.0/client/systemEvent",
feature: "blackberry.system.event"
path: "webworks.tablet/2.0.0/client/systemEvent"
}
}
},
Expand Down
146 changes: 146 additions & 0 deletions lib/ripple/platform/webworks.tablet/2.0.0/spec/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright 2011 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var event = require('ripple/event');

module.exports = {
"transports": {
"TCPCellular": {
"name": "Cellular TCP",
"control": {
"type": "checkbox",
"value": true
}
},
"WAP": {
"name": "WAP",
"control": {
"type": "checkbox",
"value": false
}
},
"WAP2": {
"name": "WAP 2.0",
"control": {
"type": "checkbox",
"value": false
}
},
"MDS": {
"name": "MDS",
"control": {
"type": "checkbox",
"value": true
}
},
"BISB": {
"name": "BIS B",
"control": {
"type": "checkbox",
"value": true
}
},
"Unite": {
"name": "Unite!",
"control": {
"type": "checkbox",
"value": false
}
},
"TCPWifi": {
"name": "Wifi TCP",
"control": {
"type": "checkbox",
"value": true
}
}
},
"identity": {
"PIN": {
"name": "PIN",
"control": {
"type": "text",
"value": "43A8C489"
}
}
},
"battery": {
"state": {
"name": "Handset is Charging",
"control": {
"type": "checkbox",
"value": true
},
"callback": function (setting) {
event.trigger("DeviceBatteryStateChanged", [setting]);
}
},
"level": {
"name": "Charge Level (% remaining)",
"control": {
"type": "select",
"value": 100
},
"options": (function () {
var i,
optionList = {};

for (i = 0; i <= 100; i++) {
optionList[i] = i;
}

return optionList;
}()),
"callback": function (setting) {
event.trigger("DeviceBatteryLevelChanged", [setting]);
}
}
},
"system": {
"isMassStorageActive": {
"name": "Mass Storage Is Connected",
"control": {
"type": "checkbox",
"value": true
}
},
"hasDataCoverage": {
"name": "Has Data Coverage",
"control": {
"type": "checkbox",
"value": true
},
"callback": function (setting) {
event.trigger("CoverageChange");
}
},
"network": {
"name": "Data Network",
"control": {
"type": "select",
"value": "3GPP"
},
"options": {
"3GPP" : "3GPP",
"CDMA": "CDMA",
"iDEN": "iDEN",
"Wi-Fi": "Wi-Fi"
},
"callback": function (setting) {
event.trigger("CoverageChange");
}
}
}
};
Loading

0 comments on commit 6ce34ae

Please sign in to comment.