Search in sources :

Example 6 with KrollDict

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");
}
Also used : HashMap(java.util.HashMap) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) KrollDict(org.appcelerator.kroll.KrollDict)

Example 7 with KrollDict

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");
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) KrollDict(org.appcelerator.kroll.KrollDict)

Example 8 with KrollDict

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");
}
Also used : HashMap(java.util.HashMap) KrollDict(org.appcelerator.kroll.KrollDict)

Aggregations

KrollDict (org.appcelerator.kroll.KrollDict)8 Intent (android.content.Intent)6 AlarmManager (android.app.AlarmManager)5 PendingIntent (android.app.PendingIntent)5 HashMap (java.util.HashMap)4 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Activity (android.app.Activity)1 RecognizerIntent (android.speech.RecognizerIntent)1 TiActivitySupport (org.appcelerator.titanium.util.TiActivitySupport)1