Commit ff2ce6e0 authored by kenan's avatar kenan

opt code

parent dfd048b6
......@@ -128,12 +128,12 @@ public class YGOMobileActivity extends NativeActivity implements
mCore = YGOCore.getInstance();
mHost = app().getGameHost();
fullscreen();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
getWindow().setAttributes(lp);
}
if(mGameConfig != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
getWindow().setAttributes(lp);
}
mGameSoundPlayer = new GameSoundPlayer(mHost.getGameAsset());
if (mGameConfig.isEnableSoundEffect()) {
mGameSoundPlayer.initSoundEffectPool();
......
package cn.garymb.ygomobile.core;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
import cn.garymb.ygodata.YGOGameOptions;
import cn.garymb.ygomobile.YGOMobileActivity;
import cn.garymb.ygomobile.interfaces.GameConfig;
public class YGOCore {
public static final float GAME_WIDTH = 1024.0f;
public static final float GAME_HEIGHT = 640.0f;
......@@ -168,6 +179,17 @@ public class YGOCore {
}
}
public static void startGame(Context activity, @Nullable YGOGameOptions options, @NonNull GameConfig gameConfig) {
Intent intent = new Intent(activity, YGOMobileActivity.class);
if (options != null) {
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY, options);
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_TIME, System.currentTimeMillis());
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(GameConfig.EXTRA_CONFIG, gameConfig);
activity.startActivity(intent);
}
//插入文本(大概是发送消息)
private native void nativeInsertText(int device, String text);
......
package cn.garymb.ygomobile;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Point;
import android.os.Build;
import android.os.Process;
import android.util.Log;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatDelegate;
......@@ -19,15 +10,9 @@ import com.bumptech.glide.Glide;
import com.yuyh.library.imgsel.ISNav;
import com.yuyh.library.imgsel.common.ImageLoader;
import java.lang.reflect.Method;
import cn.garymb.ygomobile.core.YGOCore;
import cn.garymb.ygomobile.interfaces.GameConfig;
import cn.garymb.ygomobile.interfaces.GameHost;
import cn.garymb.ygomobile.interfaces.GameSize;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.utils.CrashHandler;
import cn.garymb.ygomobile.utils.ScreenUtil;
import jonathanfinerty.once.Once;
public class App extends GameApplication {
......@@ -66,86 +51,6 @@ public class App extends GameApplication {
return gameHost;
}
private class LocalGameHost extends GameHost {
LocalGameHost(Context context) {
super(context);
}
@Override
public String getSetting(String key) {
return AppsSettings.get().getSettings(key);
}
@Override
public int getIntSetting(String key, int def) {
return AppsSettings.get().getIntSettings(key, def);
}
@Override
public void saveIntSetting(String key, int value) {
AppsSettings.get().saveIntSettings(key, value);
}
@Override
public void saveSetting(String key, String value) {
AppsSettings.get().saveSettings(key, value);
}
@Override
public void runWindbot(String cmd) {
Intent intent = new Intent();
intent.putExtra("args", cmd);
intent.setAction("RUN_WINDBOT");
sendBroadcast(intent);
}
@Override
public AssetManager getGameAsset() {
return getAssets();
}
@Override
public GameSize getGameSize(Activity activity) {
int maxW, maxH;
int w1 = activity.getWindowManager().getDefaultDisplay().getWidth();
int h1 = activity.getWindowManager().getDefaultDisplay().getHeight();
maxW = Math.max(w1, h1);
maxH = Math.min(w1, h1);
if (AppsSettings.get().isImmerSiveMode()) {
maxH += ScreenUtil.getCurrentNavigationBarHeight(activity);
}
float sx, sy, scale;
int gw, gh;
if (AppsSettings.get().isKeepScale()) {
sx = (float) maxW / YGOCore.GAME_WIDTH;
sy = (float) maxH / YGOCore.GAME_HEIGHT;
scale = Math.min(sx, sy);
gw = (int) (YGOCore.GAME_WIDTH * scale);
gh = (int) (YGOCore.GAME_HEIGHT * scale);
} else {
gw = maxW;
gh = maxH;
}
//fix touch point
int left = (maxW - gw) / 2;
int top = (maxH - gh) / 2;
//if(huawei and liuhai){
// left-=liuhai
// }
return new GameSize(gw, gh, left, top);
}
@Override
public boolean isDebugMode() {
return BuildConfig.DEBUG;
}
@Override
public boolean isAutoKeepGame() {
return false;
}
}
public static GameConfig genConfig() {
GameConfig config = new GameConfig();
config.setNativeInitOptions(AppsSettings.get().getNativeInitOptions());
......
package cn.garymb.ygomobile;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Point;
import android.util.Log;
import cn.garymb.ygomobile.core.YGOCore;
import cn.garymb.ygomobile.interfaces.GameHost;
import cn.garymb.ygomobile.interfaces.GameSize;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.utils.ScreenUtil;
class LocalGameHost extends GameHost {
private Context context;
LocalGameHost(Context context) {
super(context);
this.context = context;
}
@Override
public String getSetting(String key) {
return AppsSettings.get().getSettings(key);
}
@Override
public int getIntSetting(String key, int def) {
return AppsSettings.get().getIntSettings(key, def);
}
@Override
public void saveIntSetting(String key, int value) {
AppsSettings.get().saveIntSettings(key, value);
}
@Override
public void saveSetting(String key, String value) {
AppsSettings.get().saveSettings(key, value);
}
@Override
public void runWindbot(String cmd) {
Intent intent = new Intent();
intent.putExtra("args", cmd);
intent.setAction("RUN_WINDBOT");
context.sendBroadcast(intent);
}
@Override
public AssetManager getGameAsset() {
return context.getAssets();
}
@Override
public GameSize getGameSize(Activity activity) {
boolean immerSiveMode = AppsSettings.get().isImmerSiveMode();
boolean keepScale = AppsSettings.get().isKeepScale();
int maxW, maxH;
int fullW,fullH,actW,actH;
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getRealSize(size);
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 / YGOCore.GAME_WIDTH;
sy = (float) maxH / YGOCore.GAME_HEIGHT;
scale = Math.min(sx, sy);
gw = (int) (YGOCore.GAME_WIDTH * scale);
gh = (int) (YGOCore.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
// }
return new GameSize(gw, gh, left, top);
}
@Override
public boolean isDebugMode() {
return BuildConfig.DEBUG;
}
@Override
public boolean isAutoKeepGame() {
return false;
}
}
......@@ -25,6 +25,7 @@ import java.io.File;
import java.util.HashMap;
import cn.garymb.ygodata.YGOGameOptions;
import cn.garymb.ygomobile.core.YGOCore;
import cn.garymb.ygomobile.interfaces.GameConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.plus.ViewTargetPlus;
......@@ -171,15 +172,8 @@ public class YGOStarter {
// } else {
// options = null;
}
Intent intent = new Intent(activity, YGOMobileActivity.class);
if (options != null) {
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY, options);
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_TIME, System.currentTimeMillis());
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(GameConfig.EXTRA_CONFIG, App.genConfig());
Log.e("YGOStarter","跳转前"+System.currentTimeMillis());
activity.startActivity(intent);
YGOCore.startGame(activity, options, App.genConfig());
Log.e("YGOStarter","跳转后"+System.currentTimeMillis());
}
}
......
......@@ -3,6 +3,7 @@ package cn.garymb.ygomobile.ui.activities;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Toast;
import cn.garymb.ygomobile.AppsSettings;
......@@ -18,6 +19,13 @@ public class LogoActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logo);
int windowsFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE/* 系统UI变化不触发relayout */
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION/* 导航栏悬浮在布局上面 */
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN/* 状态栏悬浮在布局上面 */
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION/* 隐藏导航栏 */
| View.SYSTEM_UI_FLAG_FULLSCREEN/* 隐藏状态栏 */
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY/* 沉浸模式 */;
getWindow().getDecorView().setSystemUiVisibility(windowsFlags);
if (AppsSettings.get().isOnlyGame()) {
YGOStarter.startGame(this, null);
finish();
......
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