Skip to content

Instantly share code, notes, and snippets.

@AppWerft
Created March 30, 2015 13:01
Show Gist options
  • Save AppWerft/ca7113b78edd687fa308 to your computer and use it in GitHub Desktop.
Save AppWerft/ca7113b78edd687fa308 to your computer and use it in GitHub Desktop.
Pebble communication
var Pebble = require('com.mcongrove.pebble'),
Moment = require('vendor/moment'),
alarmManagerModule = require('bencoding.alarmmanager');
alarmManagerModule.enableLogging();
var Модул = function(_args) {
Pebble.setAppUUID("226834ae-786e-4302-a52f-6e7efc9f990b");
var seconds = Moment(_args.time_isostring).unix() - Moment().unix();
this.alarmManager = alarmManagerModule.createAlarmManager();
this.alarmManager.addAlarmNotification({
service : 'de.appwerft.hoerdat.RadioweckerService',
requestCode : parseInt(seconds) - 600,
second : parseInt(seconds) - 600,
showLights : true,
contentTitle : _args.title.trim(),
contentText : _args.station + ' :: ' + Moment(_args.time_isostring).format('dddd HH:mm') + ' Uhr\nvorgemerkt',
icon : Ti.App.Android.R.drawable.appicon,
playSound : true,
sound : Ti.Filesystem.getResRawDirectory() + 'kkj', //Set a custom sound to play
});
Ti.Media.vibrate([0, 40]);
Ti.Android.NotificationManager.notify(1, Ti.Android.createNotification({
contentTitle : _args.title.trim(),
contentText : 'beginnt in 10 Minuten auf ' + _args.station,
contentIntent : Ti.Android.createPendingIntent({
intent : Ti.Android.createIntent({})
}),
playSound : true,
sound : Ti.Filesystem.getResRawDirectory() + 'kkj',
icon : Ti.App.Android.R.drawable.appicon,
number : 1,
when : Moment(_args.time_isostring).toDate()
}));
Ti.UI.createNotification({
message : _args.station + ' :: ' + Moment(_args.time_isostring).format('dddd HH:mm') + ' Uhr\nvorgemerkt'
}).show();
Pebble.connect({
success : function(_event) {
console.log(_event);
console.log("Connected to Pebble");
},
error : function(_event) {
console.log("Cannot Connect to Pebble");
}
});
};
Модул.prototype = {};
exports.createReminder = function(_args) {
return new Модул(_args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment