v0.9.2b: fixed URL opening bug in Android 11, and re-final commit

This commit is contained in:
Evan Debenham 2021-03-20 17:13:33 -04:00
parent d20383935b
commit c991208b9b
5 changed files with 33 additions and 2 deletions

View File

@ -64,7 +64,7 @@ public class DeviceCompat {
}
public static void openURI( String URI ){
Gdx.net.openURI( URI );
Game.platform.openURI(URI);
}
public static void log( String tag, String message ){

View File

@ -30,6 +30,10 @@ public abstract class PlatformSupport {
public abstract void updateSystemUI();
public abstract boolean connectedToUnmeteredNetwork();
//FIXME this is a temporary method to workaround a bug in libGDX with Android 11+
//it can be removed once Shattered is updated to libGDX 1.9.14+
public abstract boolean openURI( String URI );
//FIXME this is currently used because no platform-agnostic text input has been implemented.
//should look into doing that using either plain openGL or libgdx's libraries

View File

@ -22,16 +22,21 @@
package com.shatteredpixel.shatteredpixeldungeon.android;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidGraphics;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
@ -168,6 +173,23 @@ public class AndroidPlatformSupport extends PlatformSupport {
}
}
@Override
public boolean openURI(String URI) {
//copied from LibGDX 1.9.14 source
final Uri uri = Uri.parse(URI);
try {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// LiveWallpaper and Daydream applications need this flag
if (!(((AndroidApplication)Gdx.app).getContext() instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
((AndroidApplication)Gdx.app).startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
return false;
}
}
@Override
public void promptTextInput(final String title, final String hintText, final int maxLen, final boolean multiLine, final String posTxt, final String negTxt, final TextCallback callback) {
Game.runOnRenderThread( new Callback() {

View File

@ -14,7 +14,7 @@ allprojects {
appName = 'Shattered Pixel Dungeon'
appPackageName = 'com.shatteredpixel.shatteredpixeldungeon'
appVersionCode = 526
appVersionCode = 528
appVersionName = '0.9.2b'
appJavaCompatibility = JavaVersion.VERSION_1_8

View File

@ -66,6 +66,11 @@ public class DesktopPlatformSupport extends PlatformSupport {
return true; //no easy way to check this in desktop, just assume user doesn't care
}
@Override
public boolean openURI(String URI) {
return Gdx.net.openURI(URI);
}
@Override
//FIXME tinyfd_inputBox isn't a full solution for this. No support for multiline, looks ugly. Ideally we'd have an opengl-based input box
public void promptTextInput(String title, String hintText, int maxLen, boolean multiLine, String posTxt, String negTxt, TextCallback callback) {