1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tests; 18 19 import com.badlogic.gdx.Gdx; 20 import com.badlogic.gdx.InputProcessor; 21 import com.badlogic.gdx.graphics.GL20; 22 import com.badlogic.gdx.graphics.g2d.BitmapFont; 23 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 24 import com.badlogic.gdx.tests.utils.GdxTest; 25 26 public class OnscreenKeyboardTest extends GdxTest implements InputProcessor { 27 28 BitmapFont font; 29 String text; 30 SpriteBatch batch; 31 create()32 public void create () { 33 batch = new SpriteBatch(); 34 font = new BitmapFont(); 35 text = ""; 36 Gdx.input.setInputProcessor(this); 37 // Gdx.input.setOnscreenKeyboardVisible(true); 38 } 39 render()40 public void render () { 41 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 42 batch.begin(); 43 font.draw(batch, "input: " + text, 0, Gdx.graphics.getHeight()); 44 batch.end(); 45 46 if (Gdx.input.justTouched()) Gdx.input.setOnscreenKeyboardVisible(true); 47 } 48 49 @Override keyDown(int keycode)50 public boolean keyDown (int keycode) { 51 52 return false; 53 } 54 55 @Override keyUp(int keycode)56 public boolean keyUp (int keycode) { 57 return false; 58 } 59 60 @Override keyTyped(char character)61 public boolean keyTyped (char character) { 62 if (character == '\b' && text.length() >= 1) { 63 text = text.substring(0, text.length() - 1); 64 } else if (character == '\n') { 65 Gdx.input.setOnscreenKeyboardVisible(false); 66 } else { 67 text += character; 68 } 69 return false; 70 } 71 72 @Override touchDown(int x, int y, int pointer, int button)73 public boolean touchDown (int x, int y, int pointer, int button) { 74 return false; 75 } 76 77 @Override touchUp(int x, int y, int pointer, int button)78 public boolean touchUp (int x, int y, int pointer, int button) { 79 // TODO Auto-generated method stub 80 return false; 81 } 82 83 @Override touchDragged(int x, int y, int pointer)84 public boolean touchDragged (int x, int y, int pointer) { 85 // TODO Auto-generated method stub 86 return false; 87 } 88 89 @Override mouseMoved(int x, int y)90 public boolean mouseMoved (int x, int y) { 91 // TODO Auto-generated method stub 92 return false; 93 } 94 95 @Override scrolled(int amount)96 public boolean scrolled (int amount) { 97 // TODO Auto-generated method stub 98 return false; 99 } 100 } 101