mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-06-28 13:29:29 +00:00
Refactor common menu GUI code into abstract base class
This commit is contained in:
parent
f2ac41e011
commit
acfb60634e
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* 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;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public abstract class Apple2AbstractMenu implements Apple2MenuView {
|
||||
|
||||
private final static String TAG = "Apple2AbstractMenu";
|
||||
|
||||
protected Apple2Activity mActivity = null;
|
||||
private View mSettingsView = null;
|
||||
|
||||
public Apple2AbstractMenu(Apple2Activity activity) {
|
||||
mActivity = activity;
|
||||
setup();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (isShowing()) {
|
||||
return;
|
||||
}
|
||||
mActivity.pushApple2View(this);
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mActivity.popApple2View(this);
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mSettingsView.isShown();
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mSettingsView;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// required overrides ...
|
||||
|
||||
public interface IMenuEnum {
|
||||
public String getTitle(final Apple2Activity activity);
|
||||
|
||||
public String getSummary(final Apple2Activity activity);
|
||||
|
||||
public View getView(final Apple2Activity activity, View convertView);
|
||||
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked);
|
||||
}
|
||||
|
||||
public abstract IMenuEnum[] allValues();
|
||||
|
||||
public abstract String[] allTitles();
|
||||
|
||||
public abstract boolean areAllItemsEnabled();
|
||||
|
||||
public abstract boolean isEnabled(int position);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// boilerplate menu view code
|
||||
|
||||
protected static View _basicView(Apple2Activity activity, IMenuEnum setting, View convertView) {
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_title);
|
||||
if (tv == null) {
|
||||
// attemping to recycle different layout ...
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.a2preference, null, false);
|
||||
tv = (TextView) convertView.findViewById(R.id.a2preference_title);
|
||||
}
|
||||
tv.setText(setting.getTitle(activity));
|
||||
|
||||
tv = (TextView) convertView.findViewById(R.id.a2preference_summary);
|
||||
tv.setText(setting.getSummary(activity));
|
||||
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
if (layout.getChildCount() > 0) {
|
||||
// layout cells appear to be reused when scrolling into view ... make sure we start with clear hierarchy
|
||||
layout.removeAllViews();
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public interface IPreferenceLoadSave {
|
||||
public int intValue();
|
||||
public void saveInt(int value);
|
||||
}
|
||||
|
||||
protected static View _sliderView(final Apple2Activity activity, final IMenuEnum setting, final int numChoices, final boolean showFloatValue, final IPreferenceLoadSave iLoadSave) {
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View view = inflater.inflate(R.layout.a2preference_slider, null, false);
|
||||
|
||||
TextView tv = (TextView) view.findViewById(R.id.a2preference_slider_summary);
|
||||
tv.setText(setting.getSummary(activity));
|
||||
|
||||
final TextView seekBarValue = (TextView) view.findViewById(R.id.a2preference_slider_seekBarValue);
|
||||
|
||||
SeekBar sb = (SeekBar) view.findViewById(R.id.a2preference_slider_seekBar);
|
||||
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (!fromUser) {
|
||||
return;
|
||||
}
|
||||
if (showFloatValue) {
|
||||
seekBarValue.setText("" + ((float) progress / numChoices));
|
||||
} else {
|
||||
seekBarValue.setText("" + progress);
|
||||
}
|
||||
iLoadSave.saveInt(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
|
||||
sb.setMax(0); // http://stackoverflow.com/questions/10278467/seekbar-not-setting-actual-progress-setprogress-not-working-on-early-android
|
||||
sb.setMax(numChoices);
|
||||
int progress = iLoadSave.intValue();
|
||||
sb.setProgress(progress);
|
||||
if (showFloatValue) {
|
||||
seekBarValue.setText("" + ((float) progress / numChoices));
|
||||
} else {
|
||||
seekBarValue.setText("" + progress);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
protected static void _alertDialogHandleSelection(final Apple2Activity activity, final String[] choices, final IPreferenceLoadSave iLoadSave) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.input_current);
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
final int checkedPosition = iLoadSave.intValue();
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.select_dialog_singlechoice, choices) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = super.getView(position, convertView, parent);
|
||||
CheckedTextView ctv = (CheckedTextView) view.findViewById(android.R.id.text1);
|
||||
ctv.setChecked(position == checkedPosition);
|
||||
return view;
|
||||
}
|
||||
};
|
||||
|
||||
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int value) {
|
||||
iLoadSave.saveInt(value);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
protected static ImageView _addPopupIcon(Apple2Activity activity, IMenuEnum setting, View convertView) {
|
||||
ImageView imageView = new ImageView(activity);
|
||||
Drawable drawable = activity.getResources().getDrawable(android.R.drawable.ic_menu_edit);
|
||||
imageView.setImageDrawable(drawable);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(imageView);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
protected static CheckBox _addCheckbox(Apple2Activity activity, IMenuEnum setting, View convertView, boolean isChecked) {
|
||||
CheckBox checkBox = new CheckBox(activity);
|
||||
checkBox.setChecked(isChecked);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(checkBox);
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mSettingsView = inflater.inflate(R.layout.activity_settings, null, false);
|
||||
|
||||
ListView settingsList = (ListView) mSettingsView.findViewById(R.id.listView_settings);
|
||||
settingsList.setEnabled(true);
|
||||
|
||||
ArrayAdapter<?> adapter = new ArrayAdapter<String>(mActivity, R.layout.a2preference, R.id.a2preference_title, allTitles()) {
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return Apple2AbstractMenu.this.areAllItemsEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return Apple2AbstractMenu.this.isEnabled(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
//View view = super.getView(position, convertView, parent);
|
||||
// ^^^ WHOA ... this is catching an NPE deep in AOSP code on the second time loading ... WTF?
|
||||
// Methinks it is related to the hack of loading a completely different R.layout.something for certain views...
|
||||
View view = convertView != null ? convertView : super.getView(position, null, parent);
|
||||
IMenuEnum setting = allValues()[position];
|
||||
return setting.getView(mActivity, view);
|
||||
}
|
||||
};
|
||||
|
||||
settingsList.setAdapter(adapter);
|
||||
settingsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
IMenuEnum setting = allValues()[position];
|
||||
LinearLayout layout = (LinearLayout) view.findViewById(R.id.a2preference_widget_frame);
|
||||
if (layout == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
View childView = layout.getChildAt(0);
|
||||
boolean selected = false;
|
||||
if (childView != null && childView instanceof CheckBox) {
|
||||
CheckBox checkBox = (CheckBox) childView;
|
||||
checkBox.setChecked(!checkBox.isChecked());
|
||||
selected = checkBox.isChecked();
|
||||
}
|
||||
setting.handleSelection(mActivity, Apple2AbstractMenu.this, selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -11,34 +11,42 @@
|
|||
|
||||
package org.deadc0de.apple2ix;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Apple2AudioSettingsMenu implements Apple2MenuView {
|
||||
public class Apple2AudioSettingsMenu extends Apple2AbstractMenu {
|
||||
|
||||
private final static String TAG = "Apple2AudioSettingsMenu";
|
||||
|
||||
private Apple2Activity mActivity = null;
|
||||
private View mSettingsView = null;
|
||||
|
||||
public Apple2AudioSettingsMenu(Apple2Activity activity) {
|
||||
mActivity = activity;
|
||||
setup();
|
||||
super(activity);
|
||||
}
|
||||
|
||||
enum SETTINGS {
|
||||
@Override
|
||||
public final String[] allTitles() {
|
||||
return SETTINGS.titles(mActivity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IMenuEnum[] allValues() {
|
||||
return SETTINGS.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean areAllItemsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isEnabled(int position) {
|
||||
if (position < 0 || position >= SETTINGS.size) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
return position == SETTINGS.MOCKINGBOARD_ENABLED.ordinal();
|
||||
}
|
||||
|
||||
enum SETTINGS implements Apple2AbstractMenu.IMenuEnum {
|
||||
SPEAKER_ENABLED {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
|
@ -71,40 +79,16 @@ public class Apple2AudioSettingsMenu implements Apple2MenuView {
|
|||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.a2preference_slider, null, false);
|
||||
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_slider_summary);
|
||||
tv.setText(getSummary(activity));
|
||||
|
||||
final TextView seekBarValue = (TextView) convertView.findViewById(R.id.a2preference_slider_seekBarValue);
|
||||
|
||||
SeekBar sb = (SeekBar) convertView.findViewById(R.id.a2preference_slider_seekBar);
|
||||
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
return _sliderView(activity, this, Apple2Preferences.Volume.MAX.ordinal() - 1, /*showFloatValue:*/false, new IPreferenceLoadSave() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (!fromUser) {
|
||||
return;
|
||||
}
|
||||
seekBarValue.setText("" + progress);
|
||||
public void saveInt(int progress) {
|
||||
Apple2Preferences.SPEAKER_VOLUME.saveVolume(activity, Apple2Preferences.Volume.values()[progress]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
public int intValue() {
|
||||
return Apple2Preferences.SPEAKER_VOLUME.intValue(activity);
|
||||
}
|
||||
});
|
||||
|
||||
sb.setMax(0); // http://stackoverflow.com/questions/10278467/seekbar-not-setting-actual-progress-setprogress-not-working-on-early-android
|
||||
sb.setMax(Apple2Preferences.Volume.MAX.ordinal() - 1);
|
||||
int vol = Apple2Preferences.SPEAKER_VOLUME.intValue(activity);
|
||||
sb.setProgress(vol);
|
||||
seekBarValue.setText("" + vol);
|
||||
return convertView;
|
||||
}
|
||||
},
|
||||
MOCKINGBOARD_ENABLED {
|
||||
|
@ -144,40 +128,16 @@ public class Apple2AudioSettingsMenu implements Apple2MenuView {
|
|||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.a2preference_slider, null, false);
|
||||
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_slider_summary);
|
||||
tv.setText(getSummary(activity));
|
||||
|
||||
final TextView seekBarValue = (TextView) convertView.findViewById(R.id.a2preference_slider_seekBarValue);
|
||||
|
||||
SeekBar sb = (SeekBar) convertView.findViewById(R.id.a2preference_slider_seekBar);
|
||||
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
return _sliderView(activity, this, Apple2Preferences.Volume.MAX.ordinal() - 1, /*showFloatValue:*/false, new IPreferenceLoadSave() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (!fromUser) {
|
||||
return;
|
||||
}
|
||||
seekBarValue.setText("" + progress);
|
||||
public void saveInt(int progress) {
|
||||
Apple2Preferences.MOCKINGBOARD_VOLUME.saveVolume(activity, Apple2Preferences.Volume.values()[progress]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
public int intValue() {
|
||||
return Apple2Preferences.MOCKINGBOARD_VOLUME.intValue(activity);
|
||||
}
|
||||
});
|
||||
|
||||
sb.setMax(0); // http://stackoverflow.com/questions/10278467/seekbar-not-setting-actual-progress-setprogress-not-working-on-early-android
|
||||
sb.setMax(Apple2Preferences.Volume.MAX.ordinal() - 1);
|
||||
int vol = Apple2Preferences.MOCKINGBOARD_VOLUME.intValue(activity);
|
||||
sb.setProgress(vol);
|
||||
seekBarValue.setText("" + vol);
|
||||
return convertView;
|
||||
}
|
||||
},
|
||||
ADVANCED_SEPARATOR {
|
||||
|
@ -204,93 +164,31 @@ public class Apple2AudioSettingsMenu implements Apple2MenuView {
|
|||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.a2preference_slider, null, false);
|
||||
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_slider_summary);
|
||||
tv.setText(getSummary(activity));
|
||||
|
||||
final TextView seekBarValue = (TextView) convertView.findViewById(R.id.a2preference_slider_seekBarValue);
|
||||
|
||||
final SeekBar sb = (SeekBar) convertView.findViewById(R.id.a2preference_slider_seekBar);
|
||||
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
return _sliderView(activity, this, Apple2Preferences.AUDIO_LATENCY_NUM_CHOICES, /*showFloatValue:*/true, new IPreferenceLoadSave() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (!fromUser) {
|
||||
return;
|
||||
}
|
||||
if (progress <= 0) {
|
||||
// buffer size cannot be zero
|
||||
public void saveInt(int progress) {
|
||||
if (progress == 0) {
|
||||
// disallow 0-length buffer ...
|
||||
progress = 1;
|
||||
sb.setProgress(progress);
|
||||
}
|
||||
float latencySecs = (float) progress / Apple2Preferences.AUDIO_LATENCY_NUM_CHOICES;
|
||||
seekBarValue.setText("" + latencySecs);
|
||||
Apple2Preferences.AUDIO_LATENCY.saveFloat(activity, latencySecs);
|
||||
Apple2Preferences.AUDIO_LATENCY.saveInt(activity, progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
public int intValue() {
|
||||
return Apple2Preferences.AUDIO_LATENCY.intValue(activity);
|
||||
}
|
||||
});
|
||||
|
||||
sb.setMax(0); // http://stackoverflow.com/questions/10278467/seekbar-not-setting-actual-progress-setprogress-not-working-on-early-android
|
||||
sb.setMax(Apple2Preferences.AUDIO_LATENCY_NUM_CHOICES);
|
||||
float latencySecs = Apple2Preferences.AUDIO_LATENCY.floatValue(activity);
|
||||
seekBarValue.setText("" + latencySecs);
|
||||
int tick = (int) (latencySecs * (float) Apple2Preferences.AUDIO_LATENCY_NUM_CHOICES);
|
||||
sb.setProgress(tick);
|
||||
return convertView;
|
||||
}
|
||||
};
|
||||
|
||||
private static View _basicView(Apple2Activity activity, SETTINGS setting, View convertView) {
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_title);
|
||||
tv.setText(setting.getTitle(activity));
|
||||
|
||||
tv = (TextView) convertView.findViewById(R.id.a2preference_summary);
|
||||
tv.setText(setting.getSummary(activity));
|
||||
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
if (layout.getChildCount() > 0) {
|
||||
// layout cells appear to be reused when scrolling into view ... make sure we start with clear hierarchy
|
||||
layout.removeAllViews();
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private static ImageView _addPopupIcon(Apple2Activity activity, SETTINGS setting, View convertView) {
|
||||
ImageView imageView = new ImageView(activity);
|
||||
Drawable drawable = activity.getResources().getDrawable(android.R.drawable.ic_menu_edit);
|
||||
imageView.setImageDrawable(drawable);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(imageView);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
private static CheckBox _addCheckbox(Apple2Activity activity, SETTINGS setting, View convertView, boolean isChecked) {
|
||||
CheckBox checkBox = new CheckBox(activity);
|
||||
checkBox.setChecked(isChecked);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(checkBox);
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
public static final int size = SETTINGS.values().length;
|
||||
|
||||
public abstract String getTitle(Apple2Activity activity);
|
||||
|
||||
public abstract String getSummary(Apple2Activity activity);
|
||||
|
||||
public void handleSelection(Apple2AudioSettingsMenu settingsMenu, boolean isChecked) {
|
||||
@Override
|
||||
public void handleSelection(Apple2Activity activity, Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(Apple2Activity activity, View convertView) {
|
||||
return _basicView(activity, this, convertView);
|
||||
}
|
||||
|
@ -304,81 +202,4 @@ public class Apple2AudioSettingsMenu implements Apple2MenuView {
|
|||
return titles;
|
||||
}
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mSettingsView = inflater.inflate(R.layout.activity_settings, null, false);
|
||||
|
||||
TextView title = (TextView) mSettingsView.findViewById(R.id.header_settings);
|
||||
title.setText(R.string.settings_audio);
|
||||
|
||||
ListView settingsList = (ListView) mSettingsView.findViewById(R.id.listView_settings);
|
||||
settingsList.setEnabled(true);
|
||||
|
||||
// This is a bit of a hack ... we're not using the ArrayAdapter as intended here, simply piggy-backing off its call to getView() to supply a completely custom view. The arguably better way would be to create a custom Apple2SettingsAdapter or something akin to that...
|
||||
ArrayAdapter<?> adapter = new ArrayAdapter<String>(mActivity, R.layout.a2preference, R.id.a2preference_title, SETTINGS.titles(mActivity)) {
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
if (position < 0 || position >= SETTINGS.size) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
return position == SETTINGS.MOCKINGBOARD_ENABLED.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
//View view = super.getView(position, convertView, parent);
|
||||
// ^^^ WHOA ... this is catching an NPE deep in AOSP code on the second time loading the audio menu, WTF?
|
||||
// Methinks it is related to the hack of loading a completely different R.layout.something for certain views...
|
||||
View view = convertView != null ? convertView : super.getView(position, null, parent);
|
||||
SETTINGS setting = SETTINGS.values()[position];
|
||||
return setting.getView(mActivity, view);
|
||||
}
|
||||
};
|
||||
|
||||
settingsList.setAdapter(adapter);
|
||||
settingsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
SETTINGS setting = SETTINGS.values()[position];
|
||||
LinearLayout layout = (LinearLayout) view.findViewById(R.id.a2preference_widget_frame);
|
||||
if (layout == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
View childView = layout.getChildAt(0);
|
||||
boolean selected = false;
|
||||
if (childView != null && childView instanceof CheckBox) {
|
||||
CheckBox checkBox = (CheckBox) childView;
|
||||
checkBox.setChecked(!checkBox.isChecked());
|
||||
selected = checkBox.isChecked();
|
||||
}
|
||||
setting.handleSelection(Apple2AudioSettingsMenu.this, selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (isShowing()) {
|
||||
return;
|
||||
}
|
||||
mActivity.pushApple2View(this);
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mActivity.popApple2View(this);
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mSettingsView.isShown();
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mSettingsView;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,338 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Apple2InputSettingsMenu implements Apple2MenuView {
|
||||
|
||||
private final static String TAG = "Apple2InputSettingsMenu";
|
||||
|
||||
private Apple2Activity mActivity = null;
|
||||
private View mSettingsView = null;
|
||||
|
||||
public Apple2InputSettingsMenu(Apple2Activity activity) {
|
||||
mActivity = activity;
|
||||
setup();
|
||||
}
|
||||
|
||||
enum SETTINGS {
|
||||
KEYBOARD_CONFIGURE {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.keyboard_configure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.keyboard_configure_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2InputSettingsMenu settingsMenu, boolean isChecked) {
|
||||
//new Apple2KeyboardSettingsMenu().show();
|
||||
}
|
||||
},
|
||||
JOYSTICK_CONFIGURE {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.joystick_configure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.joystick_configure_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2InputSettingsMenu settingsMenu, boolean isChecked) {
|
||||
//new Apple2JoystickSettingsMenu().show();
|
||||
}
|
||||
},
|
||||
TOUCH_MENU_ENABLED {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.touch_menu_enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.touch_menu_enable_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
convertView = _basicView(activity, this, convertView);
|
||||
CheckBox cb = _addCheckbox(activity, this, convertView, Apple2Preferences.TOUCH_MENU_ENABLED.booleanValue(activity));
|
||||
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Apple2Preferences.TOUCH_MENU_ENABLED.saveBoolean(activity, isChecked);
|
||||
}
|
||||
});
|
||||
return convertView;
|
||||
}
|
||||
},
|
||||
TOUCH_MENU_VISIBILITY {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.touch_menu_visibility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.touch_menu_visibility_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.a2preference_slider, null, false);
|
||||
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_slider_summary);
|
||||
tv.setText(getSummary(activity));
|
||||
|
||||
final TextView seekBarValue = (TextView) convertView.findViewById(R.id.a2preference_slider_seekBarValue);
|
||||
|
||||
SeekBar sb = (SeekBar) convertView.findViewById(R.id.a2preference_slider_seekBar);
|
||||
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (!fromUser) {
|
||||
return;
|
||||
}
|
||||
float alpha = (float) progress / Apple2Preferences.ALPHA_SLIDER_NUM_CHOICES;
|
||||
seekBarValue.setText("" + alpha);
|
||||
Apple2Preferences.TOUCH_MENU_VISIBILITY.saveInt(activity, progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
|
||||
sb.setMax(0); // http://stackoverflow.com/questions/10278467/seekbar-not-setting-actual-progress-setprogress-not-working-on-early-android
|
||||
sb.setMax(Apple2Preferences.ALPHA_SLIDER_NUM_CHOICES);
|
||||
int progress = Apple2Preferences.TOUCH_MENU_VISIBILITY.intValue(activity);
|
||||
sb.setProgress(progress);
|
||||
seekBarValue.setText("" + ((float) progress / Apple2Preferences.ALPHA_SLIDER_NUM_CHOICES));
|
||||
return convertView;
|
||||
}
|
||||
},
|
||||
CURRENT_INPUT {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.input_current);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.input_current_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
convertView = _basicView(activity, this, convertView);
|
||||
_addPopupIcon(activity, this, convertView);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2InputSettingsMenu settingsMenu, boolean isChecked) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.input_current);
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
String[] touch_choices = new String[]{
|
||||
activity.getResources().getString(R.string.joystick),
|
||||
activity.getResources().getString(R.string.keyboard),
|
||||
};
|
||||
final int checkedPosition = Apple2Preferences.CURRENT_TOUCH_DEVICE.intValue(activity) - 1;
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.select_dialog_singlechoice, touch_choices) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = super.getView(position, convertView, parent);
|
||||
CheckedTextView ctv = (CheckedTextView) view.findViewById(android.R.id.text1);
|
||||
ctv.setChecked(position == checkedPosition);
|
||||
return view;
|
||||
}
|
||||
};
|
||||
|
||||
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int color) {
|
||||
Apple2Preferences.CURRENT_TOUCH_DEVICE.saveTouchDevice(activity, Apple2Preferences.TouchDevice.values()[color + 1]);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
};
|
||||
|
||||
private static View _basicView(Apple2Activity activity, SETTINGS setting, View convertView) {
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_title);
|
||||
tv.setText(setting.getTitle(activity));
|
||||
|
||||
tv = (TextView) convertView.findViewById(R.id.a2preference_summary);
|
||||
tv.setText(setting.getSummary(activity));
|
||||
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
if (layout.getChildCount() > 0) {
|
||||
// layout cells appear to be reused when scrolling into view ... make sure we start with clear hierarchy
|
||||
layout.removeAllViews();
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private static ImageView _addPopupIcon(Apple2Activity activity, SETTINGS setting, View convertView) {
|
||||
ImageView imageView = new ImageView(activity);
|
||||
Drawable drawable = activity.getResources().getDrawable(android.R.drawable.ic_menu_edit);
|
||||
imageView.setImageDrawable(drawable);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(imageView);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
private static CheckBox _addCheckbox(Apple2Activity activity, SETTINGS setting, View convertView, boolean isChecked) {
|
||||
CheckBox checkBox = new CheckBox(activity);
|
||||
checkBox.setChecked(isChecked);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(checkBox);
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
public static final int size = SETTINGS.values().length;
|
||||
|
||||
public abstract String getTitle(Apple2Activity activity);
|
||||
|
||||
public abstract String getSummary(Apple2Activity activity);
|
||||
|
||||
public void handleSelection(Apple2Activity activity, Apple2InputSettingsMenu settingsMenu, boolean isChecked) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
public View getView(Apple2Activity activity, View convertView) {
|
||||
return _basicView(activity, this, convertView);
|
||||
}
|
||||
|
||||
public static String[] titles(Apple2Activity activity) {
|
||||
String[] titles = new String[size];
|
||||
int i = 0;
|
||||
for (SETTINGS setting : values()) {
|
||||
titles[i++] = setting.getTitle(activity);
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mSettingsView = inflater.inflate(R.layout.activity_settings, null, false);
|
||||
|
||||
TextView title = (TextView) mSettingsView.findViewById(R.id.header_settings);
|
||||
title.setText(R.string.settings_audio);
|
||||
|
||||
ListView settingsList = (ListView) mSettingsView.findViewById(R.id.listView_settings);
|
||||
settingsList.setEnabled(true);
|
||||
|
||||
// This is a bit of a hack ... we're not using the ArrayAdapter as intended here, simply piggy-backing off its call to getView() to supply a completely custom view. The arguably better way would be to create a custom Apple2SettingsAdapter or something akin to that...
|
||||
ArrayAdapter<?> adapter = new ArrayAdapter<String>(mActivity, R.layout.a2preference, R.id.a2preference_title, SETTINGS.titles(mActivity)) {
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
if (position < 0 || position >= SETTINGS.size) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
//View view = super.getView(position, convertView, parent);
|
||||
// ^^^ WHOA ... this is catching an NPE deep in AOSP code on the second time loading the audio menu, WTF?
|
||||
// Methinks it is related to the hack of loading a completely different R.layout.something for certain views...
|
||||
View view = convertView != null ? convertView : super.getView(position, null, parent);
|
||||
SETTINGS setting = SETTINGS.values()[position];
|
||||
return setting.getView(mActivity, view);
|
||||
}
|
||||
};
|
||||
|
||||
settingsList.setAdapter(adapter);
|
||||
settingsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
SETTINGS setting = SETTINGS.values()[position];
|
||||
LinearLayout layout = (LinearLayout) view.findViewById(R.id.a2preference_widget_frame);
|
||||
if (layout == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
View childView = layout.getChildAt(0);
|
||||
boolean selected = false;
|
||||
if (childView != null && childView instanceof CheckBox) {
|
||||
CheckBox checkBox = (CheckBox) childView;
|
||||
checkBox.setChecked(!checkBox.isChecked());
|
||||
selected = checkBox.isChecked();
|
||||
}
|
||||
setting.handleSelection(mActivity, Apple2InputSettingsMenu.this, selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (isShowing()) {
|
||||
return;
|
||||
}
|
||||
mActivity.pushApple2View(this);
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mActivity.popApple2View(this);
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mSettingsView.isShown();
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mSettingsView;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ package org.deadc0de.apple2ix;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.util.Log;
|
||||
|
||||
public enum Apple2Preferences {
|
||||
PREFS_CONFIGURED {
|
||||
|
@ -102,25 +101,24 @@ public enum Apple2Preferences {
|
|||
AUDIO_LATENCY {
|
||||
@Override
|
||||
public void load(Apple2Activity activity) {
|
||||
nativeSetAudioLatency(floatValue(activity));
|
||||
int tick = intValue(activity);
|
||||
nativeSetAudioLatency(((float) tick / AUDIO_LATENCY_NUM_CHOICES));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue(Apple2Activity activity) {
|
||||
public int intValue(Apple2Activity activity) {
|
||||
|
||||
float defaultLatency = 0.f;
|
||||
if (defaultLatency == 0.f) {
|
||||
int sampleRateCanary = DevicePropertyCalculator.getRecommendedSampleRate(activity);
|
||||
if (sampleRateCanary == DevicePropertyCalculator.defaultSampleRate) {
|
||||
// quite possibly an audio-challenged device
|
||||
defaultLatency = 0.4f;
|
||||
} else {
|
||||
// reasonable default for high-end devices
|
||||
defaultLatency = 0.25f;
|
||||
}
|
||||
int defaultLatency = 0;
|
||||
int sampleRateCanary = DevicePropertyCalculator.getRecommendedSampleRate(activity);
|
||||
if (sampleRateCanary == DevicePropertyCalculator.defaultSampleRate) {
|
||||
// quite possibly an audio-challenged device
|
||||
defaultLatency = 8; // /AUDIO_LATENCY_NUM_CHOICES -> 0.4f
|
||||
} else {
|
||||
// reasonable default for high-end devices
|
||||
defaultLatency = 5; // /AUDIO_LATENCY_NUM_CHOICES -> 0.25f
|
||||
}
|
||||
|
||||
return activity.getPreferences(Context.MODE_PRIVATE).getFloat(toString(), defaultLatency);
|
||||
return activity.getPreferences(Context.MODE_PRIVATE).getInt(toString(), defaultLatency);
|
||||
}
|
||||
},
|
||||
CURRENT_TOUCH_DEVICE {
|
||||
|
@ -226,11 +224,6 @@ public enum Apple2Preferences {
|
|||
load(activity);
|
||||
}
|
||||
|
||||
public void saveFloat(Apple2Activity activity, float value) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putFloat(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);
|
||||
|
@ -256,10 +249,6 @@ public enum Apple2Preferences {
|
|||
return activity.getPreferences(Context.MODE_PRIVATE).getInt(toString(), 0);
|
||||
}
|
||||
|
||||
public float floatValue(Apple2Activity activity) {
|
||||
return activity.getPreferences(Context.MODE_PRIVATE).getFloat(toString(), 0.0f);
|
||||
}
|
||||
|
||||
public static void loadPreferences(Apple2Activity activity) {
|
||||
for (Apple2Preferences pref : Apple2Preferences.values()) {
|
||||
pref.load(activity);
|
||||
|
|
|
@ -12,51 +12,160 @@
|
|||
package org.deadc0de.apple2ix;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
public class Apple2SettingsMenu implements Apple2MenuView {
|
||||
public class Apple2SettingsMenu extends Apple2AbstractMenu {
|
||||
|
||||
private final static String TAG = "Apple2SettingsMenu";
|
||||
|
||||
private Apple2Activity mActivity = null;
|
||||
private View mSettingsView = null;
|
||||
|
||||
public Apple2SettingsMenu(Apple2Activity activity) {
|
||||
mActivity = activity;
|
||||
setup();
|
||||
super(activity);
|
||||
}
|
||||
|
||||
enum SETTINGS {
|
||||
INPUT_CONFIGURE {
|
||||
@Override
|
||||
public final String[] allTitles() {
|
||||
return SETTINGS.titles(mActivity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IMenuEnum[] allValues() {
|
||||
return SETTINGS.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean areAllItemsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isEnabled(int position) {
|
||||
if (position < 0 || position >= SETTINGS.size) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
enum SETTINGS implements Apple2AbstractMenu.IMenuEnum {
|
||||
TOUCH_MENU_ENABLED {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.input_configure);
|
||||
return activity.getResources().getString(R.string.touch_menu_enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.input_configure_summary);
|
||||
return activity.getResources().getString(R.string.touch_menu_enable_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(Apple2Activity activity, Apple2SettingsMenu settingsMenu, boolean isChecked) {
|
||||
new Apple2InputSettingsMenu(activity).show();
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
convertView = _basicView(activity, this, convertView);
|
||||
CheckBox cb = _addCheckbox(activity, this, convertView, Apple2Preferences.TOUCH_MENU_ENABLED.booleanValue(activity));
|
||||
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Apple2Preferences.TOUCH_MENU_ENABLED.saveBoolean(activity, isChecked);
|
||||
}
|
||||
});
|
||||
return convertView;
|
||||
}
|
||||
},
|
||||
TOUCH_MENU_VISIBILITY {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.touch_menu_visibility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.touch_menu_visibility_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
return _sliderView(activity, this, Apple2Preferences.ALPHA_SLIDER_NUM_CHOICES, /*showFloatValue:*/true, new IPreferenceLoadSave() {
|
||||
@Override
|
||||
public void saveInt(int progress) {
|
||||
Apple2Preferences.TOUCH_MENU_VISIBILITY.saveInt(activity, progress);
|
||||
}
|
||||
@Override
|
||||
public int intValue() {
|
||||
return Apple2Preferences.TOUCH_MENU_VISIBILITY.intValue(activity);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
CURRENT_INPUT {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.input_current);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.input_current_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final Apple2Activity activity, View convertView) {
|
||||
convertView = _basicView(activity, this, convertView);
|
||||
_addPopupIcon(activity, this, convertView);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
_alertDialogHandleSelection(activity, new String[]{
|
||||
activity.getResources().getString(R.string.joystick),
|
||||
activity.getResources().getString(R.string.keyboard),
|
||||
}, new IPreferenceLoadSave() {
|
||||
@Override
|
||||
public int intValue() {
|
||||
return Apple2Preferences.CURRENT_TOUCH_DEVICE.intValue(activity) - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveInt(int value) {
|
||||
Apple2Preferences.CURRENT_TOUCH_DEVICE.saveTouchDevice(activity, Apple2Preferences.TouchDevice.values()[value + 1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
KEYBOARD_CONFIGURE {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.keyboard_configure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.keyboard_configure_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
//new Apple2KeyboardSettingsMenu().show();
|
||||
}
|
||||
},
|
||||
JOYSTICK_CONFIGURE {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.joystick_configure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.joystick_configure_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
//new Apple2JoystickSettingsMenu(activity).show();
|
||||
}
|
||||
},
|
||||
AUDIO_CONFIGURE {
|
||||
|
@ -71,7 +180,7 @@ public class Apple2SettingsMenu implements Apple2MenuView {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(Apple2Activity activity, Apple2SettingsMenu settingsMenu, boolean isChecked) {
|
||||
public void handleSelection(Apple2Activity activity, Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
new Apple2AudioSettingsMenu(activity).show();
|
||||
}
|
||||
},
|
||||
|
@ -94,60 +203,62 @@ public class Apple2SettingsMenu implements Apple2MenuView {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(Apple2Activity activity, final Apple2SettingsMenu settingsMenu, boolean isChecked) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(settingsMenu.mActivity).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.video_configure);
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
String[] color_choices = new String[]{
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
_alertDialogHandleSelection(activity, new String[]{
|
||||
settingsMenu.mActivity.getResources().getString(R.string.color_bw),
|
||||
settingsMenu.mActivity.getResources().getString(R.string.color_color),
|
||||
settingsMenu.mActivity.getResources().getString(R.string.color_interpolated),
|
||||
};
|
||||
final int checkedPosition = Apple2Preferences.HIRES_COLOR.intValue(activity);
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(settingsMenu.mActivity, android.R.layout.select_dialog_singlechoice, color_choices) {
|
||||
}, new IPreferenceLoadSave() {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = super.getView(position, convertView, parent);
|
||||
CheckedTextView ctv = (CheckedTextView) view.findViewById(android.R.id.text1);
|
||||
ctv.setChecked(position == checkedPosition);
|
||||
return view;
|
||||
public int intValue() {
|
||||
return Apple2Preferences.HIRES_COLOR.intValue(activity);
|
||||
}
|
||||
};
|
||||
|
||||
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int color) {
|
||||
Apple2Preferences.HIRES_COLOR.saveHiresColor(settingsMenu.mActivity, Apple2Preferences.HiresColor.values()[color]);
|
||||
dialog.dismiss();
|
||||
public void saveInt(int value) {
|
||||
Apple2Preferences.HIRES_COLOR.saveHiresColor(settingsMenu.mActivity, Apple2Preferences.HiresColor.values()[value]);
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
},
|
||||
ABOUT {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.about_title);
|
||||
return activity.getResources().getString(R.string.about_apple2ix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.about_summary);
|
||||
return activity.getResources().getString(R.string.about_apple2ix_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(Apple2Activity activity, final Apple2SettingsMenu settingsMenu, boolean isChecked) {
|
||||
public void handleSelection(Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
String url = "http://github.com/mauiaaron/apple2";
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse(url));
|
||||
activity.startActivity(i);
|
||||
}
|
||||
},
|
||||
ABOUT_APPLE2 {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.about_apple2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary(Apple2Activity activity) {
|
||||
return activity.getResources().getString(R.string.about_apple2_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
String url = "http://wikipedia.org/wiki/Apple_II";
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse(url));
|
||||
activity.startActivity(i);
|
||||
}
|
||||
},
|
||||
RESET_PREFERENCES {
|
||||
@Override
|
||||
public String getTitle(Apple2Activity activity) {
|
||||
|
@ -160,7 +271,7 @@ public class Apple2SettingsMenu implements Apple2MenuView {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2SettingsMenu settingsMenu, boolean isChecked) {
|
||||
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.preferences_reset_really).setMessage(R.string.preferences_reset_warning).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -172,47 +283,14 @@ public class Apple2SettingsMenu implements Apple2MenuView {
|
|||
}
|
||||
};
|
||||
|
||||
private static View _basicView(Apple2Activity activity, SETTINGS setting, View convertView) {
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.a2preference_title);
|
||||
tv.setText(setting.getTitle(activity));
|
||||
|
||||
tv = (TextView) convertView.findViewById(R.id.a2preference_summary);
|
||||
tv.setText(setting.getSummary(activity));
|
||||
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
if (layout.getChildCount() > 0) {
|
||||
// layout cells appear to be reused when scrolling into view ... make sure we start with clear hierarchy
|
||||
layout.removeAllViews();
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private static ImageView _addPopupIcon(Apple2Activity activity, SETTINGS setting, View convertView) {
|
||||
ImageView imageView = new ImageView(activity);
|
||||
Drawable drawable = activity.getResources().getDrawable(android.R.drawable.ic_menu_edit);
|
||||
imageView.setImageDrawable(drawable);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(imageView);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
private static CheckBox _addCheckbox(Apple2Activity activity, SETTINGS setting, View convertView, boolean isChecked) {
|
||||
CheckBox checkBox = new CheckBox(activity);
|
||||
checkBox.setChecked(isChecked);
|
||||
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.a2preference_widget_frame);
|
||||
layout.addView(checkBox);
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
public static final int size = SETTINGS.values().length;
|
||||
|
||||
public abstract String getTitle(Apple2Activity activity);
|
||||
|
||||
public abstract String getSummary(Apple2Activity activity);
|
||||
|
||||
public abstract void handleSelection(Apple2Activity activity, Apple2SettingsMenu settingsMenu, boolean isChecked);
|
||||
@Override
|
||||
public void handleSelection(Apple2Activity activity, Apple2AbstractMenu settingsMenu, boolean isChecked) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(Apple2Activity activity, View convertView) {
|
||||
return _basicView(activity, this, convertView);
|
||||
}
|
||||
|
@ -226,72 +304,4 @@ public class Apple2SettingsMenu implements Apple2MenuView {
|
|||
return titles;
|
||||
}
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mSettingsView = inflater.inflate(R.layout.activity_settings, null, false);
|
||||
|
||||
ListView settingsList = (ListView) mSettingsView.findViewById(R.id.listView_settings);
|
||||
settingsList.setEnabled(true);
|
||||
|
||||
ArrayAdapter<?> adapter = new ArrayAdapter<String>(mActivity, R.layout.a2preference, R.id.a2preference_title, SETTINGS.titles(mActivity)) {
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return super.isEnabled(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = super.getView(position, convertView, parent);
|
||||
SETTINGS setting = SETTINGS.values()[position];
|
||||
return setting.getView(mActivity, view);
|
||||
}
|
||||
};
|
||||
|
||||
settingsList.setAdapter(adapter);
|
||||
settingsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
SETTINGS setting = SETTINGS.values()[position];
|
||||
LinearLayout layout = (LinearLayout) view.findViewById(R.id.a2preference_widget_frame);
|
||||
View childView = layout.getChildAt(0);
|
||||
boolean selected = false;
|
||||
if (childView != null && childView instanceof CheckBox) {
|
||||
CheckBox checkBox = (CheckBox) childView;
|
||||
checkBox.setChecked(!checkBox.isChecked());
|
||||
selected = checkBox.isChecked();
|
||||
}
|
||||
setting.handleSelection(mActivity, Apple2SettingsMenu.this, selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void showJoystickConfiguration() {
|
||||
Log.d(TAG, "showJoystickConfiguration...");
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (isShowing()) {
|
||||
return;
|
||||
}
|
||||
mActivity.pushApple2View(this);
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mActivity.popApple2View(this);
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mSettingsView.isShown();
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mSettingsView;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
<color name="black">#000000</color>
|
||||
<color name="white">#ffffff</color>
|
||||
|
||||
<string name="about_title">About Apple2ix…</string>
|
||||
<string name="about_summary">Various shout-outs and acknowledgements</string>
|
||||
<string name="about_apple2ix">About Apple2ix…</string>
|
||||
<string name="about_apple2ix_summary">About this software</string>
|
||||
<string name="about_apple2">About Apple //e…</string>
|
||||
<string name="about_apple2_summary">More information about the Apple //e computer</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="app_name">Apple2ix</string>
|
||||
<string name="audio_configure">Configure audio…</string>
|
||||
|
@ -20,6 +22,7 @@
|
|||
<string name="diskB">Drive 2</string>
|
||||
<string name="disk_read_write">Read/write</string>
|
||||
<string name="emulation_continue">Continue…</string>
|
||||
<string name="emulation_preferences">Preferences…</string>
|
||||
<string name="header_disks">Insert disk:</string>
|
||||
<string name="joystick">Joystick</string>
|
||||
<string name="input_configure">Configure input devices…</string>
|
||||
|
@ -30,9 +33,10 @@
|
|||
<string name="input_first_keyboard">Touch keyboard</string>
|
||||
<string name="joystick_configure">Configure joysticks…</string>
|
||||
<string name="joystick_configure_summary">Touch/tilt, axis and buttons, etc</string>
|
||||
<string name="joystick_enable">Enable emulated joystick</string>
|
||||
<string name="joystick_keyA">Key Joystick 1</string>
|
||||
<string name="joystick_keyB">Key Joystick 2</string>
|
||||
<string name="joystick_current_variant">Choose joystick type</string>
|
||||
<string name="joystick_current_variant_summary">Choose from emulated joystick or keypad devices</string>
|
||||
<string name="joystickA">Touch Joystick</string>
|
||||
<string name="keypadA">Touch Keypad</string>
|
||||
<string name="keyboard">Keyboard</string>
|
||||
<string name="keyboard_configure">Configure keyboard…</string>
|
||||
<string name="keyboard_configure_summary">Transparency, fading, custom keys</string>
|
||||
|
@ -78,7 +82,7 @@
|
|||
<string name="tab_joystick">Joystick</string>
|
||||
<string name="title_activity_second">SecondActivity</string>
|
||||
<string name="touch_menu_enable">Enable touch menus</string>
|
||||
<string name="touch_menu_enable_summary">Enables menu buttons in top screen corners</string>
|
||||
<string name="touch_menu_enable_summary">Enables soft menu buttons in top screen corners</string>
|
||||
<string name="touch_menu_visibility">Touch menu visibility</string>
|
||||
<string name="touch_menu_visibility_summary">Touch menu visibility when inactive</string>
|
||||
<string name="video_configure">Configure video…</string>
|
||||
|
|
Loading…
Reference in New Issue
Block a user