mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-10 08:02:40 +01:00
Use binding in EditOptions root also
This commit is contained in:
committed by
Peter Osterlund
parent
a912458ffb
commit
7e4a0314c9
@@ -31,11 +31,12 @@ import android.view.View;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemSelectedListener;
|
import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.LinearLayout;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.Util;
|
import org.petero.droidfish.Util;
|
||||||
|
import org.petero.droidfish.databinding.EditoptionsBinding;
|
||||||
import org.petero.droidfish.databinding.UciOptionButtonBinding;
|
import org.petero.droidfish.databinding.UciOptionButtonBinding;
|
||||||
import org.petero.droidfish.databinding.UciOptionCheckBinding;
|
import org.petero.droidfish.databinding.UciOptionCheckBinding;
|
||||||
import org.petero.droidfish.databinding.UciOptionComboBinding;
|
import org.petero.droidfish.databinding.UciOptionComboBinding;
|
||||||
@@ -92,33 +93,32 @@ public class EditOptions extends Activity {
|
|||||||
title = title + ": " + engineName;
|
title = title + ": " + engineName;
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
|
|
||||||
View view = View.inflate(this, R.layout.editoptions, null);
|
EditoptionsBinding binding = DataBindingUtil.setContentView(this, R.layout.editoptions);
|
||||||
|
|
||||||
if (uciOpts != null) {
|
if (uciOpts != null) {
|
||||||
LinearLayout content = view.findViewById(R.id.eo_content);
|
|
||||||
for (String name : uciOpts.getOptionNames()) {
|
for (String name : uciOpts.getOptionNames()) {
|
||||||
UCIOptions.OptionBase o = uciOpts.getOption(name);
|
UCIOptions.OptionBase o = uciOpts.getOption(name);
|
||||||
if (!o.visible)
|
if (!o.visible)
|
||||||
continue;
|
continue;
|
||||||
switch (o.type) {
|
switch (o.type) {
|
||||||
case CHECK: {
|
case CHECK: {
|
||||||
UciOptionCheckBinding binding = UciOptionCheckBinding.inflate(getLayoutInflater(), null, false);
|
UciOptionCheckBinding holder = UciOptionCheckBinding.inflate(getLayoutInflater(), null, false);
|
||||||
binding.eoValue.setText(o.name);
|
holder.eoValue.setText(o.name);
|
||||||
final UCIOptions.CheckOption co = (UCIOptions.CheckOption) o;
|
final UCIOptions.CheckOption co = (UCIOptions.CheckOption) o;
|
||||||
binding.eoValue.setChecked(co.value);
|
holder.eoValue.setChecked(co.value);
|
||||||
binding.eoValue.setOnCheckedChangeListener((buttonView, isChecked) -> co.set(isChecked));
|
holder.eoValue.setOnCheckedChangeListener((buttonView, isChecked) -> co.set(isChecked));
|
||||||
content.addView(binding.getRoot());
|
binding.eoContent.addView(holder.getRoot());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SPIN: {
|
case SPIN: {
|
||||||
UciOptionSpinBinding binding = UciOptionSpinBinding.inflate(getLayoutInflater(), null, false);
|
UciOptionSpinBinding holder = UciOptionSpinBinding.inflate(getLayoutInflater(), null, false);
|
||||||
final UCIOptions.SpinOption so = (UCIOptions.SpinOption) o;
|
final UCIOptions.SpinOption so = (UCIOptions.SpinOption) o;
|
||||||
String labelText = String.format(Locale.US, "%s (%d\u2013%d)", so.name, so.minValue, so.maxValue);
|
String labelText = String.format(Locale.US, "%s (%d\u2013%d)", so.name, so.minValue, so.maxValue);
|
||||||
binding.eoLabel.setText(labelText);
|
holder.eoLabel.setText(labelText);
|
||||||
binding.eoValue.setText(so.getStringValue());
|
holder.eoValue.setText(so.getStringValue());
|
||||||
if (so.minValue >= 0)
|
if (so.minValue >= 0)
|
||||||
binding.eoValue.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
|
holder.eoValue.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
|
||||||
binding.eoValue.addTextChangedListener(new TextWatcher() {
|
holder.eoValue.addTextChangedListener(new TextWatcher() {
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,20 +139,20 @@ public class EditOptions extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
content.addView(binding.getRoot());
|
binding.eoContent.addView(holder.getRoot());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COMBO: {
|
case COMBO: {
|
||||||
UciOptionComboBinding binding = UciOptionComboBinding.inflate(getLayoutInflater(), null, false);
|
UciOptionComboBinding holder = UciOptionComboBinding.inflate(getLayoutInflater(), null, false);
|
||||||
binding.eoLabel.setText(o.name);
|
holder.eoLabel.setText(o.name);
|
||||||
final UCIOptions.ComboOption co = (UCIOptions.ComboOption) o;
|
final UCIOptions.ComboOption co = (UCIOptions.ComboOption) o;
|
||||||
ArrayAdapter<CharSequence> adapter =
|
ArrayAdapter<CharSequence> adapter =
|
||||||
new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
|
new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
|
||||||
co.allowedValues);
|
co.allowedValues);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
binding.eoValue.setAdapter(adapter);
|
holder.eoValue.setAdapter(adapter);
|
||||||
binding.eoValue.setSelection(adapter.getPosition(co.value));
|
holder.eoValue.setSelection(adapter.getPosition(co.value));
|
||||||
binding.eoValue.setOnItemSelectedListener(new OnItemSelectedListener() {
|
holder.eoValue.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> av, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> av, View view, int position, long id) {
|
||||||
if ((position >= 0) && (position < co.allowedValues.length))
|
if ((position >= 0) && (position < co.allowedValues.length))
|
||||||
@@ -162,26 +162,26 @@ public class EditOptions extends Activity {
|
|||||||
public void onNothingSelected(AdapterView<?> arg0) {
|
public void onNothingSelected(AdapterView<?> arg0) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
content.addView(binding.getRoot());
|
binding.eoContent.addView(holder.getRoot());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BUTTON: {
|
case BUTTON: {
|
||||||
UciOptionButtonBinding binding = UciOptionButtonBinding.inflate(getLayoutInflater(), null, false);
|
UciOptionButtonBinding holder = UciOptionButtonBinding.inflate(getLayoutInflater(), null, false);
|
||||||
final UCIOptions.ButtonOption bo = (UCIOptions.ButtonOption) o;
|
final UCIOptions.ButtonOption bo = (UCIOptions.ButtonOption) o;
|
||||||
bo.trigger = false;
|
bo.trigger = false;
|
||||||
binding.eoLabel.setText(o.name);
|
holder.eoLabel.setText(o.name);
|
||||||
binding.eoLabel.setTextOn(o.name);
|
holder.eoLabel.setTextOn(o.name);
|
||||||
binding.eoLabel.setTextOff(o.name);
|
holder.eoLabel.setTextOff(o.name);
|
||||||
binding.eoLabel.setOnCheckedChangeListener((buttonView, isChecked) -> bo.trigger = isChecked);
|
holder.eoLabel.setOnCheckedChangeListener((buttonView, isChecked) -> bo.trigger = isChecked);
|
||||||
content.addView(binding.getRoot());
|
binding.eoContent.addView(holder.getRoot());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING: {
|
case STRING: {
|
||||||
UciOptionStringBinding binding = UciOptionStringBinding.inflate(getLayoutInflater(), null, false);
|
UciOptionStringBinding holder = UciOptionStringBinding.inflate(getLayoutInflater(), null, false);
|
||||||
binding.eoLabel.setText(String.format("%s ", o.name));
|
holder.eoLabel.setText(String.format("%s ", o.name));
|
||||||
final UCIOptions.StringOption so = (UCIOptions.StringOption) o;
|
final UCIOptions.StringOption so = (UCIOptions.StringOption) o;
|
||||||
binding.eoValue.setText(so.value);
|
holder.eoValue.setText(so.value);
|
||||||
binding.eoValue.addTextChangedListener(new TextWatcher() {
|
holder.eoValue.addTextChangedListener(new TextWatcher() {
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,25 +193,21 @@ public class EditOptions extends Activity {
|
|||||||
so.set(s.toString());
|
so.set(s.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
content.addView(binding.getRoot());
|
binding.eoContent.addView(holder.getRoot());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(view);
|
Util.overrideViewAttribs(binding.eoContent);
|
||||||
Util.overrideViewAttribs(findViewById(android.R.id.content));
|
|
||||||
Button okButton = findViewById(R.id.eo_ok);
|
|
||||||
Button cancelButton = findViewById(R.id.eo_cancel);
|
|
||||||
Button resetButton = findViewById(R.id.eo_reset);
|
|
||||||
|
|
||||||
okButton.setOnClickListener(v -> sendBackResult());
|
binding.eoOk.setOnClickListener(v -> sendBackResult());
|
||||||
cancelButton.setOnClickListener(v -> {
|
binding.eoCancel.setOnClickListener(v -> {
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
resetButton.setOnClickListener(v -> {
|
binding.eoReset.setOnClickListener(v -> {
|
||||||
if (uciOpts != null) {
|
if (uciOpts != null) {
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
for (String name : uciOpts.getOptionNames()) {
|
for (String name : uciOpts.getOptionNames()) {
|
||||||
|
|||||||
@@ -1,45 +1,51 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:baselineAligned="false">
|
android:baselineAligned="false"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/eo_content"
|
android:id="@+id/eo_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical" />
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:text="@string/cancel"
|
|
||||||
android:id="@+id/eo_cancel"
|
android:id="@+id/eo_cancel"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
</Button>
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:text="@string/reset"
|
|
||||||
android:id="@+id/eo_reset"
|
android:id="@+id/eo_reset"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
</Button>
|
android:text="@string/reset" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:text="@android:string/ok"
|
|
||||||
android:id="@+id/eo_ok"
|
android:id="@+id/eo_ok"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
</Button>
|
android:text="@android:string/ok" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</layout>
|
||||||
|
|||||||
@@ -1,44 +1,52 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<layout>
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/eo_content"
|
android:id="@+id/eo_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical" />
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:text="@string/cancel"
|
|
||||||
android:id="@+id/eo_cancel"
|
android:id="@+id/eo_cancel"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
</Button>
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:text="@string/reset"
|
|
||||||
android:id="@+id/eo_reset"
|
android:id="@+id/eo_reset"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
</Button>
|
android:text="@string/reset" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:text="@android:string/ok"
|
|
||||||
android:id="@+id/eo_ok"
|
android:id="@+id/eo_ok"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
</Button>
|
android:text="@android:string/ok" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</layout>
|
||||||
|
|||||||
Reference in New Issue
Block a user