Commit 501dbe09 authored by kenan's avatar kenan

fix size

parent 8ccaf9c4
...@@ -24,6 +24,7 @@ import android.view.MotionEvent; ...@@ -24,6 +24,7 @@ import android.view.MotionEvent;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.PopupWindow; import android.widget.PopupWindow;
...@@ -129,7 +130,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -129,7 +130,7 @@ public class YGOMobileActivity extends NativeActivity implements
mGameConfig = getIntent().getParcelableExtra(GameConfig.EXTRA_CONFIG); mGameConfig = getIntent().getParcelableExtra(GameConfig.EXTRA_CONFIG);
mCore = YGOCore.getInstance(); mCore = YGOCore.getInstance();
mHost = app().getGameHost(); mHost = app().getGameHost();
fullscreen(); fullscreen(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes(); WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER; lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
...@@ -164,7 +165,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -164,7 +165,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override @Override
public void onSystemUiVisibilityChange(int visibility) { public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
fullscreen(); fullscreen(true);
} }
} }
}); });
...@@ -250,15 +251,17 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -250,15 +251,17 @@ public class YGOMobileActivity extends NativeActivity implements
} }
} }
private void fullscreen() { private void fullscreen(boolean resize) {
if (mGameConfig.isImmerSiveMode()) { if (mGameConfig.isImmerSiveMode()) {
//沉浸模式 //沉浸模式
getWindow().getDecorView().setSystemUiVisibility(windowsFlags); getWindow().getDecorView().setSystemUiVisibility(windowsFlags);
} else { } else {
getWindow().getDecorView().setSystemUiVisibility(windowsFlags2); getWindow().getDecorView().setSystemUiVisibility(windowsFlags2);
} }
int[] size = getGameSize(); if(resize){
setGameSize(size[0], size[1]); int[] size = getGameSize();
setGameSize(size[0], size[1]);
}
} }
private int[] getGameSize() { private int[] getGameSize() {
...@@ -364,7 +367,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -364,7 +367,7 @@ public class YGOMobileActivity extends NativeActivity implements
public void onWindowFocusChanged(boolean hasFocus) { public void onWindowFocusChanged(boolean hasFocus) {
// Log.e("YGOMobileActivity","窗口变化"+hasFocus); // Log.e("YGOMobileActivity","窗口变化"+hasFocus);
if (hasFocus) { if (hasFocus) {
fullscreen(); fullscreen(true);
mContentView.setHapticFeedbackEnabled(true); mContentView.setHapticFeedbackEnabled(true);
} else { } else {
mContentView.setHapticFeedbackEnabled(false); mContentView.setHapticFeedbackEnabled(false);
......
...@@ -29,14 +29,14 @@ public class GameConfig implements Parcelable { ...@@ -29,14 +29,14 @@ public class GameConfig implements Parcelable {
private boolean enableSoundEffect; private boolean enableSoundEffect;
private int notouchHeight; private int notchHeight;
public int getNotouchHeight() { public int getNotchHeight() {
return notouchHeight; return notchHeight;
} }
public void setNotouchHeight(int notouchHeight) { public void setNotchHeight(int notchHeight) {
this.notouchHeight = notouchHeight; this.notchHeight = notchHeight;
} }
public NativeInitOptions getNativeInitOptions() { public NativeInitOptions getNativeInitOptions() {
...@@ -127,7 +127,7 @@ public class GameConfig implements Parcelable { ...@@ -127,7 +127,7 @@ public class GameConfig implements Parcelable {
dest.writeByte(this.keepScale ? (byte) 1 : (byte) 0); dest.writeByte(this.keepScale ? (byte) 1 : (byte) 0);
dest.writeByte(this.immerSiveMode ? (byte) 1 : (byte) 0); dest.writeByte(this.immerSiveMode ? (byte) 1 : (byte) 0);
dest.writeByte(this.enableSoundEffect ? (byte) 1 : (byte) 0); dest.writeByte(this.enableSoundEffect ? (byte) 1 : (byte) 0);
dest.writeInt(this.notouchHeight); dest.writeInt(this.notchHeight);
} }
protected GameConfig(Parcel in) { protected GameConfig(Parcel in) {
...@@ -137,7 +137,7 @@ public class GameConfig implements Parcelable { ...@@ -137,7 +137,7 @@ public class GameConfig implements Parcelable {
this.keepScale = in.readByte() != 0; this.keepScale = in.readByte() != 0;
this.immerSiveMode = in.readByte() != 0; this.immerSiveMode = in.readByte() != 0;
this.enableSoundEffect = in.readByte() != 0; this.enableSoundEffect = in.readByte() != 0;
this.notouchHeight = in.readInt(); this.notchHeight = in.readInt();
} }
public static final Creator<GameConfig> CREATOR = new Creator<GameConfig>() { public static final Creator<GameConfig> CREATOR = new Creator<GameConfig>() {
...@@ -161,7 +161,7 @@ public class GameConfig implements Parcelable { ...@@ -161,7 +161,7 @@ public class GameConfig implements Parcelable {
", keepScale=" + keepScale + ", keepScale=" + keepScale +
", immerSiveMode=" + immerSiveMode + ", immerSiveMode=" + immerSiveMode +
", enableSoundEffect=" + enableSoundEffect + ", enableSoundEffect=" + enableSoundEffect +
", notouchHeight=" + notouchHeight + ", notchHeight=" + notchHeight +
'}'; '}';
} }
} }
...@@ -8,8 +8,8 @@ android { ...@@ -8,8 +8,8 @@ android {
applicationId "cn.garymb.ygomobile" applicationId "cn.garymb.ygomobile"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 352001024 versionCode 352001025
versionName "3.5.2" versionName "3.5.2.1"
flavorDimensions "versionCode" flavorDimensions "versionCode"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
ndk { ndk {
......
...@@ -71,7 +71,7 @@ public class App extends GameApplication { ...@@ -71,7 +71,7 @@ public class App extends GameApplication {
public static GameConfig genConfig() { public static GameConfig genConfig() {
GameConfig config = new GameConfig(); GameConfig config = new GameConfig();
config.setNotouchHeight(AppsSettings.get().getNotchHeight()); config.setNotchHeight(AppsSettings.get().getNotchHeight());
config.setNativeInitOptions(AppsSettings.get().getNativeInitOptions()); config.setNativeInitOptions(AppsSettings.get().getNativeInitOptions());
config.setLockScreenOrientation(AppsSettings.get().isLockScreenOrientation()); config.setLockScreenOrientation(AppsSettings.get().isLockScreenOrientation());
config.setSensorRefresh(AppsSettings.get().isSensorRefresh()); config.setSensorRefresh(AppsSettings.get().isSensorRefresh());
......
...@@ -136,14 +136,15 @@ class LocalGameHost extends GameHost { ...@@ -136,14 +136,15 @@ class LocalGameHost extends GameHost {
w1 = fullW; w1 = fullW;
h1 = fullH; h1 = fullH;
} else { } else {
//全面屏,非沉浸模式,自动隐藏虚拟键,需要适配
w1 = actW; w1 = actW;
h1 = actH; h1 = actH;
} }
maxW = Math.max(w1, h1); maxW = Math.max(w1, h1);
maxH = Math.min(w1, h1); maxH = Math.min(w1, h1);
boolean hasNotouch = ScreenUtil.hasNotchInformation(activity); int notchHeight = config.getNotchHeight();
if(hasNotouch && immerSiveMode){ if(notchHeight > 0 && immerSiveMode){
maxW -= config.getNotouchHeight(); maxW -= notchHeight;
} }
Log.i("kk", "real=" + fullW + "x" + fullH + ",cur=" + actW + "x" + actH + ",use=" + maxW + "x" + maxH); Log.i("kk", "real=" + fullW + "x" + fullH + ",cur=" + actW + "x" + actH + ",use=" + maxW + "x" + maxH);
float sx, sy, scale; float sx, sy, scale;
...@@ -162,9 +163,10 @@ class LocalGameHost extends GameHost { ...@@ -162,9 +163,10 @@ class LocalGameHost extends GameHost {
//fix touch point //fix touch point
int left = (maxW - gw) / 2; int left = (maxW - gw) / 2;
int top = (maxH - gh) / 2; int top = (maxH - gh) / 2;
if(hasNotouch && !immerSiveMode){ if(notchHeight > 0 && !immerSiveMode){
left += notchHeight;
//fix touch //fix touch
left = (maxW - gw - config.getNotouchHeight()) / 2; //left = (maxW - gw - config.getNotchHeight()) / 2;
} }
Log.i("kk", "touch fix=" + left + "x" + top); Log.i("kk", "touch fix=" + left + "x" + top);
//if(huawei and liuhai){ //if(huawei and liuhai){
...@@ -223,11 +225,17 @@ class LocalGameHost extends GameHost { ...@@ -223,11 +225,17 @@ class LocalGameHost extends GameHost {
size = getGameSize(activity, config); size = getGameSize(activity, config);
Log.i("kk", "gen size " + size); Log.i("kk", "gen size " + size);
} }
((TextView) dlg.findViewById(R.id.tv_version)).setText(BuildConfig.VERSION_NAME + "/" + BuildConfig.VERSION_CODE);
((TextView) dlg.findViewById(R.id.tv_model)).setText(Build.MODEL + "/" + Build.PRODUCT); ((TextView) dlg.findViewById(R.id.tv_model)).setText(Build.MODEL + "/" + Build.PRODUCT);
((TextView) dlg.findViewById(R.id.tv_android)).setText(Build.VERSION.RELEASE+" ("+Build.VERSION.SDK_INT+")"); ((TextView) dlg.findViewById(R.id.tv_android)).setText(Build.VERSION.RELEASE + " (" + Build.VERSION.SDK_INT + ")");
((TextView) dlg.findViewById(R.id.tv_rom)).setText(String.valueOf(RomIdentifier.getRomInfo(activity))); ((TextView) dlg.findViewById(R.id.tv_rom)).setText(String.valueOf(RomIdentifier.getRomInfo(activity)));
((TextView) dlg.findViewById(R.id.tv_cut_screen)).setText(ScreenUtil.hasNotchInformation(activity) ? "Yes/("+config.getNotouchHeight()+")" : "No"); ((TextView) dlg.findViewById(R.id.tv_cut_screen)).setText((config.getNotchHeight() > 0) ? "Yes/" + config.getNotchHeight() : "No");
((TextView) dlg.findViewById(R.id.tv_nav_bar)).setText(ScreenUtil.isNavigationBarShown(activity) ? "Yes" : "No"); if (ScreenUtil.hasNavigationBar(activity)) {
((TextView) dlg.findViewById(R.id.tv_nav_bar)).setText("Yes/" + (ScreenUtil.isNavigationBarShown(activity) ? "Show" : "Hide"));
} else {
((TextView) dlg.findViewById(R.id.tv_nav_bar)).setText("No");
}
((TextView) dlg.findViewById(R.id.tv_screen_size)).setText(String.format("r:%dx%d,a=%dx%d,k=%s, g=%dx%d,c=%dx%d", ((TextView) dlg.findViewById(R.id.tv_screen_size)).setText(String.format("r:%dx%d,a=%dx%d,k=%s, g=%dx%d,c=%dx%d",
size.getFullW(), size.getFullH(), size.getActW(), size.getActH(), config.isKeepScale()?"Y":"N", size.getWidth(), size.getHeight(), size.getTouchX(), size.getTouchY())); size.getFullW(), size.getFullH(), size.getActW(), size.getActH(), config.isKeepScale()?"Y":"N", size.getWidth(), size.getHeight(), size.getTouchX(), size.getTouchY()));
dlg.findViewById(R.id.btn_ok).setOnClickListener((v) -> { dlg.findViewById(R.id.btn_ok).setOnClickListener((v) -> {
......
...@@ -7,6 +7,7 @@ import android.os.Build; ...@@ -7,6 +7,7 @@ import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.DisplayCutout; import android.view.DisplayCutout;
import android.view.View; import android.view.View;
import android.view.WindowInsets;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
...@@ -34,33 +35,8 @@ public class ScreenUtil { ...@@ -34,33 +35,8 @@ public class ScreenUtil {
void onNotchInformation(boolean isNotch, int notchHeight, int phoneType); void onNotchInformation(boolean isNotch, int notchHeight, int phoneType);
} }
public static boolean hasNotchInformation(Activity activity) {
if (isNotchVivo(activity)) {
return true;
} else if (isNotchOPPO(activity)) {
return true;
} else if (isNotchHuawei(activity)) {
return true;
} else if (isNotchXiaomi(activity)) {
return true;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
DisplayCutout cutout = activity.getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
if (cutout == null) {
return false;
}
List<Rect> rects = cutout.getBoundingRects();
return rects != null && rects.size() > 0;
} else {
return false;
}
}
}
//是否是刘海屏 //是否是刘海屏
public static void findNotchInformation(Activity activity, FindNotchInformation findNotchInformation) { public static void findNotchInformation(Activity activity, FindNotchInformation findNotchInformation) {
if (isNotchVivo(activity)) { if (isNotchVivo(activity)) {
findNotchInformation.onNotchInformation(true, getNotchHeightVivo(activity), NOTCH_TYPE_PHONE_VIVO); findNotchInformation.onNotchInformation(true, getNotchHeightVivo(activity), NOTCH_TYPE_PHONE_VIVO);
} else if (isNotchOPPO(activity)) { } else if (isNotchOPPO(activity)) {
...@@ -314,10 +290,14 @@ public class ScreenUtil { ...@@ -314,10 +290,14 @@ public class ScreenUtil {
} }
} }
public static boolean hasNavigationBar(Activity activity) {
//虚拟键的view,为空或者不可见时是隐藏状态
View view = activity.findViewById(android.R.id.navigationBarBackground);
return view != null;
}
/** /**
* 非全面屏下 虚拟按键是否打开 * 非全面屏下 虚拟按键是否打开
*
* @param activity
*/ */
public static boolean isNavigationBarShown(Activity activity) { public static boolean isNavigationBarShown(Activity activity) {
//虚拟键的view,为空或者不可见时是隐藏状态 //虚拟键的view,为空或者不可见时是隐藏状态
......
...@@ -5,7 +5,29 @@ ...@@ -5,7 +5,29 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="#88000000" android:background="#88000000"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white"
android:text="@string/lb_version"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_version"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="@color/white"
android:textSize="12sp"
tools:text="xxxx" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -281,4 +281,5 @@ ...@@ -281,4 +281,5 @@
<string name="lb_rom_version">ROM Version:</string> <string name="lb_rom_version">ROM Version:</string>
<string name="lb_cut_screen">Cut Screen:</string> <string name="lb_cut_screen">Cut Screen:</string>
<string name="lb_cut_screen_state">Cut Screen State:</string> <string name="lb_cut_screen_state">Cut Screen State:</string>
<string name="lb_version">Version:</string>
</resources> </resources>
...@@ -280,4 +280,5 @@ ...@@ -280,4 +280,5 @@
<string name="lb_rom_version">ROM Version:</string> <string name="lb_rom_version">ROM Version:</string>
<string name="lb_cut_screen">Cut Screen:</string> <string name="lb_cut_screen">Cut Screen:</string>
<string name="lb_cut_screen_state">Cut Screen State:</string> <string name="lb_cut_screen_state">Cut Screen State:</string>
<string name="lb_version">Version:</string>
</resources> </resources>
...@@ -283,4 +283,5 @@ ...@@ -283,4 +283,5 @@
<string name="lb_rom_version">ROM Version:</string> <string name="lb_rom_version">ROM Version:</string>
<string name="lb_cut_screen">Cut Screen:</string> <string name="lb_cut_screen">Cut Screen:</string>
<string name="lb_cut_screen_state">Cut Screen State:</string> <string name="lb_cut_screen_state">Cut Screen State:</string>
<string name="lb_version">Version:</string>
</resources> </resources>
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