Skip to content

Commit

Permalink
Merge branch 'master' into pauseOnLostFocus
Browse files Browse the repository at this point in the history
  • Loading branch information
obigu committed Apr 20, 2024
2 parents 2d07651 + 2849926 commit eade552
Show file tree
Hide file tree
Showing 143 changed files with 3,403 additions and 3,978 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[1.12.2-SNAPSHOT]
- [BREAKING CHANGE] GWT: Updated to 2.10.0. `com.google.jsinterop:jsinterop-annotations:2.0.2:sources` must be added as a dependency to your html project dependencies.
- [BREAKING CHANGE] Android: Minimum API level is now level 19 (Android 4.4)
- [BREAKING CHANGE] Android, iOS: Exceptions occurring in Runnable tasks scheduled through Gdx.app.postRunnable() are no longer swallowed and will crash the app (add a protection if required).
- iOS: The iOS backend now implements AudioDevice. It can be configured through IOSApplicationConfiguration with audioDeviceBufferSize/audioDeviceBufferCount
- Fixed GlyphLayout for fixed width glyph offsets at the start and end of lines.
- Fixed scene2d.ui layout for fractional positions and sizes.
- LWJGL3: Added pauseWhenMinimized and pauseWhenLostFocus flags to Lwjgl3ApplicationConfiguration.
- libGDX is now built using Java 17 due to Gradle 8 requirements.
- New GDX Setup projects now use Gradle 8.4 and AGP Plugin 8.1.2 which require at least Java 17.
- Fixed Timer#stop, remember time spent stopped and delay tasks when started again. #7281
- Android: Add configuration option to render under the cutout if available on the device.
- Fix: Keep SelectBox popup from extending past right edge of stage.
- Added Framebuffer multisample support (see GL31FrameBufferMultisampleTest.java for basic usage)

[1.12.1]
- LWJGL3 Improvement: Audio device is automatically switched if it was changed in the operating system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import android.view.WindowManager;
import android.widget.FrameLayout;
import com.badlogic.gdx.*;
import com.badlogic.gdx.backends.android.keyboardheight.AndroidXKeyboardHeightProvider;
import com.badlogic.gdx.backends.android.keyboardheight.KeyboardHeightProvider;
import com.badlogic.gdx.backends.android.keyboardheight.StandardKeyboardHeightProvider;
import com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy;
import com.badlogic.gdx.utils.*;

Expand Down Expand Up @@ -60,6 +63,9 @@ public class AndroidApplication extends Activity implements AndroidApplicationBa
protected boolean useImmersiveMode = false;
private int wasFocusChanged = -1;
private boolean isWaitingForAudio = false;
private KeyboardHeightProvider keyboardHeightProvider;

protected boolean renderUnderCutout = false;

