Search in sources :

Example 1 with InputConnectionCommandEditor

use of ee.ioc.phon.android.speechutils.editor.InputConnectionCommandEditor 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)

Example 2 with InputConnectionCommandEditor

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

the class SpeechInputMethodService method onStartInputView.

/**
 * Note that when editing a HTML page, then switching between form fields might fail to call
 * this method with restarting=false, we thus always update the editor info (incl. inputType).
 */
@Override
public void onStartInputView(EditorInfo editorInfo, boolean restarting) {
    super.onStartInputView(editorInfo, restarting);
    Log.i("onStartInputView: " + editorInfo.inputType + "/" + editorInfo.imeOptions + "/" + restarting);
    InputConnection ic = getCurrentInputConnection();
    // TODO: review, e.g. move to after restarting-check
    if (ic == null) {
        toast(R.string.errorFailedGetCurrentInputConnection);
        // switchToLastIme();
        return;
    }
    ((InputConnectionCommandEditor) mCommandEditor).setInputConnection(ic);
    // TODO: quick hack to add app to the matcher, not sure if we can access the class name of the app
    // TODO: use getPackageName() or editorInfo.packageName, but not both
    String packageName = editorInfo.packageName;
    ComponentName app = new ComponentName(packageName, packageName);
    mInputView.init(R.array.keysIme, new CallerInfo(makeExtras(), editorInfo, getPackageName()), true, app);
    // TODO: update this less often (in onStart)
    closeSession();
    if (restarting) {
        return;
    }
    mInputView.setListener(getSpeechInputViewListener(getMyWindow(), app, mRuleManager), editorInfo);
    mShowPartialResults = PreferenceUtils.getPrefBoolean(mPrefs, mRes, R.string.keyImeShowPartialResults, R.bool.defaultImeShowPartialResults);
    // Launch recognition immediately (if set so)
    if (PreferenceUtils.getPrefBoolean(mPrefs, mRes, R.string.keyImeAutoStart, R.bool.defaultImeAutoStart)) {
        Log.i("Auto-starting");
        mInputView.start();
    }
}
Also used : InputConnection(android.view.inputmethod.InputConnection) CallerInfo(ee.ioc.phon.android.speak.model.CallerInfo) ComponentName(android.content.ComponentName) InputConnectionCommandEditor(ee.ioc.phon.android.speechutils.editor.InputConnectionCommandEditor)

Aggregations

InputConnectionCommandEditor (ee.ioc.phon.android.speechutils.editor.InputConnectionCommandEditor)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 ComponentName (android.content.ComponentName)1 InputConnection (android.view.inputmethod.InputConnection)1 CallerInfo (ee.ioc.phon.android.speak.model.CallerInfo)1 Rewrites (ee.ioc.phon.android.speak.model.Rewrites)1 RuleManager (ee.ioc.phon.android.speechutils.editor.RuleManager)1 UtteranceRewriter (ee.ioc.phon.android.speechutils.editor.UtteranceRewriter)1