Created
October 22, 2014 02:08
-
-
Save jasalt/36e099140e872b74216f to your computer and use it in GitHub Desktop.
pebble-coffee-watch-app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Helpers */ | |
| // Send request to server | |
| var sendRequest = function(substance){ | |
| var req = new XMLHttpRequest(); | |
| req.open('GET', 'http://XXsecretXX:YY/' + substance, true); | |
| req.onload = function (e) { | |
| if (req.readyState === 4) { | |
| if (req.status === 200) { | |
| console.log(req.responseText); | |
| successfulAction(); | |
| // Navigate back to start | |
| //successfulAction(); | |
| } else { | |
| console.error(req.statusText); | |
| } | |
| } | |
| }; | |
| req.onerror = function (e) { | |
| console.error(req.statusText); | |
| }; | |
| req.send(); | |
| }; | |
| // Hide menu and get back to start-screen | |
| var successfulAction = function(){ | |
| menu.hide(); | |
| var splashScreen = new UI.Card({ title: "200/OK/Oh yeah!" }); | |
| splashScreen.show(); | |
| setTimeout(function() { | |
| main.show(); | |
| // Hide the splashScreen to avoid showing it when the user press Back. | |
| splashScreen.hide(); | |
| }, 700); | |
| }; | |
| /* Define UI */ | |
| var UI = require('ui'); | |
| var menu = new UI.Menu({ | |
| sections: [{ | |
| items: [{ | |
| title: 'Coffee', | |
| icon: 'images/coffee.png', | |
| subtitle: 'Drank a cup of coffee.' | |
| }, { | |
| title: 'Yerba Mate', | |
| icon: 'images/mate.png', | |
| subtitle: 'Drank a decent amount of mate.' | |
| }] | |
| }] | |
| }); | |
| menu.on('select', function(e) { | |
| switch(e.itemIndex) { | |
| case 0: | |
| sendRequest("coffee"); | |
| break; | |
| case 1: | |
| sendRequest("mate"); | |
| break; | |
| default: | |
| console.log("missed case.."); | |
| break; | |
| } | |
| console.log('Selected item #' + e.itemIndex + ' of section #' + e.sectionIndex); | |
| console.log('The item is titled "' + e.item.title + '"'); | |
| }); | |
| var main = new UI.Card({ | |
| title: '!@#$', | |
| icon: 'images/coffee.png', | |
| subtitle: 'coffee-watcher', | |
| body: 'Press UP-key.' | |
| }); | |
| main.on('click', 'up', function(e) { | |
| menu.show(); | |
| }); | |
| main.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment