Files
AVA2/android/app/src/main/java/com/metin2/ava2/Ava2Activity.java
T
2026-10-13 11:45:47 +09:00

71 lines
3.1 KiB
Java

package com.metin2.ava2;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Insets;
import android.os.Build;
import android.view.View;
import android.view.WindowInsets;
import org.libsdl.app.SDLActivity;
import org.libsdl.app.SDLSurface;
/**
* SDLActivity with command-line arguments for development runs:
* {@code adb shell "am start -n com.metin2.ava2/.Ava2Activity --es args '--phase game --preview-data'"}.
* A normal launch (no extra) passes none, as before.
*/
public class Ava2Activity extends SDLActivity {
@Override
protected String[] getArguments() {
String args = getIntent() != null ? getIntent().getStringExtra("args") : null;
if (args == null || args.trim().isEmpty()) return new String[0];
return args.trim().split("\\s+");
}
/**
* The game is landscape-only. SDL re-requests an orientation whenever a window is created or
* resized (FULL_USER for a resizable window without SDL_HINT_ORIENTATIONS), which would override
* the manifest's sensorLandscape; keep both landscape directions regardless of the hint.
*/
@Override
public void setOrientationBis(int w, int h, boolean resizable, String hint) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
@Override
protected SDLSurface createSDLSurface(Context context) {
return new Ava2Surface(context);
}
/**
* SDL folds the system-gesture insets into the safe area. In landscape fullscreen the status bar
* is hidden, but its swipe-down gesture zone still reported a 120 px top inset, which pushed the
* top HUD row down. The left inset is the same story: Android measures the back-gesture zone
* (90 px) from the cutout edge, so it reported 120 + 90 px and the left HUD column sat far from
* the edge. Taps in the gesture zone still reach the app, so take top and left only from what
* really covers the screen (display cutout and visible system bars); keep SDL's right/bottom.
*/
static class Ava2Surface extends SDLSurface {
Ava2Surface(Context context) {
super(context);
}
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
WindowInsets result = super.onApplyWindowInsets(v, insets);
if (Build.VERSION.SDK_INT >= 30 /* Android 11 (R) */) {
Insets combined = insets.getInsets(WindowInsets.Type.systemBars() |
WindowInsets.Type.systemGestures() |
WindowInsets.Type.mandatorySystemGestures() |
WindowInsets.Type.tappableElement() |
WindowInsets.Type.displayCutout());
Insets covering = insets.getInsets(WindowInsets.Type.systemBars() |
WindowInsets.Type.displayCutout());
SDLActivity.onNativeInsetsChanged(covering.left, combined.right, covering.top, combined.bottom);
}
return result;
}
}
}