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

Commit

Permalink
Merge pull request #5 from blackberry-webworks/invoker-update
Browse files Browse the repository at this point in the history
fixes invoker after BlobBuilder deprecation and uses ArrayBufferView ins...
  • Loading branch information
haahmad committed Oct 2, 2012
2 parents 7613de2 + bc45a2d commit 66be347
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
1 change: 1 addition & 0 deletions invoke/invoker/config.xml
Expand Up @@ -30,4 +30,5 @@ limitations under the License.
<rim:permit>access_shared</rim:permit>
</rim:permissions>
<feature id="blackberry.invoke" required="true" version="1.0.0.0"/>
<feature id="blackberry.io" required="true" version="1.0.0.0" />
</widget>
8 changes: 6 additions & 2 deletions invoke/invoker/index.html
Expand Up @@ -18,7 +18,11 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="webworks-1.0.1.5.js"></script>
<script src="webworks-1.0.0.7.js"></script>
<!--
Include BlackBerry 10 WebWorks JavaScript framework file.
When doing an SDK upgrade, always make sure you grab the latest from the SDK/Framework/clientFiles folder.
-->
<script src="invocations.js"></script>
<link rel="stylesheet" type="text/css" href="jquery/jquery.mobile-1.1.0.min.css" />
<script src="jquery/jquery-1.7.1.min.js"></script>
Expand All @@ -31,7 +35,7 @@
document.getElementById("adobeReader").onclick = invokeAdobeReader;
document.getElementById("adobeReaderPdf").onclick = invokeAdobeReaderPdf;
document.getElementById("userApp").onclick = invokeApp;
document.getElementById("pictures").onclick = invokePictures;
document.getElementById("pictures").onclick = saveFileInvoke;
}
//register ready event after window has loaded
window.addEventListener("load", function (e) {
Expand Down
59 changes: 21 additions & 38 deletions invoke/invoker/invocations.js
Expand Up @@ -66,50 +66,33 @@ function invokeApp() {
}, onSuccess, onError);
}

//This is an unbound invocation (no target specified): the OS will choose what target to use based on URI
function invokePictures() {

downloadPicture();

blackberry.invoke.invoke({
uri: "file:///accounts/1000/shared/downloads/cliffs.jpg",
}, onSuccess, onError);
}

//Supported in HTML5: getting binary data from XHR request
function downloadPicture() {
function saveFileInvoke () {
var xhr = new XMLHttpRequest();
xhr.open('GET', "/cliffs.jpg", true);
xhr.responseType = 'arraybuffer';
xhr.open('GET', '/cliffs.jpg', false);
xhr.responseType = 'blob';

xhr.onload = function(e) {
if (this.status == 200) {
var bb = new window.WebKitBlobBuilder();
bb.append(this.response);
var blob = bb.getBlob('image/jpeg');
saveFile(blob);
}
};
xhr.send();
}
blackberry.io.sandbox = false;
window.webkitRequestFileSystem(PERSISTENT, 1024 * 1024, function(fs) {
fs.root.getFile(blackberry.io.sharedFolder + '/downloads/cliffs.jpg', {create: true}, function(fileEntry) {
fileEntry.createWriter(function(writer) {

//This function demonstrates how to use the HTML5 FileSystem API: a .png blob is saved to a URI which is used for invocation
function saveFile (blob) {
function gotFs(fs) {
fs.root.getFile("/accounts/1000/shared/downloads/cliffs.jpg", {create: true}, gotFile, errorHandler);
}
writer.onerror = function(e) { alert(e) };

function gotFile(fileEntry) {
fileEntry.createWriter(gotWriter, errorHandler);
}
var blob = new Blob([xhr.response], {type: 'image/jpeg'});

function gotWriter(fileWriter) {
fileWriter.onerror = function (e) {
alert("Failed to write JPEG: " + e.toString());
}
fileWriter.write(blob);
writer.write(blob);

}, errorHandler);
}, errorHandler);
}, errorHandler);
}
window.webkitRequestFileSystem(PERSISTENT, 10 * 1024, gotFs, errorHandler);

xhr.send();

blackberry.invoke.invoke({
uri: "file:///accounts/1000/shared/downloads/cliffs.jpg",
}, onSuccess, onError);
}

function errorHandler(fileError) {
Expand Down

0 comments on commit 66be347

Please sign in to comment.