Skip to content

Commit

Permalink
Merge pull request #3321 from Ghabry/android
Browse files Browse the repository at this point in the history
Android: Fix common crashes / various improvements
  • Loading branch information
carstene1ns authored Jan 8, 2025
2 parents 7976386 + aebda10 commit 85d12a2
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 64 deletions.
12 changes: 7 additions & 5 deletions builds/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ android {
assetPacks = [":assets"]
defaultConfig {
applicationId "org.easyrpg.player"
compileSdk 34
compileSdk 35
minSdkVersion 21
targetSdkVersion 34
targetSdkVersion 35
versionName VERSION_NAME
versionCode Integer.parseInt(VERSION_CODE)
}
Expand Down Expand Up @@ -53,12 +53,14 @@ android {
"-DBUILD_SHARED_LIBS=ON",
"-DPLAYER_ENABLE_TESTS=OFF"

if (project.hasProperty("toolchainDirs")) {
arguments.add('-DPLAYER_ANDROID_TOOLCHAIN_PATH=' + project.properties['toolchainDirs'])
if (project.hasProperty("toolchainDirs") && project.toolchainDirs) {
arguments.add('-DPLAYER_ANDROID_TOOLCHAIN_PATH=' + project.toolchainDirs)
} else if (System.getenv('EASYRPG_BUILDSCRIPTS')) {
arguments.add('-DPLAYER_ANDROID_TOOLCHAIN_PATH=' + System.getenv('EASYRPG_BUILDSCRIPTS') + '/android')
}

if (project.hasProperty("cmakeOptions")) {
arguments.addAll(project.properties['cmakeOptions'].split(" "))
arguments.addAll(project.cmakeOptions.split(" "))
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions builds/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@
<activity
android:name=".button_mapping.ButtonMappingActivity"
android:configChanges="orientation|screenSize" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.easyrpg.player;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import org.easyrpg.player.settings.SettingsManager;

public class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Retrieve User's preferences
SettingsManager.init(getApplicationContext());
}

@Override
protected void onResume() {
super.onResume();

// Retrieve User's preferences
SettingsManager.init(getApplicationContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ public static DocumentFile findFile(Context context, Uri folderUri, String fileN
}

public static DocumentFile getFileFromURI (Context context, Uri fileURI) {
if (fileURI == null) {
return null;
}

try {
return DocumentFile.fromTreeUri(context, fileURI);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* To start the standalone mode : put your project in assets/games
* ("game" is the project directory, no sub folder)
*/
public class InitActivity extends AppCompatActivity {
public class InitActivity extends BaseActivity {
private boolean standaloneMode = false;
private GameBrowserHelper.SafError safError = GameBrowserHelper.SafError.OK;

Expand All @@ -37,9 +37,6 @@ protected void onCreate(Bundle savedInstanceState) {

safError = GameBrowserHelper.SafError.OK;

// Retrieve User's preferences
SettingsManager.init(getApplicationContext());

Activity thisActivity = this;
(findViewById(R.id.set_games_folder)).setOnClickListener(v -> GameBrowserHelper.pickAGamesFolder(thisActivity));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.button_mapping_activity);

SettingsManager.init(getApplicationContext());

// Menu configuration
this.drawer = findViewById(R.id.drawer_layout);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Expand Down Expand Up @@ -81,6 +83,14 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Override
protected void onResume() {
super.onResume();

// Retrieve User's preferences
SettingsManager.init(getApplicationContext());
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
pointerCount = ev.getPointerCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ public char getAppropriateChar(int keyCode) {
char charButton;

if (keyCode == ENTER) {
if (SettingsManager.getShowZXasAB()) {
charButton = 'A';
} else {
if (SettingsManager.getShowABasZX()) {
charButton = 'Z';
} else {
charButton = 'A';
}
} else if (keyCode == CANCEL) {
if (SettingsManager.getShowZXasAB()) {
charButton = 'B';
} else {
if (SettingsManager.getShowABasZX()) {
charButton = 'X';
} else {
charButton = 'B';
}
} else if (keyCode == SHIFT) {
charButton = 'S';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@

import com.google.android.material.navigation.NavigationView;

import org.easyrpg.player.BaseActivity;
import org.easyrpg.player.R;
import org.easyrpg.player.settings.SettingsManager;
import org.libsdl.app.SDL;

import java.util.Collections;
import java.util.List;

public class GameBrowserActivity extends AppCompatActivity
public class GameBrowserActivity extends BaseActivity
implements NavigationView.OnNavigationItemSelectedListener {
public static Boolean libraryLoaded = false;

Expand Down Expand Up @@ -178,7 +179,10 @@ public void openView() {
.setPositiveButton(R.string.ok, (dialog, id) -> {
int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
SettingsManager.setGameBrowserLabelMode(selectedPosition);
displayGamesList();
if (displayedGamesList != null) {
// handle error case (no games displayed)
displayGamesList();
}
})
.setNegativeButton(R.string.cancel, null);
builder.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@ public static void launchGame(Context context, Game game, boolean debugMode) {

String savePath = path;
if (!game.getSavePath().isEmpty()) {
DocumentFile saveFolder = Helper.createFolderInSave(context, game.getSavePath());

// In error case the native code will try to put a save folder next to the zip
if (saveFolder != null) {
savePath = saveFolder.getUri().toString();
if (game.isStandalone()) {
savePath = game.getSavePath();
args.add("--save-path");
args.add(savePath);
} else {
DocumentFile saveFolder = Helper.createFolderInSave(context, game.getSavePath());

// In error case the native code will try to put a save folder next to the zip
if (saveFolder != null) {
savePath = saveFolder.getUri().toString();
args.add("--save-path");
args.add(savePath);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import androidx.core.content.FileProvider;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

Expand All @@ -65,6 +66,7 @@
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Locale;

/**
* EasyRPG Player for Android (inheriting from SDLActivity)
Expand Down Expand Up @@ -239,12 +241,27 @@ private void reportBug() {
.setPositiveButton(R.string.ok, (dialog, id) -> {
// Attach to the email : the easyrpg log file and savefiles
ArrayList<Uri> files = new ArrayList<>();
// The easyrpg_log.txt

String savepath = getIntent().getStringExtra(TAG_SAVE_PATH);

if (getIntent().getBooleanExtra(TAG_STANDALONE, false)) {
// FIXME: Attaching files does not work because the files are in /data and
// other apps have no permission
File logFile = new File(savepath, "easyrpg_log.txt");
if (logFile.exists()) {
Uri logUri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", logFile);
if (logUri != null) {
files.add(logUri);
}
}

for (int i = 1; i <= 15; ++i) {
File saveFile = new File(savepath, String.format(Locale.ROOT, "Save%02d.lsd", i));
if (saveFile.exists()) {
Uri saveUri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", saveFile);
if (saveUri != null) {
files.add(saveUri);
}
}
}
} else {
Uri saveFolder = Uri.parse(savepath);
Uri log = Helper.findFileUri(getContext(), saveFolder, "easyrpg_log.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.documentfile.provider.DocumentFile;

import org.easyrpg.player.BaseActivity;
import org.easyrpg.player.Helper;
import org.easyrpg.player.R;

import java.util.ArrayList;
import java.util.List;

public class SettingsAudioActivity extends AppCompatActivity {
public class SettingsAudioActivity extends BaseActivity {
private LinearLayout soundfontsListLayout;
List<SoundfontItemList> soundfontList;

Expand All @@ -33,8 +34,6 @@ protected void onCreate(Bundle savedInstanceState) {

soundfontsListLayout = findViewById(R.id.settings_sound_fonts_list);

SettingsManager.init(getApplicationContext());

// Setup UI components
// The Soundfont Button
Button button = this.findViewById(R.id.button_open_soundfont_folder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum SettingsEnum {
FONT1_SIZE("Font1Size"),
FONT2_SIZE("Font2Size"),
GAME_BROWSER_LABEL_MODE("GAME_BROWSER_LABEL_MODE"),
SHOW_ZX_AS_AB("SHOW_ZX_AS_AB")
SHOW_AB_AS_ZX("SHOW_AB_AS_ZX")
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.documentfile.provider.DocumentFile;

import org.easyrpg.player.BaseActivity;
import org.easyrpg.player.Helper;
import org.easyrpg.player.R;
import org.libsdl.app.SDL;

import java.util.ArrayList;
import java.util.List;

public class SettingsFontActivity extends AppCompatActivity {
public class SettingsFontActivity extends BaseActivity {
private LinearLayout fonts1ListLayout;
private LinearLayout fonts2ListLayout;
private String[] extensions = new String[] {".fon", ".fnt", ".bdf", ".ttf", ".ttc", ".otf", ".woff2", ".woff"};
Expand All @@ -43,7 +44,6 @@ protected void onCreate(Bundle savedInstanceState) {
fonts1ListLayout = findViewById(R.id.settings_font1_list);
fonts2ListLayout = findViewById(R.id.settings_font2_list);

SettingsManager.init(getApplicationContext());
SDL.setContext(getApplicationContext());

// Setup UI components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

import androidx.appcompat.app.AppCompatActivity;

import org.easyrpg.player.BaseActivity;
import org.easyrpg.player.R;
import org.easyrpg.player.game_browser.GameBrowserActivity;
import org.easyrpg.player.game_browser.GameBrowserHelper;
import org.libsdl.app.SDL;

public class SettingsGamesFolderActivity extends AppCompatActivity {
public class SettingsGamesFolderActivity extends BaseActivity {
private GameBrowserHelper.SafError safError = GameBrowserHelper.SafError.OK;

@Override
Expand All @@ -28,8 +29,6 @@ public void onCreate(Bundle savedInstanceState) {

safError = GameBrowserHelper.SafError.OK;

SettingsManager.init(getApplicationContext());

Activity thisActivity = this;
Button setGamesFolderButton = findViewById(R.id.set_games_folder);
setGamesFolderButton.setOnClickListener(v -> GameBrowserHelper.pickAGamesFolder(thisActivity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatSpinner;

import org.easyrpg.player.BaseActivity;
import org.easyrpg.player.R;
import org.easyrpg.player.button_mapping.ButtonMappingActivity;
import org.easyrpg.player.button_mapping.InputLayout;

public class SettingsInputActivity extends AppCompatActivity implements View.OnClickListener {
public class SettingsInputActivity extends BaseActivity implements View.OnClickListener {
private CheckBox enableVibrateWhenSlidingCheckbox;
private SeekBar layoutTransparencyLayout, layoutSizeSeekBar, fastForwardMultiplierSeekBar;
private TextView layoutTransparencyTextView, layoutSizeTextView, fastForwardMultiplierTextView;
Expand All @@ -26,8 +26,6 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_settings_inputs);

SettingsManager.init(getApplicationContext());

// Setting UI components
CheckBox enableVibrationCheckBox = findViewById(R.id.settings_enable_vibration);
enableVibrationCheckBox.setChecked(SettingsManager.isVibrationEnabled());
Expand All @@ -37,9 +35,9 @@ public void onCreate(Bundle savedInstanceState) {
enableVibrateWhenSlidingCheckbox.setChecked(SettingsManager.isVibrateWhenSlidingDirectionEnabled());
enableVibrateWhenSlidingCheckbox.setOnClickListener(this);

CheckBox showZXasABcheckbox = findViewById(R.id.settings_show_zx_as_ab);
showZXasABcheckbox.setChecked(SettingsManager.getShowZXasAB());
showZXasABcheckbox.setOnClickListener(this);
CheckBox showABasZXcheckbox = findViewById(R.id.settings_show_ab_as_zx);
showABasZXcheckbox.setChecked(SettingsManager.getShowABasZX());
showABasZXcheckbox.setOnClickListener(this);

configureFastForwardButton();
configureLayoutTransparencySystem();
Expand All @@ -61,8 +59,8 @@ public void onClick(View v) {
enableVibrateWhenSlidingCheckbox.setEnabled(c.isChecked());
} else if (id == R.id.settings_vibrate_when_sliding){
SettingsManager.setVibrateWhenSlidingDirectionEnabled(((CheckBox) v).isChecked());
} else if (id == R.id.settings_show_zx_as_ab) {
SettingsManager.setShowZXasAB(((CheckBox)v).isChecked());
} else if (id == R.id.settings_show_ab_as_zx) {
SettingsManager.setShowABasZX(((CheckBox)v).isChecked());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import androidx.appcompat.app.AppCompatActivity;

import org.easyrpg.player.BaseActivity;
import org.easyrpg.player.R;

public class SettingsMainActivity extends AppCompatActivity implements View.OnClickListener {
public class SettingsMainActivity extends BaseActivity implements View.OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down
Loading

0 comments on commit 85d12a2

Please sign in to comment.