Two-finger-touch pops up softkeyboard and adjusts GL viewport

This commit is contained in:
Aaron Culliney 2015-03-11 12:54:50 -07:00
parent d934e06d8a
commit 2965afe12e
6 changed files with 64 additions and 10 deletions

View File

@ -16,7 +16,7 @@
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation"
android:windowSoftInputMode="adjustPan">
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@ -16,10 +16,12 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewTreeObserver;
import java.io.File;
import java.io.InputStream;
@ -29,14 +31,14 @@ import java.io.FileOutputStream;
public class Apple2Activity extends Activity {
private final static String TAG = "Apple2Activity";
private final static int BUF_SZ = 4096;
private final static String PREFS_CONFIGURED = "prefs_configured";
private final static int SOFTKEYBOARD_THRESHOLD = 10;
private Apple2View mView = null;
private int mWidth = 0;
private int mHeight = 0;
private boolean mSoftKeyboardShowing = false;
static {
System.loadLibrary("apple2ix");
@ -46,6 +48,7 @@ public class Apple2Activity extends Activity {
public native void nativeOnResume();
public native void nativeOnPause();
private native void nativeGraphicsInitialized(int width, int height);
private native void nativeGraphicsChanged(int width, int height);
public native void nativeRender();
private native void nativeOnKeyDown(int keyCode, int metaState);
private native void nativeOnKeyUp(int keyCode, int metaState);
@ -128,6 +131,21 @@ public class Apple2Activity extends Activity {
mView = new Apple2View(this);
setContentView(mView);
mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
Rect rect = new Rect();
mView.getWindowVisibleDisplayFrame(rect);
int h = rect.height();
if (mView.getHeight() - h > SOFTKEYBOARD_THRESHOLD) {
Log.d(TAG, "Soft keyboard appears to be occupying screen real estate ...");
Apple2Activity.this.mSoftKeyboardShowing = true;
} else {
Apple2Activity.this.mSoftKeyboardShowing = false;
}
nativeGraphicsChanged(rect.width(), h);
}
});
}
@Override
@ -175,4 +193,8 @@ public class Apple2Activity extends Activity {
public int getHeight() {
return mHeight;
}
public boolean isSoftKeyboardShowing() {
return mSoftKeyboardShowing;
}
}

View File

@ -15,10 +15,12 @@
package org.deadc0de.apple2ix;
import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
@ -152,7 +154,7 @@ class Apple2View extends GLSurfaceView {
case (MotionEvent.ACTION_POINTER_UP):
if (mUltiTapEventBegin) {
showMultiTapMenu();
toggleMultiTapMenu();
}
mTapEventBegin = false;
mUltiTapEventBegin = false;
@ -172,12 +174,16 @@ class Apple2View extends GLSurfaceView {
public void showMainMenu() {
if (mMainMenu != null) {
if (mActivity.isSoftKeyboardShowing()) {
toggleMultiTapMenu();
}
mMainMenu.show();
}
}
public void showMultiTapMenu() {
Log.d(TAG, "showMultiTapMenu...");
public void toggleMultiTapMenu() {
InputMethodManager inputMethodManager=(InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {

View File

@ -21,6 +21,11 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje
LOG("nativeOnCreate(%s)...", data_dir);
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsChanged(JNIEnv *env, jobject obj, jint width, jint height) {
LOG("%s", "native graphicsChanged...");
video_driver_reshape(width, height);
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv *env, jobject obj, jint width, jint height) {
LOG("%s", "native graphicsInitialized...");
video_driver_reshape(width, height);
@ -100,4 +105,3 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyUp(JNIEnv *env, jobjec
android_keycode_to_emulator(keyCode, metaState, false);
#endif
}

View File

@ -31,5 +31,5 @@ APPLE2_MAIN_SRC = \
$(APPLE2_SRC_PATH)/timing.c $(APPLE2_SRC_PATH)/zlib-helpers.c $(APPLE2_SRC_PATH)/joystick.c $(APPLE2_SRC_PATH)/keys.c \
$(APPLE2_SRC_PATH)/disk.c $(APPLE2_SRC_PATH)/cpu-supp.c
APPLE2_BASE_CFLAGS := -DAPPLE2IX=1 -DVIDEO_OPENGL=1 -DDEBUGGER=1 -std=gnu11 -I$(APPLE2_SRC_PATH)
APPLE2_BASE_CFLAGS := -DAPPLE2IX=1 -DMOBILE_DEVICE=1 -DVIDEO_OPENGL=1 -DDEBUGGER=1 -std=gnu11 -I$(APPLE2_SRC_PATH)

View File

@ -52,6 +52,9 @@ static int viewportX = 0;
static int viewportY = 0;
static int viewportWidth = SCANWIDTH*1.5;
static int viewportHeight = SCANHEIGHT*1.5;
#if MOBILE_DEVICE
static int adjustedHeight = 0;
#endif
static GLint uniformMVPIdx;
static GLenum crtElementType;
@ -533,8 +536,12 @@ static demoSource *_create_shader_source(const char *fileName) {
static void gldriver_init_common(void) {
LOG("%s %s", glGetString(GL_RENDERER), glGetString(GL_VERSION));
viewportWidth = 400;
viewportHeight = 400;
if (!viewportWidth) {
viewportWidth = 400;
}
if (!viewportHeight) {
viewportHeight = 400;
}
// ----------------------------
// Create CRT model VAO/VBOs
@ -651,6 +658,9 @@ static void gldriver_render(void) {
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#if MOBILE_DEVICE
glViewport(viewportX, adjustedHeight, viewportWidth, viewportHeight);
#endif
#if PERSPECTIVE
// Calculate modelview and projection matrices
@ -748,6 +758,10 @@ static void gldriver_reshape(int w, int h) {
windowWidth = w;
windowHeight = h;
#if MOBILE_DEVICE
int viewportHeightPrevious = viewportHeight;
#endif
int w2 = ((float)h * (SCANWIDTH/(float)SCANHEIGHT));
int h2 = ((float)w / (SCANWIDTH/(float)SCANHEIGHT));
@ -772,6 +786,14 @@ static void gldriver_reshape(int w, int h) {
//LOG("small viewport : x:%d,y:%d w:%d,h:%d", viewportX, viewportY, viewportWidth, viewportHeight);
}
#if MOBILE_DEVICE
if (viewportHeight < viewportHeightPrevious) {
adjustedHeight = viewportHeightPrevious - viewportHeight;
} else {
adjustedHeight = 0;
}
#endif
glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
}