Commit 7f6e461c authored by 247321453's avatar 247321453

监听游戏暂停状态

parent 8f484a26
...@@ -150,9 +150,7 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt, int errNo) { ...@@ -150,9 +150,7 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt, int errNo) {
if(pStmt) if(pStmt)
sqlite3_finalize(pStmt); sqlite3_finalize(pStmt);
int len = strlen(msg); int len = strlen(msg);
char buff[len+32]; ALOGE("cdb Error code=%d,msg=%s", errNo, msg);
sprintf(buff, "cdb Error code=%d,msg=%s", errNo, msg);
os::Printer::log(buff);
spmemvfs_close_db(pDB); spmemvfs_close_db(pDB);
spmemvfs_env_fini(); spmemvfs_env_fini();
return false; return false;
......
...@@ -33,12 +33,68 @@ void Game::process(irr::SEvent &event) { ...@@ -33,12 +33,68 @@ void Game::process(irr::SEvent &event) {
s32 y = event.MouseInput.Y; s32 y = event.MouseInput.Y;
event.MouseInput.X = optX(x); event.MouseInput.X = optX(x);
event.MouseInput.Y = optY(y); event.MouseInput.Y = optY(y);
// __android_log_print(ANDROID_LOG_DEBUG, "ygo", "Android comman process %d,%d -> %d,%d", x, y,
// event.MouseInput.X, event.MouseInput.Y);
} }
} }
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
void Game::stopBGM() {
ALOGD("stop bgm");
gMutex.lock();
soundManager->StopBGM();
gMutex.unlock();
}
void Game::playBGM() {
ALOGV("play bgm");
gMutex.lock();
if(dInfo.isStarted) {
if(dInfo.isFinished && showcardcode == 1)
soundManager->PlayBGM(SoundManager::BGM::WIN);
else if(dInfo.isFinished && (showcardcode == 2 || showcardcode == 3))
soundManager->PlayBGM(SoundManager::BGM::LOSE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] <= dInfo.lp[1] / 2)
soundManager->PlayBGM(SoundManager::BGM::DISADVANTAGE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] >= dInfo.lp[1] * 2)
soundManager->PlayBGM(SoundManager::BGM::ADVANTAGE);
else
soundManager->PlayBGM(SoundManager::BGM::DUEL);
} else if(is_building) {
soundManager->PlayBGM(SoundManager::BGM::DECK);
} else {
soundManager->PlayBGM(SoundManager::BGM::MENU);
}
gMutex.unlock();
}
void Game::onHandleAndroidCommand(ANDROID_APP app, int32_t cmd){
switch (cmd)
{
case APP_CMD_PAUSE:
ALOGD("APP_CMD_PAUSE");
if(ygo::mainGame != nullptr){
ygo::mainGame->stopBGM();
}
break;
case APP_CMD_RESUME:
//第一次不一定调用
ALOGD("APP_CMD_RESUME");
if(ygo::mainGame != nullptr){
ygo::mainGame->playBGM();
}
break;
case APP_CMD_STOP:
case APP_CMD_INIT_WINDOW:
case APP_CMD_SAVE_STATE:
case APP_CMD_TERM_WINDOW:
case APP_CMD_GAINED_FOCUS:
case APP_CMD_LOST_FOCUS:
case APP_CMD_DESTROY:
case APP_CMD_WINDOW_RESIZED:
default:
break;
}
}
bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
this->appMain = app; this->appMain = app;
#endif #endif
...@@ -76,6 +132,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -76,6 +132,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
// logger->setLogLevel(ELL_WARNING); // logger->setLogLevel(ELL_WARNING);
isPSEnabled = options->isPendulumScaleEnabled(); isPSEnabled = options->isPendulumScaleEnabled();
dataManager.FileSystem = device->getFileSystem(); dataManager.FileSystem = device->getFileSystem();
((CIrrDeviceAndroid*)device)->onAppCmd = onHandleAndroidCommand;
xScale = android::getXScale(app); xScale = android::getXScale(app);
yScale = android::getYScale(app); yScale = android::getYScale(app);
...@@ -112,9 +169,9 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -112,9 +169,9 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
for(int i=0;i<len;i++){ for(int i=0;i<len;i++){
io::path zip_path = zips[i]; io::path zip_path = zips[i];
if(dataManager.FileSystem->addFileArchive(zip_path.c_str(), false, false, EFAT_ZIP)) { if(dataManager.FileSystem->addFileArchive(zip_path.c_str(), false, false, EFAT_ZIP)) {
os::Printer::log("add arrchive ok ", zip_path.c_str()); ALOGD("add arrchive ok ", zip_path.c_str());
}else{ }else{
os::Printer::log("add arrchive fail ", zip_path.c_str()); ALOGW("add arrchive fail ", zip_path.c_str());
} }
} }
#endif #endif
...@@ -174,15 +231,15 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -174,15 +231,15 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
wchar_t wpath[1024]; wchar_t wpath[1024];
BufferIO::DecodeUTF8(cdb_path.c_str(), wpath); BufferIO::DecodeUTF8(cdb_path.c_str(), wpath);
if(dataManager.LoadDB(wpath)) { if(dataManager.LoadDB(wpath)) {
os::Printer::log("add cdb ok ", cdb_path.c_str()); ALOGD("add cdb ok ", cdb_path.c_str());
}else{ }else{
os::Printer::log("add cdb fail ", cdb_path.c_str()); ALOGW("add cdb fail ", cdb_path.c_str());
} }
} }
//if(!dataManager.LoadDB(workingDir.append("/cards.cdb").c_str())) //if(!dataManager.LoadDB(workingDir.append("/cards.cdb").c_str()))
// return false; // return false;
if(dataManager.LoadStrings((workingDir + path("/expansions/strings.conf")).c_str())){ if(dataManager.LoadStrings((workingDir + path("/expansions/strings.conf")).c_str())){
os::Printer::log("loadStrings expansions/strings.conf"); ALOGD("loadStrings expansions/strings.conf");
} }
if(!dataManager.LoadStrings((workingDir + path("/strings.conf")).c_str())) if(!dataManager.LoadStrings((workingDir + path("/strings.conf")).c_str()))
return false; return false;
...@@ -195,7 +252,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -195,7 +252,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
titleFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, (int)32 * yScale, isAntialias, true); titleFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, (int)32 * yScale, isAntialias, true);
textFont = guiFont; textFont = guiFont;
if(!numFont || !textFont) { if(!numFont || !textFont) {
os::Printer::log("add font fail "); ALOGW("add font fail ");
} }
smgr = device->getSceneManager(); smgr = device->getSceneManager();
device->setWindowCaption(L"[---]"); device->setWindowCaption(L"[---]");
...@@ -1291,6 +1348,7 @@ void Game::MainLoop() { ...@@ -1291,6 +1348,7 @@ void Game::MainLoop() {
} }
#endif #endif
while(device->run()) { while(device->run()) {
ALOGV("game draw frame");
linePatternD3D = (linePatternD3D + 1) % 30; linePatternD3D = (linePatternD3D + 1) % 30;
linePatternGL = (linePatternGL << 1) | (linePatternGL >> 15); linePatternGL = (linePatternGL << 1) | (linePatternGL >> 15);
atkframe += 0.1f; atkframe += 0.1f;
...@@ -1317,16 +1375,6 @@ void Game::MainLoop() { ...@@ -1317,16 +1375,6 @@ void Game::MainLoop() {
#endif #endif
gMutex.lock(); gMutex.lock();
if(dInfo.isStarted) { if(dInfo.isStarted) {
if(dInfo.isFinished && showcardcode == 1)
soundManager->PlayBGM(SoundManager::BGM::WIN);
else if(dInfo.isFinished && (showcardcode == 2 || showcardcode == 3))
soundManager->PlayBGM(SoundManager::BGM::LOSE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] <= dInfo.lp[1] / 2)
soundManager->PlayBGM(SoundManager::BGM::DISADVANTAGE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] >= dInfo.lp[1] * 2)
soundManager->PlayBGM(SoundManager::BGM::ADVANTAGE);
else
soundManager->PlayBGM(SoundManager::BGM::DUEL);
DrawBackImage(imageManager.tBackGround); DrawBackImage(imageManager.tBackGround);
DrawBackGround(); DrawBackGround();
DrawCards(); DrawCards();
...@@ -1335,14 +1383,12 @@ void Game::MainLoop() { ...@@ -1335,14 +1383,12 @@ void Game::MainLoop() {
driver->setMaterial(irr::video::IdentityMaterial); driver->setMaterial(irr::video::IdentityMaterial);
driver->clearZBuffer(); driver->clearZBuffer();
} else if(is_building) { } else if(is_building) {
soundManager->PlayBGM(SoundManager::BGM::DECK);
DrawBackImage(imageManager.tBackGround_deck); DrawBackImage(imageManager.tBackGround_deck);
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
driver->enableMaterial2D(true); driver->enableMaterial2D(true);
DrawDeckBd(); DrawDeckBd();
driver->enableMaterial2D(false); driver->enableMaterial2D(false);
} else { } else {
soundManager->PlayBGM(SoundManager::BGM::MENU);
DrawBackImage(imageManager.tBackGround_menu); DrawBackImage(imageManager.tBackGround_menu);
} }
driver->enableMaterial2D(true); driver->enableMaterial2D(true);
...@@ -1351,13 +1397,15 @@ void Game::MainLoop() { ...@@ -1351,13 +1397,15 @@ void Game::MainLoop() {
driver->enableMaterial2D(false); driver->enableMaterial2D(false);
#else #else
} else { } else {
soundManager->PlayBGM(SoundManager::BGM::MENU);
DrawBackImage(imageManager.tBackGround_menu); DrawBackImage(imageManager.tBackGround_menu);
} }
DrawGUI(); DrawGUI();
DrawSpec(); DrawSpec();
#endif #endif
gMutex.unlock(); gMutex.unlock();
#ifdef _IRR_ANDROID_PLATFORM_
playBGM();
#endif
if(signalFrame > 0) { if(signalFrame > 0) {
signalFrame--; signalFrame--;
if(!signalFrame) if(!signalFrame)
......
...@@ -12,6 +12,14 @@ ...@@ -12,6 +12,14 @@
namespace ygo { namespace ygo {
#ifdef _IRR_ANDROID_PLATFORM_
#define LOG_TAG "ygo-jni"
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG ,__VA_ARGS__)
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG ,__VA_ARGS__)
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG ,__VA_ARGS__)
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG ,__VA_ARGS__)
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG ,__VA_ARGS__)
#endif
struct Config { struct Config {
bool _init; bool _init;
bool use_d3d; bool use_d3d;
...@@ -121,6 +129,8 @@ class Game :IProcessEventReceiver{ ...@@ -121,6 +129,8 @@ class Game :IProcessEventReceiver{
public: public:
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
void stopBGM();
void playBGM();
bool Initialize(ANDROID_APP app, android::InitOptions *options); bool Initialize(ANDROID_APP app, android::InitOptions *options);
#else #else
bool Initialize(); bool Initialize();
...@@ -643,6 +653,7 @@ public: ...@@ -643,6 +653,7 @@ public:
s32 ogles2BlendTexture; s32 ogles2BlendTexture;
irr::android::CustomShaderConstantSetCallBack customShadersCallback; irr::android::CustomShaderConstantSetCallBack customShadersCallback;
Signal externalSignal; Signal externalSignal;
static void onHandleAndroidCommand(ANDROID_APP app, int32_t cmd);
#endif #endif
void setPositionFix(core::position2di fix){ void setPositionFix(core::position2di fix){
InputFix = fix; InputFix = fix;
......
...@@ -64,7 +64,7 @@ int main(int argc, char* argv[]) { ...@@ -64,7 +64,7 @@ int main(int argc, char* argv[]) {
*/ */
bool keep_on_return = false; bool keep_on_return = false;
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_WARN, "ygo", "handle args %d", argc); ALOGD("handle args %d", argc);
//android //android
for(int i = 0; i < argc; ++i) { for(int i = 0; i < argc; ++i) {
const char* arg = argv[i].c_str(); const char* arg = argv[i].c_str();
...@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) { ...@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) {
wchar_t fname[1024]; wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname); BufferIO::DecodeUTF8(name, fname);
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname); index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "open replay file:index=%d, name=%s", index, name); ALOGD("open replay file:index=%d, name=%s", index, name);
} }
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu); ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
...@@ -138,7 +138,7 @@ int main(int argc, char* argv[]) { ...@@ -138,7 +138,7 @@ int main(int argc, char* argv[]) {
wchar_t fname[1024]; wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname); BufferIO::DecodeUTF8(name, fname);
index = GetListBoxIndex(ygo::mainGame->lstSinglePlayList, fname); index = GetListBoxIndex(ygo::mainGame->lstSinglePlayList, fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "open single file:index=%d, name=%s", index, name); ALOGD("open single file:index=%d, name=%s", index, name);
} }
if(index >= 0){ if(index >= 0){
ygo::mainGame->lstSinglePlayList->setSelected(index); ygo::mainGame->lstSinglePlayList->setSelected(index);
......
...@@ -285,9 +285,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -285,9 +285,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
prev_operation = id; prev_operation = id;
prev_sel = sel; prev_sel = sel;
#if defined(_IRR_ANDROID_PLATFORM_) #if defined(_IRR_ANDROID_PLATFORM_)
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "1share replay file=%s", name); ALOGD("1share replay file=%s", name);
android::OnShareFile(mainGame->appMain, "yrp", name); android::OnShareFile(mainGame->appMain, "yrp", name);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "2after share replay file:index=%d", sel); ALOGD("2after share replay file:index=%d", sel);
#endif #endif
break; break;
} }
......
...@@ -200,7 +200,9 @@ E_DEVICE_TYPE CIrrDeviceAndroid::getType() const ...@@ -200,7 +200,9 @@ E_DEVICE_TYPE CIrrDeviceAndroid::getType() const
void CIrrDeviceAndroid::handleAndroidCommand(ANDROID_APP app, int32_t cmd) void CIrrDeviceAndroid::handleAndroidCommand(ANDROID_APP app, int32_t cmd)
{ {
CIrrDeviceAndroid* device = (CIrrDeviceAndroid*)app->userData; CIrrDeviceAndroid* device = (CIrrDeviceAndroid*)app->userData;
if(device->onAppCmd != nullptr){
device->onAppCmd(app, cmd);
}
switch (cmd) switch (cmd)
{ {
case APP_CMD_SAVE_STATE: case APP_CMD_SAVE_STATE:
......
...@@ -58,6 +58,19 @@ namespace irr ...@@ -58,6 +58,19 @@ namespace irr
core::array<EKEY_CODE> KeyMap; core::array<EKEY_CODE> KeyMap;
bool isPaused(){
return Paused;
}
bool isFocused(){
return Focused;
}
bool isDestroy(){
return !Initialized;
}
void (*onAppCmd)(struct android_app* app, int32_t cmd) = nullptr;
private: private:
static void handleAndroidCommand(ANDROID_APP app, int32_t cmd); static void handleAndroidCommand(ANDROID_APP app, int32_t cmd);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <android_native_app_glue.h> #include <android_native_app_glue.h>
#include <signal.h> #include <signal.h>
#include <android/log.h> #include <android/log.h>
#include <Android/CIrrDeviceAndroid.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "ygomobile-native", __VA_ARGS__)) #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "ygomobile-native", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "ygomobile-native", __VA_ARGS__)) #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "ygomobile-native", __VA_ARGS__))
......
...@@ -297,7 +297,7 @@ static void* join_game_thread(void* param) { ...@@ -297,7 +297,7 @@ static void* join_game_thread(void* param) {
JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSetInputFix( JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSetInputFix(
JNIEnv* env, jclass clazz, jlong handle, jint x, jint y) { JNIEnv* env, jclass clazz, jlong handle, jint x, jint y) {
if(ygo::mainGame) { if(ygo::mainGame) {
__android_log_print(ANDROID_LOG_INFO, "ygo", "setInputFix posX=%d, posY=%d", x, y); ALOGD("setInputFix posX=%d, posY=%d", x, y);
ygo::mainGame->setPositionFix(core::position2di(x, y)); ygo::mainGame->setPositionFix(core::position2di(x, y));
} }
} }
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
<application> <application>
<activity <activity
android:name="cn.garymb.ygomobile.YGOMobileActivity" android:name="cn.garymb.ygomobile.YGOMobileActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|keyboardHidden|screenSize" android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:exported="true" android:exported="true"
android:label="YGOMobile" android:label="YGOMobile"
android:process=":game" android:process=":game"
......
...@@ -16,19 +16,15 @@ public class GameReceiver extends BroadcastReceiver { ...@@ -16,19 +16,15 @@ public class GameReceiver extends BroadcastReceiver {
if (ACTION_START.equals(action)) { if (ACTION_START.equals(action)) {
// //
IrrlichtBridge.gPid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0); IrrlichtBridge.gPid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0);
// Log.w("ygo", "pid=" + IrrlichtBridge.gPid);
} else if (ACTION_STOP.equals(action)) { } else if (ACTION_STOP.equals(action)) {
int pid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0); int pid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0);
if (pid == 0 && IrrlichtBridge.gPid != 0) { if (pid == 0 && IrrlichtBridge.gPid != 0) {
pid = IrrlichtBridge.gPid; pid = IrrlichtBridge.gPid;
// Log.w("ygo", "will kill last pid=" + pid);
} }
if (pid == 0) { if (pid == 0) {
pid = android.os.Process.myPid(); pid = android.os.Process.myPid();
// Log.w("ygo", "will kill now pid=" + pid);
} }
try { try {
// Log.w("ygo", "kill pid=" + pid);
android.os.Process.killProcess(pid); android.os.Process.killProcess(pid);
} catch (Exception e) { } catch (Exception e) {
//ignore //ignore
......
...@@ -89,6 +89,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -89,6 +89,7 @@ public class YGOMobileActivity extends NativeActivity implements
private boolean replaced = false; private boolean replaced = false;
private static boolean USE_SURFACE = true; private static boolean USE_SURFACE = true;
private String[] mArgV; private String[] mArgV;
private boolean onGameExiting;
// public static int notchHeight; // public static int notchHeight;
...@@ -291,7 +292,6 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -291,7 +292,6 @@ public class YGOMobileActivity extends NativeActivity implements
int h = (int) app().getScreenWidth(); int h = (int) app().getScreenWidth();
int spX = (int) ((w - size[0]) / 2.0f); int spX = (int) ((w - size[0]) / 2.0f);
int spY = (int) ((h - size[1]) / 2.0f); int spY = (int) ((h - size[1]) / 2.0f);
// Log.i("ygo", "Android command 1:posX=" + spX + ",posY=" + spY);
boolean update = false; boolean update = false;
synchronized (this) { synchronized (this) {
if (spX != mPositionX || spY != mPositionY) { if (spX != mPositionX || spY != mPositionY) {
...@@ -301,7 +301,6 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -301,7 +301,6 @@ public class YGOMobileActivity extends NativeActivity implements
} }
} }
if (update) { if (update) {
// Log.i("ygo", "Android command setInputFix2:posX=" + spX + ",posY=" + spY);
IrrlichtBridge.setInputFix(mPositionX, mPositionY); IrrlichtBridge.setInputFix(mPositionX, mPositionY);
} }
} }
...@@ -548,15 +547,26 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -548,15 +547,26 @@ public class YGOMobileActivity extends NativeActivity implements
@Override @Override
public void onGameExit() { public void onGameExit() {
if(onGameExiting){
return;
}
onGameExiting = true;
Log.e("ygomobile", "game exit"); Log.e("ygomobile", "game exit");
Intent intent = new Intent("ygomobile.intent.action.GAME"); final Intent intent = new Intent("ygomobile.intent.action.GAME");
intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.putExtra("game_exit_time", System.currentTimeMillis());
intent.setPackage(getPackageName()); intent.setPackage(getPackageName());
try { runOnUiThread(new Runnable() {
startActivity(intent); @Override
} catch (Throwable ignore) {} public void run() {
Process.killProcess(Process.myPid()); try {
startActivity(intent);
} catch (Throwable ignore) {}
finishAndRemoveTask();
Process.killProcess(Process.myPid());
}
});
} }
} }
...@@ -17,6 +17,8 @@ import java.io.InputStream; ...@@ -17,6 +17,8 @@ import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import cn.garymb.ygodata.YGOGameOptions;
import static cn.garymb.ygomobile.utils.ByteUtils.byte2int; import static cn.garymb.ygomobile.utils.ByteUtils.byte2int;
import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint; import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint;
......
...@@ -37,10 +37,12 @@ android { ...@@ -37,10 +37,12 @@ android {
buildTypes { buildTypes {
debug { debug {
debuggable false debuggable false
buildConfigField 'boolean', 'DEBUG_MODE', 'true'
} }
release { release {
shrinkResources false shrinkResources false
minifyEnabled false minifyEnabled false
buildConfigField 'boolean', 'DEBUG_MODE', 'false'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:extractNativeLibs="true" android:extractNativeLibs="true"
android:requestLegacyExternalStorage="true" android:requestLegacyExternalStorage="true"
android:taskAffinity="cn.garymb.ygomobile.task"
tools:replace="android:allowBackup,android:supportsRtl" tools:replace="android:allowBackup,android:supportsRtl"
tools:targetApi="m"> tools:targetApi="m">
<activity <activity
android:name="cn.garymb.ygomobile.ui.activities.LogoActivity" android:name="cn.garymb.ygomobile.ui.activities.LogoActivity"
android:excludeFromRecents="false" android:excludeFromRecents="false"
android:taskAffinity="cn.garymb.logo"
android:theme="@style/TranslucentTheme"> android:theme="@style/TranslucentTheme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
...@@ -33,14 +33,18 @@ ...@@ -33,14 +33,18 @@
</activity> </activity>
<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:launchMode="singleTop"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
android:excludeFromRecents="true"/>
<activity <activity
android:name="cn.garymb.ygomobile.ui.home.MainActivity" android:name="cn.garymb.ygomobile.ui.home.MainActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize" android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:excludeFromRecents="false"
android:exported="true" android:exported="true"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:launchMode="singleTop" android:launchMode="singleTop"
android:stateNotNeeded="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"> android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter> <intent-filter>
...@@ -119,6 +123,11 @@ ...@@ -119,6 +123,11 @@
android:name="cn.garymb.ygomobile.YGOMobileActivity" android:name="cn.garymb.ygomobile.YGOMobileActivity"
android:theme="@style/AppTheme.Game" android:theme="@style/AppTheme.Game"
tools:replace="android:theme" /> tools:replace="android:theme" />
<receiver
android:name="cn.garymb.ygomobile.GameReceiver"
android:enabled="false" />
<activity <activity
android:name="cn.garymb.ygomobile.ui.preference.SettingsActivity" android:name="cn.garymb.ygomobile.ui.preference.SettingsActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize" android:configChanges="orientation|keyboardHidden|navigation|screenSize"
...@@ -187,11 +196,6 @@ ...@@ -187,11 +196,6 @@
<activity <activity
android:name="cn.garymb.ygomobile.ui.activities.PermissionsActivity" android:name="cn.garymb.ygomobile.ui.activities.PermissionsActivity"
android:theme="@style/TranslucentTheme"/> android:theme="@style/TranslucentTheme"/>
<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
android:theme="@android:style/Theme.Translucent" />
<meta-data <meta-data
android:name="BUGLY_APPID" android:name="BUGLY_APPID"
android:value="${APP_ID}" /> android:value="${APP_ID}" />
......
...@@ -18,7 +18,9 @@ import com.tencent.bugly.beta.Beta; ...@@ -18,7 +18,9 @@ import com.tencent.bugly.beta.Beta;
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.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.utils.CrashHandler; import cn.garymb.ygomobile.utils.CrashHandler;
public class App extends GameApplication { public class App extends GameApplication {
...@@ -153,6 +155,12 @@ public class App extends GameApplication { ...@@ -153,6 +155,12 @@ public class App extends GameApplication {
Beta.strToastYourAreTheLatestVersion = this.getString(R.string.Already_Lastest); Beta.strToastYourAreTheLatestVersion = this.getString(R.string.Already_Lastest);
Beta.strToastCheckingUpgrade = this.getString(R.string.Checking_Update); Beta.strToastCheckingUpgrade = this.getString(R.string.Checking_Update);
Beta.upgradeDialogLayoutId = R.layout.dialog_upgrade; Beta.upgradeDialogLayoutId = R.layout.dialog_upgrade;
Beta.enableHotfix = false;
Beta.autoCheckHotfix = false;
Beta.autoCheckUpgrade = false;
Beta.autoCheckAppUpgrade = false;
//添加可显示弹窗的Activity
Beta.canShowUpgradeActs.add(MainActivity.class);
ApplicationInfo appInfo = null; ApplicationInfo appInfo = null;
try { try {
appInfo = this.getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); appInfo = this.getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
...@@ -160,6 +168,6 @@ public class App extends GameApplication { ...@@ -160,6 +168,6 @@ public class App extends GameApplication {
e.printStackTrace(); e.printStackTrace();
} }
String msg = appInfo.metaData.getString("BUGLY_APPID"); String msg = appInfo.metaData.getString("BUGLY_APPID");
Bugly.init(this, msg, true); Bugly.init(this, msg, BuildConfig.DEBUG_MODE);
} }
} }
...@@ -678,4 +678,8 @@ public class AppsSettings { ...@@ -678,4 +678,8 @@ public class AppsSettings {
// Log.i("kk", "saveTemp:" + array); // Log.i("kk", "saveTemp:" + array);
mSharedPreferences.putString(Constants.PREF_LAST_ROOM_LIST, array.toString()); mSharedPreferences.putString(Constants.PREF_LAST_ROOM_LIST, array.toString());
} }
public boolean isAutoCheckUpdate(){
return true;//mSharedPreferences.getBoolean(Constants.PREF_CHECK_UPDATE, false);
}
} }
...@@ -222,4 +222,6 @@ public interface Constants { ...@@ -222,4 +222,6 @@ public interface Constants {
//打开ydk,是否复制到文件夹 //打开ydk,是否复制到文件夹
boolean COPY_YDK_FILE = false; boolean COPY_YDK_FILE = false;
String TAG = "ygo-java";
} }
...@@ -47,7 +47,7 @@ public class GameUriManager { ...@@ -47,7 +47,7 @@ public class GameUriManager {
} }
public boolean doIntent(Intent intent) { public boolean doIntent(Intent intent) {
Log.i("ygo", "doIntent"); Log.i(Constants.TAG, "doIntent");
if (ACTION_OPEN_DECK.equals(intent.getAction())) { if (ACTION_OPEN_DECK.equals(intent.getAction())) {
if (intent.getData() != null) { if (intent.getData() != null) {
doUri(intent.getData()); doUri(intent.getData());
...@@ -85,7 +85,7 @@ public class GameUriManager { ...@@ -85,7 +85,7 @@ public class GameUriManager {
private String getPathName(String path, boolean withOutEx) { private String getPathName(String path, boolean withOutEx) {
Log.d("ygo", "path=" + path); Log.d(Constants.TAG, "path=" + path);
if (path != null) { if (path != null) {
int index = path.lastIndexOf("/"); int index = path.lastIndexOf("/");
if (index > 0) { if (index > 0) {
...@@ -146,11 +146,11 @@ public class GameUriManager { ...@@ -146,11 +146,11 @@ public class GameUriManager {
} }
try { try {
if (!remoteFile.canRead()) { if (!remoteFile.canRead()) {
Log.w("ygo", "don't read file " + remoteFile.getAbsolutePath()); Log.w(Constants.TAG, "don't read file " + remoteFile.getAbsolutePath());
return null; return null;
} }
} catch (Throwable e) { } catch (Throwable e) {
Log.e("ygo", "don't read file " + remoteFile.getAbsolutePath(), e); Log.e(Constants.TAG, "don't read file " + remoteFile.getAbsolutePath(), e);
return null; return null;
} }
} }
...@@ -169,11 +169,11 @@ public class GameUriManager { ...@@ -169,11 +169,11 @@ public class GameUriManager {
local = new File(AppsSettings.get().getResourcePath() + "/temp", name); local = new File(AppsSettings.get().getResourcePath() + "/temp", name);
} }
if (local.exists()) { if (local.exists()) {
Log.w("ygo", "Overwrite file "+local.getAbsolutePath()); Log.w(Constants.TAG, "Overwrite file "+local.getAbsolutePath());
} }
if(remoteFile != null && TextUtils.equals(remoteFile.getAbsolutePath(), local.getAbsolutePath())){ if(remoteFile != null && TextUtils.equals(remoteFile.getAbsolutePath(), local.getAbsolutePath())){
//is same path //is same path
Log.i("ygo", "is same file " + remoteFile.getAbsolutePath() + "==" + local.getAbsolutePath()); Log.i(Constants.TAG, "is same file " + remoteFile.getAbsolutePath() + "==" + local.getAbsolutePath());
return local; return local;
} }
//copy //copy
...@@ -192,7 +192,7 @@ public class GameUriManager { ...@@ -192,7 +192,7 @@ public class GameUriManager {
FileUtils.copyFile(input, local); FileUtils.copyFile(input, local);
} }
} catch (Throwable e) { } catch (Throwable e) {
Log.w("ygo", "copy file " + path + "->" + local.getAbsolutePath(), e); Log.w(Constants.TAG, "copy file " + path + "->" + local.getAbsolutePath(), e);
return null; return null;
} finally { } finally {
IOUtils.close(input); IOUtils.close(input);
...@@ -213,7 +213,7 @@ public class GameUriManager { ...@@ -213,7 +213,7 @@ public class GameUriManager {
boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(".ypk"); boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(".ypk");
boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(".yrp"); boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(".yrp");
boolean isLua = file.getName().toLowerCase(Locale.US).endsWith(".lua"); boolean isLua = file.getName().toLowerCase(Locale.US).endsWith(".lua");
Log.i("ygo", "open file:" + uri + "->" + file.getAbsolutePath()); Log.i(Constants.TAG, "open file:" + uri + "->" + file.getAbsolutePath());
if(isYdk){ if(isYdk){
Intent intent = new Intent(getActivity(), DeckManagerActivity.getDeckManager()); Intent intent = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
intent.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath()); intent.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
...@@ -231,14 +231,14 @@ public class GameUriManager { ...@@ -231,14 +231,14 @@ public class GameUriManager {
YGOStarter.startGame(getActivity(), null, "-r", file.getName()); YGOStarter.startGame(getActivity(), null, "-r", file.getName());
Toast.makeText(activity, activity.getString(R.string.yrp_installed), Toast.LENGTH_LONG).show(); Toast.makeText(activity, activity.getString(R.string.yrp_installed), Toast.LENGTH_LONG).show();
} else { } else {
Log.w("ygo", "game is running"); Log.w(Constants.TAG, "game is running");
} }
} else if(isLua){ } else if(isLua){
if (!YGOStarter.isGameRunning(getActivity())) { if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(getActivity(), null, "-s", file.getName()); YGOStarter.startGame(getActivity(), null, "-s", file.getName());
Toast.makeText(activity, "load single lua file", Toast.LENGTH_LONG).show(); Toast.makeText(activity, "load single lua file", Toast.LENGTH_LONG).show();
} else { } else {
Log.w("ygo", "game is running"); Log.w(Constants.TAG, "game is running");
} }
} }
} else { } else {
......
...@@ -12,6 +12,7 @@ import android.os.Build; ...@@ -12,6 +12,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.Gravity; import android.view.Gravity;
import android.view.Menu; import android.view.Menu;
...@@ -143,8 +144,15 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie ...@@ -143,8 +144,15 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
}; };
//x5内核初始化接口 //x5内核初始化接口
QbSdk.initX5Environment(this, cb); QbSdk.initX5Environment(this, cb);
//check update if(AppsSettings.get().isAutoCheckUpdate()) {
Beta.checkUpgrade(false, false); if (!"ygomobile.intent.action.GAME".equals(getIntent().getAction())) {
Log.d("kk-test", "start check update");
//check update
Beta.checkUpgrade(false, false);
} else {
Log.d("kk-test", "skip check update");
}
}
//初始化决斗助手 //初始化决斗助手
initDuelAssistant(); initDuelAssistant();
//萌卡 //萌卡
......
...@@ -8,6 +8,7 @@ import androidx.annotation.NonNull; ...@@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.Console;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
...@@ -19,6 +20,8 @@ import java.io.OutputStream; ...@@ -19,6 +20,8 @@ import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import cn.garymb.ygomobile.Constants;
public class FileUtils { public class FileUtils {
...@@ -116,7 +119,7 @@ public class FileUtils { ...@@ -116,7 +119,7 @@ public class FileUtils {
outputStream = new FileOutputStream(out); outputStream = new FileOutputStream(out);
copy(inputStream, outputStream); copy(inputStream, outputStream);
} catch (Throwable e) { } catch (Throwable e) {
Log.e("ygo", "copy file", e); Log.e(Constants.TAG, "copy file", e);
return false; return false;
} finally { } finally {
IOUtils.close(outputStream); IOUtils.close(outputStream);
......
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