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. Keep SDL's left/right/bottom; take the top only from what really covers the * screen there (display cutout and visible system bars). */ 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(combined.left, combined.right, covering.top, combined.bottom); } return result; } } }