|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one |
|
* or more contributor license agreements. See the NOTICE file |
|
* distributed with this work for additional information |
|
* regarding copyright ownership. The ASF licenses this file |
|
* to you 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 logMessage = function(message) { |
|
var messageLog = document.getElementById("message-log"); |
|
messageLog.textContent = message; |
|
console.log("Cordova: " + message); |
|
}; |
|
|
|
var app = { |
|
initialize: function() { |
|
this.bindEvents(); |
|
}, |
|
bindEvents: function() { |
|
document.addEventListener('deviceready', this.onDeviceReady, false); |
|
document.addEventListener('resume', this.onResume, false); |
|
document.addEventListener('pause', this.onPause, false); |
|
console.log("Cordova: Events bound!"); |
|
}, |
|
onDeviceReady: function() { |
|
app.receivedEvent('deviceready'); |
|
|
|
// Setup the picture buttons |
|
var getPicture = function(source) { |
|
navigator.camera.getPicture( |
|
function(imageUri) { |
|
var image = document.getElementById('camera-result'); |
|
image.src = imageUri; |
|
}, function(error) { |
|
logMessage(error); |
|
}, { |
|
sourceType: source, |
|
destinationType: Camera.DestinationType.FILE_URI, |
|
Quality: 50, |
|
targetWidth: 225, |
|
targetHeight: 225, |
|
correctOrientation: true, |
|
encodingType: Camera.EncodingType.JPEG, |
|
saveToPhotoAlbum: false |
|
} |
|
); |
|
}; |
|
|
|
document.getElementById("take-picture").addEventListener("click", function() { |
|
getPicture(Camera.PictureSourceType.CAMERA); |
|
}); |
|
|
|
document.getElementById("pick-picture").addEventListener("click", function() { |
|
getPicture(Camera.PictureSourceType.PHOTOLIBRARY); |
|
}); |
|
|
|
}, |
|
onPause: function() { |
|
// Here is where we should save our state in local storage |
|
}, |
|
onResume: function(event) { |
|
// Here is where we should restore the state from onPause |
|
|
|
// If the Activity was killed as part of a camera request, there will |
|
// be a pending result as part of the object |
|
if(event.pendingResult) { |
|
// Status codes can be found in PluginResult.java |
|
if(event.pendingResult.pluginStatus === "OK") { |
|
var image = document.getElementById('camera-result'); |
|
|
|
image.src = event.pendingResult.result; |
|
logMessage("Image source obtained from plugin result"); |
|
} else { |
|
logMessage("Plugin result status: " + event.pendingResult.pluginStatus + ", result: " + event.pendingResult.result); |
|
} |
|
} else { |
|
logMessage("No pending result in resume event"); |
|
} |
|
}, |
|
// Update DOM on a Received Event |
|
receivedEvent: function(id) { |
|
var parentElement = document.getElementById(id); |
|
var listeningElement = parentElement.querySelector('.listening'); |
|
var receivedElement = parentElement.querySelector('.received'); |
|
|
|
listeningElement.setAttribute('style', 'display:none;'); |
|
receivedElement.setAttribute('style', 'display:block;'); |
|
|
|
console.log('Received Event: ' + id); |
|
} |
|
}; |
|
|
|
app.initialize(); |