From a70eb598ef2392c2adf3ad1e2b80b3b57ef02939 Mon Sep 17 00:00:00 2001 From: pelya Date: Wed, 3 Nov 2010 17:42:59 +0200 Subject: [PATCH] EditableSurfaceView by Angus Lees, not yet integrated --- project/java/EditableSurfaceView.java | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 project/java/EditableSurfaceView.java diff --git a/project/java/EditableSurfaceView.java b/project/java/EditableSurfaceView.java new file mode 100644 index 000000000..e22bf593c --- /dev/null +++ b/project/java/EditableSurfaceView.java @@ -0,0 +1,69 @@ +// EditableSurfaceView by Angus Lees, taken from ScummVM + +package org.inodes.gus.scummvm; + +import android.content.Context; +import android.text.InputType; +import android.util.AttributeSet; +import android.view.SurfaceView; +import android.view.inputmethod.BaseInputConnection; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputMethodManager; +import android.view.KeyEvent; + +public class EditableSurfaceView extends SurfaceView { + public EditableSurfaceView(Context context) { + super(context); + } + + public EditableSurfaceView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public EditableSurfaceView(Context context, AttributeSet attrs, + int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public boolean onCheckIsTextEditor() { + return true; + } + + private class MyInputConnection extends BaseInputConnection { + public MyInputConnection() { + super(EditableSurfaceView.this, false); + } + + @Override + public boolean performEditorAction(int actionCode) { + if (actionCode == EditorInfo.IME_ACTION_DONE) { + InputMethodManager imm = (InputMethodManager) + getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(getWindowToken(), 0); + } + return super.performEditorAction(actionCode); // Sends enter key + } + + @Override + public boolean sendKeyEvent(KeyEvent event) + { + System.out.println("SDL: MyInputConnection: got key " + event.toString() ); + return true; + } + } + + @Override + public InputConnection onCreateInputConnection(EditorInfo outAttrs) { + outAttrs.initialCapsMode = 0; + outAttrs.initialSelEnd = outAttrs.initialSelStart = -1; + outAttrs.inputType = (InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_NORMAL | + InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE); + outAttrs.imeOptions = (EditorInfo.IME_ACTION_DONE | + EditorInfo.IME_FLAG_NO_EXTRACT_UI); + + return new MyInputConnection(); + } +}