Replace anonymous classes with lambda

This commit is contained in:
Hamidreza Bayat 2019-04-22 02:09:11 +04:30
parent d9bbc01d19
commit 0ea27cbfbd
26 changed files with 1024 additions and 1469 deletions

View File

@ -61,23 +61,15 @@ public class ButtonActions {
/** Connect GUI button. */
public void setImageButton(ImageButton button, final Activity activity) {
this.button = button;
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mainAction != null) {
if (mainAction.enabled())
mainAction.run();
} else {
showMenu(activity);
}
}
});
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return showMenu(activity);
button.setOnClickListener(v -> {
if (mainAction != null) {
if (mainAction.enabled())
mainAction.run();
} else {
showMenu(activity);
}
});
button.setOnLongClickListener(v -> showMenu(activity));
}
private boolean showMenu(Activity activity) {

File diff suppressed because it is too large Load Diff

View File

@ -65,42 +65,39 @@ public class Speech {
initialized = true;
if (initialized)
return;
tts = new TextToSpeech(context, new OnInitListener() {
@Override
public void onInit(int status) {
initialized = true;
int toast = -1;
if (status == TextToSpeech.SUCCESS) {
int code = TextToSpeech.LANG_NOT_SUPPORTED;
try {
code = tts.setLanguage(loc);
} catch (Throwable t) {
// Some Samsung devices are broken and throw an
// exception if the language is not supported
}
switch (code) {
case TextToSpeech.LANG_AVAILABLE:
case TextToSpeech.LANG_COUNTRY_AVAILABLE:
case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
lang = Language.fromString(langStr);
tts.addEarcon("[move]", "org.petero.droidfish", R.raw.movesound);
say(toSpeak);
break;
case TextToSpeech.LANG_MISSING_DATA:
toast = R.string.tts_data_missing;
break;
case TextToSpeech.LANG_NOT_SUPPORTED:
toast = R.string.tts_not_supported_for_lang;
break;
default:
break;
}
} else {
toast = R.string.tts_failed_to_init;
tts = new TextToSpeech(context, status -> {
initialized = true;
int toast = -1;
if (status == TextToSpeech.SUCCESS) {
int code = TextToSpeech.LANG_NOT_SUPPORTED;
try {
code = tts.setLanguage(loc);
} catch (Throwable t) {
// Some Samsung devices are broken and throw an
// exception if the language is not supported
}
if (toast != -1)
DroidFishApp.toast(toast, Toast.LENGTH_LONG);
switch (code) {
case TextToSpeech.LANG_AVAILABLE:
case TextToSpeech.LANG_COUNTRY_AVAILABLE:
case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
lang = Language.fromString(langStr);
tts.addEarcon("[move]", "org.petero.droidfish", R.raw.movesound);
say(toSpeak);
break;
case TextToSpeech.LANG_MISSING_DATA:
toast = R.string.tts_data_missing;
break;
case TextToSpeech.LANG_NOT_SUPPORTED:
toast = R.string.tts_not_supported_for_lang;
break;
default:
break;
}
} else {
toast = R.string.tts_failed_to_init;
}
if (toast != -1)
DroidFishApp.toast(toast, Toast.LENGTH_LONG);
});
}

View File

@ -173,25 +173,14 @@ public class EditBoard extends Activity {
initDrawers();
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(Gravity.LEFT);
}
};
OnClickListener listener = v -> drawerLayout.openDrawer(Gravity.LEFT);
firstTitleLine.setOnClickListener(listener);
secondTitleLine.setOnClickListener(listener);
okButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sendBackResult();
}
});
cancelButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setResult(RESULT_CANCELED);
finish();
}
okButton.setOnClickListener(v -> sendBackResult());
cancelButton.setOnClickListener(v -> {
setResult(RESULT_CANCELED);
finish();
});
status.setFocusable(false);
@ -294,80 +283,76 @@ public class EditBoard extends Activity {
leftDrawer.setAdapter(new ArrayAdapter<>(this,
R.layout.drawer_list_item,
leftItems.toArray(new DrawerItem[0])));
leftDrawer.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
drawerLayout.closeDrawer(Gravity.LEFT);
leftDrawer.clearChoices();
DrawerItem di = leftItems.get(position);
switch (di.id) {
case SIDE_TO_MOVE:
showDialog(SIDE_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case CLEAR_BOARD: {
Position pos = new Position();
leftDrawer.setOnItemClickListener((parent, view, position, id) -> {
drawerLayout.closeDrawer(Gravity.LEFT);
leftDrawer.clearChoices();
DrawerItem di = leftItems.get(position);
switch (di.id) {
case SIDE_TO_MOVE:
showDialog(SIDE_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case CLEAR_BOARD: {
Position pos = new Position();
cb.setPosition(pos);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
}
case INITIAL_POS: {
try {
Position pos = TextIO.readFEN(TextIO.startPosFEN);
cb.setPosition(pos);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
} catch (ChessParseError ignore) {
}
case INITIAL_POS: {
try {
Position pos = TextIO.readFEN(TextIO.startPosFEN);
cb.setPosition(pos);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
} catch (ChessParseError ignore) {
break;
}
case CASTLING_FLAGS:
reShowDialog(CASTLE_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case EN_PASSANT_FILE:
reShowDialog(EP_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case MOVE_COUNTERS:
reShowDialog(MOVCNT_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case COPY_POSITION: {
setPosFields();
String fen = TextIO.toFEN(cb.pos) + "\n";
ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(new ClipData(fen,
new String[]{ "application/x-chess-fen", ClipDescription.MIMETYPE_TEXT_PLAIN },
new ClipData.Item(fen)));
setSelection(-1);
break;
}
case PASTE_POSITION: {
ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null) {
if (clip.getItemCount() > 0) {
String fen = clip.getItemAt(0).coerceToText(getApplicationContext()).toString();
setFEN(fen);
}
break;
}
case CASTLING_FLAGS:
reShowDialog(CASTLE_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case EN_PASSANT_FILE:
reShowDialog(EP_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case MOVE_COUNTERS:
reShowDialog(MOVCNT_DIALOG);
setSelection(-1);
checkValidAndUpdateMaterialDiff();
break;
case COPY_POSITION: {
setPosFields();
String fen = TextIO.toFEN(cb.pos) + "\n";
ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(new ClipData(fen,
new String[]{ "application/x-chess-fen", ClipDescription.MIMETYPE_TEXT_PLAIN },
new ClipData.Item(fen)));
setSelection(-1);
break;
}
case PASTE_POSITION: {
ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null) {
if (clip.getItemCount() > 0) {
String fen = clip.getItemAt(0).coerceToText(getApplicationContext()).toString();
setFEN(fen);
}
}
break;
}
case GET_FEN:
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("application/x-chess-fen");
try {
startActivityForResult(i, RESULT_GET_FEN);
} catch (ActivityNotFoundException e) {
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
}
break;
}
case GET_FEN:
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("application/x-chess-fen");
try {
startActivityForResult(i, RESULT_GET_FEN);
} catch (ActivityNotFoundException e) {
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
}
}
});
@ -519,17 +504,15 @@ public class EditBoard extends Activity {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.select_side_to_move_first);
final int selectedItem = (cb.pos.whiteMove) ? 0 : 1;
builder.setSingleChoiceItems(new String[]{getString(R.string.white), getString(R.string.black)}, selectedItem, new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (id == 0) { // white to move
cb.pos.setWhiteMove(true);
checkValidAndUpdateMaterialDiff();
dialog.cancel();
} else {
cb.pos.setWhiteMove(false);
checkValidAndUpdateMaterialDiff();
dialog.cancel();
}
builder.setSingleChoiceItems(new String[]{getString(R.string.white), getString(R.string.black)}, selectedItem, (dialog, id1) -> {
if (id1 == 0) { // white to move
cb.pos.setWhiteMove(true);
checkValidAndUpdateMaterialDiff();
dialog.cancel();
} else {
cb.pos.setWhiteMove(false);
checkValidAndUpdateMaterialDiff();
dialog.cancel();
}
});
return builder.create();
@ -545,29 +528,26 @@ public class EditBoard extends Activity {
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.castling_flags);
builder.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
Position pos = new Position(cb.pos);
boolean a1Castle = pos.a1Castle();
boolean h1Castle = pos.h1Castle();
boolean a8Castle = pos.a8Castle();
boolean h8Castle = pos.h8Castle();
switch (which) {
case 0: h1Castle = isChecked; break;
case 1: a1Castle = isChecked; break;
case 2: h8Castle = isChecked; break;
case 3: a8Castle = isChecked; break;
}
int castleMask = 0;
if (a1Castle) castleMask |= 1 << Position.A1_CASTLE;
if (h1Castle) castleMask |= 1 << Position.H1_CASTLE;
if (a8Castle) castleMask |= 1 << Position.A8_CASTLE;
if (h8Castle) castleMask |= 1 << Position.H8_CASTLE;
pos.setCastleMask(castleMask);
cb.setPosition(pos);
checkValidAndUpdateMaterialDiff();
builder.setMultiChoiceItems(items, checkedItems, (dialog, which, isChecked) -> {
Position pos = new Position(cb.pos);
boolean a1Castle = pos.a1Castle();
boolean h1Castle = pos.h1Castle();
boolean a8Castle = pos.a8Castle();
boolean h8Castle = pos.h8Castle();
switch (which) {
case 0: h1Castle = isChecked; break;
case 1: a1Castle = isChecked; break;
case 2: h8Castle = isChecked; break;
case 3: a8Castle = isChecked; break;
}
int castleMask = 0;
if (a1Castle) castleMask |= 1 << Position.A1_CASTLE;
if (h1Castle) castleMask |= 1 << Position.H1_CASTLE;
if (a8Castle) castleMask |= 1 << Position.A8_CASTLE;
if (h8Castle) castleMask |= 1 << Position.H8_CASTLE;
pos.setCastleMask(castleMask);
cb.setPosition(pos);
checkValidAndUpdateMaterialDiff();
});
return builder.create();
}
@ -577,11 +557,9 @@ public class EditBoard extends Activity {
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.select_en_passant_file);
builder.setSingleChoiceItems(items, getEPFile(), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
setEPFile(item);
dialog.cancel();
}
builder.setSingleChoiceItems(items, getEPFile(), (dialog, item) -> {
setEPFile(item);
dialog.cancel();
});
return builder.create();
}
@ -595,36 +573,28 @@ public class EditBoard extends Activity {
final EditText fullMoveCounter = content.findViewById(R.id.ed_cnt_fullmove);
halfMoveClock.setText(String.format(Locale.US, "%d", cb.pos.halfMoveClock));
fullMoveCounter.setText(String.format(Locale.US, "%d", cb.pos.fullMoveCounter));
final Runnable setCounters = new Runnable() {
public void run() {
try {
int halfClock = Integer.parseInt(halfMoveClock.getText().toString());
int fullCount = Integer.parseInt(fullMoveCounter.getText().toString());
cb.pos.halfMoveClock = halfClock;
cb.pos.fullMoveCounter = fullCount;
} catch (NumberFormatException nfe) {
DroidFishApp.toast(R.string.invalid_number_format, Toast.LENGTH_SHORT);
}
final Runnable setCounters = () -> {
try {
int halfClock = Integer.parseInt(halfMoveClock.getText().toString());
int fullCount = Integer.parseInt(fullMoveCounter.getText().toString());
cb.pos.halfMoveClock = halfClock;
cb.pos.fullMoveCounter = fullCount;
} catch (NumberFormatException nfe) {
DroidFishApp.toast(R.string.invalid_number_format, Toast.LENGTH_SHORT);
}
};
builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setCounters.run();
}
});
builder.setPositiveButton("Ok", (dialog, which) -> setCounters.run());
builder.setNegativeButton("Cancel", null);
final Dialog dialog = builder.create();
fullMoveCounter.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
setCounters.run();
dialog.cancel();
return true;
}
return false;
fullMoveCounter.setOnKeyListener((v, keyCode, event) -> {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
setCounters.run();
dialog.cancel();
return true;
}
return false;
});
return dialog;
}

View File

@ -107,12 +107,7 @@ public class EditOptions extends Activity {
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);
}
});
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> co.set(isChecked));
content.addView(v);
break;
}
@ -177,12 +172,7 @@ public class EditOptions extends Activity {
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;
}
});
button.setOnCheckedChangeListener((buttonView, isChecked) -> bo.trigger = isChecked);
content.addView(v);
break;
}
@ -214,60 +204,49 @@ public class EditOptions extends Activity {
Button cancelButton = findViewById(R.id.eo_cancel);
Button resetButton = findViewById(R.id.eo_reset);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sendBackResult();
}
okButton.setOnClickListener(v -> sendBackResult());
cancelButton.setOnClickListener(v -> {
setResult(RESULT_CANCELED);
finish();
});
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setResult(RESULT_CANCELED);
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;
}
case BUTTON:
break;
}
resetButton.setOnClickListener(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;
}
case BUTTON:
break;
}
if (modified)
initUI();
}
if (modified)
initUI();
}
});
}

