Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile-Cn-Ko-En
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-Cn-Ko-En
Commits
4d92c3b2
Commit
4d92c3b2
authored
Oct 23, 2019
by
kenan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
settings
parent
e8f52553
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
612 additions
and
699 deletions
+612
-699
libcore/android/android_tools.cpp
libcore/android/android_tools.cpp
+0
-50
libcore/android/android_tools.h
libcore/android/android_tools.h
+0
-14
libcore/build.gradle
libcore/build.gradle
+1
-1
libcore/src/main/java/cn/garymb/ygomobile/GameApplication.java
...re/src/main/java/cn/garymb/ygomobile/GameApplication.java
+49
-22
libcore/src/main/java/cn/garymb/ygomobile/NativeInitOptions.java
.../src/main/java/cn/garymb/ygomobile/NativeInitOptions.java
+64
-1
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
.../src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
+29
-48
libcore/src/main/java/cn/garymb/ygomobile/core/GameConfig.java
...re/src/main/java/cn/garymb/ygomobile/core/GameConfig.java
+156
-14
libcore/src/main/java/cn/garymb/ygomobile/core/GameSize.java
libcore/src/main/java/cn/garymb/ygomobile/core/GameSize.java
+69
-0
libcore/src/main/java/cn/garymb/ygomobile/core/IrrlichtBridge.java
...rc/main/java/cn/garymb/ygomobile/core/IrrlichtBridge.java
+2
-4
libygo/build.gradle
libygo/build.gradle
+1
-1
mobile/src/main/AndroidManifest.xml
mobile/src/main/AndroidManifest.xml
+0
-5
mobile/src/main/java/cn/garymb/ygomobile/App.java
mobile/src/main/java/cn/garymb/ygomobile/App.java
+95
-67
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
+7
-55
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
+3
-0
mobile/src/main/java/cn/garymb/ygomobile/LocalConfig.java
mobile/src/main/java/cn/garymb/ygomobile/LocalConfig.java
+70
-0
mobile/src/main/java/cn/garymb/ygomobile/YGOStarter.java
mobile/src/main/java/cn/garymb/ygomobile/YGOStarter.java
+16
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/SharedPreferencesPlus.java
...garymb/ygomobile/ui/preference/SharedPreferencesPlus.java
+0
-258
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/YGOPreferencesProvider.java
...arymb/ygomobile/ui/preference/YGOPreferencesProvider.java
+0
-151
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
...mb/ygomobile/ui/preference/fragments/SettingFragment.java
+8
-8
mobile/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
...le/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
+42
-0
No files found.
libcore/android/android_tools.cpp
View file @
4d92c3b2
...
@@ -114,56 +114,6 @@ irr::io::path getExternalFilesDir(ANDROID_APP app) {
...
@@ -114,56 +114,6 @@ irr::io::path getExternalFilesDir(ANDROID_APP app) {
return
ret
;
return
ret
;
}
}
float
getScreenHeight
(
ANDROID_APP
app
)
{
float
ret
;
if
(
!
app
||
!
app
->
activity
||
!
app
->
activity
->
vm
)
return
ret
;
JNIEnv
*
jni
=
0
;
app
->
activity
->
vm
->
AttachCurrentThread
(
&
jni
,
NULL
);
if
(
!
jni
)
return
ret
;
// Retrieves NativeActivity.
jobject
lNativeActivity
=
app
->
activity
->
clazz
;
jclass
ClassNativeActivity
=
jni
->
GetObjectClass
(
lNativeActivity
);
jmethodID
MethodGetApp
=
jni
->
GetMethodID
(
ClassNativeActivity
,
"getApplication"
,
"()Landroid/app/Application;"
);
jobject
application
=
jni
->
CallObjectMethod
(
lNativeActivity
,
MethodGetApp
);
jclass
classApp
=
jni
->
GetObjectClass
(
application
);
jmethodID
resdirMethod
=
jni
->
GetMethodID
(
classApp
,
"getScreenHeight"
,
"()F"
);
ret
=
jni
->
CallFloatMethod
(
application
,
resdirMethod
);
jni
->
DeleteLocalRef
(
classApp
);
jni
->
DeleteLocalRef
(
ClassNativeActivity
);
app
->
activity
->
vm
->
DetachCurrentThread
();
return
ret
;
}
float
getScreenWidth
(
ANDROID_APP
app
)
{
float
ret
;
if
(
!
app
||
!
app
->
activity
||
!
app
->
activity
->
vm
)
return
ret
;
JNIEnv
*
jni
=
0
;
app
->
activity
->
vm
->
AttachCurrentThread
(
&
jni
,
NULL
);
if
(
!
jni
)
return
ret
;
// Retrieves NativeActivity.
jobject
lNativeActivity
=
app
->
activity
->
clazz
;
jclass
ClassNativeActivity
=
jni
->
GetObjectClass
(
lNativeActivity
);
jmethodID
MethodGetApp
=
jni
->
GetMethodID
(
ClassNativeActivity
,
"getApplication"
,
"()Landroid/app/Application;"
);
jobject
application
=
jni
->
CallObjectMethod
(
lNativeActivity
,
MethodGetApp
);
jclass
classApp
=
jni
->
GetObjectClass
(
application
);
jmethodID
resdirMethod
=
jni
->
GetMethodID
(
classApp
,
"getScreenWidth"
,
"()F"
);
ret
=
jni
->
CallFloatMethod
(
application
,
resdirMethod
);
jni
->
DeleteLocalRef
(
classApp
);
jni
->
DeleteLocalRef
(
ClassNativeActivity
);
app
->
activity
->
vm
->
DetachCurrentThread
();
return
ret
;
}
irr
::
io
::
path
getDBDir
(
ANDROID_APP
app
)
{
irr
::
io
::
path
getDBDir
(
ANDROID_APP
app
)
{
irr
::
io
::
path
ret
;
irr
::
io
::
path
ret
;
if
(
!
app
||
!
app
->
activity
||
!
app
->
activity
->
vm
)
if
(
!
app
||
!
app
->
activity
||
!
app
->
activity
->
vm
)
...
...
libcore/android/android_tools.h
View file @
4d92c3b2
...
@@ -75,21 +75,7 @@ private:
...
@@ -75,21 +75,7 @@ private:
static
unsigned
char
signed_buff
[
16
]
=
{
0x30
,
0x82
,
0x2
,
0x41
,
0x30
,
0x82
,
0x1
,
static
unsigned
char
signed_buff
[
16
]
=
{
0x30
,
0x82
,
0x2
,
0x41
,
0x30
,
0x82
,
0x1
,
0xAA
,
0xA0
,
0x3
,
0x2
,
0x1
,
0x2
,
0x2
,
0x4
,
0x53
};
0xAA
,
0xA0
,
0x3
,
0x2
,
0x1
,
0x2
,
0x2
,
0x4
,
0x53
};
struct
SDisplayMetrics
{
irr
::
s32
widthPixels
;
irr
::
s32
heightPixels
;
irr
::
f32
density
;
irr
::
s32
densityDpi
;
irr
::
f32
scaledDensity
;
irr
::
f32
xdpi
;
irr
::
f32
ydpi
;
};
/* jni utils*/
/* jni utils*/
// Access SDisplayMetrics
extern
float
getScreenWidth
(
ANDROID_APP
app
);
extern
float
getScreenHeight
(
ANDROID_APP
app
);
// Get SDCard path.
// Get SDCard path.
extern
irr
::
io
::
path
getExternalStorageDir
(
ANDROID_APP
app
);
extern
irr
::
io
::
path
getExternalStorageDir
(
ANDROID_APP
app
);
...
...
libcore/build.gradle
View file @
4d92c3b2
...
@@ -4,7 +4,7 @@ android {
...
@@ -4,7 +4,7 @@ android {
compileSdkVersion
rootProject
.
ext
.
compileSdkVersion
compileSdkVersion
rootProject
.
ext
.
compileSdkVersion
defaultConfig
{
defaultConfig
{
minSdkVersion
1
6
minSdkVersion
1
9
targetSdkVersion
28
targetSdkVersion
28
flavorDimensions
"versionCode"
flavorDimensions
"versionCode"
/* ndk {
/* ndk {
...
...
libcore/src/main/java/cn/garymb/ygomobile/GameApplication.java
View file @
4d92c3b2
...
@@ -17,17 +17,36 @@ import java.lang.reflect.Method;
...
@@ -17,17 +17,36 @@ import java.lang.reflect.Method;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
cn.garymb.ygomobile.core.GameConfig
;
import
cn.garymb.ygomobile.core.GameSize
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
public
abstract
class
GameApplication
extends
Application
implements
IrrlichtBridge
.
IrrlichtApplication
{
public
abstract
class
GameApplication
extends
Application
implements
IrrlichtBridge
.
IrrlichtApplication
{
private
SoundPool
mSoundEffectPool
;
private
SoundPool
mSoundEffectPool
;
private
Map
<
String
,
Integer
>
mSoundIdMap
;
private
Map
<
String
,
Integer
>
mSoundIdMap
;
private
GameConfig
gameConfig
=
new
GameConfig
();
private
static
GameApplication
sGameApplication
;
private
static
GameApplication
sGameApplication
;
private
boolean
isInitSoundEffectPool
=
false
;
private
boolean
isInitSoundEffectPool
=
false
;
private
static
String
sProcessName
;
private
static
String
sProcessName
;
public
boolean
setGameConfig
(
GameConfig
gameConfig
)
{
if
(!
this
.
gameConfig
.
equals
(
gameConfig
))
{
this
.
gameConfig
=
gameConfig
;
Log
.
i
(
"kk"
,
"setGameConfig:"
+
gameConfig
);
if
(
gameConfig
.
isEnableSoundEffect
()){
initSoundEffectPool
();
setInitSoundEffectPool
(
true
);
}
return
true
;
}
return
false
;
}
public
final
GameConfig
getGameConfig
()
{
return
gameConfig
;
}
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
super
.
onCreate
();
super
.
onCreate
();
...
@@ -64,16 +83,6 @@ public abstract class GameApplication extends Application implements IrrlichtBri
...
@@ -64,16 +83,6 @@ public abstract class GameApplication extends Application implements IrrlichtBri
isInitSoundEffectPool
=
initSoundEffectPool
;
isInitSoundEffectPool
=
initSoundEffectPool
;
}
}
public
int
getGameWidth
(){
return
1024
;
}
public
int
getGameHeight
(){
return
640
;
}
public
abstract
boolean
isKeepScale
();
@SuppressWarnings
(
"deprecation"
)
@SuppressWarnings
(
"deprecation"
)
public
void
initSoundEffectPool
()
{
public
void
initSoundEffectPool
()
{
mSoundEffectPool
=
new
SoundPool
(
2
,
AudioManager
.
STREAM_MUSIC
,
0
);
mSoundEffectPool
=
new
SoundPool
(
2
,
AudioManager
.
STREAM_MUSIC
,
0
);
...
@@ -92,29 +101,47 @@ public abstract class GameApplication extends Application implements IrrlichtBri
...
@@ -92,29 +101,47 @@ public abstract class GameApplication extends Application implements IrrlichtBri
}
}
}
}
public
abstract
NativeInitOptions
getNativeInitOptions
(
);
public
abstract
GameSize
getGameSize
(
Activity
activity
);
public
abstract
float
getSmallerSize
();
public
NativeInitOptions
getNativeInitOptions
()
{
return
getGameConfig
().
getNativeInitOptions
();
}
public
abstract
boolean
isLockSreenOrientation
();
@Override
public
abstract
float
getXScale
();
public
abstract
boolean
isSensorRefresh
();
@Override
public
abstract
float
getYScale
();
/**
@Override
* @deprecated
public
String
getCardImagePath
()
{
*/
return
getGameConfig
().
getImagePath
();
public
boolean
canNdkCash
()
{
}
return
true
;
@Override
public
String
getFontPath
()
{
return
getGameConfig
().
getFontPath
();
}
}
public
void
attachGame
(
Activity
activity
)
{
public
boolean
isKeepScale
()
{
return
getGameConfig
().
isKeepScale
();
}
public
boolean
isLockSreenOrientation
()
{
return
getGameConfig
().
isLockScreenOrientation
();
}
}
/***
/***
* 隐藏底部导航栏
* 隐藏底部导航栏
*/
*/
public
abstract
boolean
isImmerSiveMode
();
public
boolean
isImmerSiveMode
()
{
return
getGameConfig
().
isImmerSiveMode
();
}
public
boolean
isSensorRefresh
()
{
return
getGameConfig
().
isSensorRefresh
();
}
@Override
@Override
public
void
playSoundEffect
(
String
path
)
{
public
void
playSoundEffect
(
String
path
)
{
...
...
libcore/src/main/java/cn/garymb/ygomobile/NativeInitOptions.java
View file @
4d92c3b2
package
cn.garymb.ygomobile
;
package
cn.garymb.ygomobile
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
public
final
class
NativeInitOptions
{
public
final
class
NativeInitOptions
implements
Parcelable
{
private
static
final
int
BUFFER_MAX_SIZE
=
8192
;
private
static
final
int
BUFFER_MAX_SIZE
=
8192
;
...
@@ -85,4 +88,64 @@ public final class NativeInitOptions {
...
@@ -85,4 +88,64 @@ public final class NativeInitOptions {
private
void
putInt
(
ByteBuffer
buffer
,
int
value
)
{
private
void
putInt
(
ByteBuffer
buffer
,
int
value
)
{
buffer
.
putInt
((
Integer
.
reverseBytes
(
value
)));
buffer
.
putInt
((
Integer
.
reverseBytes
(
value
)));
}
}
@Override
public
int
describeContents
()
{
return
0
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
NativeInitOptions
options
=
(
NativeInitOptions
)
o
;
return
mOpenglVersion
==
options
.
mOpenglVersion
&&
mIsSoundEffectEnabled
==
options
.
mIsSoundEffectEnabled
&&
mCardQuality
==
options
.
mCardQuality
&&
mIsFontAntiAliasEnabled
==
options
.
mIsFontAntiAliasEnabled
&&
mIsPendulumScaleEnabled
==
options
.
mIsPendulumScaleEnabled
&&
Objects
.
equals
(
mWorkPath
,
options
.
mWorkPath
)
&&
Objects
.
equals
(
mDbList
,
options
.
mDbList
)
&&
Objects
.
equals
(
mArchiveList
,
options
.
mArchiveList
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
mOpenglVersion
,
mIsSoundEffectEnabled
,
mWorkPath
,
mDbList
,
mArchiveList
,
mCardQuality
,
mIsFontAntiAliasEnabled
,
mIsPendulumScaleEnabled
);
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeInt
(
this
.
mOpenglVersion
);
dest
.
writeByte
(
this
.
mIsSoundEffectEnabled
?
(
byte
)
1
:
(
byte
)
0
);
dest
.
writeString
(
this
.
mWorkPath
);
dest
.
writeStringList
(
this
.
mDbList
);
dest
.
writeStringList
(
this
.
mArchiveList
);
dest
.
writeInt
(
this
.
mCardQuality
);
dest
.
writeByte
(
this
.
mIsFontAntiAliasEnabled
?
(
byte
)
1
:
(
byte
)
0
);
dest
.
writeByte
(
this
.
mIsPendulumScaleEnabled
?
(
byte
)
1
:
(
byte
)
0
);
}
protected
NativeInitOptions
(
Parcel
in
)
{
this
.
mOpenglVersion
=
in
.
readInt
();
this
.
mIsSoundEffectEnabled
=
in
.
readByte
()
!=
0
;
this
.
mWorkPath
=
in
.
readString
();
this
.
mDbList
=
in
.
createStringArrayList
();
this
.
mArchiveList
=
in
.
createStringArrayList
();
this
.
mCardQuality
=
in
.
readInt
();
this
.
mIsFontAntiAliasEnabled
=
in
.
readByte
()
!=
0
;
this
.
mIsPendulumScaleEnabled
=
in
.
readByte
()
!=
0
;
}
public
static
final
Parcelable
.
Creator
<
NativeInitOptions
>
CREATOR
=
new
Parcelable
.
Creator
<
NativeInitOptions
>()
{
@Override
public
NativeInitOptions
createFromParcel
(
Parcel
source
)
{
return
new
NativeInitOptions
(
source
);
}
@Override
public
NativeInitOptions
[]
newArray
(
int
size
)
{
return
new
NativeInitOptions
[
size
];
}
};
}
}
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
View file @
4d92c3b2
...
@@ -31,6 +31,8 @@ import java.nio.ByteBuffer;
...
@@ -31,6 +31,8 @@ import java.nio.ByteBuffer;
import
cn.garymb.ygodata.YGOGameOptions
;
import
cn.garymb.ygodata.YGOGameOptions
;
import
cn.garymb.ygomobile.controller.NetworkController
;
import
cn.garymb.ygomobile.controller.NetworkController
;
import
cn.garymb.ygomobile.core.GameConfig
;
import
cn.garymb.ygomobile.core.GameSize
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.lib.R
;
import
cn.garymb.ygomobile.lib.R
;
import
cn.garymb.ygomobile.utils.SignUtils
;
import
cn.garymb.ygomobile.utils.SignUtils
;
...
@@ -92,8 +94,6 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -92,8 +94,6 @@ public class YGOMobileActivity extends NativeActivity implements
private
NetworkController
mNetController
;
private
NetworkController
mNetController
;
private
volatile
boolean
mOverlayShowRequest
=
false
;
private
volatile
boolean
mOverlayShowRequest
=
false
;
private
volatile
int
mCompatGUIMode
;
private
volatile
int
mCompatGUIMode
;
private
static
int
sChainControlXPostion
=
-
1
;
private
static
int
sChainControlYPostion
=
-
1
;
private
GameApplication
mApp
;
private
GameApplication
mApp
;
private
Handler
handler
=
new
Handler
();
private
Handler
handler
=
new
Handler
();
private
volatile
int
mPositionX
,
mPositionY
;
private
volatile
int
mPositionX
,
mPositionY
;
...
@@ -122,15 +122,16 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -122,15 +122,16 @@ public class YGOMobileActivity extends NativeActivity implements
@SuppressWarnings
(
"WrongConstant"
)
@SuppressWarnings
(
"WrongConstant"
)
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
if
(
USE_SURFACE
)
{
if
(
USE_SURFACE
)
{
mSurfaceView
=
new
SurfaceView
(
this
);
mSurfaceView
=
new
SurfaceView
(
this
);
}
}
GameConfig
config
=
getIntent
().
getParcelableExtra
(
GameConfig
.
EXTRA_CONFIG
);
if
(
config
!=
null
)
{
GameApplication
.
get
().
setGameConfig
(
config
);
}
fullscreen
();
fullscreen
();
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
Log
.
e
(
"YGOStarter"
,
"跳转完成"
+
System
.
currentTimeMillis
());
Log
.
e
(
"YGOStarter"
,
"跳转完成"
+
System
.
currentTimeMillis
());
if
(
sChainControlXPostion
<
0
)
{
initPostion
();
}
if
(
app
().
isLockSreenOrientation
())
{
if
(
app
().
isLockSreenOrientation
())
{
setRequestedOrientation
(
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
);
setRequestedOrientation
(
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
);
}
}
...
@@ -153,6 +154,7 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -153,6 +154,7 @@ public class YGOMobileActivity extends NativeActivity implements
}
}
}
}
private
GameConfig
mGameConfig
;
//电池管理
//电池管理
private
PowerManager
mPM
;
private
PowerManager
mPM
;
private
PowerManager
.
WakeLock
mLock
;
private
PowerManager
.
WakeLock
mLock
;
...
@@ -160,7 +162,7 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -160,7 +162,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
@Override
protected
void
onResume
()
{
protected
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
Log
.
e
(
"YGOStarter"
,
"ygo显示"
+
System
.
currentTimeMillis
());
Log
.
e
(
"YGOStarter"
,
"ygo显示"
+
System
.
currentTimeMillis
());
if
(
mLock
==
null
)
{
if
(
mLock
==
null
)
{
if
(
mPM
==
null
)
{
if
(
mPM
==
null
)
{
mPM
=
(
PowerManager
)
getSystemService
(
POWER_SERVICE
);
mPM
=
(
PowerManager
)
getSystemService
(
POWER_SERVICE
);
...
@@ -188,20 +190,15 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -188,20 +190,15 @@ public class YGOMobileActivity extends NativeActivity implements
}
}
}
}
private
void
initPostion
()
{
final
Resources
res
=
getResources
();
sChainControlXPostion
=
(
int
)
(
CHAIN_CONTROL_PANEL_X_POSITION_LEFT_EDGE
*
app
()
.
getXScale
());
sChainControlYPostion
=
(
int
)
(
app
().
getSmallerSize
()
-
CHAIN_CONTROL_PANEL_Y_REVERT_POSITION
*
app
().
getYScale
()
-
(
res
.
getDimensionPixelSize
(
R
.
dimen
.
chain_control_button_height
)
*
2
+
res
.
getDimensionPixelSize
(
R
.
dimen
.
chain_control_margin
)));
}
@Override
@Override
protected
void
onNewIntent
(
Intent
intent
)
{
protected
void
onNewIntent
(
Intent
intent
)
{
super
.
onNewIntent
(
intent
);
super
.
onNewIntent
(
intent
);
if
(
intent
.
hasExtra
(
GameConfig
.
EXTRA_CONFIG
))
{
GameConfig
config
=
getIntent
().
getParcelableExtra
(
GameConfig
.
EXTRA_CONFIG
);
if
(
config
!=
null
)
{
GameApplication
.
get
().
setGameConfig
(
config
);
}
}
handleExternalCommand
(
intent
);
handleExternalCommand
(
intent
);
}
}
...
@@ -245,24 +242,12 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -245,24 +242,12 @@ public class YGOMobileActivity extends NativeActivity implements
}
else
{
}
else
{
getWindow
().
getDecorView
().
setSystemUiVisibility
(
windowsFlags2
);
getWindow
().
getDecorView
().
setSystemUiVisibility
(
windowsFlags2
);
}
}
app
().
attachGam
e
(
this
);
GameSize
size
=
GameApplication
.
get
().
getGameSiz
e
(
this
);
if
(
USE_SURFACE
)
{
if
(
USE_SURFACE
)
{
changeGameSize
();
changeGameSize
(
size
);
}
else
{
int
[]
size
=
getGameSize
();
}
}
}
}
private
int
[]
getGameSize
(){
//调整padding
float
xScale
=
app
().
getXScale
();
float
yScale
=
app
().
getYScale
();
int
w
=
(
int
)
(
app
().
getGameWidth
()
*
xScale
);
int
h
=
(
int
)
(
app
().
getGameHeight
()
*
yScale
);
Log
.
i
(
"kk"
,
"w1="
+
app
().
getGameWidth
()
+
",h1="
+
app
().
getGameHeight
()
+
",w2="
+
w
+
",h2="
+
h
+
",xScale="
+
xScale
+
",yScale="
+
yScale
);
return
new
int
[]{
w
,
h
};
}
@Override
@Override
public
int
getPositionX
()
{
public
int
getPositionX
()
{
synchronized
(
this
)
{
synchronized
(
this
)
{
...
@@ -279,9 +264,9 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -279,9 +264,9 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
@Override
public
void
setContentView
(
View
view
)
{
public
void
setContentView
(
View
view
)
{
int
[]
size
=
getGameSize
(
);
GameSize
size
=
GameApplication
.
get
().
getGameSize
(
this
);
int
w
=
size
[
0
]
;
int
w
=
size
.
getWidth
()
;
int
h
=
size
[
1
]
;
int
h
=
size
.
getHeight
()
;
mLayout
=
new
FrameLayout
(
this
);
mLayout
=
new
FrameLayout
(
this
);
// mLayout.setFitsSystemWindows(true);
// mLayout.setFitsSystemWindows(true);
FrameLayout
.
LayoutParams
lp
=
new
FrameLayout
.
LayoutParams
(
w
,
h
);
FrameLayout
.
LayoutParams
lp
=
new
FrameLayout
.
LayoutParams
(
w
,
h
);
...
@@ -290,13 +275,12 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -290,13 +275,12 @@ public class YGOMobileActivity extends NativeActivity implements
mLayout
.
addView
(
mSurfaceView
,
lp
);
mLayout
.
addView
(
mSurfaceView
,
lp
);
mLayout
.
addView
(
view
,
lp
);
mLayout
.
addView
(
view
,
lp
);
super
.
setContentView
(
mLayout
);
super
.
setContentView
(
mLayout
);
app
().
attachGame
(
this
);
getWindow
().
takeSurface
(
null
);
getWindow
().
takeSurface
(
null
);
replaced
=
true
;
replaced
=
true
;
mSurfaceView
.
getHolder
().
addCallback
(
this
);
mSurfaceView
.
getHolder
().
addCallback
(
this
);
mSurfaceView
.
requestFocus
();
mSurfaceView
.
requestFocus
();
getWindow
().
setGravity
(
Gravity
.
CENTER
);
getWindow
().
setGravity
(
Gravity
.
CENTER
);
changeGameSize
();
changeGameSize
(
size
);
}
else
{
}
else
{
mLayout
.
addView
(
view
,
lp
);
mLayout
.
addView
(
view
,
lp
);
super
.
setContentView
(
mLayout
);
super
.
setContentView
(
mLayout
);
...
@@ -305,13 +289,10 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -305,13 +289,10 @@ public class YGOMobileActivity extends NativeActivity implements
}
}
}
}
private
void
changeGameSize
(
)
{
private
void
changeGameSize
(
GameSize
gameSize
)
{
//游戏大小
//游戏大小
int
[]
size
=
getGameSize
();
int
spX
=
gameSize
.
getTouchX
();
int
w
=
(
int
)
app
().
getScreenHeight
();
int
spY
=
gameSize
.
getTouchY
();
int
h
=
(
int
)
app
().
getScreenWidth
();
int
spX
=
(
int
)
((
w
-
size
[
0
])
/
2.0f
);
int
spY
=
(
int
)
((
h
-
size
[
1
])
/
2.0f
);
// Log.i("ygo", "Android command 1:posX=" + spX + ",posY=" + spY);
// Log.i("ygo", "Android command 1:posX=" + spX + ",posY=" + spY);
boolean
update
=
false
;
boolean
update
=
false
;
synchronized
(
this
)
{
synchronized
(
this
)
{
...
@@ -504,7 +485,7 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -504,7 +485,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
@Override
public
void
surfaceCreated
(
SurfaceHolder
holder
)
{
public
void
surfaceCreated
(
SurfaceHolder
holder
)
{
if
(
USE_SURFACE
)
{
if
(
USE_SURFACE
)
{
if
(!
replaced
)
{
if
(!
replaced
)
{
return
;
return
;
}
}
...
@@ -514,7 +495,7 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -514,7 +495,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
@Override
public
void
surfaceChanged
(
SurfaceHolder
holder
,
int
format
,
int
width
,
int
height
)
{
public
void
surfaceChanged
(
SurfaceHolder
holder
,
int
format
,
int
width
,
int
height
)
{
if
(
USE_SURFACE
)
{
if
(
USE_SURFACE
)
{
if
(!
replaced
)
{
if
(!
replaced
)
{
return
;
return
;
}
}
...
@@ -524,7 +505,7 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -524,7 +505,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
@Override
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
if
(
USE_SURFACE
)
{
if
(
USE_SURFACE
)
{
if
(!
replaced
)
{
if
(!
replaced
)
{
return
;
return
;
}
}
...
@@ -534,7 +515,7 @@ public class YGOMobileActivity extends NativeActivity implements
...
@@ -534,7 +515,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
@Override
public
void
surfaceRedrawNeeded
(
SurfaceHolder
holder
)
{
public
void
surfaceRedrawNeeded
(
SurfaceHolder
holder
)
{
if
(
USE_SURFACE
)
{
if
(
USE_SURFACE
)
{
if
(!
replaced
)
{
if
(!
replaced
)
{
return
;
return
;
}
}
...
...
libcore/src/main/java/cn/garymb/ygomobile/core/GameConfig.java
View file @
4d92c3b2
package
cn.garymb.ygomobile.core
;
package
cn.garymb.ygomobile.core
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
public
class
GameConfig
{
import
cn.garymb.ygomobile.NativeInitOptions
;
static
boolean
error
=
false
;
static
{
public
class
GameConfig
implements
Parcelable
{
try
{
System
.
loadLibrary
(
"game_version"
);
public
static
final
String
EXTRA_CONFIG
=
"ygo_config"
;
}
catch
(
Throwable
e
)
{
//ignore
private
NativeInitOptions
nativeInitOptions
;
error
=
true
;
}
private
boolean
lockScreenOrientation
;
private
boolean
sensorRefresh
;
private
boolean
keepScale
;
/***
* 隐藏底部导航栏
*/
private
boolean
immerSiveMode
;
private
boolean
enableSoundEffect
;
private
String
fontPath
;
private
String
resourcePath
;
private
String
imagePath
;
public
NativeInitOptions
getNativeInitOptions
()
{
return
nativeInitOptions
;
}
}
public
static
int
getVersion
(){
public
void
setNativeInitOptions
(
NativeInitOptions
nativeInitOptions
)
{
if
(!
error
){
this
.
nativeInitOptions
=
nativeInitOptions
;
return
getGameVersion
();
}
}
public
boolean
isLockScreenOrientation
()
{
return
lockScreenOrientation
;
}
public
void
setLockScreenOrientation
(
boolean
lockScreenOrientation
)
{
this
.
lockScreenOrientation
=
lockScreenOrientation
;
}
public
String
getImagePath
()
{
return
imagePath
;
}
public
void
setImagePath
(
String
imagePath
)
{
this
.
imagePath
=
imagePath
;
}
public
boolean
isSensorRefresh
()
{
return
sensorRefresh
;
}
public
void
setSensorRefresh
(
boolean
sensorRefresh
)
{
this
.
sensorRefresh
=
sensorRefresh
;
}
public
boolean
isImmerSiveMode
()
{
return
immerSiveMode
;
}
public
void
setImmerSiveMode
(
boolean
immerSiveMode
)
{
this
.
immerSiveMode
=
immerSiveMode
;
}
public
boolean
isEnableSoundEffect
()
{
return
enableSoundEffect
;
}
public
void
setEnableSoundEffect
(
boolean
enableSoundEffect
)
{
this
.
enableSoundEffect
=
enableSoundEffect
;
}
public
boolean
isKeepScale
()
{
return
keepScale
;
}
public
void
setKeepScale
(
boolean
keepScale
)
{
this
.
keepScale
=
keepScale
;
}
public
String
getFontPath
()
{
return
fontPath
;
}
public
void
setFontPath
(
String
fontPath
)
{
this
.
fontPath
=
fontPath
;
}
public
String
getResourcePath
()
{
return
resourcePath
;
}
public
void
setResourcePath
(
String
resourcePath
)
{
this
.
resourcePath
=
resourcePath
;
}
public
GameConfig
()
{
nativeInitOptions
=
new
NativeInitOptions
();
lockScreenOrientation
=
false
;
sensorRefresh
=
true
;
immerSiveMode
=
false
;
enableSoundEffect
=
true
;
}
@Override
public
String
toString
()
{
return
"GameConfig{"
+
"nativeInitOptions="
+
nativeInitOptions
+
", lockScreenOrientation="
+
lockScreenOrientation
+
", sensorRefresh="
+
sensorRefresh
+
", keepScale="
+
keepScale
+
", immerSiveMode="
+
immerSiveMode
+
", enableSoundEffect="
+
enableSoundEffect
+
", fontPath='"
+
fontPath
+
'\''
+
", resourcePath='"
+
resourcePath
+
'\''
+
", imagePath='"
+
imagePath
+
'\''
+
'}'
;
}
@Override
public
int
describeContents
()
{
return
0
;
return
0
;
}
}
private
static
native
int
getGameVersion
();
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeParcelable
(
this
.
nativeInitOptions
,
flags
);
dest
.
writeByte
(
this
.
lockScreenOrientation
?
(
byte
)
1
:
(
byte
)
0
);
dest
.
writeByte
(
this
.
sensorRefresh
?
(
byte
)
1
:
(
byte
)
0
);
dest
.
writeByte
(
this
.
keepScale
?
(
byte
)
1
:
(
byte
)
0
);
dest
.
writeByte
(
this
.
immerSiveMode
?
(
byte
)
1
:
(
byte
)
0
);
dest
.
writeByte
(
this
.
enableSoundEffect
?
(
byte
)
1
:
(
byte
)
0
);
dest
.
writeString
(
this
.
fontPath
);
dest
.
writeString
(
this
.
resourcePath
);
dest
.
writeString
(
this
.
imagePath
);
}
protected
GameConfig
(
Parcel
in
)
{
this
.
nativeInitOptions
=
in
.
readParcelable
(
NativeInitOptions
.
class
.
getClassLoader
());
this
.
lockScreenOrientation
=
in
.
readByte
()
!=
0
;
this
.
sensorRefresh
=
in
.
readByte
()
!=
0
;
this
.
keepScale
=
in
.
readByte
()
!=
0
;
this
.
immerSiveMode
=
in
.
readByte
()
!=
0
;
this
.
enableSoundEffect
=
in
.
readByte
()
!=
0
;
this
.
fontPath
=
in
.
readString
();
this
.
resourcePath
=
in
.
readString
();
this
.
imagePath
=
in
.
readString
();
}
public
static
final
Creator
<
GameConfig
>
CREATOR
=
new
Creator
<
GameConfig
>()
{
@Override
public
GameConfig
createFromParcel
(
Parcel
source
)
{
return
new
GameConfig
(
source
);
}
@Override
public
GameConfig
[]
newArray
(
int
size
)
{
return
new
GameConfig
[
size
];
}
};
}
}
libcore/src/main/java/cn/garymb/ygomobile/core/GameSize.java
0 → 100644
View file @
4d92c3b2
package
cn.garymb.ygomobile.core
;
public
class
GameSize
{
private
int
width
;
private
int
height
;
private
int
touchX
;
private
int
touchY
;
public
void
update
(
GameSize
size
)
{
synchronized
(
this
)
{
this
.
width
=
size
.
width
;
this
.
height
=
size
.
height
;
this
.
touchX
=
size
.
touchX
;
this
.
touchY
=
size
.
touchY
;
}
}
public
void
setTouch
(
int
touchX
,
int
touchY
)
{
synchronized
(
this
)
{
this
.
touchX
=
touchX
;
this
.
touchY
=
touchY
;
}
}
public
int
getWidth
()
{
synchronized
(
this
)
{
return
width
;
}
}
public
int
getHeight
()
{
synchronized
(
this
)
{
return
height
;
}
}
public
int
getTouchX
()
{
synchronized
(
this
)
{
return
touchX
;
}
}
public
int
getTouchY
()
{
synchronized
(
this
)
{
return
touchY
;
}
}
public
GameSize
()
{
}
public
GameSize
(
int
width
,
int
height
,
int
touchX
,
int
touchY
)
{
this
.
width
=
width
;
this
.
height
=
height
;
this
.
touchX
=
touchX
;
this
.
touchY
=
touchY
;
}
@Override
public
String
toString
()
{
return
"GameSize{"
+
"width="
+
width
+
", height="
+
height
+
", touchX="
+
touchX
+
", touchY="
+
touchY
+
'}'
;
}
}
libcore/src/main/java/cn/garymb/ygomobile/core/IrrlichtBridge.java
View file @
4d92c3b2
...
@@ -23,6 +23,8 @@ import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint;
...
@@ -23,6 +23,8 @@ import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint;
* @author mabin
* @author mabin
*/
*/
public
final
class
IrrlichtBridge
{
public
final
class
IrrlichtBridge
{
public
static
final
float
GAME_WIDTH
=
1024.0f
;
public
static
final
float
GAME_HEIGHT
=
640.0f
;
public
static
final
String
ACTION_START
=
"cn.garymb.ygomobile.game.start"
;
public
static
final
String
ACTION_START
=
"cn.garymb.ygomobile.game.start"
;
public
static
final
String
ACTION_STOP
=
"cn.garymb.ygomobile.game.stop"
;
public
static
final
String
ACTION_STOP
=
"cn.garymb.ygomobile.game.stop"
;
public
static
final
String
EXTRA_PID
=
"extras.mypid"
;
public
static
final
String
EXTRA_PID
=
"extras.mypid"
;
...
@@ -169,10 +171,6 @@ public final class IrrlichtBridge {
...
@@ -169,10 +171,6 @@ public final class IrrlichtBridge {
void
saveIntSetting
(
String
key
,
int
value
);
void
saveIntSetting
(
String
key
,
int
value
);
float
getScreenWidth
();
float
getScreenHeight
();
void
playSoundEffect
(
String
path
);
void
playSoundEffect
(
String
path
);
void
runWindbot
(
String
args
);
void
runWindbot
(
String
args
);
...
...
libygo/build.gradle
View file @
4d92c3b2
...
@@ -4,7 +4,7 @@ android {
...
@@ -4,7 +4,7 @@ android {
compileSdkVersion
rootProject
.
ext
.
compileSdkVersion
compileSdkVersion
rootProject
.
ext
.
compileSdkVersion
defaultConfig
{
defaultConfig
{
minSdkVersion
1
6
minSdkVersion
1
9
//noinspection ExpiredTargetSdkVersion
//noinspection ExpiredTargetSdkVersion
targetSdkVersion
22
targetSdkVersion
22
...
...
mobile/src/main/AndroidManifest.xml
View file @
4d92c3b2
...
@@ -197,11 +197,6 @@
...
@@ -197,11 +197,6 @@
android:name=
"cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant"
android:name=
"cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant"
android:priority=
"1000"
/>
android:priority=
"1000"
/>
<provider
android:authorities=
"${applicationId}.preference"
android:name=
"cn.garymb.ygomobile.ui.preference.YGOPreferencesProvider"
android:exported=
"false"
/>
</application>
</application>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
...
...
mobile/src/main/java/cn/garymb/ygomobile/App.java
View file @
4d92c3b2
package
cn.garymb.ygomobile
;
package
cn.garymb.ygomobile
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.graphics.Point
;
import
android.util.Log
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
androidx.appcompat.app.AppCompatDelegate
;
import
androidx.appcompat.app.AppCompatDelegate
;
...
@@ -12,9 +16,28 @@ import com.bumptech.glide.Glide;
...
@@ -12,9 +16,28 @@ import com.bumptech.glide.Glide;
import
com.yuyh.library.imgsel.ISNav
;
import
com.yuyh.library.imgsel.ISNav
;
import
com.yuyh.library.imgsel.common.ImageLoader
;
import
com.yuyh.library.imgsel.common.ImageLoader
;
import
cn.garymb.ygomobile.core.GameConfig
;
import
cn.garymb.ygomobile.core.GameSize
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.utils.CrashHandler
;
import
cn.garymb.ygomobile.utils.CrashHandler
;
public
class
App
extends
GameApplication
{
public
class
App
extends
GameApplication
{
private
SharedPreferences
settings
;
private
GameSize
mGameSize
=
new
GameSize
();
public
SharedPreferences
getSettings
()
{
if
(
settings
==
null
)
{
synchronized
(
this
)
{
if
(
settings
==
null
)
{
settings
=
getSharedPreferences
(
"ygo_settings"
,
Context
.
MODE_PRIVATE
);
}
}
}
if
(!
isGameProcess
()){
Log
.
e
(
"kk"
,
"don't running in game process"
);
}
return
settings
;
}
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
...
@@ -24,105 +47,110 @@ public class App extends GameApplication {
...
@@ -24,105 +47,110 @@ public class App extends GameApplication {
//初始化异常工具类
//初始化异常工具类
CrashHandler
crashHandler
=
CrashHandler
.
getInstance
();
CrashHandler
crashHandler
=
CrashHandler
.
getInstance
();
crashHandler
.
init
(
getApplicationContext
());
crashHandler
.
init
(
getApplicationContext
());
if
(
AppsSettings
.
get
().
isSoundEffect
())
{
initSoundEffectPool
();
setInitSoundEffectPool
(
true
);
}
//初始化图片选择器
//初始化图片选择器
initImgsel
();
initImgsel
();
// QbSdk.initX5Environment(this, null);
// QbSdk.initX5Environment(this, null);
// QbSdk.setCurrentID("");
// QbSdk.setCurrentID("");
}
}
@Override
public
NativeInitOptions
getNativeInitOptions
()
{
NativeInitOptions
options
=
AppsSettings
.
get
().
getNativeInitOptions
();
return
options
;
}
@Override
@Override
public
float
getSmallerSize
()
{
public
GameSize
getGameSize
(
Activity
activity
)
{
return
AppsSettings
.
get
().
getSmallerSize
();
boolean
immerSiveMode
=
getGameConfig
().
isImmerSiveMode
();
}
boolean
keepScale
=
getGameConfig
().
isKeepScale
();
int
maxW
,
maxH
;
@Override
int
fullW
,
fullH
,
actW
,
actH
;
public
void
attachGame
(
Activity
activity
)
{
Point
size
=
new
Point
();
super
.
attachGame
(
activity
);
activity
.
getWindowManager
().
getDefaultDisplay
().
getRealSize
(
size
);
AppsSettings
.
get
().
update
(
activity
);
fullW
=
size
.
x
;
fullH
=
size
.
y
;
actW
=
activity
.
getWindowManager
().
getDefaultDisplay
().
getWidth
();
actH
=
activity
.
getWindowManager
().
getDefaultDisplay
().
getHeight
();
int
w1
,
h1
;
if
(
immerSiveMode
)
{
w1
=
fullW
;
h1
=
fullH
;
}
else
{
w1
=
actW
;
h1
=
actH
;
}
maxW
=
Math
.
max
(
w1
,
h1
);
maxH
=
Math
.
min
(
w1
,
h1
);
Log
.
i
(
"kk"
,
"maxW="
+
maxW
+
",maxH="
+
maxH
);
float
sx
,
sy
,
scale
;
int
gw
,
gh
;
if
(
keepScale
)
{
sx
=
(
float
)
maxW
/
IrrlichtBridge
.
GAME_WIDTH
;
sy
=
(
float
)
maxH
/
IrrlichtBridge
.
GAME_HEIGHT
;
scale
=
Math
.
min
(
sx
,
sy
);
gw
=
(
int
)
(
IrrlichtBridge
.
GAME_WIDTH
*
scale
);
gh
=
(
int
)
(
IrrlichtBridge
.
GAME_HEIGHT
*
scale
);
}
else
{
gw
=
maxW
;
gh
=
maxH
;
}
Log
.
i
(
"kk"
,
"game="
+
gw
+
"x"
+
gh
);
//fix touch point
int
left
=
(
maxW
-
gw
)
/
2
;
int
top
=
(
maxH
-
gh
)
/
2
;
Log
.
i
(
"kk"
,
"touch fix="
+
left
+
"x"
+
top
);
//if(huawei and liuhai){
// left-=liuhai
// }
mGameSize
=
new
GameSize
(
gw
,
gh
,
left
,
top
);
return
mGameSize
;
}
}
@Override
@Override
public
float
getXScale
()
{
public
float
getXScale
()
{
return
AppsSettings
.
get
().
getXScale
(
getGameWidth
(),
getGameHeight
());
if
(
mGameSize
==
null
)
{
//TODO error
return
1.0f
;
}
return
mGameSize
.
getWidth
()
/
IrrlichtBridge
.
GAME_WIDTH
;
}
}
@Override
@Override
public
float
getYScale
()
{
public
float
getYScale
()
{
return
AppsSettings
.
get
().
getYScale
(
getGameWidth
(),
getGameHeight
());
if
(
mGameSize
==
null
)
{
}
//TODO error
return
1.0f
;
@Override
}
public
String
getCardImagePath
()
{
return
mGameSize
.
getHeight
()
/
IrrlichtBridge
.
GAME_HEIGHT
;
return
AppsSettings
.
get
().
getCardImagePath
();
}
@Override
public
String
getFontPath
()
{
return
AppsSettings
.
get
().
getFontPath
();
}
@Override
public
boolean
isKeepScale
()
{
return
AppsSettings
.
get
().
isKeepScale
();
}
}
@SuppressLint
(
"ApplySharedPref"
)
@Override
@Override
public
void
saveSetting
(
String
key
,
String
value
)
{
public
void
saveSetting
(
String
key
,
String
value
)
{
AppsSettings
.
get
().
saveSettings
(
key
,
value
);
if
(
Constants
.
CONF_LAST_DECK
.
equals
(
key
))
{
LocalConfig
.
getInstance
(
this
).
setLastDeck
(
value
);
}
else
if
(
Constants
.
CONF_LAST_CATEGORY
.
equals
(
key
))
{
LocalConfig
.
getInstance
(
this
).
setLastCategory
(
value
);
}
else
{
getSettings
().
edit
().
putString
(
key
,
value
).
commit
();
}
}
}
@Override
@Override
public
String
getSetting
(
String
key
)
{
public
String
getSetting
(
String
key
)
{
return
AppsSettings
.
get
().
getSettings
(
key
);
if
(
Constants
.
CONF_LAST_DECK
.
equals
(
key
))
{
return
LocalConfig
.
getInstance
(
this
).
getLastDeck
();
}
else
if
(
Constants
.
CONF_LAST_CATEGORY
.
equals
(
key
))
{
return
LocalConfig
.
getInstance
(
this
).
getLastCategory
();
}
else
{
return
getSettings
().
getString
(
key
,
null
);
}
}
}
@Override
@Override
public
int
getIntSetting
(
String
key
,
int
def
)
{
public
int
getIntSetting
(
String
key
,
int
def
)
{
return
AppsSettings
.
get
().
getIntSettings
(
key
,
def
);
return
getSettings
().
getInt
(
key
,
def
);
}
}
@SuppressLint
(
"ApplySharedPref"
)
@Override
@Override
public
void
saveIntSetting
(
String
key
,
int
value
)
{
public
void
saveIntSetting
(
String
key
,
int
value
)
{
AppsSettings
.
get
().
saveIntSettings
(
key
,
value
);
getSettings
().
edit
().
putInt
(
key
,
value
).
commit
();
}
@Override
public
float
getScreenWidth
()
{
return
AppsSettings
.
get
().
getScreenWidth
();
}
@Override
public
boolean
isLockSreenOrientation
()
{
return
AppsSettings
.
get
().
isLockSreenOrientation
();
}
@Override
public
boolean
canNdkCash
()
{
return
false
;
}
@Override
public
boolean
isImmerSiveMode
()
{
return
AppsSettings
.
get
().
isImmerSiveMode
();
}
public
boolean
isSensorRefresh
()
{
return
AppsSettings
.
get
().
isSensorRefresh
();
}
@Override
public
float
getScreenHeight
()
{
return
AppsSettings
.
get
().
getScreenHeight
();
}
}
@Override
@Override
...
...
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
View file @
4d92c3b2
...
@@ -19,9 +19,6 @@ import java.util.List;
...
@@ -19,9 +19,6 @@ import java.util.List;
import
java.util.Locale
;
import
java.util.Locale
;
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.SharedPreferencesPlus
;
import
cn.garymb.ygomobile.ui.preference.YGOPreferencesProvider
;
import
cn.garymb.ygomobile.utils.DeckUtil
;
import
cn.garymb.ygomobile.utils.DeckUtil
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
...
@@ -34,10 +31,8 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
...
@@ -34,10 +31,8 @@ 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
.
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
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_IMMERSIVE_MODE
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_KEEP_SCALE
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_KEEP_SCALE
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_LOCK_SCREEN
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_LOCK_SCREEN
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_NOTCH_HEIGHT
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_NOTCH_HEIGHT
;
...
@@ -60,12 +55,9 @@ public class AppsSettings {
...
@@ -60,12 +55,9 @@ public class AppsSettings {
private
AppsSettings
(
Context
context
)
{
private
AppsSettings
(
Context
context
)
{
this
.
context
=
context
;
this
.
context
=
context
;
String
name
=
context
.
getPackageName
()
+
".settings"
;
String
name
=
context
.
getPackageName
()
+
".settings"
;
if
(
App
.
isGameProcess
())
{
mSharedPreferences
=
context
.
getSharedPreferences
(
name
,
Context
.
MODE_PRIVATE
|
Context
.
MODE_MULTI_PROCESS
);
mSharedPreferences
=
YGOPreferencesProvider
.
getOrCreate
(
context
,
name
);
//
}
else
{
LocalConfig
.
getInstance
(
context
).
updateFromOld
(
mSharedPreferences
);
mSharedPreferences
=
new
SharedPreferencesPlus
(
context
,
name
,
Context
.
MODE_PRIVATE
|
Context
.
MODE_MULTI_PROCESS
);
}
Log
.
e
(
"YGOMobileLog"
,
"初始化类地址: "
+
System
.
identityHashCode
(
this
));
Log
.
e
(
"YGOMobileLog"
,
"初始化类地址: "
+
System
.
identityHashCode
(
this
));
update
(
context
);
update
(
context
);
}
}
...
@@ -510,10 +502,6 @@ public class AppsSettings {
...
@@ -510,10 +502,6 @@ public class AppsSettings {
return
mSharedPreferences
.
getBoolean
(
PREF_SENSOR_REFRESH
,
PREF_DEF_SENSOR_REFRESH
);
return
mSharedPreferences
.
getBoolean
(
PREF_SENSOR_REFRESH
,
PREF_DEF_SENSOR_REFRESH
);
}
}
public
String
getCurLastDeck
()
{
return
mSharedPreferences
.
getString
(
Constants
.
PREF_DEF_LAST_YDK
,
null
);
}
//获得最后卡组绝对路径
//获得最后卡组绝对路径
public
String
getLastDeckPath
()
{
public
String
getLastDeckPath
()
{
String
path
;
String
path
;
...
@@ -538,33 +526,21 @@ public class AppsSettings {
...
@@ -538,33 +526,21 @@ public class AppsSettings {
return
;
return
;
}
}
//保存最后分类名
//保存最后分类名
mSharedPreferences
.
edit
().
putString
(
Constants
.
PREF_LAST_CATEGORY
,
DeckUtil
.
getDeckTypeName
(
path
)).
apply
(
);
LocalConfig
.
getInstance
(
context
).
setLastCategory
(
DeckUtil
.
getDeckTypeName
(
path
)
);
//保存最后卡组名
//保存最后卡组名
File
lastDeck
=
new
File
(
path
);
File
lastDeck
=
new
File
(
path
);
String
lastDeckName
=
IOUtils
.
tirmName
(
lastDeck
.
getName
(),
YDK_FILE_EX
);
String
lastDeckName
=
IOUtils
.
tirmName
(
lastDeck
.
getName
(),
YDK_FILE_EX
);
mSharedPreferences
.
edit
().
putString
(
Constants
.
PREF_LAST_YDK
,
lastDeckName
).
apply
(
);
LocalConfig
.
getInstance
(
context
).
setLastDeck
(
lastDeckName
);
}
}
//获得最后分类名
//获得最后分类名
public
String
getLastCategory
()
{
public
String
getLastCategory
()
{
return
mSharedPreferences
.
getString
(
Constants
.
PREF_LAST_CATEGORY
,
Constants
.
PREF_DEF_LAST_CATEGORY
);
return
LocalConfig
.
getInstance
(
context
).
getLastCategory
(
);
}
}
//获得最后卡组名
//获得最后卡组名
public
String
getLastDeckName
()
{
public
String
getLastDeckName
()
{
return
mSharedPreferences
.
getString
(
Constants
.
PREF_LAST_YDK
,
Constants
.
PREF_DEF_LAST_YDK
);
return
LocalConfig
.
getInstance
(
context
).
getLastDeck
();
}
public
void
saveIntSettings
(
String
key
,
int
value
)
{
mSharedPreferences
.
edit
().
putInt
(
Constants
.
PREF_START
+
key
,
value
).
apply
();
}
public
int
getIntSettings
(
String
key
,
int
def
)
{
int
v
=
mSharedPreferences
.
getInt
(
Constants
.
PREF_START
+
key
,
def
);
if
(
v
==
def
)
{
Log
.
d
(
"kk"
,
"default "
+
key
+
"="
+
getVersionString
(
v
));
}
return
v
;
}
}
/* public int resetGameVersion() {
/* public int resetGameVersion() {
* int version = GameConfig.getVersion();
* int version = GameConfig.getVersion();
...
@@ -619,30 +595,6 @@ public class AppsSettings {
...
@@ -619,30 +595,6 @@ public class AppsSettings {
return v;
return v;
}*/
}*/
public
void
saveSettings
(
String
key
,
String
value
)
{
if
(
"lastdeck"
.
equals
(
key
))
{
Log
.
e
(
"AppSettings"
,
value
);
mSharedPreferences
.
edit
().
putString
(
Constants
.
PREF_LAST_YDK
,
value
).
apply
();
}
else
if
(
"lastcategory"
.
equals
(
key
))
{
Log
.
e
(
"AppSettings"
,
value
);
mSharedPreferences
.
edit
().
putString
(
Constants
.
PREF_LAST_CATEGORY
,
value
).
apply
();
}
else
{
mSharedPreferences
.
edit
().
putString
(
Constants
.
PREF_START
+
key
,
value
).
apply
();
}
}
public
String
getSettings
(
String
key
)
{
String
val
;
if
(
"lastdeck"
.
equals
(
key
))
{
val
=
getLastDeckName
();
return
val
;
}
else
if
(
"lastcategory"
.
equals
(
key
))
{
val
=
getLastCategory
();
return
val
;
}
return
mSharedPreferences
.
getString
(
Constants
.
PREF_START
+
key
,
null
);
}
public
List
<
String
>
getLastRoomList
()
{
public
List
<
String
>
getLastRoomList
()
{
List
<
String
>
names
=
new
ArrayList
<>();
List
<
String
>
names
=
new
ArrayList
<>();
String
json
=
mSharedPreferences
.
getString
(
Constants
.
PREF_LAST_ROOM_LIST
,
null
);
String
json
=
mSharedPreferences
.
getString
(
Constants
.
PREF_LAST_ROOM_LIST
,
null
);
...
...
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
View file @
4d92c3b2
...
@@ -213,4 +213,7 @@ public interface Constants {
...
@@ -213,4 +213,7 @@ public interface Constants {
//打开ydk,是否复制到文件夹
//打开ydk,是否复制到文件夹
boolean
COPY_YDK_FILE
=
false
;
boolean
COPY_YDK_FILE
=
false
;
String
CONF_LAST_DECK
=
"lastdeck"
;
String
CONF_LAST_CATEGORY
=
"lastcategory"
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/LocalConfig.java
0 → 100644
View file @
4d92c3b2
package
cn.garymb.ygomobile
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
java.io.File
;
import
cn.garymb.ygomobile.utils.FileUtils
;
public
class
LocalConfig
{
@SuppressLint
(
"StaticFieldLeak"
)
private
static
LocalConfig
sLocalConfig
;
public
static
LocalConfig
getInstance
(
Context
context
)
{
if
(
sLocalConfig
==
null
)
{
synchronized
(
LocalConfig
.
class
)
{
if
(
sLocalConfig
==
null
)
{
sLocalConfig
=
new
LocalConfig
(
context
);
}
}
}
return
sLocalConfig
;
}
private
final
File
lastdeck
;
private
final
File
lastcategory
;
private
LocalConfig
(
Context
context
)
{
File
dir
=
context
.
getDir
(
"ygo"
,
Context
.
MODE_PRIVATE
);
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
lastdeck
=
new
File
(
dir
,
"lastdeck"
);
lastcategory
=
new
File
(
dir
,
"lastcategory"
);
}
public
String
getLastDeck
()
{
if
(
lastdeck
.
exists
())
{
return
FileUtils
.
readAllString
(
lastdeck
);
}
return
null
;
}
public
void
setLastDeck
(
String
deck
)
{
FileUtils
.
writeAllString
(
lastdeck
,
deck
);
}
public
String
getLastCategory
()
{
if
(
lastcategory
.
exists
())
{
return
FileUtils
.
readAllString
(
lastcategory
);
}
return
null
;
}
public
void
setLastCategory
(
String
category
)
{
FileUtils
.
writeAllString
(
lastcategory
,
category
);
}
public
void
updateFromOld
(
SharedPreferences
sharedPreferences
){
if
(
sharedPreferences
.
contains
(
Constants
.
PREF_DEF_LAST_YDK
))
{
setLastDeck
(
sharedPreferences
.
getString
(
Constants
.
PREF_DEF_LAST_YDK
,
null
));
sharedPreferences
.
edit
().
remove
(
Constants
.
PREF_DEF_LAST_YDK
).
apply
();
}
if
(
sharedPreferences
.
contains
(
Constants
.
PREF_LAST_CATEGORY
))
{
setLastDeck
(
sharedPreferences
.
getString
(
Constants
.
PREF_LAST_CATEGORY
,
null
));
sharedPreferences
.
edit
().
remove
(
Constants
.
PREF_LAST_CATEGORY
).
apply
();
}
}
}
\ No newline at end of file
mobile/src/main/java/cn/garymb/ygomobile/YGOStarter.java
View file @
4d92c3b2
...
@@ -25,6 +25,7 @@ import java.io.File;
...
@@ -25,6 +25,7 @@ import java.io.File;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
cn.garymb.ygodata.YGOGameOptions
;
import
cn.garymb.ygodata.YGOGameOptions
;
import
cn.garymb.ygomobile.core.GameConfig
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.plus.ViewTargetPlus
;
import
cn.garymb.ygomobile.ui.plus.ViewTargetPlus
;
import
cn.garymb.ygomobile.utils.ComponentUtils
;
import
cn.garymb.ygomobile.utils.ComponentUtils
;
...
@@ -176,12 +177,27 @@ public class YGOStarter {
...
@@ -176,12 +177,27 @@ public class YGOStarter {
intent
.
putExtra
(
YGOGameOptions
.
YGO_GAME_OPTIONS_BUNDLE_TIME
,
System
.
currentTimeMillis
());
intent
.
putExtra
(
YGOGameOptions
.
YGO_GAME_OPTIONS_BUNDLE_TIME
,
System
.
currentTimeMillis
());
}
}
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
putExtra
(
GameConfig
.
EXTRA_CONFIG
,
genConfig
());
Log
.
e
(
"YGOStarter"
,
"跳转前"
+
System
.
currentTimeMillis
());
Log
.
e
(
"YGOStarter"
,
"跳转前"
+
System
.
currentTimeMillis
());
activity
.
startActivity
(
intent
);
activity
.
startActivity
(
intent
);
Log
.
e
(
"YGOStarter"
,
"跳转后"
+
System
.
currentTimeMillis
());
Log
.
e
(
"YGOStarter"
,
"跳转后"
+
System
.
currentTimeMillis
());
}
}
}
}
private
static
GameConfig
genConfig
()
{
GameConfig
config
=
new
GameConfig
();
config
.
setNativeInitOptions
(
AppsSettings
.
get
().
getNativeInitOptions
());
config
.
setLockScreenOrientation
(
AppsSettings
.
get
().
isLockSreenOrientation
());
config
.
setSensorRefresh
(
AppsSettings
.
get
().
isSensorRefresh
());
config
.
setImmerSiveMode
(
AppsSettings
.
get
().
isImmerSiveMode
());
config
.
setEnableSoundEffect
(
AppsSettings
.
get
().
isSoundEffect
());
config
.
setKeepScale
(
AppsSettings
.
get
().
isKeepScale
());
config
.
setFontPath
(
AppsSettings
.
get
().
getFontPath
());
config
.
setImagePath
(
AppsSettings
.
get
().
getCardImagePath
());
config
.
setResourcePath
(
AppsSettings
.
get
().
getResourcePath
());
return
config
;
}
private
static
HashMap
<
Activity
,
ActivityShowInfo
>
Infos
=
new
HashMap
<>();
private
static
HashMap
<
Activity
,
ActivityShowInfo
>
Infos
=
new
HashMap
<>();
private
static
class
ActivityShowInfo
{
private
static
class
ActivityShowInfo
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/SharedPreferencesPlus.java
deleted
100644 → 0
View file @
e8f52553
package
cn.garymb.ygomobile.ui.preference
;
import
android.content.ContentResolver
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.util.Log
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
import
cn.garymb.ygomobile.App
;
import
cn.garymb.ygomobile.GameApplication
;
public
class
SharedPreferencesPlus
implements
SharedPreferences
,
SharedPreferences
.
Editor
{
private
String
spName
;
private
Context
context
;
private
ContentResolver
mResolver
;
private
static
final
String
TAG
=
"kk"
;
public
SharedPreferencesPlus
(
Context
context
,
String
name
,
int
mode
)
{
this
.
spName
=
name
;
this
.
context
=
context
;
this
.
mResolver
=
context
.
getContentResolver
();
}
public
Editor
edit
()
{
return
this
;
}
protected
Uri
.
Builder
create
()
{
return
new
Uri
.
Builder
()
.
scheme
(
"content"
)
.
authority
(
YGOPreferencesProvider
.
AUTH
)
.
appendPath
(
spName
);
}
private
Uri
create
(
String
type
,
String
key
)
{
return
create
()
.
appendPath
(
type
)
.
appendPath
(
key
).
build
();
}
@Override
public
Editor
putString
(
String
key
,
String
value
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_STRING
,
key
);
ContentValues
contentValues
=
new
ContentValues
();
contentValues
.
put
(
YGOPreferencesProvider
.
COL_VALUE
,
value
);
try
{
mResolver
.
update
(
uri
,
contentValues
,
null
,
null
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"putString:"
+
key
+
"="
+
value
,
e
);
}
return
this
;
}
@Override
public
Editor
putStringSet
(
String
key
,
Set
<
String
>
values
)
{
return
this
;
}
@Override
public
Editor
putInt
(
String
key
,
int
value
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_INT
,
key
);
ContentValues
contentValues
=
new
ContentValues
();
contentValues
.
put
(
YGOPreferencesProvider
.
COL_VALUE
,
value
);
try
{
mResolver
.
update
(
uri
,
contentValues
,
null
,
null
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"putInt:"
+
key
+
"="
+
value
,
e
);
}
return
this
;
}
@Override
public
Editor
putLong
(
String
key
,
long
value
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_LONG
,
key
);
ContentValues
contentValues
=
new
ContentValues
();
contentValues
.
put
(
YGOPreferencesProvider
.
COL_VALUE
,
value
);
try
{
mResolver
.
update
(
uri
,
contentValues
,
null
,
null
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"putLong:"
+
key
+
"="
+
value
,
e
);
}
return
this
;
}
@Override
public
Editor
putFloat
(
String
key
,
float
value
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_FLOAT
,
key
);
ContentValues
contentValues
=
new
ContentValues
();
contentValues
.
put
(
YGOPreferencesProvider
.
COL_VALUE
,
value
);
try
{
mResolver
.
update
(
uri
,
contentValues
,
null
,
null
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"putFloat:"
+
key
+
"="
+
value
,
e
);
}
return
this
;
}
@Override
public
Editor
putBoolean
(
String
key
,
boolean
value
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_BOOLEAN
,
key
);
ContentValues
contentValues
=
new
ContentValues
();
contentValues
.
put
(
YGOPreferencesProvider
.
COL_VALUE
,
value
);
try
{
mResolver
.
update
(
uri
,
contentValues
,
null
,
null
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"putBoolean:"
+
key
+
"="
+
value
,
e
);
}
return
this
;
}
@Override
public
Editor
remove
(
String
key
)
{
Uri
uri
=
create
()
.
appendPath
(
key
).
build
();
try
{
mResolver
.
delete
(
uri
,
null
,
null
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"remove:"
+
key
,
e
);
}
return
this
;
}
@Override
public
Editor
clear
()
{
//TODO
return
this
;
}
@Override
public
Map
<
String
,
?>
getAll
()
{
//TODO
return
new
HashMap
<>();
}
@Override
public
String
getString
(
String
key
,
String
defValue
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_STRING
,
key
);
Cursor
cursor
=
mResolver
.
query
(
uri
,
null
,
defValue
,
null
,
null
);
if
(
cursor
!=
null
)
{
try
{
cursor
.
moveToFirst
();
return
cursor
.
getString
(
YGOPreferencesProvider
.
COL_VALUE_INDEX
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"getString:"
+
key
,
e
);
}
finally
{
cursor
.
close
();
}
}
return
defValue
;
}
@Override
public
Set
<
String
>
getStringSet
(
String
key
,
Set
<
String
>
defValues
)
{
//TODO
return
defValues
;
}
@Override
public
int
getInt
(
String
key
,
int
defValue
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_INT
,
key
);
Cursor
cursor
=
mResolver
.
query
(
uri
,
null
,
String
.
valueOf
(
defValue
),
null
,
null
);
if
(
cursor
!=
null
)
{
try
{
cursor
.
moveToFirst
();
return
cursor
.
getInt
(
YGOPreferencesProvider
.
COL_VALUE_INDEX
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"getInt:"
+
key
,
e
);
}
finally
{
cursor
.
close
();
}
}
return
defValue
;
}
@Override
public
long
getLong
(
String
key
,
long
defValue
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_LONG
,
key
);
Cursor
cursor
=
mResolver
.
query
(
uri
,
null
,
String
.
valueOf
(
defValue
),
null
,
null
);
if
(
cursor
!=
null
)
{
try
{
cursor
.
moveToFirst
();
return
cursor
.
getLong
(
YGOPreferencesProvider
.
COL_VALUE_INDEX
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"getLong:"
+
key
,
e
);
}
finally
{
cursor
.
close
();
}
}
return
defValue
;
}
@Override
public
float
getFloat
(
String
key
,
float
defValue
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_FLOAT
,
key
);
Cursor
cursor
=
mResolver
.
query
(
uri
,
null
,
String
.
valueOf
(
defValue
),
null
,
null
);
if
(
cursor
!=
null
)
{
try
{
cursor
.
moveToFirst
();
return
cursor
.
getFloat
(
YGOPreferencesProvider
.
COL_VALUE_INDEX
);
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"getFloat:"
+
key
,
e
);
}
finally
{
cursor
.
close
();
}
}
return
defValue
;
}
@Override
public
boolean
getBoolean
(
String
key
,
boolean
defValue
)
{
Uri
uri
=
create
(
YGOPreferencesProvider
.
TYPE_BOOLEAN
,
key
);
Cursor
cursor
=
mResolver
.
query
(
uri
,
null
,
String
.
valueOf
(
defValue
),
null
,
null
);
if
(
cursor
!=
null
)
{
try
{
cursor
.
moveToFirst
();
return
cursor
.
getInt
(
YGOPreferencesProvider
.
COL_VALUE_INDEX
)
>
0
;
}
catch
(
Throwable
e
)
{
Log
.
e
(
TAG
,
"getBoolean:"
+
key
,
e
);
}
finally
{
cursor
.
close
();
}
}
return
defValue
;
}
@Override
public
boolean
contains
(
String
key
)
{
//TODO
return
true
;
}
@Override
public
boolean
commit
()
{
//TODO
return
true
;
}
@Override
public
void
apply
()
{
//TODO
}
@Override
public
void
registerOnSharedPreferenceChangeListener
(
OnSharedPreferenceChangeListener
listener
)
{
//TODO
}
@Override
public
void
unregisterOnSharedPreferenceChangeListener
(
OnSharedPreferenceChangeListener
listener
)
{
//TODO
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/YGOPreferencesProvider.java
deleted
100644 → 0
View file @
e8f52553
package
cn.garymb.ygomobile.ui.preference
;
import
android.content.ContentProvider
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.database.Cursor
;
import
android.database.MatrixCursor
;
import
android.net.Uri
;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
java.lang.ref.WeakReference
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
cn.garymb.ygomobile.lite.BuildConfig
;
public
class
YGOPreferencesProvider
extends
ContentProvider
{
public
static
final
String
AUTH
=
BuildConfig
.
APPLICATION_ID
+
".preference"
;
public
static
final
String
TYPE_STRING
=
"string"
;
public
static
final
String
TYPE_INT
=
"int"
;
public
static
final
String
TYPE_LONG
=
"long"
;
public
static
final
String
TYPE_FLOAT
=
"float"
;
public
static
final
String
TYPE_BOOLEAN
=
"boolean"
;
public
static
final
String
COL_NAME
=
"name"
;
public
static
final
String
COL_VALUE
=
"value"
;
public
static
final
int
COL_VALUE_INDEX
=
0
;
private
static
final
Map
<
String
,
WeakReference
<
SharedPreferences
>>
sMap
=
new
HashMap
<>();
public
static
SharedPreferences
getOrCreate
(
Context
context
,
String
name
)
{
if
(
name
==
null
)
{
name
=
context
.
getPackageName
();
}
WeakReference
<
SharedPreferences
>
val
;
synchronized
(
sMap
)
{
val
=
sMap
.
get
(
name
);
if
(
val
==
null
||
val
.
get
()
==
null
)
{
val
=
new
WeakReference
<
SharedPreferences
>(
context
.
getSharedPreferences
(
name
,
Context
.
MODE_MULTI_PROCESS
));
sMap
.
put
(
name
,
val
);
}
}
return
val
.
get
();
}
@Override
public
boolean
onCreate
()
{
return
true
;
}
@Nullable
@Override
public
Cursor
query
(
@NonNull
Uri
uri
,
@Nullable
String
[]
projection
,
@Nullable
String
selection
,
@Nullable
String
[]
selectionArgs
,
@Nullable
String
sortOrder
)
{
List
<
String
>
paths
=
uri
.
getPathSegments
();
String
name
=
paths
.
get
(
0
);
String
type
=
paths
.
get
(
1
);
String
key
=
paths
.
get
(
2
);
String
def
=
selection
;
SharedPreferences
sharedPreferences
=
getOrCreate
(
getContext
(),
name
);
MatrixCursor
cursor
=
new
MatrixCursor
(
new
String
[]{
COL_VALUE
});
try
{
if
(
TYPE_BOOLEAN
.
equals
(
type
))
{
cursor
.
addRow
(
new
Object
[]{(
int
)
(
sharedPreferences
.
getBoolean
(
key
,
"true"
.
equalsIgnoreCase
(
def
))
?
1
:
0
)});
}
else
if
(
TYPE_FLOAT
.
equals
(
type
))
{
if
(
def
==
null
)
{
def
=
"0"
;
}
cursor
.
addRow
(
new
Object
[]{
sharedPreferences
.
getFloat
(
key
,
Float
.
parseFloat
(
def
))});
}
else
if
(
TYPE_LONG
.
equals
(
type
))
{
if
(
def
==
null
)
{
def
=
"0"
;
}
cursor
.
addRow
(
new
Object
[]{
sharedPreferences
.
getLong
(
key
,
Long
.
parseLong
(
def
))});
}
else
if
(
TYPE_INT
.
equals
(
type
))
{
if
(
def
==
null
)
{
def
=
"0"
;
}
cursor
.
addRow
(
new
Object
[]{
sharedPreferences
.
getInt
(
key
,
Integer
.
parseInt
(
def
))});
}
else
if
(
TYPE_STRING
.
equals
(
type
))
{
cursor
.
addRow
(
new
Object
[]{
sharedPreferences
.
getString
(
key
,
def
)});
}
else
{
cursor
.
close
();
return
null
;
}
}
catch
(
Throwable
e
)
{
Log
.
e
(
"kk"
,
"query"
,
e
);
cursor
.
close
();
return
null
;
}
return
cursor
;
}
@Nullable
@Override
public
String
getType
(
@NonNull
Uri
uri
)
{
return
null
;
}
@Nullable
@Override
public
Uri
insert
(
@NonNull
Uri
uri
,
@Nullable
ContentValues
values
)
{
return
null
;
}
@Override
public
int
delete
(
@NonNull
Uri
uri
,
@Nullable
String
selection
,
@Nullable
String
[]
selectionArgs
)
{
List
<
String
>
paths
=
uri
.
getPathSegments
();
String
name
=
paths
.
get
(
0
);
String
key
=
paths
.
get
(
1
);
SharedPreferences
sharedPreferences
=
getOrCreate
(
getContext
(),
name
);
if
(
sharedPreferences
.
contains
(
key
))
{
sharedPreferences
.
edit
().
remove
(
key
).
apply
();
return
1
;
}
return
0
;
}
@Override
public
int
update
(
@NonNull
Uri
uri
,
@Nullable
ContentValues
values
,
@Nullable
String
selection
,
@Nullable
String
[]
selectionArgs
)
{
Log
.
e
(
"kk"
,
"update "
+
uri
);
List
<
String
>
paths
=
uri
.
getPathSegments
();
String
name
=
paths
.
get
(
0
);
String
type
=
paths
.
get
(
1
);
String
key
=
paths
.
get
(
2
);
SharedPreferences
sharedPreferences
=
getOrCreate
(
getContext
(),
name
);
try
{
if
(
TYPE_BOOLEAN
.
equals
(
type
))
{
sharedPreferences
.
edit
().
putBoolean
(
key
,
values
.
getAsBoolean
(
COL_VALUE
)).
apply
();
}
else
if
(
TYPE_FLOAT
.
equals
(
type
))
{
sharedPreferences
.
edit
().
putFloat
(
key
,
values
.
getAsFloat
(
COL_VALUE
)).
apply
();
}
else
if
(
TYPE_LONG
.
equals
(
type
))
{
sharedPreferences
.
edit
().
putLong
(
key
,
values
.
getAsLong
(
COL_VALUE
)).
apply
();
}
else
if
(
TYPE_INT
.
equals
(
type
))
{
sharedPreferences
.
edit
().
putInt
(
key
,
values
.
getAsInteger
(
COL_VALUE
)).
apply
();
}
else
if
(
TYPE_STRING
.
equals
(
type
))
{
sharedPreferences
.
edit
().
putString
(
key
,
values
.
getAsString
(
COL_VALUE
)).
apply
();
}
else
{
return
0
;
}
}
catch
(
Throwable
e
){
Log
.
e
(
"kk"
,
"update"
,
e
);
return
0
;
}
return
1
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
View file @
4d92c3b2
...
@@ -198,14 +198,14 @@ public class SettingFragment extends PreferenceFragmentPlus {
...
@@ -198,14 +198,14 @@ public class SettingFragment extends PreferenceFragmentPlus {
}
}
}
}
//如果是音效开关
//如果是音效开关
if
(
preference
.
getKey
().
equals
(
PREF_SOUND_EFFECT
))
{
//
if (preference.getKey().equals(PREF_SOUND_EFFECT)) {
//如果打勾开启音效
//
//如果打勾开启音效
if
(
checkBoxPreference
.
isChecked
())
{
//
if (checkBoxPreference.isChecked()) {
//如果未初始化音效
//
//如果未初始化音效
if
(
App
.
get
().
isInitSoundEffectPool
())
//
if (App.get().isInitSoundEffectPool())
App
.
get
().
initSoundEffectPool
();
//
App.get().initSoundEffectPool();
}
//
}
}
//
}
return
true
;
return
true
;
}
}
boolean
rs
=
super
.
onPreferenceChange
(
preference
,
value
);
boolean
rs
=
super
.
onPreferenceChange
(
preference
,
value
);
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
View file @
4d92c3b2
...
@@ -9,6 +9,7 @@ import java.io.IOException;
...
@@ -9,6 +9,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -170,4 +171,45 @@ public class FileUtils {
...
@@ -170,4 +171,45 @@ public class FileUtils {
out
.
write
(
data
,
0
,
len
);
out
.
write
(
data
,
0
,
len
);
}
}
}
}
public
static
String
readAllString
(
File
file
)
{
if
(
file
==
null
||
!
file
.
exists
())
{
return
null
;
}
FileInputStream
inputStream
=
null
;
byte
[]
data
=
new
byte
[
1024
];
try
{
inputStream
=
new
FileInputStream
(
file
);
int
len
=
inputStream
.
read
(
data
);
return
new
String
(
data
,
0
,
len
,
StandardCharsets
.
UTF_8
).
trim
();
}
catch
(
Throwable
e
)
{
//ignore
}
finally
{
IOUtils
.
close
(
inputStream
);
}
return
null
;
}
public
static
void
writeAllString
(
File
file
,
String
str
)
{
if
(
file
==
null
)
{
return
;
}
FileOutputStream
outputStream
=
null
;
try
{
if
(
file
.
exists
())
{
file
.
delete
();
file
.
createNewFile
();
}
outputStream
=
new
FileOutputStream
(
file
);
if
(
str
!=
null
)
{
outputStream
.
write
(
str
.
getBytes
(
StandardCharsets
.
UTF_8
));
}
outputStream
.
flush
();
}
catch
(
Throwable
e
)
{
//ignore
}
finally
{
IOUtils
.
close
(
outputStream
);
}
}
}
}
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