Commit 88049212 authored by fallenstardust's avatar fallenstardust

精准点击事件

parent 9b5de90a
...@@ -749,9 +749,9 @@ void toggleGlobalIME(ANDROID_APP app, bool pShow) { ...@@ -749,9 +749,9 @@ void toggleGlobalIME(ANDROID_APP app, bool pShow) {
app->activity->vm->DetachCurrentThread(); app->activity->vm->DetachCurrentThread();
} }
core::position2di initJavaBridge(ANDROID_APP app, void* handle) { void initJavaBridge(ANDROID_APP app, void* handle) {
if (!app || !app->activity || !app->activity->vm) if (!app || !app->activity || !app->activity->vm)
return core::position2di(0, 0); return;
JNIEnv* jni = nullptr; JNIEnv* jni = nullptr;
app->activity->vm->AttachCurrentThread(&jni, NULL); app->activity->vm->AttachCurrentThread(&jni, NULL);
jobject lNativeActivity = app->activity->clazz; jobject lNativeActivity = app->activity->clazz;
...@@ -760,18 +760,9 @@ core::position2di initJavaBridge(ANDROID_APP app, void* handle) { ...@@ -760,18 +760,9 @@ core::position2di initJavaBridge(ANDROID_APP app, void* handle) {
"setNativeHandle", "(J)V"); "setNativeHandle", "(J)V");
jlong code = (jlong) handle; jlong code = (jlong) handle;
jni->CallVoidMethod(lNativeActivity, MethodSetHandle, code); jni->CallVoidMethod(lNativeActivity, MethodSetHandle, code);
jmethodID methodX = jni->GetMethodID(ClassNativeActivity,
"getPositionX", "()I");
jint posX = jni->CallIntMethod(lNativeActivity, methodX);
jmethodID methodY = jni->GetMethodID(ClassNativeActivity,
"getPositionY", "()I");
jint posY = jni->CallIntMethod(lNativeActivity, methodY);
jni->DeleteLocalRef(ClassNativeActivity); jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread(); app->activity->vm->DetachCurrentThread();
__android_log_print(ANDROID_LOG_INFO, "ygo", "Android command initJavaBridge posX=%d, posY=%d", posX, posY); __android_log_print(ANDROID_LOG_INFO, "ygo", "Android command initJavaBridge");
return core::position2di((int)posX, (int)posY);
} }
InitOptions* getInitOptions(ANDROID_APP app) { InitOptions* getInitOptions(ANDROID_APP app) {
...@@ -807,7 +798,7 @@ int getLocalAddr(ANDROID_APP app) { ...@@ -807,7 +798,7 @@ int getLocalAddr(ANDROID_APP app) {
return addr; return addr;
} }
void OnShareFile(ANDROID_APP app, const char* title, const char* ext){ void OnShareFile(ANDROID_APP app, const char* _type, const char* name){
if (!app || !app->activity || !app->activity->vm) if (!app || !app->activity || !app->activity->vm)
return; return;
JNIEnv* jni = nullptr; JNIEnv* jni = nullptr;
...@@ -817,8 +808,8 @@ void OnShareFile(ANDROID_APP app, const char* title, const char* ext){ ...@@ -817,8 +808,8 @@ void OnShareFile(ANDROID_APP app, const char* title, const char* ext){
jobject lNativeActivity = app->activity->clazz; jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity); jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID methodId = jni->GetMethodID(ClassNativeActivity, "shareFile", "(Ljava/lang/String;Ljava/lang/String;)V"); jmethodID methodId = jni->GetMethodID(ClassNativeActivity, "shareFile", "(Ljava/lang/String;Ljava/lang/String;)V");
jstring s_title = jni->NewStringUTF(title); jstring s_title = jni->NewStringUTF(_type);
jstring s_ext = jni->NewStringUTF(ext); jstring s_ext = jni->NewStringUTF(name);
jni->CallVoidMethod(lNativeActivity, methodId, s_title, s_ext); jni->CallVoidMethod(lNativeActivity, methodId, s_title, s_ext);
if (s_title) { if (s_title) {
//不需要用ReleaseStringUTFChars,因为是c变量,函数外面自己释放 //不需要用ReleaseStringUTFChars,因为是c变量,函数外面自己释放
...@@ -869,30 +860,6 @@ void toggleOverlayView(ANDROID_APP app, bool pShow) { ...@@ -869,30 +860,6 @@ void toggleOverlayView(ANDROID_APP app, bool pShow) {
app->activity->vm->DetachCurrentThread(); app->activity->vm->DetachCurrentThread();
} }
void process_input(ANDROID_APP app,
struct android_poll_source* source) {
AInputEvent* event = NULL;
if (AInputQueue_getEvent(app->inputQueue, &event) >= 0) {
int type = AInputEvent_getType(event);
bool skip_predispatch = AInputEvent_getType(event)
== AINPUT_EVENT_TYPE_KEY
&& AKeyEvent_getKeyCode(event) == AKEYCODE_BACK;
// skip predispatch (all it does is send to the IME)
if (!skip_predispatch
&& AInputQueue_preDispatchEvent(app->inputQueue, event)) {
return;
}
int32_t handled = 0;
if (app->onInputEvent != NULL)
handled = app->onInputEvent(app, event);
AInputQueue_finishEvent(app->inputQueue, event, handled);
} else {
// LOGE("Failure reading next input event: %s\n", strerror(errno));
}
}
void onGameExit(ANDROID_APP app){ void onGameExit(ANDROID_APP app){
if (!app || !app->activity || !app->activity->vm) if (!app || !app->activity || !app->activity->vm)
return; return;
......
package cn.garymb.ygomobile.controller;
import android.os.Looper;
import android.util.Log;
import android.view.InputEvent;
import android.view.InputQueue;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import cn.garymb.ygomobile.utils.AndroidHideApi;
/**
* 仅测试安卓7-11
*/
public class InputQueueCompat implements InvocationHandler {
private static final String TAG = "kk-java";
private static Constructor<InputQueue> InputQueue_ctr;
private static Method getNativePtr_method;
private static Class<?> FinishedInputEventCallback_class;
//sendInputEvent(InputEvent e, Object token, boolean predispatch,
// FinishedInputEventCallback callback)
private static Method sendInputEvent_method;
private FinishedInputEventCallbackCompat finishedInputEventCallbackCompat;
static {
AndroidHideApi.enableHideApi();
try {
Looper.getMainLooper();
InputQueue_ctr = InputQueue.class.getDeclaredConstructor();
// InputQueue_ctr.setAccessible(true);
getNativePtr_method = InputQueue.class.getMethod("getNativePtr");
// getNativePtr_method.setAccessible(true);
FinishedInputEventCallback_class = Class.forName(InputQueue.class.getName() + "$FinishedInputEventCallback");
sendInputEvent_method = InputQueue.class.getMethod("sendInputEvent", InputEvent.class, Object.class, boolean.class,
FinishedInputEventCallback_class);
} catch (Throwable e) {
Log.e(TAG, "InputQueueCompat init", e);
}
}
private final InputQueue inputQueue;
private final Object callback;
public InputQueueCompat(InputQueue inputQueue) {
this.inputQueue = inputQueue;
if(inputQueue != null) {
callback = Proxy.newProxyInstance(InputQueue.class.getClassLoader(), new Class[]{FinishedInputEventCallback_class},
this);
} else {
callback = null;
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
//void onFinishedInputEvent(Object token, boolean handled);
if ("onFinishedInputEvent".equals(method.getName())) {
Object token = args[0];
boolean handled = (boolean) args[1];
onFinishedInputEvent(token, handled);
return 0;
}
return 0;
}
public InputQueueCompat() {
this(create());
}
public void setFinishedInputEventCallback(FinishedInputEventCallbackCompat finishedInputEventCallbackCompat) {
this.finishedInputEventCallbackCompat = finishedInputEventCallbackCompat;
}
public boolean isValid() {
return inputQueue != null && sendInputEvent_method != null && getNativePtr_method != null;
}
private static InputQueue create() {
try {
return InputQueue_ctr.newInstance();
} catch (Throwable e) {
Log.w(TAG, "InputQueue<init>", e);
return null;
}
}
public long getNativePtr() {
if (getNativePtr_method == null || inputQueue == null) {
return 0;
}
try {
Long ret = (Long) getNativePtr_method.invoke(inputQueue);
if (ret == null) {
return 0;
}
return ret;
} catch (Throwable e) {
Log.w(TAG, "getNativePtr", e);
return 0;
}
}
public InputQueue getInputQueue() {
return inputQueue;
}
public void sendInputEvent(InputEvent e, Object token, boolean predispatch) {
if (sendInputEvent_method == null) {
return;
}
try {
Log.d(TAG, "inputQueue:sendInputEvent:" + e);
sendInputEvent_method.invoke(inputQueue, e, token, predispatch, callback);
} catch (Throwable ex) {
Log.w(TAG, "inputQueue:sendInputEvent", ex);
}
}
public void onFinishedInputEvent(Object token, boolean handled) {
//TODO
Log.d(TAG, "onFinishedInputEvent:" + token + ", handled=" + handled);
if(this.finishedInputEventCallbackCompat != null){
finishedInputEventCallbackCompat.onFinishedInputEvent(token, handled);
}
}
public interface FinishedInputEventCallbackCompat{
void onFinishedInputEvent(Object token, boolean handled);
}
}
package cn.garymb.ygomobile.utils;
import android.os.Build;
import java.lang.reflect.Method;
public class AndroidHideApi {
private static boolean sBypassedP = false;
public static void enableHideApi() {
if (sBypassedP) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try {
Method forNameMethod = Class.class.getDeclaredMethod("forName", String.class);
Class<?> clazz = (Class<?>) forNameMethod.invoke(null, "dalvik.system.VMRuntime");
Method getMethodMethod = Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class);
Method getRuntime = (Method) getMethodMethod.invoke(clazz, "getRuntime", new Class[0]);
Method setHiddenApiExemptions = (Method) getMethodMethod.invoke(clazz, "setHiddenApiExemptions", new Class[]{String[].class});
Object runtime = getRuntime.invoke(null);
setHiddenApiExemptions.invoke(runtime, new Object[]{
new String[]{
"Landroid/",
"Lcom/android/",
"Ljava/lang/",
"Ldalvik/system/",
"Llibcore/io/",
"Lhuawei/"
}
});
} catch (Throwable e) {
e.printStackTrace();
}
}
sBypassedP = true;
}
}
...@@ -64,6 +64,16 @@ public class App extends GameApplication { ...@@ -64,6 +64,16 @@ public class App extends GameApplication {
public float getYScale() { public float getYScale() {
return AppsSettings.get().getYScale(getGameWidth(), getGameHeight()); return AppsSettings.get().getYScale(getGameWidth(), getGameHeight());
} }
//
// @Override
// public int getGameHeight() {
// return 720;
// }
//
// @Override
// public int getGameWidth() {
// return 1280;
// }
@Override @Override
public String getCardImagePath() { public String getCardImagePath() {
......
...@@ -3,6 +3,7 @@ package cn.garymb.ygomobile; ...@@ -3,6 +3,7 @@ package cn.garymb.ygomobile;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.Point; import android.graphics.Point;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.WindowManager; import android.view.WindowManager;
...@@ -18,9 +19,11 @@ import java.util.Arrays; ...@@ -18,9 +19,11 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus; import cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus;
import cn.garymb.ygomobile.utils.DeckUtil; import cn.garymb.ygomobile.utils.DeckUtil;
import cn.garymb.ygomobile.utils.DensityUtils;
import cn.garymb.ygomobile.utils.IOUtils; import cn.garymb.ygomobile.utils.IOUtils;
import static cn.garymb.ygomobile.Constants.CORE_DECK_PATH; import static cn.garymb.ygomobile.Constants.CORE_DECK_PATH;
...@@ -33,6 +36,7 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE; ...@@ -33,6 +36,7 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT; import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME; import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX; import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX;
import static cn.garymb.ygomobile.Constants.DEF_PREF_WINDOW_TOP_BOTTOM;
import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE; import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH; import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE; import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE;
...@@ -43,6 +47,7 @@ import static cn.garymb.ygomobile.Constants.PREF_NOTCH_HEIGHT; ...@@ -43,6 +47,7 @@ import static cn.garymb.ygomobile.Constants.PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME; import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.PREF_READ_EX; import static cn.garymb.ygomobile.Constants.PREF_READ_EX;
import static cn.garymb.ygomobile.Constants.PREF_SENSOR_REFRESH; import static cn.garymb.ygomobile.Constants.PREF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_WINDOW_TOP_BOTTOM;
import static cn.garymb.ygomobile.Constants.WINDBOT_DECK_PATH; import static cn.garymb.ygomobile.Constants.WINDBOT_DECK_PATH;
import static cn.garymb.ygomobile.Constants.WINDBOT_PATH; import static cn.garymb.ygomobile.Constants.WINDBOT_PATH;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX; import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
...@@ -53,8 +58,8 @@ public class AppsSettings { ...@@ -53,8 +58,8 @@ public class AppsSettings {
private static AppsSettings sAppsSettings; private static AppsSettings sAppsSettings;
private final Point mScreenSize = new Point(); private final Point mScreenSize = new Point();
private final Point mRealScreenSize = new Point(); private final Point mRealScreenSize = new Point();
private Context context; private final Context context;
private PreferenceFragmentPlus.SharedPreferencesPlus mSharedPreferences; private final PreferenceFragmentPlus.SharedPreferencesPlus mSharedPreferences;
private float mDensity; private float mDensity;
private AppsSettings(Context context) { private AppsSettings(Context context) {
...@@ -134,6 +139,7 @@ public class AppsSettings { ...@@ -134,6 +139,7 @@ public class AppsSettings {
} }
public float getXScale(int w, int h) { public float getXScale(int w, int h) {
//曲面屏
if (isKeepScale()) { if (isKeepScale()) {
float sx = getScreenHeight() / w; float sx = getScreenHeight() / w;
float sy = getScreenWidth() / h; float sy = getScreenWidth() / h;
...@@ -156,6 +162,15 @@ public class AppsSettings { ...@@ -156,6 +162,15 @@ public class AppsSettings {
return mSharedPreferences.getBoolean(PREF_KEEP_SCALE, DEF_PREF_KEEP_SCALE); return mSharedPreferences.getBoolean(PREF_KEEP_SCALE, DEF_PREF_KEEP_SCALE);
} }
public int getScreenPadding() {
//ListPreference都是string
String str = mSharedPreferences.getString(PREF_WINDOW_TOP_BOTTOM, null);
if (!TextUtils.isEmpty(str) && TextUtils.isDigitsOnly(str)) {
return Integer.parseInt(str);
}
return 0;
}
public float getScreenWidth() { public float getScreenWidth() {
int w, h; int w, h;
if (isImmerSiveMode()) { if (isImmerSiveMode()) {
...@@ -165,7 +180,11 @@ public class AppsSettings { ...@@ -165,7 +180,11 @@ public class AppsSettings {
w = mScreenSize.x; w = mScreenSize.x;
h = mScreenSize.y; h = mScreenSize.y;
} }
return Math.min(w, h); int ret = Math.min(w, h);
//测试代码,曲面屏左右2变需要留空白,但是游戏画面比例不对,需要修改c那边代码
int fix_h = DensityUtils.dp2px(context, getScreenPadding());
Log.d(IrrlichtBridge.TAG, "screen padding=" + fix_h);
return ret - fix_h * 2;
} }
public float getScreenHeight() { public float getScreenHeight() {
...@@ -518,7 +537,8 @@ public class AppsSettings { ...@@ -518,7 +537,8 @@ public class AppsSettings {
} }
//获得最后卡组绝对路径 //获得最后卡组绝对路径
public @Nullable String getLastDeckPath() { public @Nullable
String getLastDeckPath() {
String path; String path;
if (TextUtils.equals(context.getString(R.string.category_pack), getLastCategory())) { if (TextUtils.equals(context.getString(R.string.category_pack), getLastCategory())) {
path = getResourcePath() + "/" + CORE_PACK_PATH + "/" + getLastDeckName() + YDK_FILE_EX; path = getResourcePath() + "/" + CORE_PACK_PATH + "/" + getLastDeckName() + YDK_FILE_EX;
...@@ -680,6 +700,6 @@ public class AppsSettings { ...@@ -680,6 +700,6 @@ public class AppsSettings {
@Deprecated @Deprecated
//获取收藏文件 //获取收藏文件
public File getFavoriteFile() { public File getFavoriteFile() {
return new File(getResourcePath(), CORE_SYSTEM_PATH); return new File(getResourcePath(), "/favorite.txt");
} }
} }
...@@ -117,6 +117,10 @@ public interface Constants { ...@@ -117,6 +117,10 @@ public interface Constants {
String PREF_KEEP_SCALE = "pref_settings_keep_scale"; String PREF_KEEP_SCALE = "pref_settings_keep_scale";
boolean DEF_PREF_KEEP_SCALE = false; boolean DEF_PREF_KEEP_SCALE = false;
//dp单位,游戏高度减少,留空白
String PREF_WINDOW_TOP_BOTTOM = "pref_settings_window_top_bottom";
int DEF_PREF_WINDOW_TOP_BOTTOM = 0;
int REQUEST_CUT_IMG = 0x1000 + 0x10; int REQUEST_CUT_IMG = 0x1000 + 0x10;
int REQUEST_CHOOSE_FILE = 0x1000 + 0x20; int REQUEST_CHOOSE_FILE = 0x1000 + 0x20;
int REQUEST_CHOOSE_IMG = 0x1000 + 0x21; int REQUEST_CHOOSE_IMG = 0x1000 + 0x21;
......
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