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