Search in sources :

Example 1 with Command

use of ee.ioc.phon.android.speechutils.editor.Command in project speechutils by Kaljurand.

the class IntentUtils method rewriteResultWithExtras.

public static String rewriteResultWithExtras(Context context, Bundle extras, String result) {
    String defaultResultUtterance = null;
    String defaultResultCommand = null;
    String defaultResultArg1 = null;
    if (extras.getBoolean(Extras.EXTRA_RESULT_LAUNCH_AS_ACTIVITY)) {
        defaultResultUtterance = "(.+)";
        defaultResultCommand = "activity";
        defaultResultArg1 = "$1";
    }
    String resultUtterance = extras.getString(Extras.EXTRA_RESULT_UTTERANCE, defaultResultUtterance);
    if (resultUtterance != null) {
        String resultReplacement = extras.getString(Extras.EXTRA_RESULT_REPLACEMENT, null);
        String resultCommand = extras.getString(Extras.EXTRA_RESULT_COMMAND, defaultResultCommand);
        String resultArg1 = extras.getString(Extras.EXTRA_RESULT_ARG1, defaultResultArg1);
        String resultArg2 = extras.getString(Extras.EXTRA_RESULT_ARG2, null);
        String[] resultArgs;
        if (resultArg1 == null) {
            resultArgs = null;
        } else if (resultArg2 == null) {
            resultArgs = new String[] { resultArg1 };
        } else {
            resultArgs = new String[] { resultArg1, resultArg2 };
        }
        List<Command> commands = new ArrayList<>();
        commands.add(new Command(resultUtterance, resultReplacement, resultCommand, resultArgs));
        result = launchIfIntent(context, new UtteranceRewriter(commands), result);
    }
    if (result != null) {
        String rewritesAsStr = extras.getString(Extras.EXTRA_RESULT_REWRITES_AS_STR, null);
        if (rewritesAsStr != null) {
            result = launchIfIntent(context, new UtteranceRewriter(rewritesAsStr), result);
        }
    }
    return result;
}
Also used : Command(ee.ioc.phon.android.speechutils.editor.Command) ArrayList(java.util.ArrayList) UtteranceRewriter(ee.ioc.phon.android.speechutils.editor.UtteranceRewriter)

Aggregations

Command (ee.ioc.phon.android.speechutils.editor.Command)1 UtteranceRewriter (ee.ioc.phon.android.speechutils.editor.UtteranceRewriter)1 ArrayList (java.util.ArrayList)1