Commit 99c7ea84 authored by fallenstardust's avatar fallenstardust

GameActivity

parent 88049212
......@@ -99,7 +99,7 @@ extern float getScreenWidth(ANDROID_APP app);
extern float getScreenHeight(ANDROID_APP app);
extern void OnShareFile(ANDROID_APP app, const char* title, const char* ext);
extern void OnShareFile(ANDROID_APP app, const char* _type, const char* name);
// Get SDCard path.
extern irr::io::path getExternalStorageDir(ANDROID_APP app);
......@@ -126,7 +126,7 @@ extern void toggleGlobalIME(ANDROID_APP app, bool pShow);
extern void toggleIME(ANDROID_APP app, bool pShow, const char* hint);
//Init Java Irrlicht world.
extern core::position2di initJavaBridge(ANDROID_APP app, void* handle);
extern void initJavaBridge(ANDROID_APP app, void* handle);
//Cause a haptic feedback.
extern void perfromHapticFeedback(ANDROID_APP app);
......@@ -186,10 +186,6 @@ extern bool getFontAntiAlias(ANDROID_APP app);
extern void showAndroidComboBoxCompat(ANDROID_APP app, bool pShow,
char** pContents, int count, int mode = 0);
/* android event handlers*/
extern void process_input(ANDROID_APP app,
struct android_poll_source* source);
extern s32 handleInput(ANDROID_APP app, AInputEvent* androidEvent);
extern bool android_deck_delete(const char* deck_name);
......
......@@ -294,14 +294,6 @@ static void* join_game_thread(void* param) {
}
}
JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSetInputFix(
JNIEnv* env, jclass clazz, jlong handle, jint x, jint y) {
if(ygo::mainGame) {
ALOGD("setInputFix posX=%d, posY=%d", x, y);
ygo::mainGame->setPositionFix(core::position2di(x, y));
}
}
static void* cancel_chain_thread(void* param) {
IrrlichtDevice* device = (IrrlichtDevice*) param;
irr::os::Printer::log("before send cancel chain");
......
package cn.garymb.ygomobile.core;
import android.annotation.SuppressLint;
import android.app.NativeActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import cn.garymb.ygomobile.controller.InputQueueCompat;
public abstract class GameActivity extends NativeActivity {
protected FrameLayout mLayout;
protected SurfaceView mSurfaceView;
private boolean replaced = false;
//自定义surface,方便控制窗口大小
private static final boolean USE_SURFACE = true;
//精准触摸事件
private static final boolean USE_MY_INPUT = true;
protected InputQueueCompat inputQueueCompat;
@Override
protected final void onCreate(Bundle savedInstanceState) {
if (USE_SURFACE) {
mSurfaceView = new SurfaceView(this);
}
if (USE_MY_INPUT) {
inputQueueCompat = new InputQueueCompat();
if (!inputQueueCompat.isValid()) {
inputQueueCompat = null;
}
}
initBeforeOnCreate();
super.onCreate(savedInstanceState);
initAfterOnCreate();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
if (inputQueueCompat != null) {
super.onInputQueueCreated(inputQueueCompat.getInputQueue());
}
} else {
if (inputQueueCompat != null) {
super.onInputQueueDestroyed(inputQueueCompat.getInputQueue());
}
}
super.onWindowFocusChanged(hasFocus);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public void setContentView(View view) {
Size size = getGameWindowSize();
mLayout = new FrameLayout(this);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(size.getWidth(), size.getHeight());
// mLayout.setBackgroundColor(Color.BLACK);
lp.gravity = Gravity.CENTER;
if (USE_SURFACE) {
mLayout.addView(mSurfaceView, lp);
mLayout.addView(view, lp);
super.setContentView(mLayout);
// app().attachGame(this);
// changeGameSize();
getWindow().takeSurface(null);
if (USE_MY_INPUT && inputQueueCompat != null) {
getWindow().takeInputQueue(null);
}
replaced = true;
mSurfaceView.getHolder().addCallback(this);
mSurfaceView.requestFocus();
getWindow().setGravity(Gravity.CENTER);
if (USE_MY_INPUT && inputQueueCompat != null) {
Log.d(IrrlichtBridge.TAG, "use java input queue:" + inputQueueCompat.getNativePtr());
mSurfaceView.setOnTouchListener((v, event) -> {
onSurfaceTouch(v, event);
return true;
});
}
} else {
mLayout.addView(view, lp);
getWindow().setGravity(Gravity.CENTER);
super.setContentView(mLayout);
}
}
protected void onSurfaceTouch(View v, MotionEvent event){
if (inputQueueCompat != null) {
inputQueueCompat.sendInputEvent(event, v, true);
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceCreated(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceChanged(holder, format, width, height);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceDestroyed(holder);
}
@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceRedrawNeeded(holder);
}
//
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// if(inputQueueCompat != null) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// inputQueueCompat.sendInputEvent(event, this, true);
// return true;
// }
// }
// return super.onKeyDown(keyCode, event);
// }
//
// @Override
// public boolean onKeyUp(int keyCode, KeyEvent event) {
// if(inputQueueCompat != null) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// inputQueueCompat.sendInputEvent(event, this, true);
// return true;
// }
// }
// return super.onKeyUp(keyCode, event);
// }
protected abstract Size getGameWindowSize();
protected abstract void initBeforeOnCreate();
protected abstract void initAfterOnCreate();
}
......@@ -82,8 +82,6 @@ public final class IrrlichtBridge {
private static native void nativeJoinGame(long handle, ByteBuffer buffer, int length);
private static native void nativeSetInputFix(long handle, int x, int y);
private static final boolean DEBUG = false;
public static void setArgs(Intent intent, String[] args) {
......@@ -155,10 +153,6 @@ public final class IrrlichtBridge {
}
}
public static void setInputFix(int x, int y) {
nativeSetInputFix(sNativeHandle, x, y);
}
public static void cancelChain() {
nativeCancelChain(sNativeHandle);
}
......@@ -231,7 +225,7 @@ public final class IrrlichtBridge {
void showComboBoxCompat(String[] items, boolean isShow, int mode);
void shareFile(String title, String ext);
void shareFile(String type, String name);
void performHapticFeedback();
......@@ -244,10 +238,6 @@ public final class IrrlichtBridge {
void setNativeHandle(long nativeHandle);
int getPositionX();
int getPositionY();
void onGameExit();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment