Commit 501dbe09 authored by kenan's avatar kenan

fix size

parent 8ccaf9c4
......@@ -24,6 +24,7 @@ import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
......@@ -129,7 +130,7 @@ public class YGOMobileActivity extends NativeActivity implements
mGameConfig = getIntent().getParcelableExtra(GameConfig.EXTRA_CONFIG);
mCore = YGOCore.getInstance();
mHost = app().getGameHost();
fullscreen();
fullscreen(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
......@@ -164,7 +165,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
fullscreen();
fullscreen(true);
}
}
});
......@@ -250,16 +251,18 @@ public class YGOMobileActivity extends NativeActivity implements
}
}
private void fullscreen() {
private void fullscreen(boolean resize) {
if (mGameConfig.isImmerSiveMode()) {
//沉浸模式
getWindow().getDecorView().setSystemUiVisibility(windowsFlags);
} else {
getWindow().getDecorView().setSystemUiVisibility(windowsFlags2);
}
if(resize){
int[] size = getGameSize();
setGameSize(size[0], size[1]);
}
}
private int[] getGameSize() {
GameSize gameSize = mHost.getGameSize(this, mGameConfig);
......@@ -364,7 +367,7 @@ public class YGOMobileActivity extends NativeActivity implements
public void onWindowFocusChanged(boolean hasFocus) {
// Log.e("YGOMobileActivity","窗口变化"+hasFocus);
if (hasFocus) {
fullscreen();
fullscreen(true);
mContentView.setHapticFeedbackEnabled(true);
} else {
mContentView.setHapticFeedbackEnabled(false);
......
......@@ -29,14 +29,14 @@ public class GameConfig implements Parcelable {
private boolean enableSoundEffect;
private int notouchHeight;
private int notchHeight;
public int getNotouchHeight() {
return notouchHeight;
public int getNotchHeight() {
return notchHeight;
}
public void setNotouchHeight(int notouchHeight) {
this.notouchHeight = notouchHeight;
public void setNotchHeight(int notchHeight) {
this.notchHeight = notchHeight;
}
public NativeInitOptions getNativeInitOptions() {
......@@ -127,7 +127,7 @@ public class GameConfig implements Parcelable {
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.writeInt(this.notouchHeight);
dest.writeInt(this.notchHeight);
}
protected GameConfig(Parcel in) {
......@@ -137,7 +137,7 @@ public class GameConfig implements Parcelable {
this.keepScale = in.readByte() != 0;
this.immerSiveMode = 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>() {
......@@ -161,7 +161,7 @@ public class GameConfig implements Parcelable {
", keepScale=" + keepScale +
", immerSiveMode=" + immerSiveMode +
", enableSoundEffect=" + enableSoundEffect +
", notouchHeight=" + notouchHeight +
", notchHeight=" + notchHeight +
'}';
}
}
......@@ -8,8 +8,8 @@ android {
applicationId "cn.garymb.ygomobile"
minSdkVersion 21
targetSdkVersion 28
versionCode 352001024
versionName "3.5.2"
versionCode 352001025
versionName "3.5.2.1"
flavorDimensions "versionCode"
vectorDrawables.useSupportLibrary = true
ndk {
......
......@@ -71,7 +71,7 @@ public class App extends GameApplication {
public static GameConfig genConfig() {
GameConfig config = new GameConfig();
config.setNotouchHeight(AppsSettings.get().getNotchHeight());
config.setNotchHeight(AppsSettings.get().getNotchHeight());
config.setNativeInitOptions(AppsSettings.get().getNativeInitOptions());
config.setLockScreenOrientation(AppsSettings.get().isLockScreenOrientation());
config.setSensorRefresh(AppsSettings.get().isSensorRefresh());
......
......@@ -136,14 +136,15 @@ class LocalGameHost extends GameHost {
w1 = fullW;
h1 = fullH;
} else {
//全面屏,非沉浸模式,自动隐藏虚拟键,需要适配
w1 = actW;
h1 = actH;
}
maxW = Math.max(w1, h1);
maxH = Math.min(w1, h1);
boolean hasNotouch = ScreenUtil.hasNotchInformation(activity);
if(hasNotouch && immerSiveMode){
maxW -= config.getNotouchHeight();
int notchHeight = config.getNotchHeight();
if(notchHeight > 0 && immerSiveMode){
maxW -= notchHeight;
}
Log.i("kk", "real=" + fullW + "x" + fullH + ",cur=" + actW + "x" + actH + ",use=" + maxW + "x" + maxH);
float sx, sy, scale;
......@@ -162,9 +163,10 @@ class LocalGameHost extends GameHost {
//fix touch point
int left = (maxW - gw) / 2;
int top = (maxH - gh) / 2;
if(hasNotouch && !immerSiveMode){
if(notchHeight > 0 && !immerSiveMode){
left += notchHeight;
//fix touch
left = (maxW - gw - config.getNotouchHeight()) / 2;
//left = (maxW - gw - config.getNotchHeight()) / 2;
}
Log.i("kk", "touch fix=" + left + "x" + top);
//if(huawei and liuhai){
......@@ -223,11 +225,17 @@ class LocalGameHost extends GameHost {
size = getGameSize(activity, config);
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_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_cut_screen)).setText(ScreenUtil.hasNotchInformation(activity) ? "Yes/("+config.getNotouchHeight()+")" : "No");
((TextView) dlg.findViewById(R.id.tv_nav_bar)).setText(ScreenUtil.isNavigationBarShown(activity) ? "Yes" : "No");
((TextView) dlg.findViewById(R.id.tv_cut_screen)).setText((config.getNotchHeight() > 0) ? "Yes/" + config.getNotchHeight() : "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",
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) -> {
......
......@@ -7,6 +7,7 @@ import android.os.Build;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.View;
import android.view.WindowInsets;
import androidx.annotation.RequiresApi;
......@@ -34,33 +35,8 @@ public class ScreenUtil {
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) {
if (isNotchVivo(activity)) {
findNotchInformation.onNotchInformation(true, getNotchHeightVivo(activity), NOTCH_TYPE_PHONE_VIVO);
} else if (isNotchOPPO(activity)) {
......@@ -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) {
//虚拟键的view,为空或者不可见时是隐藏状态
......
......@@ -5,7 +5,29 @@
android:layout_height="wrap_content"
android:background="#88000000"
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
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
......@@ -281,4 +281,5 @@
<string name="lb_rom_version">ROM Version:</string>
<string name="lb_cut_screen">Cut Screen:</string>
<string name="lb_cut_screen_state">Cut Screen State:</string>
<string name="lb_version">Version:</string>
</resources>
......@@ -280,4 +280,5 @@
<string name="lb_rom_version">ROM Version:</string>
<string name="lb_cut_screen">Cut Screen:</string>
<string name="lb_cut_screen_state">Cut Screen State:</string>
<string name="lb_version">Version:</string>
</resources>
......@@ -283,4 +283,5 @@
<string name="lb_rom_version">ROM Version:</string>
<string name="lb_cut_screen">Cut Screen:</string>
<string name="lb_cut_screen_state">Cut Screen State:</string>
<string name="lb_version">Version:</string>
</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