/** This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
* input, render via OpenGL and so on. Uses a default {@link AndroidApplicationConfiguration}.
Expand Down Expand Up @@ -124,6 +130,7 @@ private void init (ApplicationListener listener, AndroidApplicationConfiguration
this.handler = new Handler();
this.useImmersiveMode = config.useImmersiveMode;
this.clipboard = new AndroidClipboard(this);
this.renderUnderCutout = config.renderUnderCutout;

// Add a specialized audio lifecycle listener
addLifecycleListener(new LifecycleListener() {
Expand Down Expand Up @@ -164,13 +171,23 @@ public void dispose () {

createWakeLock(config.useWakelock);
useImmersiveMode(this.useImmersiveMode);
if (this.useImmersiveMode && getVersion() >= Build.VERSION_CODES.KITKAT) {
if (this.useImmersiveMode) {
AndroidVisibilityListener vlistener = new AndroidVisibilityListener();
vlistener.createListener(this);
}

// detect an already connected bluetooth keyboardAvailable
if (getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS) input.setKeyboardAvailable(true);

setLayoutInDisplayCutoutMode(this.renderUnderCutout);

// As per the docs, it might work unreliable < 23 https://developer.android.com/jetpack/androidx/releases/core#1.5.0-alpha02
// So, I guess since 23 is pretty rare we can use the old API for the users
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
keyboardHeightProvider = new AndroidXKeyboardHeightProvider(this);
} else {
keyboardHeightProvider = new StandardKeyboardHeightProvider(this);
}
}

protected FrameLayout.LayoutParams createLayoutParams () {
Expand All @@ -186,6 +203,14 @@ protected void createWakeLock (boolean use) {
}
}

@TargetApi(Build.VERSION_CODES.P)
private void setLayoutInDisplayCutoutMode (boolean render) {
if (render && getVersion() >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
}

@Override
public void onWindowFocusChanged (boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Expand All @@ -201,10 +226,9 @@ public void onWindowFocusChanged (boolean hasFocus) {
}
}

@TargetApi(19)
@Override
public void useImmersiveMode (boolean use) {
if (!use || getVersion() < Build.VERSION_CODES.KITKAT) return;
if (!use) return;

View view = getWindow().getDecorView();
int code = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Expand Down Expand Up @@ -238,6 +262,7 @@ protected void onPause () {
graphics.onPauseGLSurfaceView();

super.onPause();
keyboardHeightProvider.setKeyboardHeightObserver(null);
}

@Override
Expand Down Expand Up @@ -266,11 +291,19 @@ protected void onResume () {
this.isWaitingForAudio = false;
}
super.onResume();
keyboardHeightProvider.setKeyboardHeightObserver((DefaultAndroidInput)Gdx.input);
((AndroidGraphics)getGraphics()).getView().post(new Runnable() {
@Override
public void run () {
keyboardHeightProvider.start();
}
});
}

@Override
protected void onDestroy () {
super.onDestroy();
keyboardHeightProvider.close();
}

@Override
Expand Down Expand Up @@ -481,7 +514,10 @@ public Handler getHandler () {

@Override
public AndroidAudio createAudio (Context context, AndroidApplicationConfiguration config) {
return new DefaultAndroidAudio(context, config);
if (!config.disableAudio)
return new DefaultAndroidAudio(context, config);
else
return new DisabledAndroidAudio();
}

@Override
Expand All @@ -493,4 +529,8 @@ protected AndroidFiles createFiles () {
this.getFilesDir(); // workaround for Android bug #10515463
return new DefaultAndroidFiles(this.getAssets(), this, true);
}

public KeyboardHeightProvider getKeyboardHeightProvider () {
return keyboardHeightProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @author davebaol */
public interface AndroidApplicationBase extends Application {

static final int MINIMUM_SDK = 14;
static final int MINIMUM_SDK = 19;

/** The application or activity context
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public class AndroidApplicationConfiguration {
/** The maximum number of threads to use for network requests. Default is {@link Integer#MAX_VALUE}. */
public int maxNetThreads = Integer.MAX_VALUE;

/** set this to true to render under the display cutout. Use the Graphics::getSafeInsetXX to get the safe render space */
public boolean renderUnderCutout;

/** The loader used to load native libraries. Override this to use a different loading strategy. */
public GdxNativeLoader nativeLoader = new GdxNativeLoader() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

package com.badlogic.gdx.backends.android;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Debug;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -43,7 +41,6 @@
* for the {@link GLSurfaceView}.
*
* @author mzechner */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class AndroidDaydream extends DreamService implements AndroidApplicationBase {

protected AndroidGraphics graphics;
Expand Down Expand Up @@ -395,7 +392,10 @@ public Handler getHandler () {

@Override
public AndroidAudio createAudio (Context context, AndroidApplicationConfiguration config) {
return new DefaultAndroidAudio(context, config);
if (!config.disableAudio)
return new DefaultAndroidAudio(context, config);
else
return new DisabledAndroidAudio();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

package com.badlogic.gdx.backends.android;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Debug;
import android.os.Handler;
import android.util.Log;
Expand Down Expand Up @@ -86,10 +84,9 @@ protected void createWakeLock (boolean use) {
}
}

@TargetApi(19)
@Override
public void useImmersiveMode (boolean use) {
if (!use || getVersion() < Build.VERSION_CODES.KITKAT) return;
if (!use) return;

View view = this.graphics.getView();

Expand Down Expand Up @@ -168,7 +165,7 @@ public void dispose () {
Gdx.net = this.getNet();
createWakeLock(config.useWakelock);
useImmersiveMode(config.useImmersiveMode);
if (config.useImmersiveMode && getVersion() >= Build.VERSION_CODES.KITKAT) {
if (config.useImmersiveMode) {
AndroidVisibilityListener vlistener = new AndroidVisibilityListener();
vlistener.createListener(this);
}
Expand Down Expand Up @@ -447,7 +444,10 @@ public Handler getHandler () {

@Override
public AndroidAudio createAudio (Context context, AndroidApplicationConfiguration config) {
return new DefaultAndroidAudio(context, config);
if (!config.disableAudio)
return new DefaultAndroidAudio(context, config);
else
return new DisabledAndroidAudio();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

package com.badlogic.gdx.backends.android;

import android.annotation.TargetApi;
import android.opengl.GLES30;

import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.utils.GdxRuntimeException;

@TargetApi(18)
public class AndroidGL30 extends AndroidGL20 implements GL30 {
@Override
public void glReadBuffer (int mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,7 @@ public void onDrawFrame (javax.microedition.khronos.opengles.GL10 gl) {
}

for (int i = 0; i < app.getExecutedRunnables().size; i++) {
try {
app.getExecutedRunnables().get(i).run();
} catch (Throwable t) {
t.printStackTrace();
}
app.getExecutedRunnables().get(i).run();
}
app.getInput().processEvents();
frameId++;
Expand Down Expand Up @@ -723,14 +719,9 @@ public DisplayMode getDisplayMode () {
Display display;
DisplayMetrics metrics = new DisplayMetrics();

if (Build.VERSION.SDK_INT >= 17) {
DisplayManager displayManager = (DisplayManager)app.getContext().getSystemService(Context.DISPLAY_SERVICE);
display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
display.getRealMetrics(metrics); // Deprecated but no direct equivalent
} else {
display = app.getWindowManager().getDefaultDisplay();
display.getMetrics(metrics); // Excludes system UI!
}
DisplayManager displayManager = (DisplayManager)app.getContext().getSystemService(Context.DISPLAY_SERVICE);
display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
display.getRealMetrics(metrics); // Deprecated but no direct equivalent

int width = metrics.widthPixels;
int height = metrics.heightPixels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ public Handler getHandler () {

@Override
public AndroidAudio createAudio (Context context, AndroidApplicationConfiguration config) {
return new DefaultAndroidAudio(context, config);
if (!config.disableAudio)
return new DefaultAndroidAudio(context, config);
else
return new DisabledAndroidAudio();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return netJavaImpl.isHttpRequestPending(httpRequest);
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String hostname, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, hostname, port, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ public class AsynchronousAndroidAudio extends DefaultAndroidAudio {

public AsynchronousAndroidAudio (Context context, AndroidApplicationConfiguration config) {
super(context, config);
if (!config.disableAudio) {
handlerThread = new HandlerThread("libGDX Sound Management");
handlerThread.start();
handler = new Handler(handlerThread.getLooper());
} else {
handler = null;
handlerThread = null;
}
handlerThread = new HandlerThread("libGDX Sound Management");
handlerThread.start();
handler = new Handler(handlerThread.getLooper());
}

@Override
Expand Down

0 comments on commit eade552

Please sign in to comment.