Search in sources :

Example 1 with TiActivitySupport

use of org.appcelerator.titanium.util.TiActivitySupport in project Utterance by benbahrenburg.

the class SpeechToTextProxy method startSpeechToText.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Kroll.method
public void startSpeechToText(HashMap hm) {
    KrollDict args = new KrollDict(hm);
    try {
        //start the speech recognition intent passing required data
        Intent listenIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        //indicate package
        listenIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
        if (args.containsKeyAndNotNull(PROPERTY_PROMPT)) {
            //message to display while listening
            listenIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, args.getString(PROPERTY_PROMPT));
        }
        //set speech model
        listenIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, args.optString(LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM));
        //specify number of results to retrieve
        listenIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, args.optInt(MAX_RESULTS, 10));
        final Activity activity = TiApplication.getAppCurrentActivity();
        final TiActivitySupport activitySupport = (TiActivitySupport) activity;
        activitySupport.launchActivityForResult(listenIntent, INTENT_ID, this);
        if (hasListeners(EVENT_STARTED)) {
            HashMap<String, Object> event = new HashMap<String, Object>();
            event.put("success", true);
            fireEvent(EVENT_STARTED, event);
            Log.d(UtteranceModule.MODULE_FULL_NAME, "event: " + EVENT_STARTED + " fired");
        } else {
            Log.d(UtteranceModule.MODULE_FULL_NAME, "event: " + EVENT_STARTED + " not found");
        }
    } catch (Exception error) {
        Log.e(UtteranceModule.MODULE_FULL_NAME, error.getMessage());
        error.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) TiActivitySupport(org.appcelerator.titanium.util.TiActivitySupport) Activity(android.app.Activity) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) KrollDict(org.appcelerator.kroll.KrollDict)

Example 2 with TiActivitySupport

use of org.appcelerator.titanium.util.TiActivitySupport in project Utterance by benbahrenburg.

the class InstallTTSDataProxy method CheckDataInstalled.

@Kroll.method
public void CheckDataInstalled() {
    Intent checkTTSIntent = new Intent();
    checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    final TiActivitySupport activitySupport = (TiActivitySupport) activity;
    activitySupport.launchActivityForResult(checkTTSIntent, CHECK_INSTALL_INTENT_ID, this);
}
Also used : TiActivitySupport(org.appcelerator.titanium.util.TiActivitySupport) Intent(android.content.Intent)

Example 3 with TiActivitySupport

use of org.appcelerator.titanium.util.TiActivitySupport in project Utterance by benbahrenburg.

the class InstallTTSDataProxy method InstallData.

@Kroll.method
public void InstallData() {
    Intent checkTTSIntent = new Intent();
    checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    final TiActivitySupport activitySupport = (TiActivitySupport) activity;
    activitySupport.launchActivityForResult(checkTTSIntent, INSTALL_INTENT_ID, this);
}
Also used : TiActivitySupport(org.appcelerator.titanium.util.TiActivitySupport) Intent(android.content.Intent)

Example 4 with TiActivitySupport

use of org.appcelerator.titanium.util.TiActivitySupport in project titanium-barcode by mwaylabs.

the class TitaniumBarcodeModule method scan.

@Kroll.method
public void scan(KrollDict options) {
    logDebug("scan() called");
    final KrollFunction successCallback = getCallback(options, "success");
    final KrollFunction cancelCallback = getCallback(options, "cancel");
    final KrollFunction errorCallback = getCallback(options, "error");
    logDebug("launchScanActivity() called");
    final Activity activity = TiApplication.getAppCurrentActivity();
    final TiActivitySupport activitySupport = (TiActivitySupport) activity;
    final TiIntentWrapper barcodeIntent = new TiIntentWrapper(new Intent(activity, TitaniumBarcodeActivity.class));
    barcodeIntent.setWindowId(TiIntentWrapper.createActivityName("SCANNER"));
    BarcodeResultHandler resultHandler = new BarcodeResultHandler();
    resultHandler.successCallback = successCallback;
    resultHandler.cancelCallback = cancelCallback;
    resultHandler.errorCallback = errorCallback;
    resultHandler.activitySupport = activitySupport;
    resultHandler.barcodeIntent = barcodeIntent.getIntent();
    activity.runOnUiThread(resultHandler);
    logDebug("scan() ended");
}
Also used : TiActivitySupport(org.appcelerator.titanium.util.TiActivitySupport) TiIntentWrapper(org.appcelerator.titanium.util.TiIntentWrapper) Activity(android.app.Activity) Intent(android.content.Intent) KrollFunction(org.appcelerator.kroll.KrollFunction)

Aggregations

Intent (android.content.Intent)4 TiActivitySupport (org.appcelerator.titanium.util.TiActivitySupport)4 Activity (android.app.Activity)2 RecognizerIntent (android.speech.RecognizerIntent)1 HashMap (java.util.HashMap)1 KrollDict (org.appcelerator.kroll.KrollDict)1 KrollFunction (org.appcelerator.kroll.KrollFunction)1 TiIntentWrapper (org.appcelerator.titanium.util.TiIntentWrapper)1