use of org.appcelerator.kroll.KrollDict in project benCoding.AlarmManager by benbahrenburg.
the class AlarmManagerProxy method cancelAlarmService.
@Kroll.method
public void cancelAlarmService(@Kroll.argument(optional = true) Object requestCode) {
// To cancel an alarm the signature needs to be the same as the submitting one.
utils.infoLog("Cancelling Alarm Service");
int intentRequestCode = AlarmmanagerModule.DEFAULT_REQUEST_CODE;
if (requestCode != null) {
if (requestCode instanceof Number) {
intentRequestCode = ((Number) requestCode).intValue();
}
}
//Create a placeholder for the args value
HashMap<String, Object> placeholder = new HashMap<String, Object>(0);
KrollDict args = new KrollDict(placeholder);
//Create the Alarm Manager
AlarmManager am = (AlarmManager) TiApplication.getInstance().getApplicationContext().getSystemService(TiApplication.ALARM_SERVICE);
Intent intent = createAlarmServiceIntent(args);
PendingIntent sender = PendingIntent.getBroadcast(TiApplication.getInstance().getApplicationContext(), intentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(sender);
sender.cancel();
utils.infoLog("Alarm Service Canceled");
}
use of org.appcelerator.kroll.KrollDict in project benCoding.AlarmManager by benbahrenburg.
the class AlarmProxy method addAlarmService.
@SuppressWarnings("unchecked")
@Kroll.method
public void addAlarmService(@SuppressWarnings("rawtypes") HashMap hm) {
Log.d(AlarmmanagerModule.MODULE_FULL_NAME, "Start creating Alarm Service Request");
KrollDict args = new KrollDict(hm);
String serviceName = args.getString("service_name");
Calendar defaultDay = Calendar.getInstance();
int day = args.optInt("day", defaultDay.get(Calendar.DAY_OF_MONTH));
int month = args.optInt("month", defaultDay.get(Calendar.MONTH));
int year = args.optInt("year", defaultDay.get(Calendar.YEAR));
int hour = args.optInt("hour", defaultDay.get(Calendar.HOUR_OF_DAY));
int minute = args.optInt("minute", defaultDay.get(Calendar.MINUTE));
Calendar cal = new GregorianCalendar(year, month, day);
cal.add(Calendar.HOUR_OF_DAY, hour);
cal.add(Calendar.MINUTE, minute);
AlarmManager am = (AlarmManager) TiApplication.getInstance().getApplicationContext().getSystemService(TiApplication.ALARM_SERVICE);
Intent intent = new Intent(TiApplication.getInstance().getApplicationContext(), AlarmServiceListener.class);
intent.putExtra("alarm_service_name", serviceName);
PendingIntent sender = PendingIntent.getBroadcast(TiApplication.getInstance().getApplicationContext(), 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
Log.d(AlarmmanagerModule.MODULE_FULL_NAME, "Alarm Created");
}
use of org.appcelerator.kroll.KrollDict in project Utterance by benbahrenburg.
the class SpeechProxy method startSpeaking.
@Kroll.method
@SuppressWarnings({ "rawtypes", "unchecked" })
public void startSpeaking(HashMap hm) {
KrollDict args = new KrollDict(hm);
if (!args.containsKeyAndNotNull("text")) {
Log.e(_logName, "the text parameter is required");
return;
}
_text = args.getString("text");
_voice = "auto";
if (args.containsKeyAndNotNull("voice") || args.containsKeyAndNotNull("language")) {
if (args.containsKeyAndNotNull("language")) {
_voice = args.getString("language");
} else {
_voice = args.getString("voice");
}
if (_voice != "auto") {
if (isLanguageAvailable(_voice)) {
_tts.setLanguage(toLocale(_voice));
} else {
Log.e(_logName, "Unsupported Language provided.");
}
}
}
if (args.containsKeyAndNotNull("rate")) {
double dRate = args.getDouble("rate");
_tts.setSpeechRate((float) (dRate));
}
if (args.containsKeyAndNotNull("pitch")) {
double dPitch = args.getDouble("pitch");
_tts.setPitch((float) (dPitch));
}
//Need to add this so OnUtteranceCompletedListener will fire
HashMap<String, String> options = new HashMap<String, String>();
options.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "FINISHED PLAYING");
_tts.speak(_text, TextToSpeech.QUEUE_FLUSH, options);
doListener("started");
}
Aggregations