v1.3.0: renamed AndroidGame to AndroidLauncher and added activity to handle missing natives

This commit is contained in:
Evan Debenham
2022-05-13 13:47:42 -04:00
parent b4713369bf
commit a4484599e6
4 changed files with 75 additions and 27 deletions

View File

@@ -33,7 +33,7 @@
android:fullBackupOnly="true"
android:backupAgent=".AndroidBackupHandler">
<activity
android:name=".AndroidGame"
android:name=".AndroidLauncher"
android:screenOrientation="nosensor"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
android:exported="true">
@@ -42,6 +42,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AndroidMissingNativesHandler">
</activity>
</application>

View File

@@ -21,15 +21,13 @@
package com.shatteredpixel.shatteredpixeldungeon.android;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewConfiguration;
import android.widget.TextView;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.android.AndroidApplication;
@@ -48,12 +46,13 @@ import com.watabou.noosa.Game;
import com.shatteredpixel.shatteredpixeldungeon.ui.Button;
import com.watabou.utils.FileUtils;
public class AndroidGame extends AndroidApplication {
public class AndroidLauncher extends AndroidApplication {
public static AndroidApplication instance;
private static AndroidPlatformSupport support;
@SuppressLint("SetTextI18n")
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -62,17 +61,10 @@ public class AndroidGame extends AndroidApplication {
GdxNativesLoader.load();
FreeType.initFreeType();
} catch (Exception e){
TextView text = new TextView(this);
text.setText("Shattered Pixel Dungeon cannot start because some of its code is missing!\n\n" +
"This usually happens when the Google Play version of the game is installed from somewhere outside of Google Play.\n\n" +
"If you're unsure of how to fix this, please email the developer (Evan@ShatteredPixel.com), and include this error message:\n\n" +
e.getMessage());
text.setTextSize(16);
text.setTextColor(0xFFFFFFFF);
text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/pixel_font.ttf"));
text.setGravity(Gravity.CENTER_VERTICAL);
text.setPadding(10, 10, 10, 10);
setContentView(text);
AndroidMissingNativesHandler.errorMsg = e.getMessage();
Intent intent = new Intent(this, AndroidMissingNativesHandler.class);
startActivity(intent);
finish();
return;
}

View File

@@ -0,0 +1,53 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2022 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.android;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
public class AndroidMissingNativesHandler extends Activity {
public static String errorMsg = "";
@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
text.setText("Shattered Pixel Dungeon cannot start because some of its code is missing!\n\n" +
"This usually happens when the Google Play version of the game is installed from somewhere outside of Google Play.\n\n" +
"If you're unsure of how to fix this, please email the developer (Evan@ShatteredPixel.com), and include this error message:\n\n" +
errorMsg);
text.setTextSize(16);
text.setTextColor(0xFFFFFFFF);
text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/pixel_font.ttf"));
text.setGravity(Gravity.CENTER_VERTICAL);
text.setPadding(10, 10, 10, 10);
setContentView(text);
}
}

View File

@@ -49,7 +49,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
public void updateDisplaySize(){
if (SPDSettings.landscape() != null) {
AndroidGame.instance.setRequestedOrientation( SPDSettings.landscape() ?
AndroidLauncher.instance.setRequestedOrientation( SPDSettings.landscape() ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE :
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT );
}
@@ -63,7 +63,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
Game.dispHeight = view.getMeasuredHeight();
boolean fullscreen = Build.VERSION.SDK_INT < Build.VERSION_CODES.N
|| !AndroidGame.instance.isInMultiWindowMode();
|| !AndroidLauncher.instance.isInMultiWindowMode();
if (fullscreen && SPDSettings.landscape() != null
&& (Game.dispWidth >= Game.dispHeight) != SPDSettings.landscape()){
@@ -98,7 +98,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
final int finalH = Math.round(renderHeight);
if (finalW != Game.width || finalH != Game.height){
AndroidGame.instance.runOnUiThread(new Runnable() {
AndroidLauncher.instance.runOnUiThread(new Runnable() {
@Override
public void run() {
view.getHolder().setFixedSize(finalW, finalH);
@@ -107,7 +107,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
}
} else {
AndroidGame.instance.runOnUiThread(new Runnable() {
AndroidLauncher.instance.runOnUiThread(new Runnable() {
@Override
public void run() {
view.getHolder().setSizeFromLayout();
@@ -118,29 +118,29 @@ public class AndroidPlatformSupport extends PlatformSupport {
public void updateSystemUI() {
AndroidGame.instance.runOnUiThread(new Runnable() {
AndroidLauncher.instance.runOnUiThread(new Runnable() {
@SuppressLint("NewApi")
@Override
public void run() {
boolean fullscreen = Build.VERSION.SDK_INT < Build.VERSION_CODES.N
|| !AndroidGame.instance.isInMultiWindowMode();
|| !AndroidLauncher.instance.isInMultiWindowMode();
if (fullscreen){
AndroidGame.instance.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
AndroidLauncher.instance.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
AndroidGame.instance.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
AndroidLauncher.instance.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
if (SPDSettings.fullscreen()) {
AndroidGame.instance.getWindow().getDecorView().setSystemUiVisibility(
AndroidLauncher.instance.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY );
} else {
AndroidGame.instance.getWindow().getDecorView().setSystemUiVisibility(
AndroidLauncher.instance.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE );
}
}
@@ -153,7 +153,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
@SuppressWarnings("deprecation")
public boolean connectedToUnmeteredNetwork() {
//Returns true if using unmetered connection, use shortcut method if available
ConnectivityManager cm = (ConnectivityManager) AndroidGame.instance.getSystemService(Context.CONNECTIVITY_SERVICE);
ConnectivityManager cm = (ConnectivityManager) AndroidLauncher.instance.getSystemService(Context.CONNECTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
return !cm.isActiveNetworkMetered();
} else {