Added QWERTY on-screen keyboard input, using built-in Android virtual keyboard and EditText widget
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,19 @@ import android.view.WindowManager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.EditText;
|
||||
import android.text.Editable;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.FrameLayout;
|
||||
import android.content.res.Configuration;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.view.View.OnKeyListener;
|
||||
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
@@ -140,7 +149,9 @@ public class MainActivity extends Activity {
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
mGLView = new DemoGLSurfaceView(this);
|
||||
setContentView(mGLView);
|
||||
_videoLayout = new FrameLayout(this);
|
||||
_videoLayout.addView(mGLView);
|
||||
setContentView(_videoLayout);
|
||||
// Receive keyboard events
|
||||
mGLView.setFocusableInTouchMode(true);
|
||||
mGLView.setFocusable(true);
|
||||
@@ -188,9 +199,55 @@ public class MainActivity extends Activity {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void hideScreenKeyboard()
|
||||
{
|
||||
if(_screenKeyboard == null)
|
||||
return;
|
||||
String text = _screenKeyboard.getText().toString();
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
if( mGLView != null )
|
||||
mGLView.nativeTextInput( text.charAt(i), text.codePointAt(i) );
|
||||
}
|
||||
_videoLayout.removeView(_screenKeyboard);
|
||||
_screenKeyboard = null;
|
||||
mGLView.setFocusableInTouchMode(true);
|
||||
mGLView.setFocusable(true);
|
||||
mGLView.requestFocus();
|
||||
};
|
||||
|
||||
public void showScreenKeyboard()
|
||||
{
|
||||
if(_screenKeyboard != null)
|
||||
return;
|
||||
class myKeyListener implements OnKeyListener
|
||||
{
|
||||
MainActivity _parent;
|
||||
myKeyListener(MainActivity parent) { _parent = parent; };
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event)
|
||||
{
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER))
|
||||
{
|
||||
_parent.hideScreenKeyboard();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
_screenKeyboard = new EditText(this);
|
||||
_screenKeyboard.setOnKeyListener(new myKeyListener(this));
|
||||
_videoLayout.addView(_screenKeyboard);
|
||||
_screenKeyboard.setFocusableInTouchMode(true);
|
||||
_screenKeyboard.setFocusable(true);
|
||||
_screenKeyboard.requestFocus();
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, final KeyEvent event) {
|
||||
// Overrides Back key to use in our app
|
||||
if(_screenKeyboard != null)
|
||||
_screenKeyboard.onKeyDown(keyCode, event);
|
||||
else
|
||||
if( mGLView != null )
|
||||
mGLView.nativeKey( keyCode, 1 );
|
||||
else
|
||||
@@ -206,16 +263,27 @@ public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, final KeyEvent event) {
|
||||
if( mGLView != null )
|
||||
mGLView.nativeKey( keyCode, 0 );
|
||||
return true;
|
||||
if(_screenKeyboard != null)
|
||||
_screenKeyboard.onKeyUp(keyCode, event);
|
||||
else
|
||||
if( mGLView != null )
|
||||
mGLView.nativeKey( keyCode, 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(final MotionEvent ev) {
|
||||
// ----- DEBUG -----
|
||||
//if( ev.getX() < 200.0 && ev.getY() < 50.0 && ev.getAction() == MotionEvent.ACTION_DOWN )
|
||||
// showScreenKeyboard();
|
||||
// ----- DEBUG -----
|
||||
if(_screenKeyboard != null)
|
||||
_screenKeyboard.dispatchTouchEvent(ev);
|
||||
else
|
||||
if(mGLView != null)
|
||||
mGLView.onTouchEvent(ev);
|
||||
else if( _btn != null )
|
||||
else
|
||||
if( _btn != null )
|
||||
return _btn.dispatchTouchEvent(ev);
|
||||
return true;
|
||||
}
|
||||
@@ -244,14 +312,42 @@ public class MainActivity extends Activity {
|
||||
this.runOnUiThread(cb);
|
||||
}
|
||||
|
||||
public void showTaskbarNotification()
|
||||
{
|
||||
showTaskbarNotification("SDL application paused", "SDL application", "Application is paused, click to activate");
|
||||
}
|
||||
|
||||
// Stolen from SDL port by Mamaich
|
||||
public void showTaskbarNotification(String text0, String text1, String text2)
|
||||
{
|
||||
NotificationManager NotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Notification n = new Notification(R.drawable.icon, text0, System.currentTimeMillis());
|
||||
n.setLatestEventInfo(this, text1, text2, pendingIntent);
|
||||
NotificationManager.notify(NOTIFY_ID, n);
|
||||
}
|
||||
|
||||
public void hideTaskbarNotification()
|
||||
{
|
||||
NotificationManager NotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationManager.cancel(NOTIFY_ID);
|
||||
}
|
||||
|
||||
static int NOTIFY_ID = 12367098; // Random ID
|
||||
|
||||
private static DemoGLSurfaceView mGLView = null;
|
||||
private static LoadLibrary mLoadLibraryStub = null;
|
||||
private static AudioThread mAudioThread = null;
|
||||
private static DataDownloader downloader = null;
|
||||
|
||||
private TextView _tv = null;
|
||||
private Button _btn = null;
|
||||
private LinearLayout _layout = null;
|
||||
private LinearLayout _layout2 = null;
|
||||
|
||||
private FrameLayout _videoLayout = null;
|
||||
private EditText _screenKeyboard = null;
|
||||
private boolean sdlInited = false;
|
||||
|
||||
}
|
||||
|
||||
@@ -465,10 +465,11 @@ class Settings
|
||||
if( Globals.UseTouchscreenKeyboard )
|
||||
{
|
||||
nativeSetTouchscreenKeyboardUsed();
|
||||
nativeSetupScreenKeyboard( Globals.TouchscreenKeyboardSize,
|
||||
nativeSetupScreenKeyboard( Globals.TouchscreenKeyboardSize,
|
||||
Globals.TouchscreenKeyboardTheme,
|
||||
Globals.AppTouchscreenKeyboardKeysAmount,
|
||||
Globals.AppTouchscreenKeyboardKeysAmountAutoFire);
|
||||
Globals.AppTouchscreenKeyboardKeysAmount,
|
||||
Globals.AppTouchscreenKeyboardKeysAmountAutoFire,
|
||||
1, 1);
|
||||
}
|
||||
SetupTouchscreenKeyboardGraphics(p);
|
||||
String lang = new String(Locale.getDefault().getLanguage());
|
||||
@@ -516,7 +517,7 @@ class Settings
|
||||
private static native void nativeSetJoystickUsed();
|
||||
private static native void nativeSetMultitouchUsed();
|
||||
private static native void nativeSetTouchscreenKeyboardUsed();
|
||||
private static native void nativeSetupScreenKeyboard(int size, int theme, int nbuttons, int nbuttonsAutoFire);
|
||||
private static native void nativeSetupScreenKeyboard(int size, int theme, int nbuttons, int nbuttonsAutoFire, int showArrows, int showTextInput);
|
||||
private static native void nativeSetupScreenKeyboardButtons(byte[] img);
|
||||
public static native void nativeSetEnv(final String name, final String value);
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ abstract class DifferentTouchInput
|
||||
|
||||
class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
|
||||
public DemoRenderer(Activity _context)
|
||||
public DemoRenderer(MainActivity _context)
|
||||
{
|
||||
context = _context;
|
||||
}
|
||||
@@ -228,6 +228,22 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void showScreenKeyboard() // Called from native code
|
||||
{
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public MainActivity parent;
|
||||
public void run()
|
||||
{
|
||||
parent.showScreenKeyboard();
|
||||
}
|
||||
}
|
||||
Callback cb = new Callback();
|
||||
cb.parent = context;
|
||||
context.runOnUiThread(cb);
|
||||
//context.showScreenKeyboard();
|
||||
}
|
||||
|
||||
public void exitApp() {
|
||||
nativeDone();
|
||||
};
|
||||
@@ -239,7 +255,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
private native void nativeGlContextLost();
|
||||
public native void nativeGlContextRecreated();
|
||||
|
||||
private Activity context = null;
|
||||
private MainActivity context = null;
|
||||
private AccelerometerReader accelerometer = null;
|
||||
|
||||
private EGL10 mEgl = null;
|
||||
@@ -253,7 +269,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
}
|
||||
|
||||
class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
public DemoGLSurfaceView(Activity context) {
|
||||
public DemoGLSurfaceView(MainActivity context) {
|
||||
super(context);
|
||||
mParent = context;
|
||||
touchInput = DifferentTouchInput.getInstance();
|
||||
@@ -306,11 +322,14 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
}
|
||||
|
||||
DemoRenderer mRenderer;
|
||||
Activity mParent;
|
||||
MainActivity mParent;
|
||||
DifferentTouchInput touchInput = null;
|
||||
|
||||
public static native void nativeMouse( int x, int y, int action, int pointerId, int pressure, int radius );
|
||||
public static native void nativeKey( int keyCode, int down );
|
||||
public static native void nativeTextInput( int ascii, int unicode );
|
||||
public static native void initJavaCallbacks();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user