Search in sources :

Example 11 with UtteranceRewriter

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

the class SpeechInputMethodService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Log.i("onCreate");
    mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    mCommandEditor = new InputConnectionCommandEditor(getApplicationContext());
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    mRes = getResources();
    mRuleManager = new RuleManager();
    Rewrites rewritesClip = new Rewrites(mPrefs, mRes, REWRITES_NAME_CLIP);
    if (rewritesClip.isSelected()) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO: remove the listener onFinish
        clipboard.addPrimaryClipChangedListener(() -> {
            ClipData clipData = clipboard.getPrimaryClip();
            if (clipData != null) {
                String clip = clipData.getItemAt(0).getText().toString();
                // Empty strings make less sense as clips
                if (!clip.isEmpty()) {
                    UtteranceRewriter ur = mRuleManager.addRecent(clip, rewritesClip.getRewrites());
                    PreferenceUtils.putPrefMapEntry(mPrefs, mRes, R.string.keyRewritesMap, REWRITES_NAME_CLIP, ur.toTsv());
                    mCommandEditor.setRewriters(Utils.makeList(Utils.genRewriters(mPrefs, mRes, null, mRuleManager.getCommandMatcher())));
                }
            }
        });
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) RuleManager(ee.ioc.phon.android.speechutils.editor.RuleManager) Rewrites(ee.ioc.phon.android.speak.model.Rewrites) UtteranceRewriter(ee.ioc.phon.android.speechutils.editor.UtteranceRewriter) InputConnectionCommandEditor(ee.ioc.phon.android.speechutils.editor.InputConnectionCommandEditor) ClipData(android.content.ClipData)

Aggregations

UtteranceRewriter (ee.ioc.phon.android.speechutils.editor.UtteranceRewriter)11 Intent (android.content.Intent)5 RecognizerIntent (android.speech.RecognizerIntent)3 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 ExecutableString (ee.ioc.phon.android.speak.ExecutableString)2 Rewrites (ee.ioc.phon.android.speak.model.Rewrites)2 RuleManager (ee.ioc.phon.android.speechutils.editor.RuleManager)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 PendingIntent (android.app.PendingIntent)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 ComponentName (android.content.ComponentName)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 ArrayAdapter (android.widget.ArrayAdapter)1 AbstractSpeechInputViewListener (ee.ioc.phon.android.speak.view.AbstractSpeechInputViewListener)1