mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-08-15 05:27:32 +00:00
Two-finger-touch pops up softkeyboard and adjusts GL viewport
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||||
android:screenOrientation="landscape"
|
android:screenOrientation="landscape"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation"
|
||||||
android:windowSoftInputMode="adjustPan">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
@@ -16,10 +16,12 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -29,14 +31,14 @@ import java.io.FileOutputStream;
|
|||||||
public class Apple2Activity extends Activity {
|
public class Apple2Activity extends Activity {
|
||||||
|
|
||||||
private final static String TAG = "Apple2Activity";
|
private final static String TAG = "Apple2Activity";
|
||||||
|
|
||||||
private final static int BUF_SZ = 4096;
|
private final static int BUF_SZ = 4096;
|
||||||
|
|
||||||
private final static String PREFS_CONFIGURED = "prefs_configured";
|
private final static String PREFS_CONFIGURED = "prefs_configured";
|
||||||
|
private final static int SOFTKEYBOARD_THRESHOLD = 10;
|
||||||
|
|
||||||
private Apple2View mView = null;
|
private Apple2View mView = null;
|
||||||
private int mWidth = 0;
|
private int mWidth = 0;
|
||||||
private int mHeight = 0;
|
private int mHeight = 0;
|
||||||
|
private boolean mSoftKeyboardShowing = false;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("apple2ix");
|
System.loadLibrary("apple2ix");
|
||||||
@@ -46,6 +48,7 @@ public class Apple2Activity extends Activity {
|
|||||||
public native void nativeOnResume();
|
public native void nativeOnResume();
|
||||||
public native void nativeOnPause();
|
public native void nativeOnPause();
|
||||||
private native void nativeGraphicsInitialized(int width, int height);
|
private native void nativeGraphicsInitialized(int width, int height);
|
||||||
|
private native void nativeGraphicsChanged(int width, int height);
|
||||||
public native void nativeRender();
|
public native void nativeRender();
|
||||||
private native void nativeOnKeyDown(int keyCode, int metaState);
|
private native void nativeOnKeyDown(int keyCode, int metaState);
|
||||||
private native void nativeOnKeyUp(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);
|
mView = new Apple2View(this);
|
||||||
setContentView(mView);
|
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
|
@Override
|
||||||
@@ -175,4 +193,8 @@ public class Apple2Activity extends Activity {
|
|||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSoftKeyboardShowing() {
|
||||||
|
return mSoftKeyboardShowing;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,10 +15,12 @@
|
|||||||
|
|
||||||
package org.deadc0de.apple2ix;
|
package org.deadc0de.apple2ix;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGL10;
|
import javax.microedition.khronos.egl.EGL10;
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
@@ -152,7 +154,7 @@ class Apple2View extends GLSurfaceView {
|
|||||||
|
|
||||||
case (MotionEvent.ACTION_POINTER_UP):
|
case (MotionEvent.ACTION_POINTER_UP):
|
||||||
if (mUltiTapEventBegin) {
|
if (mUltiTapEventBegin) {
|
||||||
showMultiTapMenu();
|
toggleMultiTapMenu();
|
||||||
}
|
}
|
||||||
mTapEventBegin = false;
|
mTapEventBegin = false;
|
||||||
mUltiTapEventBegin = false;
|
mUltiTapEventBegin = false;
|
||||||
@@ -172,12 +174,16 @@ class Apple2View extends GLSurfaceView {
|
|||||||
|
|
||||||
public void showMainMenu() {
|
public void showMainMenu() {
|
||||||
if (mMainMenu != null) {
|
if (mMainMenu != null) {
|
||||||
|
if (mActivity.isSoftKeyboardShowing()) {
|
||||||
|
toggleMultiTapMenu();
|
||||||
|
}
|
||||||
mMainMenu.show();
|
mMainMenu.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showMultiTapMenu() {
|
public void toggleMultiTapMenu() {
|
||||||
Log.d(TAG, "showMultiTapMenu...");
|
InputMethodManager inputMethodManager=(InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager.toggleSoftInputFromWindow(getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
|
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
|
||||||
|
@@ -21,6 +21,11 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje
|
|||||||
LOG("nativeOnCreate(%s)...", data_dir);
|
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) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv *env, jobject obj, jint width, jint height) {
|
||||||
LOG("%s", "native graphicsInitialized...");
|
LOG("%s", "native graphicsInitialized...");
|
||||||
video_driver_reshape(width, height);
|
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);
|
android_keycode_to_emulator(keyCode, metaState, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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)/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_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)
|
||||||
|
|
||||||
|
@@ -52,6 +52,9 @@ static int viewportX = 0;
|
|||||||
static int viewportY = 0;
|
static int viewportY = 0;
|
||||||
static int viewportWidth = SCANWIDTH*1.5;
|
static int viewportWidth = SCANWIDTH*1.5;
|
||||||
static int viewportHeight = SCANHEIGHT*1.5;
|
static int viewportHeight = SCANHEIGHT*1.5;
|
||||||
|
#if MOBILE_DEVICE
|
||||||
|
static int adjustedHeight = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
static GLint uniformMVPIdx;
|
static GLint uniformMVPIdx;
|
||||||
static GLenum crtElementType;
|
static GLenum crtElementType;
|
||||||
@@ -533,8 +536,12 @@ static demoSource *_create_shader_source(const char *fileName) {
|
|||||||
static void gldriver_init_common(void) {
|
static void gldriver_init_common(void) {
|
||||||
LOG("%s %s", glGetString(GL_RENDERER), glGetString(GL_VERSION));
|
LOG("%s %s", glGetString(GL_RENDERER), glGetString(GL_VERSION));
|
||||||
|
|
||||||
viewportWidth = 400;
|
if (!viewportWidth) {
|
||||||
viewportHeight = 400;
|
viewportWidth = 400;
|
||||||
|
}
|
||||||
|
if (!viewportHeight) {
|
||||||
|
viewportHeight = 400;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
// Create CRT model VAO/VBOs
|
// Create CRT model VAO/VBOs
|
||||||
@@ -651,6 +658,9 @@ static void gldriver_render(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
#if MOBILE_DEVICE
|
||||||
|
glViewport(viewportX, adjustedHeight, viewportWidth, viewportHeight);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if PERSPECTIVE
|
#if PERSPECTIVE
|
||||||
// Calculate modelview and projection matrices
|
// Calculate modelview and projection matrices
|
||||||
@@ -748,6 +758,10 @@ static void gldriver_reshape(int w, int h) {
|
|||||||
windowWidth = w;
|
windowWidth = w;
|
||||||
windowHeight = h;
|
windowHeight = h;
|
||||||
|
|
||||||
|
#if MOBILE_DEVICE
|
||||||
|
int viewportHeightPrevious = viewportHeight;
|
||||||
|
#endif
|
||||||
|
|
||||||
int w2 = ((float)h * (SCANWIDTH/(float)SCANHEIGHT));
|
int w2 = ((float)h * (SCANWIDTH/(float)SCANHEIGHT));
|
||||||
int h2 = ((float)w / (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);
|
//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);
|
glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user