Code reformatting

This commit is contained in:
Peter Osterlund 2019-04-24 23:25:13 +02:00
parent 068b97ac85
commit 5d599c2782
5 changed files with 209 additions and 215 deletions

11
.editorconfig Normal file
View File

@ -0,0 +1,11 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=true
indent_style=space
indent_size=4
[*.json]
indent_style=space
indent_size=2

View File

@ -101,101 +101,91 @@ public class EditOptions extends Activity {
if (!o.visible)
continue;
switch (o.type) {
case CHECK: {
UciOptionCheckBinding holder = UciOptionCheckBinding.inflate(getLayoutInflater(), null, false);
holder.eoValue.setText(o.name);
final UCIOptions.CheckOption co = (UCIOptions.CheckOption) o;
holder.eoValue.setChecked(co.value);
holder.eoValue.setOnCheckedChangeListener((buttonView, isChecked) -> co.set(isChecked));
binding.eoContent.addView(holder.getRoot());
break;
}
case SPIN: {
UciOptionSpinBinding holder = UciOptionSpinBinding.inflate(getLayoutInflater(), null, false);
final UCIOptions.SpinOption so = (UCIOptions.SpinOption) o;
String labelText = String.format(Locale.US, "%s (%d\u2013%d)", so.name, so.minValue, so.maxValue);
holder.eoLabel.setText(labelText);
holder.eoValue.setText(so.getStringValue());
if (so.minValue >= 0)
holder.eoValue.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
holder.eoValue.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
case CHECK: {
UciOptionCheckBinding holder = UciOptionCheckBinding.inflate(getLayoutInflater(), null, false);
holder.eoValue.setText(o.name);
final UCIOptions.CheckOption co = (UCIOptions.CheckOption) o;
holder.eoValue.setChecked(co.value);
holder.eoValue.setOnCheckedChangeListener((buttonView, isChecked) -> co.set(isChecked));
binding.eoContent.addView(holder.getRoot());
break;
}
case SPIN: {
UciOptionSpinBinding holder = UciOptionSpinBinding.inflate(getLayoutInflater(), null, false);
final UCIOptions.SpinOption so = (UCIOptions.SpinOption) o;
String labelText = String.format(Locale.US, "%s (%d\u2013%d)", so.name, so.minValue, so.maxValue);
holder.eoLabel.setText(labelText);
holder.eoValue.setText(so.getStringValue());
if (so.minValue >= 0)
holder.eoValue.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
holder.eoValue.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 ignore) {
}
}
});
binding.eoContent.addView(holder.getRoot());
break;
}
case COMBO: {
UciOptionComboBinding holder = UciOptionComboBinding.inflate(getLayoutInflater(), null, false);
holder.eoLabel.setText(o.name);
final UCIOptions.ComboOption co = (UCIOptions.ComboOption) o;
ArrayAdapter<CharSequence> adapter =
new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, co.allowedValues);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.eoValue.setAdapter(adapter);
holder.eoValue.setSelection(adapter.getPosition(co.value));
holder.eoValue.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 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 ignore) {
}
}
});
binding.eoContent.addView(holder.getRoot());
break;
}
case COMBO: {
UciOptionComboBinding holder = UciOptionComboBinding.inflate(getLayoutInflater(), null, false);
holder.eoLabel.setText(o.name);
final UCIOptions.ComboOption co = (UCIOptions.ComboOption) o;
ArrayAdapter<CharSequence> adapter =
new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
co.allowedValues);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.eoValue.setAdapter(adapter);
holder.eoValue.setSelection(adapter.getPosition(co.value));
holder.eoValue.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) {
}
});
binding.eoContent.addView(holder.getRoot());
break;
}
case BUTTON: {
UciOptionButtonBinding holder = UciOptionButtonBinding.inflate(getLayoutInflater(), null, false);
final UCIOptions.ButtonOption bo = (UCIOptions.ButtonOption) o;
bo.trigger = false;
holder.eoLabel.setText(o.name);
holder.eoLabel.setTextOn(o.name);
holder.eoLabel.setTextOff(o.name);
holder.eoLabel.setOnCheckedChangeListener((buttonView, isChecked) -> bo.trigger = isChecked);
binding.eoContent.addView(holder.getRoot());
break;
}
case STRING: {
UciOptionStringBinding holder = UciOptionStringBinding.inflate(getLayoutInflater(), null, false);
holder.eoLabel.setText(String.format("%s ", o.name));
final UCIOptions.StringOption so = (UCIOptions.StringOption) o;
holder.eoValue.setText(so.value);
holder.eoValue.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());
}
});
binding.eoContent.addView(holder.getRoot());
break;
}
public void onNothingSelected(AdapterView<?> arg0) { }
});
binding.eoContent.addView(holder.getRoot());
break;
}
case BUTTON: {
UciOptionButtonBinding holder = UciOptionButtonBinding.inflate(getLayoutInflater(), null, false);
final UCIOptions.ButtonOption bo = (UCIOptions.ButtonOption) o;
bo.trigger = false;
holder.eoLabel.setText(o.name);
holder.eoLabel.setTextOn(o.name);
holder.eoLabel.setTextOff(o.name);
holder.eoLabel.setOnCheckedChangeListener((buttonView, isChecked) -> bo.trigger = isChecked);
binding.eoContent.addView(holder.getRoot());
break;
}
case STRING: {
UciOptionStringBinding holder = UciOptionStringBinding.inflate(getLayoutInflater(), null, false);
holder.eoLabel.setText(String.format("%s ", o.name));
final UCIOptions.StringOption so = (UCIOptions.StringOption) o;
holder.eoValue.setText(so.value);
holder.eoValue.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());
}
});
binding.eoContent.addView(holder.getRoot());
break;
}
}
}
}
@ -215,32 +205,28 @@ public class EditOptions extends Activity {
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;
}
case BUTTON:
break;
case CHECK: {
UCIOptions.CheckOption co = (UCIOptions.CheckOption) o;
modified |= co.set(co.defaultValue);
break;
}
case SPIN: {
UCIOptions.SpinOption so = (UCIOptions.SpinOption) o;
modified |= so.set(so.defaultValue);
break;
}
case COMBO: {
UCIOptions.ComboOption co = (UCIOptions.ComboOption) o;
modified |= co.set(co.defaultValue);
break;
}
case STRING: {
UCIOptions.StringOption so = (UCIOptions.StringOption) o;
modified |= so.set(so.defaultValue);
break;
}
case BUTTON:
break;
}
}
if (modified)

