Search in sources :

Example 6 with UtteranceRewriter

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

the class Utils method genRewriters.

/**
 * Generates rewriters based on the list of names of rewrite tables.
 * If a name does not resolve to a rewrite table then generates null.
 * If the given list is null, then the default rewriter is returned (currently at most one).
 * Passing an empty list effectively turns off rewriting.
 */
public static Iterable<UtteranceRewriter> genRewriters(final SharedPreferences prefs, final Resources resources, String[] rewritesByName, String language, ComponentName service, ComponentName app) {
    final String[] names;
    if (rewritesByName == null) {
        Set<String> defaults = PreferenceUtils.getPrefStringSet(prefs, resources, R.string.defaultRewriteTables);
        if (defaults.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        names = defaults.toArray(new String[defaults.size()]);
        // TODO: defaults should be a list (not a set that needs to be sorted)
        Arrays.sort(names);
    } else {
        names = rewritesByName;
    }
    final int length = names.length;
    if (length == 0) {
        return Collections.EMPTY_LIST;
    }
    final CommandMatcher commandMatcher = CommandMatcherFactory.createCommandFilter(language, service, app);
    return new Iterable<UtteranceRewriter>() {

        @Override
        public Iterator<UtteranceRewriter> iterator() {
            return new Iterator<UtteranceRewriter>() {

                private int mCurrent = 0;

                @Override
                public boolean hasNext() {
                    return mCurrent < length;
                }

                @Override
                public UtteranceRewriter next() {
                    String rewritesAsStr = PreferenceUtils.getPrefMapEntry(prefs, resources, R.string.keyRewritesMap, names[mCurrent++]);
                    if (rewritesAsStr == null) {
                        return null;
                    }
                    return new UtteranceRewriter(rewritesAsStr, commandMatcher);
                }
            };
        }
    };
}
Also used : CommandMatcher(ee.ioc.phon.android.speechutils.editor.CommandMatcher) Iterator(java.util.Iterator) UtteranceRewriter(ee.ioc.phon.android.speechutils.editor.UtteranceRewriter) ExecutableString(ee.ioc.phon.android.speak.ExecutableString) SpannableString(android.text.SpannableString) Paint(android.graphics.Paint)

Example 7 with UtteranceRewriter

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

the class Rewrites method getSendIntent.

public Intent getSendIntent() {
    String rewrites = PreferenceUtils.getPrefMapEntry(mPrefs, mRes, R.string.keyRewritesMap, mId);
    UtteranceRewriter ur = new UtteranceRewriter(rewrites);
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_SUBJECT, mId);
    intent.putExtra(Intent.EXTRA_TEXT, ur.toTsv());
    intent.setType("text/tab-separated-values");
    return intent;
}
Also used : UtteranceRewriter(ee.ioc.phon.android.speechutils.editor.UtteranceRewriter) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent)

Aggregations

UtteranceRewriter (ee.ioc.phon.android.speechutils.editor.UtteranceRewriter)7 Intent (android.content.Intent)3 RecognizerIntent (android.speech.RecognizerIntent)2 ArrayList (java.util.ArrayList)2 PendingIntent (android.app.PendingIntent)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 SpannableString (android.text.SpannableString)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1