2016-04-28 70 views
0

嗨! 我目前正在扩展一个Android游戏框架,我在Mario Zechner编写的一本书(他也开发Libgdx)中发现了这个框架。全屏Android软键盘表面视图

到目前为止它工作良好,我完成了该框架的Java桌面实现。

但是有一个小小的东西丢失了,SoftKeyboard的正确用法。

你可以尝试并重现我的bug,整个项目在github上, 和android模块是“app”文件夹。 Java版本(左箭头键=键返回)位于javalib模块中。

https://github.com/Railwanderer/AndroidGameFramework

框架使用窗口FullScreenFlags和NoTitle标志结合从表面上看渲染。

在AndroidGame类标志:

// set FullScreen 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 

表面观:

public class AndroidFastRenderView extends SurfaceView implements Runnable { 

AndroidGame game; 
Bitmap framebuffer; 
Thread renderThread = null; 
SurfaceHolder holder; 

// Fps Counting Stuff... 
static long    lastTime; 
static double   fps; 
static String   FPS = ""; 


volatile boolean running = false; 


public AndroidFastRenderView(AndroidGame game, Bitmap framebuffer) { 
    super(game); 
    this.game = game; 
    this.framebuffer = framebuffer; 
    this.holder = getHolder(); 
} 

public void resume() { 
    running = true; 
    renderThread = new Thread(this); 
    renderThread.start(); 
} 

public void run() { 
    Rect dstRect = new Rect(); 
    long startTime = System.nanoTime(); 
    while (running) { 
     if (!holder.getSurface().isValid()) 
      continue; 

     lastTime = System.nanoTime(); 
     float deltaTime = (System.nanoTime() - startTime)/1000000000.0f; 
     startTime = System.nanoTime(); 

     game.getCurrentScreen().update(deltaTime); 
     Graphics g = game.getGraphics(); 
     g.clear(Color.BLACK); 
     game.getCurrentScreen().present(deltaTime); 
     g.drawString(FPS,framebuffer.getWidth()-100,framebuffer.getHeight()-30); 

     Canvas canvas = holder.lockCanvas(); 
     canvas.getClipBounds(dstRect); 
     canvas.drawBitmap(framebuffer, null, dstRect, null); 
     holder.unlockCanvasAndPost(canvas); 

     //one second(nano) divided by amount of time it takes for one frame to finish 
     fps = 1000000000.0/(System.nanoTime() - lastTime); 
     lastTime = System.nanoTime(); 
     FPS = "FPS: " + (int) fps; 
    } 
} 

public void pause() { 
    running = false; 
    while (true) { 
     try { 
      renderThread.join(); 
      break; 
     } catch (InterruptedException e) { 
      // retry 
     } 
    } 
} 

我的问题是,当我试图拉起SoftKeyboard,那么,当 与SHOW_FORCED调用显示。它也在我的表面视图上放置,但触摸事件不会触发键盘,但会以某种方式通过并打到我的表面视图。

public void showKeyboard(){ 
    inputManager.showSoftInput(view, InputMethodManager.SHOW_FORCED); 
} 

当我像疯了一样击中软键盘的最上边界(第一行键上边缘)时,最终某些触摸事件实际上会触发键。但它只适用于第一行按键,并且根本不令人满意。 我得到印象,因为记录的触摸事件返回一个偏移量,整个事物发生了变化。

我目前正在用任何keyEvent(键监听器的第一行onKey()方法)调用软键盘。所以后退键会触发键盘。此密钥始终可以识别,因为它是我设备上的硬键。

- 是否有可能使用可调整大小的布局存档全屏?我猜它的标志阻止键盘正常工作。 - 其他想法结合起来吗?

另外我在这里的Android清单,该应用程序使用唯一的XML文件:

<application android:icon="@mipmap/ic_launcher" android:label="TestGame"> 

    <activity android:name="railwanderer.androidgameframework.ExampleAndroidGame.StartClass" 
     android:label="StartClass" 
     android:screenOrientation="landscape" 
     android:configChanges="keyboard|keyboardHidden|orientation"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 
</application> 

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.WAKE_LOCK"/> 
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9"/> 

回答

1

我发现了一个解决:d https://stackoverflow.com/questions/33561137/soft-keyboard-not-receiving-touches-over-surfaceview

我没有覆盖onCreateInputConnection方法上CustomSurfaceView类,就像发布的链接一样。

@Override 
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) { 
    InputConnection conn = super.onCreateInputConnection(outAttrs); 
    outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN; 
    return conn; 
} 

它现在有效,请尝试一下,我会立即上传,看看它是否也适用于您的设备。