Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Properly handle rotations #3356

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import android.app.AlertDialog;
import android.content.ClipDescription;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Configuration;
Expand Down Expand Up @@ -62,6 +63,7 @@
import org.easyrpg.player.game_browser.GameBrowserActivity;
import org.easyrpg.player.settings.SettingsManager;
import org.libsdl.app.SDLActivity;
import org.libsdl.app.SDLSurface;

import java.io.File;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -94,6 +96,11 @@ protected String[] getLibraries() {
};
}

@Override
protected SDLSurface createSDLSurface(Context context) {
return new EasyRpgSurface(context, this);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -438,7 +445,6 @@ public void showInputLayout() {
public void updateScreenPosition() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
int topMargin, leftMargin;

// Determine the multiplier
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.easyrpg.player.player;

import android.content.Context;
import android.view.SurfaceHolder;

import org.libsdl.app.SDLSurface;

public class EasyRpgSurface extends SDLSurface {
private EasyRpgPlayerActivity activity = null;

public EasyRpgSurface(Context context, EasyRpgPlayerActivity activity) {
super(context);

this.activity = activity;
}

@Override
public void surfaceChanged(SurfaceHolder holder,
int format, int width, int height) {
// configurationChanged is not always sent because of Android bugs in various versions
// SDL uses the surfaceChanged event to detect rotations instead
super.surfaceChanged(holder, format, width, height);

activity.updateScreenPosition();
}
}
5 changes: 5 additions & 0 deletions src/platform/sdl/sdl2_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,11 @@ void Sdl2Ui::ProcessWindowEvent(SDL_Event &evnt) {
SDL_Event wait_event;

while (SDL_WaitEvent(&wait_event)) {
if (wait_event.type == SDL_WINDOWEVENT && wait_event.window.event != SDL_WINDOWEVENT_FOCUS_LOST) {
// Process size change etc. events
ProcessWindowEvent(wait_event);
}

if (FilterUntilFocus(&wait_event)) {
break;
}
Expand Down
7 changes: 6 additions & 1 deletion src/platform/sdl/sdl3_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Sdl3Ui::~Sdl3Ui() {

#ifdef SUPPORT_AUDIO
audio_.reset();
#endif
#endif

SDL_Quit();
}
Expand Down Expand Up @@ -732,6 +732,11 @@ void Sdl3Ui::ProcessWindowEvent(SDL_Event &evnt) {
SDL_Event wait_event;

while (SDL_WaitEvent(&wait_event)) {
if (wait_event.type >= SDL_EVENT_WINDOW_FIRST && wait_event.type <= SDL_EVENT_WINDOW_LAST && wait_event.type != SDL_EVENT_WINDOW_FOCUS_LOST) {
// Process size change etc. events
ProcessWindowEvent(wait_event);
}

if (FilterUntilFocus(&wait_event)) {
break;
}
Expand Down
Loading