View File

@ -110,21 +110,17 @@ public abstract class EditPGN extends ListActivity {
loadGame = true;
showDialog(PROGRESS_DIALOG);
final EditPGN lpgn = this;
workThread = new Thread(new Runnable() {
public void run() {
if (!readFile())
return;
runOnUiThread(new Runnable() {
public void run() {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
} else {
lpgn.showList();
}
}
});
}
workThread = new Thread(() -> {
if (!readFile())
return;
runOnUiThread(() -> {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
} else {
lpgn.showList();
}
});
});
workThread.start();
} else if ("org.petero.droidfish.loadFileNextGame".equals(action) ||
@ -138,23 +134,19 @@ public abstract class EditPGN extends ListActivity {
setResult(RESULT_CANCELED);
finish();
} else {
workThread = new Thread(new Runnable() {
public void run() {
if (!readFile())
return;
runOnUiThread(new Runnable() {
public void run() {
if (loadItem >= gamesInFile.size()) {
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
setResult(RESULT_CANCELED);
finish();
} else {
defaultItem = loadItem;
sendBackResult(gamesInFile.get(loadItem));
}
}
});
}
workThread = new Thread(() -> {
if (!readFile())
return;
runOnUiThread(() -> {
if (loadItem >= gamesInFile.size()) {
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
setResult(RESULT_CANCELED);
finish();
} else {
defaultItem = loadItem;
sendBackResult(gamesInFile.get(loadItem));
}
});
});
workThread.start();
}
@ -170,24 +162,20 @@ public abstract class EditPGN extends ListActivity {
pgnFile = new PGNFile(fileName);
showDialog(PROGRESS_DIALOG);
final EditPGN lpgn = this;
workThread = new Thread(new Runnable() {
public void run() {
if (!readFile())
return;
runOnUiThread(new Runnable() {
public void run() {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
} else if (gamesInFile.size() == 0) {
pgnFile.appendPGN(pgnToSave);
finish();
} else {
lpgn.showList();
}
}
});
}
workThread = new Thread(() -> {
if (!readFile())
return;
runOnUiThread(() -> {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
} else if (gamesInFile.size() == 0) {
pgnFile.appendPGN(pgnToSave);
finish();
} else {
lpgn.showList();
}
});
});
workThread.start();
}
@ -266,28 +254,22 @@ public abstract class EditPGN extends ListActivity {
ListView lv = getListView();
lv.setSelectionFromTop(defaultItem, 0);
lv.setFastScrollEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
selectedGi = aa.getItem(pos);
if (selectedGi == null)
return;
if (loadGame) {
defaultItem = pos;
sendBackResult(selectedGi);
} else {
reShowDialog(SAVE_GAME_DIALOG);
}
lv.setOnItemClickListener((parent, view, pos, id) -> {
selectedGi = aa.getItem(pos);
if (selectedGi == null)
return;
if (loadGame) {
defaultItem = pos;
sendBackResult(selectedGi);
} else {
reShowDialog(SAVE_GAME_DIALOG);
}
});
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) {
selectedGi = aa.getItem(pos);
if (selectedGi != null && !selectedGi.isNull())
reShowDialog(DELETE_GAME_DIALOG);
return true;
}
lv.setOnItemLongClickListener((parent, view, pos, id) -> {
selectedGi = aa.getItem(pos);
if (selectedGi != null && !selectedGi.isNull())
reShowDialog(DELETE_GAME_DIALOG);
return true;
});
filterText = findViewById(R.id.select_game_filter);
@ -335,14 +317,11 @@ public abstract class EditPGN extends ListActivity {
progress = new ProgressDialog(this);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setTitle(R.string.reading_pgn_file);
progress.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
canceled = true;
Thread thr = workThread;
if (thr != null)
thr.interrupt();
}
progress.setOnCancelListener(dialog -> {
canceled = true;
Thread thr = workThread;
if (thr != null)
thr.interrupt();
});
return progress;
case DELETE_GAME_DIALOG: {
@ -354,17 +333,11 @@ public abstract class EditPGN extends ListActivity {
builder.setTitle(R.string.delete_game);
String msg = gi.toString();
builder.setMessage(msg);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
deleteGame(gi);
dialog.cancel();
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
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: {
@ -379,19 +352,17 @@ public abstract class EditPGN extends ListActivity {
getString(R.string.after_selected),
getString(R.string.replace_selected),
};
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int 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();
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();
}
@ -401,17 +372,11 @@ public abstract class EditPGN extends ListActivity {
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, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
pgnFile.delete();
finish();
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
builder.setPositiveButton(R.string.yes, (dialog, id12) -> {
pgnFile.delete();
finish();
});
builder.setNegativeButton(R.string.no, (dialog, id1) -> dialog.cancel());
return builder.create();
}
default:
@ -431,18 +396,10 @@ public abstract class EditPGN extends ListActivity {
gamesInFile = new ArrayList<>();
switch (p.first) {
case OUT_OF_MEMORY:
runOnUiThread(new Runnable() {
public void run() {
DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT);
}
});
runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT));
break;
case NOT_PGN:
runOnUiThread(new Runnable() {
public void run() {
DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT);
}
});
runOnUiThread(() -> DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT));
break;
case CANCEL:
case OK:

View File

@ -86,11 +86,7 @@ public class FENFile {
if (newPercent > percent) {
percent = newPercent;
if (progress != null) {
activity.runOnUiThread(new Runnable() {
public void run() {
progress.setProgress(newPercent);
}
});
activity.runOnUiThread(() -> progress.setProgress(newPercent));
}
}
if (Thread.currentThread().isInterrupted())

View File

@ -105,28 +105,24 @@ public class LoadFEN extends ListActivity {
progressLatch = new CountDownLatch(1);
showProgressDialog();
final LoadFEN lfen = this;
workThread = new Thread(new Runnable() {
public void run() {
try {
progressLatch.await();
} catch (InterruptedException e) {
workThread = new Thread(() -> {
try {
progressLatch.await();
} catch (InterruptedException e) {
setResult(RESULT_CANCELED);
finish();
return;
}
if (!readFile())
return;
runOnUiThread(() -> {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
return;
} else {
lfen.showList();
}
if (!readFile())
return;
runOnUiThread(new Runnable() {
public void run() {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
} else {
lfen.showList();
}
}
});
}
});
});
workThread.start();
} else if ("org.petero.droidfish.loadNextFen".equals(action) ||
@ -139,23 +135,19 @@ public class LoadFEN extends ListActivity {
setResult(RESULT_CANCELED);
finish();
} else {
workThread = new Thread(new Runnable() {
public void run() {
if (!readFile())
return;
runOnUiThread(new Runnable() {
public void run() {
if (loadItem >= fensInFile.size()) {
DroidFishApp.toast(R.string.no_next_fen, Toast.LENGTH_SHORT);
setResult(RESULT_CANCELED);
finish();
} else {
defaultItem = loadItem;
sendBackResult(fensInFile.get(loadItem), true);
}
}
});
}
workThread = new Thread(() -> {
if (!readFile())
return;
runOnUiThread(() -> {
if (loadItem >= fensInFile.size()) {
DroidFishApp.toast(R.string.no_next_fen, Toast.LENGTH_SHORT);
setResult(RESULT_CANCELED);
finish();
} else {
defaultItem = loadItem;
sendBackResult(fensInFile.get(loadItem), true);
}
});
});
workThread.start();
}
@ -206,17 +198,13 @@ public class LoadFEN extends ListActivity {
Button cancelButton = findViewById(R.id.loadfen_cancel);
okButton.setEnabled(false);
okButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (selectedFi != null)
sendBackResult(selectedFi, false);
}
okButton.setOnClickListener(v -> {
if (selectedFi != null)
sendBackResult(selectedFi, false);
});
cancelButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setResult(RESULT_CANCELED);
finish();
}
cancelButton.setOnClickListener(v -> {
setResult(RESULT_CANCELED);
finish();
});
Util.overrideViewAttribs(findViewById(android.R.id.content));
@ -235,42 +223,36 @@ public class LoadFEN extends ListActivity {
final ListView lv = getListView();
lv.setSelectionFromTop(defaultItem, 0);
lv.setFastScrollEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
selectedFi = aa.getItem(pos);
if (selectedFi == null)
return;
defaultItem = pos;
Position chessPos;
try {
chessPos = TextIO.readFEN(selectedFi.fen);
} catch (ChessParseError e2) {
chessPos = e2.pos;
}
if (chessPos != null) {
cb.setPosition(chessPos);
okButton.setEnabled(true);
}
lv.setOnItemClickListener((parent, view, pos, id) -> {
selectedFi = aa.getItem(pos);
if (selectedFi == null)
return;
defaultItem = pos;
Position chessPos;
try {
chessPos = TextIO.readFEN(selectedFi.fen);
} catch (ChessParseError e2) {
chessPos = e2.pos;
}
if (chessPos != null) {
cb.setPosition(chessPos);
okButton.setEnabled(true);
}
});
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) {
selectedFi = aa.getItem(pos);
if (selectedFi == null)
return false;
defaultItem = pos;
Position chessPos;
try {
chessPos = TextIO.readFEN(selectedFi.fen);
} catch (ChessParseError e2) {
chessPos = e2.pos;
}
if (chessPos != null)
sendBackResult(selectedFi, false);
return true;
lv.setOnItemLongClickListener((parent, view, pos, id) -> {
selectedFi = aa.getItem(pos);
if (selectedFi == null)
return false;
defaultItem = pos;
Position chessPos;
try {
chessPos = TextIO.readFEN(selectedFi.fen);
} catch (ChessParseError e2) {
chessPos = e2.pos;
}
if (chessPos != null)
sendBackResult(selectedFi, false);
return true;
});
lv.requestFocus();
}
@ -334,11 +316,7 @@ public class LoadFEN extends ListActivity {
if (p.first != FenInfoResult.OK) {
fensInFile = new ArrayList<>();
if (p.first == FenInfoResult.OUT_OF_MEMORY) {
runOnUiThread(new Runnable() {
public void run() {
DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT);
}
});
runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT));
}
setResult(RESULT_CANCELED);
finish();

View File

@ -101,11 +101,7 @@ public class LoadScid extends ListActivity {
}
@Override
public void onLoadFinished(Loader<Cursor> loader, final Cursor cursor) {
workThread = new Thread(new Runnable() {
public void run() {
r.run(cursor);
}
});
workThread = new Thread(() -> r.run(cursor));
workThread.start();
}
@Override
@ -139,29 +135,24 @@ public class LoadScid extends ListActivity {
progressLatch = new CountDownLatch(1);
showProgressDialog();
final LoadScid lpgn = this;
startReadFile(new OnCursorReady() {
@Override
public void run(Cursor cursor) {
try {
progressLatch.await();
} catch (InterruptedException e) {
startReadFile(cursor -> {
try {
progressLatch.await();
} catch (InterruptedException e) {
setResult(RESULT_CANCELED);
finish();
return;
}
if (!readFile(cursor))
return;
runOnUiThread(() -> {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
return;
} else {
lpgn.showList();
}
if (!readFile(cursor))
return;
runOnUiThread(new Runnable() {
public void run() {
if (canceled) {
setResult(RESULT_CANCELED);
finish();
} else {
lpgn.showList();
}
}
});
}
});
});
} else if ("org.petero.droidfish.loadScidNextGame".equals(action) ||
"org.petero.droidfish.loadScidPrevGame".equals(action)) {
@ -172,24 +163,19 @@ public class LoadScid extends ListActivity {
setResult(RESULT_CANCELED);
finish();
} else {
startReadFile(new OnCursorReady() {
@Override
public void run(Cursor cursor) {
if (!readFile(cursor))
return;
runOnUiThread(new Runnable() {
public void run() {
if (loadItem >= gamesInFile.size()) {
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
setResult(RESULT_CANCELED);
finish();
} else {
defaultItem = loadItem;
sendBackResult(gamesInFile.get(loadItem));
}
}
});
}
startReadFile(cursor -> {
if (!readFile(cursor))
return;
runOnUiThread(() -> {
if (loadItem >= gamesInFile.size()) {
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
setResult(RESULT_CANCELED);
finish();
} else {
defaultItem = loadItem;
sendBackResult(gamesInFile.get(loadItem));
}
});
});
}
} else { // Unsupported action
@ -249,12 +235,9 @@ public class LoadScid extends ListActivity {
Util.overrideViewAttribs(lv);
lv.setSelectionFromTop(defaultItem, 0);
lv.setFastScrollEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
defaultItem = pos;
sendBackResult(aa.getItem(pos));
}
lv.setOnItemClickListener((parent, view, pos, id) -> {
defaultItem = pos;
sendBackResult(aa.getItem(pos));
});
}
@ -323,11 +306,7 @@ public class LoadScid extends ListActivity {
if (newPercent > percent) {
percent = newPercent;
if (progress != null) {
runOnUiThread(new Runnable() {
public void run() {
progress.setProgress(newPercent);
}
});
runOnUiThread(() -> progress.setProgress(newPercent));
}
}
}

View File

@ -342,11 +342,7 @@ public class PGNFile {
if (newPercent > percent) {
percent = newPercent;
if (progress != null) {
activity.runOnUiThread(new Runnable() {
public void run() {
progress.setProgress(newPercent);
}
});
activity.runOnUiThread(() -> progress.setProgress(newPercent));
}
}
if (Thread.currentThread().isInterrupted())

View File

@ -64,12 +64,9 @@ public class Preferences extends PreferenceActivity {
currentItem = firstVisibleItem;
}
});
lv.post(new Runnable() {
@Override
public void run() {
if (initialItem >= 0)
lv.setSelection(initialItem);
}
lv.post(() -> {
if (initialItem >= 0)
lv.setSelection(initialItem);
});
}

View File

@ -127,52 +127,41 @@ public class SeekBarPreference extends Preference
layout.addView(summary);
layout.setId(android.R.id.widget_frame);
currValBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
builder.setView(content);
String title = "";
String key = getKey();
if (key.equals("strength")) {
title = getContext().getString(R.string.edit_strength);
} else if (key.equals("bookRandom")) {
title = getContext().getString(R.string.edit_randomization);
}
builder.setTitle(title);
final EditText valueView = content.findViewById(R.id.selpercentage_number);
valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
final Runnable selectValue = new Runnable() {
public void run() {
try {
String txt = valueView.getText().toString();
int value = (int)(Double.parseDouble(txt) * 10 + 0.5);
if (value < 0) value = 0;
if (value > maxValue) value = maxValue;
onProgressChanged(bar, value, false);
} catch (NumberFormatException ignore) {
}
}
};
valueView.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
selectValue.run();
return true;
}
return false;
}
});
builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
selectValue.run();
}
});
builder.setNegativeButton("Cancel", null);
builder.create().show();
currValBox.setOnClickListener(v -> {
View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
builder.setView(content);
String title = "";
String key = getKey();
if (key.equals("strength")) {
title = getContext().getString(R.string.edit_strength);
} else if (key.equals("bookRandom")) {
title = getContext().getString(R.string.edit_randomization);
}
builder.setTitle(title);
final EditText valueView = content.findViewById(R.id.selpercentage_number);
valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
final Runnable selectValue = () -> {
try {
String txt = valueView.getText().toString();
int value = (int) (Double.parseDouble(txt) * 10 + 0.5);
if (value < 0) value = 0;
if (value > maxValue) value = maxValue;
onProgressChanged(bar, value, false);
} catch (NumberFormatException ignore) {
}
};
valueView.setOnKeyListener((v1, keyCode, event) -> {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
selectValue.run();
return true;
}
return false;
});
builder.setPositiveButton("Ok", (dialog, which) -> selectValue.run());
builder.setNegativeButton("Cancel", null);
builder.create().show();
});
return layout;

View File

@ -135,15 +135,14 @@ public final class DroidBook {
}
if (bookMoves != null) {
Collections.sort(bookMoves, new Comparator<BookEntry>() {
public int compare(BookEntry arg0, BookEntry arg1) {
double wd = arg1.weight - arg0.weight;
if (wd != 0)
return (wd > 0) ? 1 : -1;
String str0 = TextIO.moveToUCIString(arg0.move);
String str1 = TextIO.moveToUCIString(arg1.move);
return str0.compareTo(str1);
}});
Collections.sort(bookMoves, (arg0, arg1) -> {
double wd = arg1.weight - arg0.weight;
if (wd != 0)
return (wd > 0) ? 1 : -1;
String str0 = TextIO.moveToUCIString(arg0.move);
String str1 = TextIO.moveToUCIString(arg1.move);
return str0.compareTo(str1);
});
double totalWeight = 0;
for (BookEntry be : bookMoves)
totalWeight += scaleWeight(be.weight);

View File

@ -41,12 +41,7 @@ final class InternalBook implements IOpeningBook {
private boolean enabled = false;
InternalBook() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
initInternalBook();
}
});
Thread t = new Thread(() -> initInternalBook());
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}

