mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-01-30 17:13:50 +01:00
DroidFish: Implemented function to reset all UCI options to default values.
This commit is contained in:
parent
d0648b9cbf
commit
0e9e6fb18b
|
@ -34,5 +34,12 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
</Button>
|
||||
<Button
|
||||
android:text="@string/reset"
|
||||
android:id="@+id/eo_reset"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
</Button>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -33,5 +33,12 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
</Button>
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:text="@string/reset"
|
||||
android:id="@+id/eo_reset"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
</Button>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -130,6 +130,7 @@ you are not actively using the program.\
|
|||
<string name="toggle_large_buttons">Toggle Large Buttons</string>
|
||||
<string name="toggle_blind_mode">Toggle Blindfold Mode</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="reset">Reset</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
<string name="move_number">Move number:</string>
|
||||
|
|
|
@ -93,115 +93,118 @@ public class EditOptions extends Activity {
|
|||
LinearLayout content = (LinearLayout)findViewById(R.id.eo_content);
|
||||
Button okButton = (Button)findViewById(R.id.eo_ok);
|
||||
Button cancelButton = (Button)findViewById(R.id.eo_cancel);
|
||||
Button resetButton = (Button)findViewById(R.id.eo_reset);
|
||||
|
||||
for (String name : uciOpts.getOptionNames()) {
|
||||
UCIOptions.OptionBase o = uciOpts.getOption(name);
|
||||
if (!o.visible)
|
||||
continue;
|
||||
switch (o.type) {
|
||||
case CHECK: {
|
||||
View v = View.inflate(this, R.layout.uci_option_check, null);
|
||||
CheckBox checkBox = (CheckBox)v.findViewById(R.id.eo_value);
|
||||
checkBox.setText(o.name);
|
||||
final UCIOptions.CheckOption co = (UCIOptions.CheckOption)o;
|
||||
checkBox.setChecked(co.value);
|
||||
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
co.set(isChecked);
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case SPIN: {
|
||||
View v = View.inflate(this, R.layout.uci_option_spin, null);
|
||||
TextView label = (TextView)v.findViewById(R.id.eo_label);
|
||||
EditText value = (EditText)v.findViewById(R.id.eo_value);
|
||||
final UCIOptions.SpinOption so = (UCIOptions.SpinOption)o;
|
||||
String labelText = String.format(Locale.US, "%s (%d\u2013%d)", so.name, so.minValue, so.maxValue);
|
||||
label.setText(labelText);
|
||||
value.setText(so.getStringValue());
|
||||
if (so.minValue >= 0)
|
||||
value.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
|
||||
value.addTextChangedListener(new TextWatcher() {
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) { }
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
try {
|
||||
int newVal = Integer.parseInt(s.toString());
|
||||
if (newVal < so.minValue)
|
||||
so.set(so.minValue);
|
||||
else if (newVal > so.maxValue)
|
||||
so.set(so.maxValue);
|
||||
else
|
||||
so.set(newVal);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (uciOpts != null) {
|
||||
for (String name : uciOpts.getOptionNames()) {
|
||||
UCIOptions.OptionBase o = uciOpts.getOption(name);
|
||||
if (!o.visible)
|
||||
continue;
|
||||
switch (o.type) {
|
||||
case CHECK: {
|
||||
View v = View.inflate(this, R.layout.uci_option_check, null);
|
||||
CheckBox checkBox = (CheckBox)v.findViewById(R.id.eo_value);
|
||||
checkBox.setText(o.name);
|
||||
final UCIOptions.CheckOption co = (UCIOptions.CheckOption)o;
|
||||
checkBox.setChecked(co.value);
|
||||
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
co.set(isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case COMBO: {
|
||||
View v = View.inflate(this, R.layout.uci_option_combo, null);
|
||||
TextView label = (TextView)v.findViewById(R.id.eo_label);
|
||||
Spinner value = (Spinner)v.findViewById(R.id.eo_value);
|
||||
label.setText(o.name);
|
||||
final UCIOptions.ComboOption co = (UCIOptions.ComboOption)o;
|
||||
ArrayAdapter<CharSequence> adapter =
|
||||
new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item,
|
||||
co.allowedValues);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
value.setAdapter(adapter);
|
||||
value.setSelection(adapter.getPosition(co.value));
|
||||
value.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> av, View view, int position, long id) {
|
||||
if ((position >= 0) && (position < co.allowedValues.length))
|
||||
co.set(co.allowedValues[position]);
|
||||
}
|
||||
public void onNothingSelected(AdapterView<?> arg0) { }
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case BUTTON: {
|
||||
View v = View.inflate(this, R.layout.uci_option_button, null);
|
||||
ToggleButton button = (ToggleButton)v.findViewById(R.id.eo_label);
|
||||
final UCIOptions.ButtonOption bo = (UCIOptions.ButtonOption)o;
|
||||
bo.trigger = false;
|
||||
button.setText(o.name);
|
||||
button.setTextOn(o.name);
|
||||
button.setTextOff(o.name);
|
||||
button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
bo.trigger = isChecked;
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case STRING: {
|
||||
View v = View.inflate(this, R.layout.uci_option_string, null);
|
||||
TextView label = (TextView)v.findViewById(R.id.eo_label);
|
||||
EditText value = (EditText)v.findViewById(R.id.eo_value);
|
||||
label.setText(o.name + " ");
|
||||
final UCIOptions.StringOption so = (UCIOptions.StringOption)o;
|
||||
value.setText(so.value);
|
||||
value.addTextChangedListener(new TextWatcher() {
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) { }
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
so.set(s.toString());
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case SPIN: {
|
||||
View v = View.inflate(this, R.layout.uci_option_spin, null);
|
||||
TextView label = (TextView)v.findViewById(R.id.eo_label);
|
||||
EditText value = (EditText)v.findViewById(R.id.eo_value);
|
||||
final UCIOptions.SpinOption so = (UCIOptions.SpinOption)o;
|
||||
String labelText = String.format(Locale.US, "%s (%d\u2013%d)", so.name, so.minValue, so.maxValue);
|
||||
label.setText(labelText);
|
||||
value.setText(so.getStringValue());
|
||||
if (so.minValue >= 0)
|
||||
value.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
|
||||
value.addTextChangedListener(new TextWatcher() {
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) { }
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
try {
|
||||
int newVal = Integer.parseInt(s.toString());
|
||||
if (newVal < so.minValue)
|
||||
so.set(so.minValue);
|
||||
else if (newVal > so.maxValue)
|
||||
so.set(so.maxValue);
|
||||
else
|
||||
so.set(newVal);
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case COMBO: {
|
||||
View v = View.inflate(this, R.layout.uci_option_combo, null);
|
||||
TextView label = (TextView)v.findViewById(R.id.eo_label);
|
||||
Spinner value = (Spinner)v.findViewById(R.id.eo_value);
|
||||
label.setText(o.name);
|
||||
final UCIOptions.ComboOption co = (UCIOptions.ComboOption)o;
|
||||
ArrayAdapter<CharSequence> adapter =
|
||||
new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item,
|
||||
co.allowedValues);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
value.setAdapter(adapter);
|
||||
value.setSelection(adapter.getPosition(co.value));
|
||||
value.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> av, View view, int position, long id) {
|
||||
if ((position >= 0) && (position < co.allowedValues.length))
|
||||
co.set(co.allowedValues[position]);
|
||||
}
|
||||
public void onNothingSelected(AdapterView<?> arg0) { }
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case BUTTON: {
|
||||
View v = View.inflate(this, R.layout.uci_option_button, null);
|
||||
ToggleButton button = (ToggleButton)v.findViewById(R.id.eo_label);
|
||||
final UCIOptions.ButtonOption bo = (UCIOptions.ButtonOption)o;
|
||||
bo.trigger = false;
|
||||
button.setText(o.name);
|
||||
button.setTextOn(o.name);
|
||||
button.setTextOff(o.name);
|
||||
button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
bo.trigger = isChecked;
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
case STRING: {
|
||||
View v = View.inflate(this, R.layout.uci_option_string, null);
|
||||
TextView label = (TextView)v.findViewById(R.id.eo_label);
|
||||
EditText value = (EditText)v.findViewById(R.id.eo_value);
|
||||
label.setText(o.name + " ");
|
||||
final UCIOptions.StringOption so = (UCIOptions.StringOption)o;
|
||||
value.setText(so.value);
|
||||
value.addTextChangedListener(new TextWatcher() {
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) { }
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
so.set(s.toString());
|
||||
}
|
||||
});
|
||||
content.addView(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,6 +221,47 @@ public class EditOptions extends Activity {
|
|||
finish();
|
||||
}
|
||||
});
|
||||
resetButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (uciOpts != null) {
|
||||
boolean modified = false;
|
||||
for (String name : uciOpts.getOptionNames()) {
|
||||
UCIOptions.OptionBase o = uciOpts.getOption(name);
|
||||
if (!o.visible)
|
||||
continue;
|
||||
switch (o.type) {
|
||||
case CHECK: {
|
||||
UCIOptions.CheckOption co = (UCIOptions.CheckOption)o;
|
||||
if (co.set(co.defaultValue))
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
case SPIN: {
|
||||
UCIOptions.SpinOption so = (UCIOptions.SpinOption)o;
|
||||
if (so.set(so.defaultValue))
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
case COMBO: {
|
||||
UCIOptions.ComboOption co = (UCIOptions.ComboOption)o;
|
||||
if (co.set(co.defaultValue))
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
case STRING: {
|
||||
UCIOptions.StringOption so = (UCIOptions.StringOption)o;
|
||||
if (so.set(so.defaultValue))
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (modified)
|
||||
initUI();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final void sendBackResult() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user