mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-06-25 09:29:28 +00:00
Persist settings for currently inserted disks, and provide a way to eject disks
This commit is contained in:
parent
e39f61d44c
commit
ebe7f82f22
|
@ -100,6 +100,8 @@ public class Apple2Activity extends Activity {
|
|||
|
||||
public native void nativeChooseDisk(String path, boolean driveA, boolean readOnly);
|
||||
|
||||
public native void nativeEjectDisk(boolean driveA);
|
||||
|
||||
|
||||
private void _setCustomExceptionHandler() {
|
||||
if (mSetUncaughtExceptionHandler) {
|
||||
|
|
|
@ -33,7 +33,6 @@ import android.widget.RadioButton;
|
|||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -327,15 +326,16 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
|||
Arrays.sort(files);
|
||||
|
||||
final boolean includeExternalStoragePath = (sExternalStorageAvailable && isRootPath);
|
||||
int idx = includeExternalStoragePath ? 1 : 0;
|
||||
final String[] fileNames = new String[files.length + idx];
|
||||
final boolean[] isDirectory = new boolean[files.length + idx];
|
||||
final int offset = includeExternalStoragePath ? 1 : 0;
|
||||
final String[] fileNames = new String[files.length + offset];
|
||||
final boolean[] isDirectory = new boolean[files.length + offset];
|
||||
|
||||
if (includeExternalStoragePath) {
|
||||
fileNames[0] = sExternalFilesDir.toString();
|
||||
isDirectory[0] = true;
|
||||
}
|
||||
|
||||
int idx = offset;
|
||||
for (File file : files) {
|
||||
isDirectory[idx] = file.isDirectory();
|
||||
fileNames[idx] = file.getName();
|
||||
|
@ -366,12 +366,47 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
|||
Drawable drawable = mActivity.getResources().getDrawable(android.R.drawable.ic_menu_more);
|
||||
imageView.setImageDrawable(drawable);
|
||||
layout.addView(imageView);
|
||||
} else {
|
||||
|
||||
String imageName = files[position - offset].getAbsolutePath();
|
||||
final int len = imageName.length();
|
||||
final String suffix = imageName.substring(len - 3, len);
|
||||
if (suffix.equalsIgnoreCase(".gz")) {
|
||||
imageName = files[position - offset].getAbsolutePath().substring(0, len - 3);
|
||||
}
|
||||
|
||||
String eject = mActivity.getResources().getString(R.string.disk_eject);
|
||||
if (imageName.equals(Apple2Preferences.CURRENT_DISK_A.stringValue(mActivity))) {
|
||||
Button ejectButton = new Button(mActivity);
|
||||
ejectButton.setText(eject + " 1");
|
||||
ejectButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mActivity.nativeEjectDisk(/*driveA:*/true);
|
||||
Apple2Preferences.CURRENT_DISK_A.saveString(mActivity, "");
|
||||
dynamicSetup();
|
||||
}
|
||||
});
|
||||
layout.addView(ejectButton);
|
||||
} else if (imageName.equals(Apple2Preferences.CURRENT_DISK_B.stringValue(mActivity))) {
|
||||
Button ejectButton = new Button(mActivity);
|
||||
ejectButton.setText(eject + " 2");
|
||||
ejectButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mActivity.nativeEjectDisk(/*driveA:*/false);
|
||||
Apple2Preferences.CURRENT_DISK_B.saveString(mActivity, "");
|
||||
dynamicSetup();
|
||||
}
|
||||
});
|
||||
layout.addView(ejectButton);
|
||||
}
|
||||
|
||||
}
|
||||
return view;
|
||||
}
|
||||
};
|
||||
|
||||
final int offset = includeExternalStoragePath ? 1 : 0;
|
||||
disksList.setAdapter(adapter);
|
||||
disksList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
|
@ -382,56 +417,89 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
|||
dynamicSetup();
|
||||
ListView disksList = (ListView) mDisksView.findViewById(R.id.listView_settings);
|
||||
disksList.postInvalidate();
|
||||
} else {
|
||||
String title = mActivity.getResources().getString(R.string.header_disks);
|
||||
title = title + " " + fileNames[position];
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity).setCancelable(true).setMessage(title);
|
||||
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
final View diskConfirmationView = inflater.inflate(R.layout.a2disk_confirmation, null, false);
|
||||
builder.setView(diskConfirmationView);
|
||||
|
||||
final RadioButton diskA = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_diskA);
|
||||
diskA.setChecked(Apple2Preferences.CURRENT_DISK_A.booleanValue(mActivity));
|
||||
diskA.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Apple2Preferences.CURRENT_DISK_A.saveBoolean(mActivity, isChecked);
|
||||
}
|
||||
});
|
||||
final RadioButton diskB = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_diskB);
|
||||
diskB.setChecked(!Apple2Preferences.CURRENT_DISK_A.booleanValue(mActivity));
|
||||
|
||||
|
||||
final RadioButton readOnly = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_readOnly);
|
||||
readOnly.setChecked(Apple2Preferences.CURRENT_DISK_RO.booleanValue(mActivity));
|
||||
readOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Apple2Preferences.CURRENT_DISK_RO.saveBoolean(mActivity, isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
final RadioButton readWrite = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_readWrite);
|
||||
readWrite.setChecked(!Apple2Preferences.CURRENT_DISK_RO.booleanValue(mActivity));
|
||||
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
mActivity.dismissAllMenus();
|
||||
mActivity.nativeChooseDisk(files[position - offset].getAbsolutePath(), diskA.isChecked(), readOnly.isChecked());
|
||||
}
|
||||
});
|
||||
|
||||
builder.show();
|
||||
return;
|
||||
}
|
||||
|
||||
String str = files[position - offset].getAbsolutePath();
|
||||
final int len = str.length();
|
||||
final String suffix = str.substring(len - 3, len);
|
||||
if (suffix.equalsIgnoreCase(".gz")) {
|
||||
str = files[position - offset].getAbsolutePath().substring(0, len - 3);
|
||||
}
|
||||
final String imageName = str;
|
||||
|
||||
if (imageName.equals(Apple2Preferences.CURRENT_DISK_A.stringValue(mActivity))) {
|
||||
mActivity.nativeEjectDisk(/*driveA:*/true);
|
||||
Apple2Preferences.CURRENT_DISK_A.saveString(mActivity, "");
|
||||
dynamicSetup();
|
||||
return;
|
||||
}
|
||||
if (imageName.equals(Apple2Preferences.CURRENT_DISK_B.stringValue(mActivity))) {
|
||||
mActivity.nativeEjectDisk(/*driveA:*/false);
|
||||
Apple2Preferences.CURRENT_DISK_B.saveString(mActivity, "");
|
||||
dynamicSetup();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
String title = mActivity.getResources().getString(R.string.header_disks);
|
||||
title = title + " " + fileNames[position];
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity).setCancelable(true).setMessage(title);
|
||||
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
final View diskConfirmationView = inflater.inflate(R.layout.a2disk_confirmation, null, false);
|
||||
builder.setView(diskConfirmationView);
|
||||
|
||||
final RadioButton diskA = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_diskA);
|
||||
diskA.setChecked(Apple2Preferences.CURRENT_DRIVE_A_BUTTON.booleanValue(mActivity));
|
||||
diskA.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Apple2Preferences.CURRENT_DRIVE_A_BUTTON.saveBoolean(mActivity, isChecked);
|
||||
}
|
||||
});
|
||||
final RadioButton diskB = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_diskB);
|
||||
diskB.setChecked(!Apple2Preferences.CURRENT_DRIVE_A_BUTTON.booleanValue(mActivity));
|
||||
|
||||
|
||||
final RadioButton readOnly = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_readOnly);
|
||||
readOnly.setChecked(Apple2Preferences.CURRENT_DISK_RO_BUTTON.booleanValue(mActivity));
|
||||
readOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Apple2Preferences.CURRENT_DISK_RO_BUTTON.saveBoolean(mActivity, isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
final RadioButton readWrite = (RadioButton) diskConfirmationView.findViewById(R.id.radioButton_readWrite);
|
||||
readWrite.setChecked(!Apple2Preferences.CURRENT_DISK_RO_BUTTON.booleanValue(mActivity));
|
||||
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
mActivity.dismissAllMenus();
|
||||
boolean isDriveA = diskA.isChecked();
|
||||
boolean diskReadOnly = readOnly.isChecked();
|
||||
if (isDriveA) {
|
||||
Apple2Preferences.CURRENT_DISK_A.saveString(mActivity, imageName);
|
||||
Apple2Preferences.CURRENT_DISK_A_RO.saveBoolean(mActivity, diskReadOnly);
|
||||
} else {
|
||||
Apple2Preferences.CURRENT_DISK_B.saveString(mActivity, imageName);
|
||||
Apple2Preferences.CURRENT_DISK_B_RO.saveBoolean(mActivity, diskReadOnly);
|
||||
}
|
||||
|
||||
mActivity.nativeChooseDisk(imageName, isDriveA, diskReadOnly);
|
||||
}
|
||||
});
|
||||
|
||||
builder.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@ package org.deadc0de.apple2ix;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public enum Apple2Preferences {
|
||||
FIRST_TIME_CONFIGURED {
|
||||
|
@ -47,7 +50,7 @@ public enum Apple2Preferences {
|
|||
//load(activity);
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_A {
|
||||
CURRENT_DRIVE_A_BUTTON {
|
||||
@Override
|
||||
public void load(final Apple2Activity activity) {
|
||||
/* ... */
|
||||
|
@ -64,7 +67,75 @@ public enum Apple2Preferences {
|
|||
//load(activity);
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_RO {
|
||||
CURRENT_DISK_RO_BUTTON {
|
||||
@Override
|
||||
public void load(final Apple2Activity activity) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean booleanValue(Apple2Activity activity) {
|
||||
return activity.getPreferences(Context.MODE_PRIVATE).getBoolean(toString(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBoolean(Apple2Activity activity, boolean value) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(toString(), value).apply();
|
||||
//load(activity);
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_A {
|
||||
@Override
|
||||
public void load(final Apple2Activity activity) {
|
||||
insertDisk(activity, stringValue(activity), /*driveA:*/true, /*readOnly:*/CURRENT_DISK_A_RO.booleanValue(activity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringValue(Apple2Activity activity) {
|
||||
return activity.getPreferences(Context.MODE_PRIVATE).getString(toString(), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveString(Apple2Activity activity, String str) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putString(toString(), str).apply();
|
||||
load(activity);
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_A_RO {
|
||||
@Override
|
||||
public void load(final Apple2Activity activity) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean booleanValue(Apple2Activity activity) {
|
||||
return activity.getPreferences(Context.MODE_PRIVATE).getBoolean(toString(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBoolean(Apple2Activity activity, boolean value) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(toString(), value).apply();
|
||||
//load(activity);
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_B {
|
||||
@Override
|
||||
public void load(final Apple2Activity activity) {
|
||||
insertDisk(activity, stringValue(activity), /*driveA:*/false, /*readOnly:*/CURRENT_DISK_B_RO.booleanValue(activity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringValue(Apple2Activity activity) {
|
||||
return activity.getPreferences(Context.MODE_PRIVATE).getString(toString(), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveString(Apple2Activity activity, String str) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putString(toString(), str).apply();
|
||||
load(activity);
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_B_RO {
|
||||
@Override
|
||||
public void load(final Apple2Activity activity) {
|
||||
/* ... */
|
||||
|
@ -830,6 +901,19 @@ public enum Apple2Preferences {
|
|||
JOYSTICK_SWIPEDOWN_BUTTON.intValue(activity));
|
||||
}
|
||||
|
||||
public static void insertDisk(Apple2Activity activity, String fullPath, boolean isDriveA, boolean isReadOnly) {
|
||||
File file = new File(fullPath);
|
||||
if (!file.exists()) {
|
||||
fullPath = fullPath + ".gz";
|
||||
file = new File(fullPath);
|
||||
}
|
||||
if (file.exists()) {
|
||||
activity.nativeChooseDisk(fullPath, isDriveA, isReadOnly);
|
||||
} else {
|
||||
Log.d(TAG, "Cannot insert: " + fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
// native hooks
|
||||
|
||||
private static native void nativeSetColor(int color);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
<string name="color_interpolated">Interpolated color</string>
|
||||
<string name="diskA">Drive 1</string>
|
||||
<string name="diskB">Drive 2</string>
|
||||
<string name="disk_eject">Eject</string>
|
||||
<string name="disk_read_only">Read only</string>
|
||||
<string name="disk_read_write">Read/write</string>
|
||||
<string name="emulation_continue">Continue…</string>
|
||||
|
|
|
@ -322,6 +322,11 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, job
|
|||
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
||||
}
|
||||
|
||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEjectDisk(JNIEnv *env, jobject obj, jboolean driveA) {
|
||||
LOG("%s", "");
|
||||
c_eject_6(!driveA);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user