View File

@ -648,22 +648,15 @@ public class DroidComputerPlayer {
engineName = "Computer";
uciEngine = UCIEngineBase.getEngine(searchRequest.engine,
engineOptions,
new UCIEngine.Report() {
@Override
public void reportError(String errMsg) {
if (errMsg == null)
errMsg = "";
listener.reportEngineError(errMsg);
}
});
errMsg -> {
if (errMsg == null)
errMsg = "";
listener.reportEngineError(errMsg);
});
uciEngine.initialize();
final UCIEngine uci = uciEngine;
engineMonitor = new Thread(new Runnable() {
public void run() {
monitorLoop(uci);
}
});
engineMonitor = new Thread(() -> monitorLoop(uci));
engineMonitor.start();
uciEngine.clearOptions();

View File

@ -80,87 +80,75 @@ public class ExternalEngine extends UCIEngineBase {
}
reNice();
startupThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
return;
}
if (startedOk && isRunning && !isUCI)
report.reportError(context.getString(R.string.uci_protocol_error));
startupThread = new Thread(() -> {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
return;
}
if (startedOk && isRunning && !isUCI)
report.reportError(context.getString(R.string.uci_protocol_error));
});
startupThread.start();
exitThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Process ep = engineProc;
if (ep != null)
ep.waitFor();
isRunning = false;
if (!startedOk)
report.reportError(context.getString(R.string.failed_to_start_engine));
else {
report.reportError(context.getString(R.string.engine_terminated));
}
} catch (InterruptedException ignore) {
exitThread = new Thread(() -> {
try {
Process ep = engineProc;
if (ep != null)
ep.waitFor();
isRunning = false;
if (!startedOk)
report.reportError(context.getString(R.string.failed_to_start_engine));
else {
report.reportError(context.getString(R.string.engine_terminated));
}
} catch (InterruptedException ignore) {
}
});
exitThread.start();
// Start a thread to read stdin
stdInThread = new Thread(new Runnable() {
@Override
public void run() {
Process ep = engineProc;
if (ep == null)
return;
InputStream is = ep.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr, 8192);
String line;
try {
boolean first = true;
while ((line = br.readLine()) != null) {
if (Thread.currentThread().isInterrupted())
return;
synchronized (inLines) {
inLines.addLine(line);
if (first) {
startedOk = true;
isRunning = true;
first = false;
}
stdInThread = new Thread(() -> {
Process ep = engineProc;
if (ep == null)
return;
InputStream is = ep.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr, 8192);
String line;
try {
boolean first = true;
while ((line = br.readLine()) != null) {
if (Thread.currentThread().isInterrupted())
return;
synchronized (inLines) {
inLines.addLine(line);
if (first) {
startedOk = true;
isRunning = true;
first = false;
}
}
} catch (IOException ignore) {
}
inLines.close();
} catch (IOException ignore) {
}
inLines.close();
});
stdInThread.start();
// Start a thread to ignore stderr
stdErrThread = new Thread(new Runnable() {
@Override
public void run() {
byte[] buffer = new byte[128];
while (true) {
Process ep = engineProc;
if ((ep == null) || Thread.currentThread().isInterrupted())
return;
try {
int len = ep.getErrorStream().read(buffer, 0, 1);
if (len < 0)
break;
} catch (IOException e) {
return;
}
stdErrThread = new Thread(() -> {
byte[] buffer = new byte[128];
while (true) {
Process ep = engineProc;
if ((ep == null) || Thread.currentThread().isInterrupted())
return;
try {
int len = ep.getErrorStream().read(buffer, 0, 1);
if (len < 0)
break;
} catch (IOException e) {
return;
}
}
});

View File

@ -112,88 +112,79 @@ public class NetworkEngine extends UCIEngineBase {
@Override
protected void startProcess() {
// Start thread to check for startup error
startupThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
return;
}
if (startedOk && isRunning && !isUCI) {
isError = true;
report.reportError(context.getString(R.string.uci_protocol_error));
}
startupThread = new Thread(() -> {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
return;
}
if (startedOk && isRunning && !isUCI) {
isError = true;
report.reportError(context.getString(R.string.uci_protocol_error));
}
});
startupThread.start();
// Start a thread to read data from engine
stdInThread = new Thread(new Runnable() {
@Override
public void run() {
connect();
try {
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr, 8192);
String line;
boolean first = true;
while ((line = br.readLine()) != null) {
if (Thread.currentThread().isInterrupted())
return;
synchronized (engineToGui) {
engineToGui.addLine(line);
if (first) {
startedOk = true;
isRunning = true;
first = false;
}
stdInThread = new Thread(() -> {
connect();
try {
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr, 8192);
String line;
boolean first = true;
while ((line = br.readLine()) != null) {
if (Thread.currentThread().isInterrupted())
return;
synchronized (engineToGui) {
engineToGui.addLine(line);
if (first) {
startedOk = true;
isRunning = true;
first = false;
}
}
} catch (IOException ignore) {
} finally {
if (isRunning) {
isError = true;
isRunning = false;
if (!startedOk)
report.reportError(context.getString(R.string.failed_to_start_engine));
else
report.reportError(context.getString(R.string.engine_terminated));
}
}
engineToGui.close();
} catch (IOException ignore) {
} finally {
if (isRunning) {
isError = true;
isRunning = false;
if (!startedOk)
report.reportError(context.getString(R.string.failed_to_start_engine));
else
report.reportError(context.getString(R.string.engine_terminated));
}
}
engineToGui.close();
});
stdInThread.start();
// Start a thread to write data to engine
stdOutThread = new Thread(new Runnable() {
@Override
public void run() {
try {
connect();
String line;
while ((line = guiToEngine.readLine()) != null) {
if (Thread.currentThread().isInterrupted())
return;
line += "\n";
socket.getOutputStream().write(line.getBytes());
}
} catch (IOException e) {
if (isRunning) {
isError = true;
report.reportError(e.getMessage());
}
} finally {
if (isRunning && !isError) {
isError = true;
report.reportError(context.getString(R.string.engine_terminated));
}
isRunning = false;
try { socket.getOutputStream().write("quit\n".getBytes()); } catch (IOException ignore) {}
try { socket.close(); } catch (IOException ignore) {}
stdOutThread = new Thread(() -> {
try {
connect();
String line;
while ((line = guiToEngine.readLine()) != null) {
if (Thread.currentThread().isInterrupted())
return;
line += "\n";
socket.getOutputStream().write(line.getBytes());
}
} catch (IOException e) {
if (isRunning) {
isError = true;
report.reportError(e.getMessage());
}
} finally {
if (isRunning && !isError) {
isError = true;
report.reportError(context.getString(R.string.engine_terminated));
}
isRunning = false;
try { socket.getOutputStream().write("quit\n".getBytes()); } catch (IOException ignore) {}
try { socket.close(); } catch (IOException ignore) {}
}
});
stdOutThread.start();

View File

@ -60,11 +60,7 @@ public class CuckooChessEngine extends UCIEngineBase {
/** @inheritDoc */
@Override
protected final void startProcess() {
engineThread = new Thread(new Runnable() {
public void run() {
mainLoop(guiToEngine, engineToGui);
}
});
engineThread = new Thread(() -> mainLoop(guiToEngine, engineToGui));
int pMin = Thread.MIN_PRIORITY;
int pNorm = Thread.NORM_PRIORITY;
int prio = pMin + (pNorm - pMin) / 2;

View File

@ -240,35 +240,33 @@ public class DroidEngineControl {
}
tt.nextGeneration();
final int srchmaxDepth = maxDepth;
Runnable run = new Runnable() {
public void run() {
Move m = null;
if (ownBook && !analyseMode) {
Book book = new Book(false);
m = book.getBookMove(pos);
Runnable run = () -> {
Move m = null;
if (ownBook && !analyseMode) {
Book book = new Book(false);
m = book.getBookMove(pos);
}
if (m == null) {
m = sc.iterativeDeepening(srchMoves, srchmaxDepth, maxNodes, false);
}
while (ponder || infinite) {
// We should not respond until told to do so. Just wait until
// we are allowed to respond.
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
break;
}
if (m == null) {
m = sc.iterativeDeepening(srchMoves, srchmaxDepth, maxNodes, false);
}
while (ponder || infinite) {
// We should not respond until told to do so. Just wait until
// we are allowed to respond.
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
break;
}
}
Move ponderMove = getPonderMove(pos, m);
synchronized (threadMutex) {
if (ponderMove != null) {
os.printLine("bestmove %s ponder %s", moveToString(m), moveToString(ponderMove));
} else {
os.printLine("bestmove %s", moveToString(m));
}
engineThread = null;
sc = null;
}
Move ponderMove = getPonderMove(pos, m);
synchronized (threadMutex) {
if (ponderMove != null) {
os.printLine("bestmove %s ponder %s", moveToString(m), moveToString(ponderMove));
} else {
os.printLine("bestmove %s", moveToString(m));
}
engineThread = null;
sc = null;
}
};
ThreadGroup tg = new ThreadGroup("searcher");

View File

@ -791,11 +791,7 @@ public class DroidChessController {
ti.pvMoves = pvMoves;
ti.bookMoves = bookMoves;
latestThinkingInfo = ti;
gui.runOnUIThread(new Runnable() {
public void run() {
setThinkingInfo(ti);
}
});
gui.runOnUIThread(() -> setThinkingInfo(ti));
}
private void appendWithPrefix(StringBuilder sb, long value) {
@ -901,34 +897,20 @@ public class DroidChessController {
@Override
public void notifySearchResult(final int id, final String cmd, final Move ponder) {
new Thread(new Runnable() {
public void run() {
gui.runOnUIThread(new Runnable() {
public void run() {
makeComputerMove(id, cmd, ponder);
}
});
}
}).start();
new Thread(() -> gui.runOnUIThread(() -> makeComputerMove(id, cmd, ponder))).start();
}
@Override
public void notifyEngineName(final String engineName) {
gui.runOnUIThread(new Runnable() {
public void run() {
updatePlayerNames(engineName);
gui.reportEngineName(engineName);
}
gui.runOnUIThread(() -> {
updatePlayerNames(engineName);
gui.reportEngineName(engineName);
});
}
@Override
public void reportEngineError(final String errMsg) {
gui.runOnUIThread(new Runnable() {
public void run() {
gui.reportEngineError(errMsg);
}
});
gui.runOnUIThread(() -> gui.reportEngineError(errMsg));
}
}

View File

@ -37,14 +37,11 @@ class GtbProbe {
public final void setPath(String tbPath, boolean forceReload) {
if (forceReload || !tbPathQueue.isEmpty() || !currTbPath.equals(tbPath)) {
tbPathQueue.add(tbPath);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// Sleep 0.5s to increase probability that engine
// is initialized before TB.
try { Thread.sleep(500); } catch (InterruptedException ignore) { }
initIfNeeded();
}
Thread t = new Thread(() -> {
// Sleep 0.5s to increase probability that engine
// is initialized before TB.
try { Thread.sleep(500); } catch (InterruptedException ignore) { }
initIfNeeded();
});
t.setPriority(Thread.MIN_PRIORITY);
t.start();

View File

@ -37,14 +37,11 @@ public class RtbProbe {
public final void setPath(String tbPath, boolean forceReload) {
if (forceReload || !tbPathQueue.isEmpty() || !currTbPath.equals(tbPath)) {
tbPathQueue.add(tbPath);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// Sleep 0.4s to increase probability that engine
// is initialized before TB.
try { Thread.sleep(400); } catch (InterruptedException ignore) { }
initIfNeeded();
}
Thread t = new Thread(() -> {
// Sleep 0.4s to increase probability that engine
// is initialized before TB.
try { Thread.sleep(400); } catch (InterruptedException ignore) { }
initIfNeeded();
});
t.setPriority(Thread.MIN_PRIORITY);
t.start();

View File

@ -183,12 +183,7 @@ public abstract class ChessBoard extends View {
long delay = 20 - (now2 - now);
// System.out.printf("delay:%d\n", delay);
if (delay < 1) delay = 1;
handlerTimer.postDelayed(new Runnable() {
@Override
public void run() {
invalidate();
}
}, delay);
handlerTimer.postDelayed(() -> invalidate(), delay);
}
private void drawAnimPiece(Canvas canvas, int piece, int from, int to, double animState) {
if (piece == Piece.EMPTY)

View File

@ -50,12 +50,9 @@ public class FrameLayoutWithHole extends FrameLayout {
if (mMotionType!=null && mMotionType == TourGuide.MotionType.ClickOnly) {
Log.d("tourguide","enforceMotionType 3");
Log.d("tourguide","only Clicking");
mViewHole.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mViewHole.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
mViewHole.setOnTouchListener((view, motionEvent) -> {
mViewHole.getParent().requestDisallowInterceptTouchEvent(true);
return false;
});
} else if (mMotionType!=null && mMotionType == TourGuide.MotionType.SwipeOnly) {
Log.d("tourguide","enforceMotionType 4");

View File

@ -38,12 +38,7 @@ public class Sequence {
if(mContinueMethod == ContinueMethod.Overlay) {
for (final TourGuide tourGuide : mTourGuideArray) {
tourGuide.mOverlay.mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mParentTourGuide.next();
}
};
tourGuide.mOverlay.mOnClickListener = v -> mParentTourGuide.next();
}
}
}

View File

@ -265,9 +265,8 @@ public class TourGuide {
Log.w("tourguide", "Overlay's default OnClickListener is null, it will proceed to next tourguide when it is clicked");
frameLayoutWithHole.setViewHole(mHighlightedView);
frameLayoutWithHole.setSoundEffectsEnabled(false);
frameLayoutWithHole.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {} // do nothing, disabled.
});
// do nothing, disabled.
frameLayoutWithHole.setOnClickListener(v -> {});
}
}