View File

@ -121,7 +121,7 @@ public abstract class EditPGN extends ListActivity {
});
workThread.start();
} else if ("org.petero.droidfish.loadFileNextGame".equals(action) ||
"org.petero.droidfish.loadFilePrevGame".equals(action)) {
"org.petero.droidfish.loadFilePrevGame".equals(action)) {
pgnFile = new PGNFile(fileName);
loadGame = true;
boolean next = action.equals("org.petero.droidfish.loadFileNextGame");
@ -224,9 +224,9 @@ public abstract class EditPGN extends ListActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_delete_file:
reShowDialog(DELETE_PGN_FILE_DIALOG);
break;
case R.id.item_delete_file:
reShowDialog(DELETE_PGN_FILE_DIALOG);
break;
}
return false;
}
@ -271,12 +271,10 @@ public abstract class EditPGN extends ListActivity {
binding.selectGameFilter.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
public void afterTextChanged(Editable s) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
@ -314,81 +312,81 @@ public abstract class EditPGN extends ListActivity {
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case PROGRESS_DIALOG:
progress = new ProgressDialog(this);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setTitle(R.string.reading_pgn_file);
progress.setOnCancelListener(dialog -> {
canceled = true;
Thread thr = workThread;
if (thr != null)
thr.interrupt();
});
return progress;
case DELETE_GAME_DIALOG: {
final GameInfo gi = selectedGi;
selectedGi = null;
if (gi == null)
return null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.delete_game);
String msg = gi.toString();
builder.setMessage(msg);
builder.setPositiveButton(R.string.yes, (dialog, id14) -> {
deleteGame(gi);
dialog.cancel();
});
builder.setNegativeButton(R.string.no, (dialog, id13) -> dialog.cancel());
return builder.create();
}
case SAVE_GAME_DIALOG: {
final GameInfo gi = selectedGi;
selectedGi = null;
if (gi == null)
return null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.save_game_question);
final CharSequence[] items = {
getString(R.string.before_selected),
getString(R.string.after_selected),
getString(R.string.replace_selected),
};
builder.setItems(items, (dialog, item) -> {
GameInfo giToReplace;
switch (item) {
case 0:
giToReplace = new GameInfo().setNull(gi.startPos);
break;
case 1:
giToReplace = new GameInfo().setNull(gi.endPos);
break;
case 2:
giToReplace = gi;
break;
default:
finish();
return;
}
pgnFile.replacePGN(pgnToSave, giToReplace);
finish();
});
return builder.create();
}
case DELETE_PGN_FILE_DIALOG: {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.delete_file_question);
String name = new File(pgnFile.getName()).getName();
String msg = String.format(Locale.US, getString(R.string.delete_named_file), name);
builder.setMessage(msg);
builder.setPositiveButton(R.string.yes, (dialog, id12) -> {
pgnFile.delete();
finish();
});
builder.setNegativeButton(R.string.no, (dialog, id1) -> dialog.cancel());
return builder.create();
}
default:
case PROGRESS_DIALOG:
progress = new ProgressDialog(this);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setTitle(R.string.reading_pgn_file);
progress.setOnCancelListener(dialog -> {
canceled = true;
Thread thr = workThread;
if (thr != null)
thr.interrupt();
});
return progress;
case DELETE_GAME_DIALOG: {
final GameInfo gi = selectedGi;
selectedGi = null;
if (gi == null)
return null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.delete_game);
String msg = gi.toString();
builder.setMessage(msg);
builder.setPositiveButton(R.string.yes, (dialog, id14) -> {
deleteGame(gi);
dialog.cancel();
});
builder.setNegativeButton(R.string.no, (dialog, id13) -> dialog.cancel());
return builder.create();
}
case SAVE_GAME_DIALOG: {
final GameInfo gi = selectedGi;
selectedGi = null;
if (gi == null)
return null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.save_game_question);
final CharSequence[] items = {
getString(R.string.before_selected),
getString(R.string.after_selected),
getString(R.string.replace_selected),
};
builder.setItems(items, (dialog, item) -> {
GameInfo giToReplace;
switch (item) {
case 0:
giToReplace = new GameInfo().setNull(gi.startPos);
break;
case 1:
giToReplace = new GameInfo().setNull(gi.endPos);
break;
case 2:
giToReplace = gi;
break;
default:
finish();
return;
}
pgnFile.replacePGN(pgnToSave, giToReplace);
finish();
});
return builder.create();
}
case DELETE_PGN_FILE_DIALOG: {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.delete_file_question);
String name = new File(pgnFile.getName()).getName();
String msg = String.format(Locale.US, getString(R.string.delete_named_file), name);
builder.setMessage(msg);
builder.setPositiveButton(R.string.yes, (dialog, id12) -> {
pgnFile.delete();
finish();
});
builder.setNegativeButton(R.string.no, (dialog, id1) -> dialog.cancel());
return builder.create();
}
default:
return null;
}
}
@ -403,15 +401,15 @@ public abstract class EditPGN extends ListActivity {
if (p.first != GameInfoResult.OK) {
gamesInFile = new ArrayList<>();
switch (p.first) {
case OUT_OF_MEMORY:
runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT));
break;
case NOT_PGN:
runOnUiThread(() -> DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT));
break;
case CANCEL:
case OK:
break;
case OUT_OF_MEMORY:
runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT));
break;
case NOT_PGN:
runOnUiThread(() -> DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT));
break;
case CANCEL:
case OK:
break;
}
setResult(RESULT_CANCELED);
finish();

View File

@ -123,7 +123,7 @@ public class LoadFEN extends ListActivity {
});
workThread.start();
} else if ("org.petero.droidfish.loadNextFen".equals(action) ||
"org.petero.droidfish.loadPrevFen".equals(action)) {
"org.petero.droidfish.loadPrevFen".equals(action)) {
fenFile = new FENFile(fileName);
boolean next = action.equals("org.petero.droidfish.loadNextFen");
final int loadItem = defaultItem + (next ? 1 : -1);

View File

@ -40,9 +40,7 @@ import org.petero.droidfish.databinding.SelectPercentageBinding;
import java.util.Locale;
/**
* Lets user enter a percentage value using a seek bar.
*/
/** Lets user enter a percentage value using a seek bar. */
public class SeekBarPreference extends Preference implements OnSeekBarChangeListener {
private final static int maxValue = 1000;
private final static int DEFAULT_VALUE = 1000;
@ -99,7 +97,8 @@ public class SeekBarPreference extends Preference implements OnSeekBarChangeList
title = getContext().getString(R.string.edit_randomization);
}
builder.setTitle(title);
selectPercentageBinding.selpercentageNumber.setText(binding.seekbarValue.getText().toString().replaceAll("%", "").replaceAll(",", "."));
String s = binding.seekbarValue.getText().toString().replaceAll("%", "").replaceAll(",", ".");
selectPercentageBinding.selpercentageNumber.setText(s);
final Runnable selectValue = () -> {
try {
String txt = selectPercentageBinding.selpercentageNumber.getText().toString();