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();
}
}
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);
}
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);
}
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");
}
Aggregations