Clean up disk selection

This commit is contained in:
Aaron Culliney 2017-07-01 11:21:49 -07:00
parent 7411a987fa
commit 25a0f69a5f
6 changed files with 86 additions and 109 deletions

View File

@ -32,6 +32,7 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
@ -170,7 +171,8 @@ public class Apple2DisksMenu implements Apple2MenuView {
@Override
public Object getPrefDefault() {
return true;
// 2017/06/30 NOTE : keep this default false to accommodate initial installs that only have access to shipped public domain images
return false;
}
};
@ -214,27 +216,43 @@ public class Apple2DisksMenu implements Apple2MenuView {
}
});
{
final Button ejectButton1 = (Button) mDisksView.findViewById(R.id.ejectButton1);
ejectButton1.setOnClickListener(new View.OnClickListener() {
for (int i = 0; i < 2; i++) {
final Button ejectButton = (Button) mDisksView.findViewById(i == 0 ? R.id.ejectButton1 : R.id.ejectButton2);
final int idx = i;
ejectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ejectDisk(/*isDriveA:*/true);
ejectDisk(/*isDriveA:*/idx == 0);
dynamicSetup();
}
});
}
{
final Button ejectButton2 = (Button) mDisksView.findViewById(R.id.ejectButton2);
ejectButton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ejectDisk(/*isDriveA:*/false);
dynamicSetup();
final CheckBox newschoolSelection = (CheckBox) mDisksView.findViewById(R.id.newschoolDiskSelectionButton);
newschoolSelection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Apple2Preferences.setJSONPref(SETTINGS.USE_NEWSCHOOL_DISK_SELECTION, newschoolSelection.isChecked());
dynamicSetup();
}
});
final View newschoolChooser = mDisksView.findViewById(R.id.disk_selection_newschool_chooser);
newschoolChooser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final boolean alreadyChoosing = Apple2DiskChooserActivity.sDiskChooserIsChoosing.getAndSet(true);
if (alreadyChoosing) {
return;
}
});
}
Intent chooserIntent = new Intent(mActivity, Apple2DiskChooserActivity.class);
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION/* | Intent.FLAG_ACTIVITY_CLEAR_TOP */);
Apple2DiskChooserActivity.sDisksCallback = mActivity;
mActivity.startActivity(chooserIntent);
}
});
Apple2Utils.getExternalStorageDirectory(activity);
}
@ -539,44 +557,17 @@ public class Apple2DisksMenu implements Apple2MenuView {
final CheckBox newschoolSelection = (CheckBox) mDisksView.findViewById(R.id.newschoolDiskSelectionButton);
newschoolSelection.setChecked(useNewschoolSelection);
newschoolSelection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Apple2Preferences.setJSONPref(SETTINGS.USE_NEWSCHOOL_DISK_SELECTION, newschoolSelection.isChecked());
dynamicSetup();
}
});
final boolean isKitKatOrBetter = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
final boolean includeExternalFileChooser = Apple2Utils.isExternalStorageAccessible(mActivity) && isKitKatOrBetter;
final View newschoolChooser = mDisksView.findViewById(R.id.disk_selection_newschool_chooser);
newschoolChooser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final boolean alreadyChoosing = Apple2DiskChooserActivity.sDiskChooserIsChoosing.getAndSet(true);
if (alreadyChoosing) {
return;
}
Intent chooserIntent = new Intent(mActivity, Apple2DiskChooserActivity.class);
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION/* | Intent.FLAG_ACTIVITY_CLEAR_TOP */);
Apple2DiskChooserActivity.sDisksCallback = mActivity;
mActivity.startActivity(chooserIntent);
}
});
final Button ejectButton1 = (Button) mDisksView.findViewById(R.id.ejectButton1);
final Button ejectButton2 = (Button) mDisksView.findViewById(R.id.ejectButton2);
if (!includeExternalFileChooser || !useNewschoolSelection) {
disksList.setEnabled(true);
disksList.setVisibility(View.VISIBLE);
newschoolChooser.setVisibility(View.INVISIBLE);
ejectButton1.setVisibility(View.VISIBLE);
ejectButton2.setVisibility(View.VISIBLE);
for (int i = 0; i < 2; i++) {
LinearLayout layout = (LinearLayout) mDisksView.findViewById((i == 0) ? R.id.a2_newschool_driveA_layout : R.id.a2_newschool_driveB_layout);
@ -594,8 +585,6 @@ public class Apple2DisksMenu implements Apple2MenuView {
disksList.setEnabled(false);
disksList.setVisibility(View.INVISIBLE);
newschoolChooser.setVisibility(View.VISIBLE);
ejectButton1.setVisibility(View.INVISIBLE);
ejectButton2.setVisibility(View.INVISIBLE);
// new external file chooser activity can allow navigation to restricted external SD Card(s) ...
newschoolSelection.setVisibility(View.VISIBLE);
@ -625,12 +614,6 @@ public class Apple2DisksMenu implements Apple2MenuView {
LinearLayout layout = (LinearLayout) mDisksView.findViewById((i == 0) ? R.id.a2_newschool_driveA_layout : R.id.a2_newschool_driveB_layout);
LinearLayout widgetLayout = (LinearLayout) mDisksView.findViewById((i == 0) ? R.id.a2_newschool_diskA_widget_frame : R.id.a2_newschool_diskB_widget_frame);
if (widgetLayout.getChildCount() > 0) {
// layout cells appear to be reused when scrolling into view ... make sure we start with clear hierarchy
widgetLayout.removeAllViews();
}
if (imageName == null || imageName.equals("")) {
layout.setVisibility(View.INVISIBLE);
} else {
@ -640,21 +623,7 @@ public class Apple2DisksMenu implements Apple2MenuView {
imageName = "(" + mActivity.getResources().getString((readOnly ? R.string.disk_read_only : R.string.disk_read_write)) + "): " + imageName;
TextView textView = (TextView) mDisksView.findViewById((i == 0) ? R.id.a2_newschool_diskA : R.id.a2_newschool_diskB);
textView.setText(imageName);
String eject = mActivity.getResources().getString(R.string.disk_eject);
Button ejectButton = new Button(mActivity);
ejectButton.setText(eject);
final boolean isDriveA = (i == 0);
ejectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ejectDisk(isDriveA);
dynamicSetup();
}
});
widgetLayout.addView(ejectButton);
}
}
}
@ -826,7 +795,11 @@ public class Apple2DisksMenu implements Apple2MenuView {
if (hasStateExtension(imageName)) {
final String jsonString = "{ \"stateFile\" : \"" + imageName + "\" }";
Apple2MainMenu.restoreEmulatorState(mActivity, jsonString);
final boolean restored = Apple2MainMenu.restoreEmulatorState(mActivity, jsonString);
mActivity.dismissAllMenus();
if (!restored) {
Toast.makeText(mActivity, R.string.state_not_restored, Toast.LENGTH_SHORT).show();
}
return;
}

View File

@ -13,21 +13,33 @@
android:background="@color/black"
android:layout_weight="1">
<!-- disk selection header -->
<LinearLayout
android:id="@+id/disks_selection_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal">
<!-- newschool checkbox -->
<CheckBox
android:id="@+id/newschoolDiskSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/disk_selection_newschoool" />
<!-- spacer that works with API 10 ... -->
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:id="@+id/ejectButton1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_menu_save"
android:drawableStart="@android:drawable/ic_menu_save"
android:text="@string/header_eject_1" />
<Button
@ -35,13 +47,10 @@
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_menu_save"
android:drawableStart="@android:drawable/ic_menu_save"
android:text="@string/header_eject_2" />
<!-- FIXME : spacer, prolly a better way ... -->
<!-- spacer that works with API 10 ... -->
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
@ -56,31 +65,23 @@
</LinearLayout>
<CheckBox
android:id="@+id/newschoolDiskSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/disks_selection_header"
android:layout_alignStart="@id/disks_selection_header"
android:layout_below="@id/disks_selection_header"
android:layout_marginTop="10dip"
android:text="@string/disk_selection_newschoool" />
<!-- oldschool list view -->
<ListView
android:id="@+id/listView_settings"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="@id/disks_selection_header"
android:layout_alignStart="@id/disks_selection_header"
android:layout_below="@id/newschoolDiskSelectionButton"
android:layout_below="@id/disks_selection_header"
android:visibility="invisible"
android:layout_weight="1" />
<!-- newschool file chooser -->
<LinearLayout
android:id="@+id/disk_selection_newschool_chooser"
android:layout_alignLeft="@id/disks_selection_header"
android:layout_alignStart="@id/disks_selection_header"
android:layout_below="@id/newschoolDiskSelectionButton"
android:layout_below="@id/disks_selection_header"
android:layout_marginLeft="5dip"
android:layout_marginStart="5dip"
android:layout_marginRight="5dip"
@ -100,9 +101,8 @@
android:text="@+string/file_chooser"
android:textAppearance="?android:attr/textAppearanceLarge" />
<!-- FIXME : spacer, prolly a better way ... -->
<!-- spacer that works with API 10 ... -->
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
@ -114,6 +114,7 @@
android:layout_height="wrap_content" />
</LinearLayout>
<!-- newschool drive A selection -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/a2_newschool_driveA_layout"
android:layout_width="match_parent"
@ -123,13 +124,17 @@
android:layout_below="@id/disk_selection_newschool_chooser"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize">
android:paddingLeft="0dp"
android:paddingStart="0dp"
android:paddingRight="?android:attr/scrollbarSize"
android:paddingEnd="?android:attr/scrollbarSize">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginRight="5dip"
android:layout_marginEnd="5dip"
android:layout_marginTop="5dip"
android:layout_weight="1">
@ -151,22 +156,13 @@
android:layout_alignStart="@id/a2_newschool_driveA"
android:layout_below="@id/a2_newschool_driveA"
android:maxLines="4"
android:text="someLongSelectedDiskName.dsk.gz"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
<!-- Custom preference should place its actual preference widget here. -->
<LinearLayout
android:id="@+id/a2_newschool_diskA_widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
<!-- newschool drive B selection -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/a2_newschool_driveB_layout"
android:layout_width="match_parent"
@ -176,7 +172,10 @@
android:layout_below="@id/a2_newschool_driveA_layout"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="?android:attr/scrollbarSize">
android:paddingLeft="0dp"
android:paddingStart="0dp"
android:paddingRight="?android:attr/scrollbarSize"
android:paddingEnd="?android:attr/scrollbarSize">
<RelativeLayout
android:layout_width="wrap_content"
@ -204,20 +203,10 @@
android:layout_alignStart="@id/a2_newschool_driveB"
android:layout_below="@id/a2_newschool_driveB"
android:maxLines="4"
android:text="someLongSelectedDiskName.dsk.gz"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
<!-- Custom preference should place its actual preference widget here. -->
<LinearLayout
android:id="@+id/a2_newschool_diskB_widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
</RelativeLayout>

View File

@ -32,13 +32,18 @@
<string name="diskA">Laufwerk 1</string>
<string name="diskB">Laufwerk 2</string>
<string name="disk_eject">Auswerfen</string>
<string name="disk_insert_toast_cannot">Cannot insert (not a disk image or state file)</string>
<string name="disk_read_only">Schreibgeschützt</string>
<string name="disk_read_write">Lesen/Schreiben</string>
<string name="disk_selection_newschoool">System chooser</string>
<string name="disk_show_operation">Zeige Disk ][ Aktivität</string>
<string name="disk_show_operation_summary">Zeigt wenn die Laufwerke lesen oder schreiben</string>
<string name="emulation_continue">Fortsetzen…</string>
<string name="emulation_disks">Lade Disk-Image…</string>
<string name="file_chooser">Choose disk image or state file…</string>
<string name="header_disks">Diskette einlegen:</string>
<string name="header_eject_1">Auswerfen 1</string>
<string name="header_eject_2">Auswerfen 2</string>
<string name="input_current">Aktuelles Touch Device</string>
<string name="input_current_summary">Wähle ein aktuelles Touch Device</string>
<string name="joystick">Joystick</string>

View File

@ -32,13 +32,18 @@
<string name="diskA">Disquetera 1</string>
<string name="diskB">Disquetera 2</string>
<string name="disk_eject">Eyectar</string>
<string name="disk_insert_toast_cannot">Cannot insert (not a disk image or state file)</string>
<string name="disk_read_only">Sólo leer</string>
<string name="disk_read_write">Leer y escribir</string>
<string name="disk_selection_newschoool">System chooser</string>
<string name="disk_show_operation">Mostrar las operaciones de "Disk ]["</string>
<string name="disk_show_operation_summary">Shows when disk drives are reading or writing</string>
<string name="emulation_continue">Continuar…</string>
<string name="emulation_disks">Insertar imagen de disquete…</string>
<string name="file_chooser">Choose disk image or state file…</string>
<string name="header_disks">Insertar imagen de disquete:</string>
<string name="header_eject_1">Eyectar 1</string>
<string name="header_eject_2">Eyectar 2</string>
<string name="input_current">Unidad de entrada actual</string>
<string name="input_current_summary">Elija unidad de entrada</string>
<string name="joystick">"Joystick"</string>

View File

@ -32,13 +32,18 @@
<string name="diskA">Lecteur 1</string>
<string name="diskB">Lecteur 2</string>
<string name="disk_eject">Ejecter</string>
<string name="disk_insert_toast_cannot">Cannot insert (not a disk image or state file)</string>
<string name="disk_selection_newschoool">System chooser</string>
<string name="disk_read_only">Lecture seulement</string>
<string name="disk_read_write">Lecture/Ecriture</string>
<string name="disk_show_operation">Afficher les opérations (disque) ][</string>
<string name="disk_show_operation_summary">Indique si les disques sont en lecture ou en écriture</string>
<string name="emulation_continue">Continuer…</string>
<string name="emulation_disks">Chargement de l\'image disque…</string>
<string name="file_chooser">Choose disk image or state file…</string>
<string name="header_disks">Insérer la disquettte :</string>
<string name="header_eject_1">Ejecter 1</string>
<string name="header_eject_2">Ejecter 2</string>
<string name="input_current">Tactile</string>
<string name="input_current_summary">Choisir l\'appareil courant</string>
<string name="joystick">Joystick</string>

View File

@ -39,12 +39,12 @@
<string name="disk_insert_toast_cannot">Cannot insert (not a disk image or state file)</string>
<string name="disk_read_only">Read only</string>
<string name="disk_read_write">Read/write</string>
<string name="disk_selection_newschoool">Use system file chooser</string>
<string name="disk_selection_newschoool">System chooser</string>
<string name="disk_show_operation">Show Disk ][ operations</string>
<string name="disk_show_operation_summary">Shows when disk drives are reading or writing</string>
<string name="emulation_continue">Continue…</string>
<string name="emulation_disks">Load disk image</string>
<string name="file_chooser">Choose disk…</string>
<string name="file_chooser">Choose disk image or state file</string>
<string name="header_disks">Insert disk:</string>
<string name="header_eject_1">Eject 1</string>
<string name="header_eject_2">Eject 2</string>