Beginning of Android persistent settings

This commit is contained in:
Aaron Culliney 2015-07-21 21:34:51 -07:00
parent 87d7d8a115
commit a60ffb8eb9
12 changed files with 240 additions and 30 deletions

View File

@ -36,7 +36,6 @@ public class Apple2Activity extends Activity {
private final static String TAG = "Apple2Activity";
private final static int BUF_SZ = 4096;
private final static String PREFS_CONFIGURED = "prefs_configured";
private final static int SOFTKEYBOARD_THRESHOLD = 50;
private final static int MAX_FINGERS = 32;// HACK ...
@ -76,8 +75,6 @@ public class Apple2Activity extends Activity {
public native void nativeReboot();
public native void nativeRender();
public native void nativeEnableTouchJoystick(boolean visibility);
public native void nativeSetColor(int color);
public native void nativeChooseDisk(String path, boolean driveA, boolean readOnly);
@ -96,8 +93,7 @@ public class Apple2Activity extends Activity {
System.exit(1);
}
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
if (settings.getBoolean(PREFS_CONFIGURED, false)) {
if (Apple2Preferences.PREFS_CONFIGURED.booleanValue(this)) {
return dataDir;
}
@ -118,9 +114,7 @@ public class Apple2Activity extends Activity {
}
Log.d(TAG, "Saving default preferences");
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(PREFS_CONFIGURED, true);
editor.apply();
Apple2Preferences.PREFS_CONFIGURED.saveBoolean(this, true);
return dataDir;
}
@ -199,7 +193,7 @@ public class Apple2Activity extends Activity {
// now append the actual stack trace
traceBuffer.append(t.getClass().getName());
traceBuffer.append("\n");
final int maxTraceSize = 2048+1024+512; // probably should keep this less than a standard Linux PAGE_SIZE
final int maxTraceSize = 2048 + 1024 + 512; // probably should keep this less than a standard Linux PAGE_SIZE
for (StackTraceElement elt : stackTraceElements) {
traceBuffer.append(elt.toString());
traceBuffer.append("\n");
@ -230,6 +224,9 @@ public class Apple2Activity extends Activity {
nativeOnCreate(mDataDir, mSampleRate, mMonoBufferSize, mStereoBufferSize);
// NOTE: load preferences after nativeOnCreate
Apple2Preferences.loadPreferences(this);
mView = new Apple2View(this);
setContentView(mView);

View File

@ -0,0 +1,155 @@
/*
* Apple // emulator for *nix
*
* This software package is subject to the GNU General Public License
* version 2 or later (your choice) as published by the Free Software
* Foundation.
*
* THERE ARE NO WARRANTIES WHATSOEVER.
*
*/
package org.deadc0de.apple2ix;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
public enum Apple2Preferences {
PREFS_CONFIGURED {
@Override public void load(Apple2Activity activity) {
// ...
}
@Override public void saveBoolean(Apple2Activity activity, boolean ignored) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(toString(), true).apply();
}
},
HIRES_COLOR {
@Override public void load(Apple2Activity activity) {
nativeSetColor(intValue(activity));
}
@Override public int intValue(Apple2Activity activity) {
return activity.getPreferences(Context.MODE_PRIVATE).getInt(toString(), HiresColor.INTERPOLATED.ordinal());
}
},
SPEAKER_ENABLED {
@Override public void load(Apple2Activity activity) {
boolean enabled = booleanValue(activity);
boolean result = nativeSetSpeakerEnabled(enabled);
if (enabled && !result) {
warnError(activity, R.string.speaker_disabled_title, R.string.speaker_disabled_mesg);
activity.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(toString(), false).apply();
}
}
@Override public boolean booleanValue(Apple2Activity activity) {
return activity.getPreferences(Context.MODE_PRIVATE).getBoolean(toString(), true);
}
},
SPEAKER_VOLUME {
@Override public void load(Apple2Activity activity) {
nativeSetSpeakerVolume(intValue(activity));
}
@Override public int intValue(Apple2Activity activity) {
return activity.getPreferences(Context.MODE_PRIVATE).getInt(toString(), Volume.MEDIUM.ordinal());
}
},
MOCKINGBOARD_ENABLED {
@Override public void load(Apple2Activity activity) {
boolean enabled = booleanValue(activity);
boolean result = nativeSetMockingboardEnabled(enabled);
if (enabled && !result) {
warnError(activity, R.string.mockingboard_disabled_title, R.string.mockingboard_disabled_mesg);
activity.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(toString(), false).apply();
}
}
},
MOCKINGBOARD_VOLUME {
@Override public void load(Apple2Activity activity) {
nativeSetMockingboardVolume(intValue(activity));
}
@Override public int intValue(Apple2Activity activity) {
return activity.getPreferences(Context.MODE_PRIVATE).getInt(toString(), Volume.MEDIUM.ordinal());
}
};
public enum HiresColor {
BW,
COLOR,
INTERPOLATED
}
public enum Volume {
OFF(0),
ONE(1),
TWO(2),
THREE(3),
FOUR(4),
MEDIUM(5),
FIVE(5),
SIX(6),
SEVEN(7),
EIGHT(8),
NINE(9),
MAX(10),
ELEVEN(11);
private int vol;
Volume(int vol) {
this.vol = vol;
}
}
protected abstract void load(Apple2Activity activity);
protected void warnError(Apple2Activity activity, int titleId, int mesgId) {
AlertDialog dialog = new AlertDialog.Builder(activity).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(titleId).setMessage(mesgId).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
dialog.show();
}
// set and apply
public void saveInt(Apple2Activity activity, int value) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putInt(toString(), value).apply();
load(activity);
}
public void saveBoolean(Apple2Activity activity, boolean value) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(toString(), value).apply();
load(activity);
}
public void saveHiresColor(Apple2Activity activity, HiresColor value) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putInt(toString(), value.ordinal()).apply();
load(activity);
}
public void saveVolume(Apple2Activity activity, Volume value) {
activity.getPreferences(Context.MODE_PRIVATE).edit().putInt(toString(), value.ordinal()).apply();
load(activity);
}
// accessors
public boolean booleanValue(Apple2Activity activity) {
return activity.getPreferences(Context.MODE_PRIVATE).getBoolean(toString(), false);
}
public int intValue(Apple2Activity activity) {
return activity.getPreferences(Context.MODE_PRIVATE).getInt(toString(), 0);
}
public static void loadPreferences(Apple2Activity activity) {
for (Apple2Preferences pref : Apple2Preferences.values()) {
pref.load(activity);
}
}
private static native void nativeEnableTouchJoystick(boolean enabled);
private static native void nativeEnableTiltJoystick(boolean enabled);
private static native void nativeSetColor(int color);
private static native boolean nativeSetSpeakerEnabled(boolean enabled);
private static native void nativeSetSpeakerVolume(int volume);
private static native boolean nativeSetMockingboardEnabled(boolean enabled);
private static native void nativeSetMockingboardVolume(int volume);
}

View File

@ -56,7 +56,7 @@ public class Apple2SettingsMenu {
@Override public void handleSelection(Apple2SettingsMenu settingsMenu, boolean selected) {
}
},
AUDIO_ENABLE {
AUDIO_CONFIGURE {
@Override public String getTitle(Context ctx) {
return ctx.getResources().getString(R.string.audio_enabled);
}
@ -99,7 +99,7 @@ public class Apple2SettingsMenu {
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int color) {
settingsMenu.mActivity.nativeSetColor(color);
Apple2Preferences.HIRES_COLOR.saveHiresColor(settingsMenu.mActivity, Apple2Preferences.HiresColor.values()[color]);
dialog.dismiss();
}
});

View File

@ -33,6 +33,8 @@
<string name="menu_disks_summary">Insert a Disk ][ image file</string>
<string name="menu_settings">Emulator settings…</string>
<string name="menu_settings_summary">General, CPU, Joystick</string>
<string name="mockingboard_disabled_title">Mockingboard disabled</string>
<string name="mockingboard_disabled_mesg">Mockingboard could not be enabled</string>
<string name="no">No</string>
<string name="ok">OK</string>
<string name="quit">Quit emulator…</string>
@ -43,6 +45,8 @@
<string name="reboot_warning">You will lose unsaved progress</string>
<string name="reboot_summary"></string>
<string name="spacer"></string>
<string name="speaker_disabled_title">Speaker disabled</string>
<string name="speaker_disabled_mesg">Speaker could not be enabled</string>
<string name="speed_alt">Alternate CPU Speed</string>
<string name="speed_cpu">CPU Speed</string>
<string name="speed_swipe">Swipe changes emulation speed</string>

View File

@ -11,8 +11,8 @@ include $(COMMON_SOURCES_MK)
# Android build config
LOCAL_MODULE := libapple2ix
LOCAL_SRC_FILES := jnihooks.c androidkeys.c
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := jniprefs.c androidkeys.c
#LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DHEADLESS=0
LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz -lOpenSLES

View File

@ -140,6 +140,9 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje
c_initialize_firsttime();
pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL);
#endif
sleep(1);
#warning FIXME TODO instead of problematic sleep ... need to preempt CPU thread by holding interface lock and displaying a splash screen and setting preferences/settings defaults before starting CPU
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsChanged(JNIEnv *env, jobject obj, jint width, jint height) {
@ -162,6 +165,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobject obj, jboolean isSystemResume) {
if (!nativePaused) {
#warning FIXME ... replace nativePaused check with cpu_isPaused()
return;
}
LOG("%s", "native onResume...");
@ -317,18 +321,6 @@ jboolean Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnTouch(JNIEnv *env, jo
return consumed;
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeSetColor(JNIEnv *env, jobject obj, jint color) {
LOG("native set color : %d", color);
if (color < COLOR_NONE || color > COLOR_INTERP) {
return;
}
color_mode = color;
video_reset();
video_setpage(!!(softswitches & SS_SCREEN));
video_redraw();
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, jobject obj, jstring jPath, jboolean driveA, jboolean readOnly) {
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
int drive = driveA ? 0 : 1;

62
Android/jni/jniprefs.c Normal file
View File

@ -0,0 +1,62 @@
/*
* Apple // emulator for *nix
*
* This software package is subject to the GNU General Public License
* version 2 or later (your choice) as published by the Free Software
* Foundation.
*
* THERE ARE NO WARRANTIES WHATSOEVER.
*
*/
#include "common.h"
#include <jni.h>
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeEnableTouchJoystick(JNIEnv *env, jclass cls, jboolean enabled) {
LOG("native enable touch joystick : %d", enabled);
}
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeEnableTiltJoystick(JNIEnv *env, jclass cls, jboolean enabled) {
LOG("native enable tilt joystick : %d", enabled);
}
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetColor(JNIEnv *env, jclass cls, jint color) {
LOG("native set hires color : %d", color);
if (color < COLOR_NONE || color > COLOR_INTERP) {
return;
}
color_mode = color;
video_reset();
video_setpage(!!(softswitches & SS_SCREEN));
video_redraw();
}
jboolean Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetSpeakerEnabled(JNIEnv *env, jclass cls, jboolean enabled) {
// NO-OP ... speaker should always be enabled (but volume could be zero)
return true;
}
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetSpeakerVolume(JNIEnv *env, jclass cls, jint goesToTen) {
LOG("native set speaker volume : %d", goesToTen);
assert(goesToTen >= 0);
speaker_setVolumeZeroToTen(goesToTen);
}
jboolean Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetMockingboardEnabled(JNIEnv *env, jclass cls, jboolean enabled) {
LOG("native set set mockingboard enabled : %d", enabled);
//assert(cpu_isPaused());
#warning FIXME ^^^ this should be true
MB_Destroy();
if (enabled) {
MB_Initialize();
}
}
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetMockingboardVolume(JNIEnv *env, jclass cls, jint goesToTen) {
LOG("native set mockingboard volume : %d", goesToTen);
assert(goesToTen >= 0);
MB_SetVolumeZeroToTen(goesToTen);
}

View File

@ -33,7 +33,7 @@ APPLE2_META_SRC = \
APPLE2_MAIN_SRC = \
$(APPLE2_SRC_PATH)/font.c $(APPLE2_SRC_PATH)/rom.c $(APPLE2_SRC_PATH)/misc.c $(APPLE2_SRC_PATH)/display.c $(APPLE2_SRC_PATH)/vm.c \
$(APPLE2_SRC_PATH)/timing.c $(APPLE2_SRC_PATH)/zlib-helpers.c $(APPLE2_SRC_PATH)/joystick.c $(APPLE2_SRC_PATH)/keys.c \
$(APPLE2_SRC_PATH)/interface.c $(APPLE2_SRC_PATH)/disk.c $(APPLE2_SRC_PATH)/cpu-supp.c
$(APPLE2_SRC_PATH)/interface.c $(APPLE2_SRC_PATH)/disk.c $(APPLE2_SRC_PATH)/cpu-supp.c jnihooks.c
APPLE2_OPTIM_CFLAGS := -g -O2
APPLE2_BASE_CFLAGS := -DAPPLE2IX=1 -DINTERFACE_TOUCH=1 -DMOBILE_DEVICE=1 -DVIDEO_OPENGL=1 -DDEBUGGER=1 -DAUDIO_ENABLED=1 -std=gnu11 $(APPLE2_OPTIM_CFLAGS) -I$(APPLE2_SRC_PATH)

View File

@ -11,7 +11,7 @@ include $(COMMON_SOURCES_MK)
# Android build config
LOCAL_MODULE := libapple2ix
LOCAL_SRC_FILES := jnihooks.c $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testcpu.c
LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testcpu.c
LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_CPU -DTESTING=1 -DHEADLESS=1
LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz

View File

@ -11,7 +11,7 @@ include $(COMMON_SOURCES_MK)
# Android build config
LOCAL_MODULE := libapple2ix
LOCAL_SRC_FILES := jnihooks.c $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testdisk.c
LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testdisk.c
LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_DISK -DTESTING=1 -DCPU_TRACING=1 -DDISK_TRACING=1 -DVM_TRACING=1
LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz

View File

@ -11,7 +11,7 @@ include $(COMMON_SOURCES_MK)
# Android build config
LOCAL_MODULE := libapple2ix
LOCAL_SRC_FILES := jnihooks.c $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testdisplay.c
LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testdisplay.c
LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_DISPLAY -DTESTING=1
LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz

View File

@ -11,7 +11,7 @@ include $(COMMON_SOURCES_MK)
# Android build config
LOCAL_MODULE := libapple2ix
LOCAL_SRC_FILES := jnihooks.c $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testvm.c
LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testvm.c
LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_VM -DTESTING=1 -DCPU_TRACING=1 -DDISK_TRACING=1 -DVM_TRACING=1
LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz