import android.view.View;\r
import android.view.View.OnKeyListener;\r
import android.view.View.OnTouchListener;\r
+import android.view.inputmethod.InputMethodManager;\r
import android.widget.EditText;\r
\r
import com.badlogic.gdx.Input;\r
\r
/** touch handler sleep time in milliseconds **/\r
private int sleepTime = 0;\r
+ \r
+ /** what system keys to catch **/ \r
+ private boolean catchBack = false; \r
\r
/**\r
* helper enum\r
\r
@Override public boolean onKey (View v, int keyCode, KeyEvent event) {\r
synchronized (eventQueue) {\r
+ char character = (char)event.getUnicodeChar();\r
+ \r
+ // Android doesn't report a unicode char for back space. hrm...\r
+ if( keyCode == 67 )\r
+ character = '\b';\r
+ \r
if (event.getAction() == KeyEvent.ACTION_DOWN) {\r
Event ev = freeEvents.get(freeEventIndex++);\r
- ev.set(EventType.KeyDown, 0, 0, 0, event.getKeyCode(), (char)event.getUnicodeChar());\r
+ ev.set(EventType.KeyDown, 0, 0, 0, event.getKeyCode(), character);\r
eventQueue.add(ev);\r
keys.add(event.getKeyCode());\r
}\r
keys.remove(event.getKeyCode());\r
\r
Event ev = freeEvents.get(freeEventIndex++);\r
- ev.set(EventType.KeyUp, 0, 0, 0, event.getKeyCode(), (char)event.getUnicodeChar());\r
+ ev.set(EventType.KeyUp, 0, 0, 0, event.getKeyCode(), character);\r
eventQueue.add(ev);\r
\r
ev = freeEvents.get(freeEventIndex++);\r
- ev.set(EventType.KeyTyped, 0, 0, 0, event.getKeyCode(), (char)event.getUnicodeChar());\r
+ ev.set(EventType.KeyTyped, 0, 0, 0, event.getKeyCode(), character);\r
eventQueue.add(ev);\r
}\r
}\r
-\r
+ \r
+ if( catchBack && keyCode == KeyEvent.KEYCODE_BACK ) return true;\r
return false;\r
}\r
\r
}\r
\r
@Override public void setOnscreenKeyboardVisible (boolean visible) {\r
- // FIXME\r
+ InputMethodManager manager = (InputMethodManager)app.getSystemService( Context.INPUT_METHOD_SERVICE );\r
+ if( visible ) { \r
+ manager.showSoftInput( ((AndroidGraphics)app.getGraphics()).getView(), 0 );\r
+ } else {\r
+ manager.hideSoftInputFromWindow( ((AndroidGraphics)app.getGraphics()).getView().getWindowToken(), 0 ); \r
+ } \r
}\r
\r
@Override public boolean supportsOnscreenKeyboard () {\r
return true;\r
}\r
+\r
+ @Override public void setCatchBackKey (boolean catchBack) {\r
+ this.catchBack = catchBack; \r
+ }\r
}\r
\r
package com.badlogic.gdx.tests;\r
\r
-import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.InputListener;\r
-import com.badlogic.gdx.RenderListener;\r
+import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.graphics.Font;\r
import com.badlogic.gdx.graphics.GL10;\r
import com.badlogic.gdx.graphics.Texture;\r
-import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
-import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
import com.badlogic.gdx.graphics.TextureAtlas;\r
import com.badlogic.gdx.graphics.TextureRegion;\r
+import com.badlogic.gdx.graphics.Font.FontStyle;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
import com.badlogic.gdx.math.Vector2;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
import com.badlogic.gdx.scenes.scene2d.Stage;\r
import com.badlogic.gdx.scenes.scene2d.actions.Sequence;\r
import com.badlogic.gdx.scenes.scene2d.actors.Button;\r
import com.badlogic.gdx.scenes.scene2d.actors.Image;\r
+import com.badlogic.gdx.scenes.scene2d.actors.Label;\r
import com.badlogic.gdx.scenes.scene2d.actors.LinearGroup;\r
+import com.badlogic.gdx.scenes.scene2d.actors.Button.ClickListener;\r
import com.badlogic.gdx.scenes.scene2d.actors.LinearGroup.LinearGroupLayout;\r
import com.badlogic.gdx.tests.utils.GdxTest;\r
\r
Texture badlogic;\r
TextureAtlas atlas;\r
Stage ui;\r
+ Font font;\r
\r
@Override public void surfaceCreated () {\r
if (uiTexture == null) {\r
Gdx.input.addInputListener(this);\r
+ Gdx.input.setCatchBackKey( true );\r
\r
+ font = Gdx.graphics.newFont( "Droid Sans", 20, FontStyle.Plain );\r
+ \r
uiTexture = Gdx.graphics.newTexture(Gdx.files.getFileHandle("data/ui.png", FileType.Internal), TextureFilter.Linear,\r
TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
\r
badlogic = Gdx.graphics.newTexture(Gdx.files.getFileHandle("data/badlogic.jpg", FileType.Internal),\r
- TextureFilter.MipMap, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
+ TextureFilter.MipMap, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); \r
\r
ui = new Stage(480, 320, false);\r
atlas = new TextureAtlas(uiTexture);\r
\r
Button button = new Button("button", atlas.getRegion("button"), atlas.getRegion("buttonDown"));\r
button.action(Forever.$(RotateBy.$(360, 4)));\r
- ui.addActor(button);\r
+ button.clickListener = new ClickListener() {\r
+ \r
+ @Override public void clicked (Button button) {\r
+ if( Gdx.input.supportsOnscreenKeyboard() )\r
+ Gdx.input.setOnscreenKeyboardVisible( true );\r
+ }\r
+ };\r
+ ui.addActor(button); \r
+ \r
+ Label label = new Label( "label", font, "text input: " );\r
+ label.x = 10; label.y = Gdx.graphics.getHeight() - 20;\r
+ ui.addActor(label);\r
\r
LinearGroup linear = new LinearGroup("linear", 64, 32 * 3, LinearGroupLayout.Vertical);\r
linear.x = 200;\r
}\r
\r
@Override public boolean keyTyped (char character) {\r
- // TODO Auto-generated method stub\r
+ Label label = ((Label)ui.findActor( "label" ));\r
+ if( character == '\b' ) {\r
+ if( label.text.length() > "text input: ".length() )\r
+ label.text = label.text.substring( 0, label.text.length()-1 ); \r
+ } else { \r
+ label.text += character;\r
+ }\r
return false;\r
}\r
\r