Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
88049212
Commit
88049212
authored
Sep 25, 2021
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精准点击事件
parent
9b5de90a
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
307 additions
and
200 deletions
+307
-200
libcore/android/android_tools.cpp
libcore/android/android_tools.cpp
+6
-39
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
.../src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
+90
-156
libcore/src/main/java/cn/garymb/ygomobile/controller/InputQueueCompat.java
...java/cn/garymb/ygomobile/controller/InputQueueCompat.java
+134
-0
libcore/src/main/java/cn/garymb/ygomobile/utils/AndroidHideApi.java
...c/main/java/cn/garymb/ygomobile/utils/AndroidHideApi.java
+38
-0
mobile/src/main/java/cn/garymb/ygomobile/App.java
mobile/src/main/java/cn/garymb/ygomobile/App.java
+10
-0
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
+25
-5
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
+4
-0
No files found.
libcore/android/android_tools.cpp
View file @
88049212
...
...
@@ -749,9 +749,9 @@ void toggleGlobalIME(ANDROID_APP app, bool pShow) {
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
)
return
core
::
position2di
(
0
,
0
)
;
return
;
JNIEnv
*
jni
=
nullptr
;
app
->
activity
->
vm
->
AttachCurrentThread
(
&
jni
,
NULL
);
jobject
lNativeActivity
=
app
->
activity
->
clazz
;
...
...
@@ -760,18 +760,9 @@ core::position2di initJavaBridge(ANDROID_APP app, void* handle) {
"setNativeHandle"
,
"(J)V"
);
jlong
code
=
(
jlong
)
handle
;
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
);
app
->
activity
->
vm
->
DetachCurrentThread
();
__android_log_print
(
ANDROID_LOG_INFO
,
"ygo"
,
"Android command initJavaBridge posX=%d, posY=%d"
,
posX
,
posY
);
return
core
::
position2di
((
int
)
posX
,
(
int
)
posY
);
__android_log_print
(
ANDROID_LOG_INFO
,
"ygo"
,
"Android command initJavaBridge"
);
}
InitOptions
*
getInitOptions
(
ANDROID_APP
app
)
{
...
...
@@ -807,7 +798,7 @@ int getLocalAddr(ANDROID_APP app) {
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
)
return
;
JNIEnv
*
jni
=
nullptr
;
...
...
@@ -817,8 +808,8 @@ void OnShareFile(ANDROID_APP app, const char* title, const char* ext){
jobject
lNativeActivity
=
app
->
activity
->
clazz
;
jclass
ClassNativeActivity
=
jni
->
GetObjectClass
(
lNativeActivity
);
jmethodID
methodId
=
jni
->
GetMethodID
(
ClassNativeActivity
,
"shareFile"
,
"(Ljava/lang/String;Ljava/lang/String;)V"
);
jstring
s_title
=
jni
->
NewStringUTF
(
titl
e
);
jstring
s_ext
=
jni
->
NewStringUTF
(
ext
);
jstring
s_title
=
jni
->
NewStringUTF
(
_typ
e
);
jstring
s_ext
=
jni
->
NewStringUTF
(
name
);
jni
->
CallVoidMethod
(
lNativeActivity
,
methodId
,
s_title
,
s_ext
);
if
(
s_title
)
{
//不需要用ReleaseStringUTFChars,因为是c变量,函数外面自己释放
...
...
@@ -869,30 +860,6 @@ void toggleOverlayView(ANDROID_APP app, bool pShow) {
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
){
if
(
!
app
||
!
app
->
activity
||
!
app
->
activity
->
vm
)
return
;
...
...
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
View file @
88049212
This diff is collapsed.
Click to expand it.
libcore/src/main/java/cn/garymb/ygomobile/controller/InputQueueCompat.java
0 → 100644
View file @
88049212
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
);
}
}
libcore/src/main/java/cn/garymb/ygomobile/utils/AndroidHideApi.java
0 → 100644
View file @
88049212
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
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/App.java
View file @
88049212
...
...
@@ -64,6 +64,16 @@ public class App extends GameApplication {
public
float
getYScale
()
{
return
AppsSettings
.
get
().
getYScale
(
getGameWidth
(),
getGameHeight
());
}
//
// @Override
// public int getGameHeight() {
// return 720;
// }
//
// @Override
// public int getGameWidth() {
// return 1280;
// }
@Override
public
String
getCardImagePath
()
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
View file @
88049212
...
...
@@ -3,6 +3,7 @@ package cn.garymb.ygomobile;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.graphics.Point
;
import
android.os.ParcelFileDescriptor
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.WindowManager
;
...
...
@@ -18,9 +19,11 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.Locale
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus
;
import
cn.garymb.ygomobile.utils.DeckUtil
;
import
cn.garymb.ygomobile.utils.DensityUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
CORE_DECK_PATH
;
...
...
@@ -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_ONLY_GAME
;
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_SENSOR_REFRESH
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_FONT_SIZE
;
...
...
@@ -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_READ_EX
;
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_PATH
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
YDK_FILE_EX
;
...
...
@@ -53,8 +58,8 @@ public class AppsSettings {
private
static
AppsSettings
sAppsSettings
;
private
final
Point
mScreenSize
=
new
Point
();
private
final
Point
mRealScreenSize
=
new
Point
();
private
Context
context
;
private
PreferenceFragmentPlus
.
SharedPreferencesPlus
mSharedPreferences
;
private
final
Context
context
;
private
final
PreferenceFragmentPlus
.
SharedPreferencesPlus
mSharedPreferences
;
private
float
mDensity
;
private
AppsSettings
(
Context
context
)
{
...
...
@@ -134,6 +139,7 @@ public class AppsSettings {
}
public
float
getXScale
(
int
w
,
int
h
)
{
//曲面屏
if
(
isKeepScale
())
{
float
sx
=
getScreenHeight
()
/
w
;
float
sy
=
getScreenWidth
()
/
h
;
...
...
@@ -156,6 +162,15 @@ public class AppsSettings {
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
()
{
int
w
,
h
;
if
(
isImmerSiveMode
())
{
...
...
@@ -165,7 +180,11 @@ public class AppsSettings {
w
=
mScreenSize
.
x
;
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
()
{
...
...
@@ -518,7 +537,8 @@ public class AppsSettings {
}
//获得最后卡组绝对路径
public
@Nullable
String
getLastDeckPath
()
{
public
@Nullable
String
getLastDeckPath
()
{
String
path
;
if
(
TextUtils
.
equals
(
context
.
getString
(
R
.
string
.
category_pack
),
getLastCategory
()))
{
path
=
getResourcePath
()
+
"/"
+
CORE_PACK_PATH
+
"/"
+
getLastDeckName
()
+
YDK_FILE_EX
;
...
...
@@ -680,6 +700,6 @@ public class AppsSettings {
@Deprecated
//获取收藏文件
public
File
getFavoriteFile
()
{
return
new
File
(
getResourcePath
(),
CORE_SYSTEM_PATH
);
return
new
File
(
getResourcePath
(),
"/favorite.txt"
);
}
}
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
View file @
88049212
...
...
@@ -117,6 +117,10 @@ public interface Constants {
String
PREF_KEEP_SCALE
=
"pref_settings_keep_scale"
;
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_CHOOSE_FILE
=
0x1000
+
0x20
;
int
REQUEST_CHOOSE_IMG
=
0x1000
+
0x21
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment