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

View File

@ -121,7 +121,7 @@ public abstract class EditPGN extends ListActivity {
}); });
workThread.start(); workThread.start();
} else if ("org.petero.droidfish.loadFileNextGame".equals(action) || } else if ("org.petero.droidfish.loadFileNextGame".equals(action) ||
"org.petero.droidfish.loadFilePrevGame".equals(action)) { "org.petero.droidfish.loadFilePrevGame".equals(action)) {
pgnFile = new PGNFile(fileName); pgnFile = new PGNFile(fileName);
loadGame = true; loadGame = true;
boolean next = action.equals("org.petero.droidfish.loadFileNextGame"); boolean next = action.equals("org.petero.droidfish.loadFileNextGame");
@ -224,9 +224,9 @@ public abstract class EditPGN extends ListActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.item_delete_file: case R.id.item_delete_file:
reShowDialog(DELETE_PGN_FILE_DIALOG); reShowDialog(DELETE_PGN_FILE_DIALOG);
break; break;
} }
return false; return false;
} }
@ -271,12 +271,10 @@ public abstract class EditPGN extends ListActivity {
binding.selectGameFilter.addTextChangedListener(new TextWatcher() { binding.selectGameFilter.addTextChangedListener(new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) { }
}
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
@ -314,81 +312,81 @@ public abstract class EditPGN extends ListActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case PROGRESS_DIALOG: case PROGRESS_DIALOG:
progress = new ProgressDialog(this); progress = new ProgressDialog(this);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setTitle(R.string.reading_pgn_file); progress.setTitle(R.string.reading_pgn_file);
progress.setOnCancelListener(dialog -> { progress.setOnCancelListener(dialog -> {
canceled = true; canceled = true;
Thread thr = workThread; Thread thr = workThread;
if (thr != null) if (thr != null)
thr.interrupt(); thr.interrupt();
}); });
return progress; return progress;
case DELETE_GAME_DIALOG: { case DELETE_GAME_DIALOG: {
final GameInfo gi = selectedGi; final GameInfo gi = selectedGi;
selectedGi = null; selectedGi = null;
if (gi == 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; 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) { if (p.first != GameInfoResult.OK) {
gamesInFile = new ArrayList<>(); gamesInFile = new ArrayList<>();
switch (p.first) { switch (p.first) {
case OUT_OF_MEMORY: case OUT_OF_MEMORY:
runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT)); runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT));
break; break;
case NOT_PGN: case NOT_PGN:
runOnUiThread(() -> DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT)); runOnUiThread(() -> DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT));
break; break;
case CANCEL: case CANCEL:
case OK: case OK:
break; break;
} }
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();

View File

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

View File

@ -40,9 +40,7 @@ import org.petero.droidfish.databinding.SelectPercentageBinding;
import java.util.Locale; 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 { public class SeekBarPreference extends Preference implements OnSeekBarChangeListener {
private final static int maxValue = 1000; private final static int maxValue = 1000;
private final static int DEFAULT_VALUE = 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); title = getContext().getString(R.string.edit_randomization);
} }
builder.setTitle(title); 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 = () -> { final Runnable selectValue = () -> {
try { try {
String txt = selectPercentageBinding.selpercentageNumber.getText().toString(); String txt = selectPercentageBinding.selpercentageNumber.getText().toString();