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