Skip to content

Commit

Permalink
WebView: create activity for setting preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Feb 16, 2022
1 parent 292ec69 commit 89dd013
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 262 deletions.
1 change: 1 addition & 0 deletions android/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TODO:
- create menu when back pressed:
- take screenshot
- set theme
- add option to have joystick style d-pad instead of arrows

BUILD TODO:
- script to download Android SDK
8 changes: 8 additions & 0 deletions android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.arianne.stendhal.client">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>
12 changes: 11 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.arianne.stendhal.client">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
Expand All @@ -24,6 +23,17 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".PreferencesActivity"
android:label="Preferences"
android:exported="true"
android:configChanges="orientation|screenSize|keyboardHidden">

<intent-filter>
<action android:name="preferences" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

Expand All @@ -37,14 +38,11 @@ protected void onCreate(final Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
instance = this;
setContentView(R.layout.activity_main);

// initialize debug logging mechanism
DebugLog.init(getExternalFilesDir(null), this);

// initialize settings store
Settings.init(getExternalFilesDir(null));

setContentView(R.layout.activity_main);
menu = new Menu(this);
client = new StendhalWebView(this);
} catch (final Exception e) {
Expand Down Expand Up @@ -112,8 +110,10 @@ public void finish() {
protected void onDestroy() {
DebugLog.debug(MainActivity.class.getName() + ".onDestroy() called");

// XXX: settings only get saved if app exited via menu
Settings.commitToFile();
super.onDestroy();
}

public void showSettings() {
startActivity(new Intent(MainActivity.this, PreferencesActivity.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ protected void onCall() {/* do nothing */}
btn_settings.setOnClickListener(new ClickListener() {
public void onClick(final View v) {
super.onClick(v);

((MainActivity) ctx).showSettings();
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/***************************************************************************
* Copyright © 2022 - Arianne *
***************************************************************************
***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
package org.arianne.stendhal.client;

import android.os.Bundle;
import android.preference.PreferenceFragment;
import androidx.appcompat.app.AppCompatActivity;


public class PreferencesActivity extends AppCompatActivity {

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);

if (findViewById(R.id.preferencesFrame) != null) {
if (savedInstanceState != null) {
return;
}

final PreferenceFragment frag = new PreferenceFragment() {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
};

getFragmentManager().beginTransaction().add(R.id.preferencesFrame, frag).commit();
}
}
}
233 changes: 0 additions & 233 deletions android/app/src/main/java/org/arianne/stendhal/client/Settings.java

This file was deleted.

Loading

0 comments on commit 89dd013

Please sign in to comment.