Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Cheatsheet from:
- // Incorporating Native Device APIs and Sensors in Your Apps (July 23, 2014)
- // http://youtu.be/mTz5BdqKlAQ [recording]
- Beep
- navigator.notification.beep(2);
- Notifications
- navigator.notification.alert(
- 'Build apps fast with Appery.io',
- null,
- 'My App',
- 'Got it.'
- );
- function alertDismissed () {
- alert ("Nice - that worked");
- }
- Geolocation
- var onSuccess = function(position) {
- Apperyio("geolist1").text(position.coords.latitude);
- Apperyio("geolist2").text(position.coords.longitude);
- };
- function onError(error) {
- alert('code: ' + error.code + '\n' +
- 'message: ' + error.message + '\n');
- }
- navigator.geolocation.getCurrentPosition(onSuccess, onError);
- Accelerometer
- $t.AccelerometerImplementation = $t.createClass(null, {
- init: function(requestOptions) {
- this.__requestOptions = $.extend({}, requestOptions);
- },
- process: function(settings) {
- if (this.__requestOptions.echo) {
- settings.success(this.__requestOptions.echo);
- } else {
- var watchID = localStorage.getItem("watchID"); //get the watchID variable
- if (watchID) { //check if it already exists or not
- navigator.accelerometer.clearWatch(watchID); //if it exists clear and stop watch
- watchID = null;
- localStorage.removeItem("watchID"); //remove this variable from the local storage
- $('[dsid=stop_watch_button]').find('.ui-btn-inner').text('Start watch'); //change button text to "Start watch"
- } else {
- //if it is not exists start watch for accelerometer data
- var options = { frequency: parseInt(settings.data.frequency)};
- watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options); //create new watchID
- localStorage.setItem("watchID", watchID); //save new watchID to the local storage
- $('[dsid=stop_watch_button]').find('.ui-btn-inner').text('Stop watch'); //change button text to "Stop watch"
- }
- }
- function onSuccess(acceleration) {
- var accelerometerData = 'AccelerationX: ' + acceleration.x + '\n'
- +'AccelerationY: ' + acceleration.y + '\n'
- +'AccelerationZ: ' + acceleration.z + '\n'
- +'Timestamp: ' + acceleration.timestamp;
- settings.success({'accelerometerData': accelerometerData});
- }
- //This fires in case of error
- function onError() {
- var accelerometerData = 'Error!';
- settings.success({'accelerometerData': accelerometerData});
- }
- settings.complete('success');
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement