Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
resetting repo, readying for pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
starpax committed Oct 18, 2012
1 parent c3c27b4 commit bf4920d
Show file tree
Hide file tree
Showing 27 changed files with 3,144 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -1,2 +1,6 @@
add
.DS_Store
.metadata/
.settings/
*.[o]
webworks-1.0.2.9.js
81 changes: 81 additions & 0 deletions BB10/COMPASS/README.md
@@ -0,0 +1,81 @@
# Compass API

The Compass API allows you to read the leading of the compass in your device.

**Tested On**

* BlackBerry 10.0.9.388

**Author(s)**

* [Arman Fallah](https://github.com/starpax)

**To contribute code to this repository you must be [signed up as an official contributor](http://blackberry.github.com/howToContribute.html).**

## How To Install The Extension

1. Clone the repo to your local machine
2. Locate your BlackBerry WebWorks SDK **C:\Program Files\Research In Motion\BlackBerry 10 WebWorks SDK <version>\Framework\ext** (Windows) or **~/SDKs/BlackBerry 10 WebWorks SDK <version>/Framework/ext** (Mac)
3. Create a new directory **community.compass** in the **ext** directory
4. Copy **output/community.compass/compassJnext.so** to **/path/to/sdk/ext/community.compass/device/compassJnext.so**
5. Copy everything in **javascript_src** to **/path/to/sdk/ext/community.compass/**

## Required Feature ID
Whenever you use the below feature id in any of your WebWorks applications this extension will be loaded for use.

<feature id="community.compass" required="true" version="1.0.0.0" />

## Summary

**community.compass.readCompass()**

Return:
number - degrees from Magnetic North

Example:

<script type="text/javascript">
var leading = community.compass.readCompass();
</script>

**community.compass.startMonitoringCompass([Function:fun])**

Parameter:
fun: a one parameter method to call each second, that parameter stores the compass leading

Return:
[String] - status message of monitoring the compass

Example:

<script type="text/javascript">
function compassCallback(compassLeading)
{
document.getElementById("leading").innerHTML = "Degrees from Magnetic North: " + compassLeading;
}

function startMonitoringCompass()
{
var ret = community.compass.startMonitoringCompass(compassCallback);
alert(ret);
}
</script>

**community.compass.stopMonitoringCompass()**

Return:
[String] - status message of stopping the monitoring the compass

Example:

<script type="text/javascript">
function stopMonitoringCompass()
{
var ret = community.compass.stopMonitoringCompass();
alert(ret);
}
</script>

## Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions BB10/COMPASS/TestApplication/README.md
@@ -0,0 +1,3 @@
# Where to find the missing file webworks-1.0.0.7.js

You will find it under Framework/clientFiles/webworks-1.0.0.7.js in your WebWorks SDK installation folder and copy it to this folder.
30 changes: 30 additions & 0 deletions BB10/COMPASS/TestApplication/config.xml
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2012 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.
-->
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0.0"
id="CompassExtension">
<name>Compass Test</name>
<content src="index.htm"/>
<author>
Research In Motion Ltd.
</author>
<description>This application shows how to use the compass extension.</description>
<feature id="community.compass" required="true" version="1.0.0.0"/>
<access uri="*"/>
<license href="http://www.apache.org/licenses/LICENSE-2.0">My License</license>
</widget>
42 changes: 42 additions & 0 deletions BB10/COMPASS/TestApplication/index.htm
@@ -0,0 +1,42 @@
<html>
<head>
<title>Community - Compass Extension</title>
<script type="text/javascript" src="webworks-1.0.2.9.js"></script>
<script type="text/javascript">
function compassCallback(compassLeading) {
document.getElementById("leading").innerHTML = "Degrees from Magnetic North: " + compassLeading;
}

function startMonitoringCompass() {
var ret = community.compass.startMonitoringCompass(compassCallback);
alert(ret);
}

function getCompassLeading() {
var ret = community.compass.readCompass();
alert(ret);
}

function stopMonitoringCompass() {
var ret = community.compass.stopMonitoringCompass();
alert(ret);
}
</script>
</head>
<body bgcolor="#FF9900">
<div align="center">
<button style="width:280px; height: 240px; font-size: 200%; background-color: lightgreen" onClick="startMonitoringCompass()">
Start Monitoring Compass
</button>
<button style="width:280px; height: 240px; font-size: 200%; background-color: lightgreen" onClick="stopMonitoringCompass()">
Stop Monitoring Compass
</button>
<button style="width:280px; height: 240px; font-size: 200%; background-color: lightgreen" onClick="getCompassLeading()">
Get Compass Leading
</button>
<br />
</div>
<div id="leading" style="font-size: 200%; background-color: lightblue">
</div>
</body>
</html>
38 changes: 38 additions & 0 deletions BB10/COMPASS/javascript_src/client.js
@@ -0,0 +1,38 @@
/*
* Copyright 2012 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 _self = {},
_ID = require("./manifest.json").namespace;

_self.readCompass = function (cb)
{
return window.webworks.execSync(_ID, "readCompassServer", null);
};

_self.stopMonitoringCompass = function (cb)
{
return window.webworks.execSync(_ID, "stopMonitoringCompassServer", null);
};


_self.startMonitoringCompass = function (cb)
{
window.webworks.event.add(_ID, "community.compass.compassEvent", cb);

return window.webworks.execSync(_ID, "startMonitoringCompassServer", null);
};

module.exports = _self;
121 changes: 121 additions & 0 deletions BB10/COMPASS/javascript_src/index.js
@@ -0,0 +1,121 @@
/*
* Copyright 2012 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 compassJNext,
_event = require("../../lib/event");

module.exports =
{
startMonitoringCompassServer: function (success, fail, args, env)
{
try
{
success(compassJNext.startMonitoringCompassJNext());
}
catch (e)
{
fail(-1, e);
}
},

stopMonitoringCompassServer: function (success, fail, args, env)
{
try
{
success(compassJNext.stopMonitoringCompassJNext());
}
catch (e)
{
fail(-1, e);
}
},

readCompassServer: function (success, fail, args, env)
{
try
{
success(compassJNext.readCompassJNext());
}
catch (e)
{
fail(-1, e);
}
},
};

///////////////////////////////////////////////////////////////////
// JavaScript wrapper for JNEXT plugin
///////////////////////////////////////////////////////////////////

JNEXT.CompassJNext = function ()
{
var _self = this;

_self.startMonitoringCompassJNext = function ()
{
return JNEXT.invoke(_self._id, "startMonitoringNative");
};

_self.stopMonitoringCompassJNext = function ()
{
return JNEXT.invoke(_self._id, "stopMonitoringNative");
};

_self.readCompassJNext = function ()
{
return JNEXT.invoke(_self._id, "readCompassNative");
};

_self.getId = function ()
{
return _self._id;
};

_self.init = function ()
{
if (!JNEXT.require("compassJnext"))
{
return false;
}

_self._id = JNEXT.createObject("compassJnext.Compass");

if (!_self._id || _self._id === "")
{
return false;
}

JNEXT.registerEvents(_self);
};

_self.onEvent = function (strData)
{
var arData = strData.split(" "),
strEventId = arData[0],
arg = arData[1];

// Trigger the event handler of specific Push events
if (strEventId === "CompassLeading")
{
_event.trigger("community.compass.compassEvent", arg);
}
};

_self._id = "";

_self.init();
};

compassJNext = new JNEXT.CompassJNext();
5 changes: 5 additions & 0 deletions BB10/COMPASS/javascript_src/manifest.json
@@ -0,0 +1,5 @@
{
"global": false,
"namespace": "community.compass",
"dependencies": []
}

0 comments on commit bf4920d

Please sign in to comment.