mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-17 09:37:50 +01:00
Replace anonymous classes with lambda
This commit is contained in:
parent
d9bbc01d19
commit
0ea27cbfbd
|
@ -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) {
|
||||
button.setOnClickListener(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.setOnLongClickListener(v -> showMenu(activity));
|
||||
}
|
||||
|
||||
private boolean showMenu(Activity activity) {
|
||||
|
|
|
@ -673,27 +673,19 @@ public class DroidFish extends Activity
|
|||
guides.add(tg);
|
||||
|
||||
tg.setOverlay(new Overlay()
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
.setOnClickListener(v -> {
|
||||
guideShowOnStart = false;
|
||||
Editor editor = settings.edit();
|
||||
editor.putBoolean("guideShowOnStart", false);
|
||||
editor.apply();
|
||||
tourGuide.next();
|
||||
tourGuide = null;
|
||||
}
|
||||
}));
|
||||
|
||||
Sequence sequence = new Sequence.SequenceBuilder()
|
||||
.add(guides.toArray(new TourGuide[0]))
|
||||
.setDefaultOverlay(new Overlay()
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
tourGuide.next();
|
||||
}
|
||||
}))
|
||||
.setOnClickListener(v -> tourGuide.next()))
|
||||
.setDefaultPointer(new Pointer())
|
||||
.setContinueMethod(Sequence.ContinueMethod.OverlayListener)
|
||||
.build();
|
||||
|
@ -1136,19 +1128,15 @@ public class DroidFish extends Activity
|
|||
}
|
||||
});
|
||||
|
||||
moveList.setOnLongClickListener(new OnLongClickListener() {
|
||||
public boolean onLongClick(View v) {
|
||||
moveList.setOnLongClickListener(v -> {
|
||||
reShowDialog(MOVELIST_MENU_DIALOG);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
thinking.setOnLongClickListener(new OnLongClickListener() {
|
||||
public boolean onLongClick(View v) {
|
||||
thinking.setOnLongClickListener(v -> {
|
||||
if (mShowThinking || gameMode.analysisMode())
|
||||
if (!pvMoves.isEmpty())
|
||||
reShowDialog(THINKING_MENU_DIALOG);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
buttons = findViewById(R.id.buttons);
|
||||
|
@ -1160,48 +1148,28 @@ public class DroidFish extends Activity
|
|||
custom3ButtonActions.setImageButton(custom3Button, this);
|
||||
|
||||
modeButton = findViewById(R.id.modeButton);
|
||||
modeButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog(GAME_MODE_DIALOG);
|
||||
}
|
||||
});
|
||||
modeButton.setOnLongClickListener(new OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
modeButton.setOnClickListener(v -> showDialog(GAME_MODE_DIALOG));
|
||||
modeButton.setOnLongClickListener(v -> {
|
||||
drawerLayout.openDrawer(Gravity.LEFT);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
undoButton = findViewById(R.id.undoButton);
|
||||
undoButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
undoButton.setOnClickListener(v -> {
|
||||
setAutoMode(AutoMode.OFF);
|
||||
ctrl.undoMove();
|
||||
}
|
||||
});
|
||||
undoButton.setOnLongClickListener(new OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
undoButton.setOnLongClickListener(v -> {
|
||||
reShowDialog(GO_BACK_MENU_DIALOG);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
redoButton = findViewById(R.id.redoButton);
|
||||
redoButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
redoButton.setOnClickListener(v -> {
|
||||
setAutoMode(AutoMode.OFF);
|
||||
ctrl.redoMove();
|
||||
}
|
||||
});
|
||||
redoButton.setOnLongClickListener(new OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
redoButton.setOnLongClickListener(v -> {
|
||||
reShowDialog(GO_FORWARD_MENU_DIALOG);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1679,13 +1647,9 @@ public class DroidFish extends Activity
|
|||
leftDrawer.setAdapter(new ArrayAdapter<>(this,
|
||||
R.layout.drawer_list_item,
|
||||
leftItems));
|
||||
leftDrawer.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
leftDrawer.setOnItemClickListener((parent, view, position, id) -> {
|
||||
DrawerItem di = leftItems[position];
|
||||
handleDrawerSelection(di.id);
|
||||
}
|
||||
});
|
||||
|
||||
final DrawerItem[] rightItems = new DrawerItem[] {
|
||||
|
@ -1697,13 +1661,9 @@ public class DroidFish extends Activity
|
|||
rightDrawer.setAdapter(new ArrayAdapter<>(this,
|
||||
R.layout.drawer_list_item,
|
||||
rightItems));
|
||||
rightDrawer.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
rightDrawer.setOnItemClickListener((parent, view, position, id) -> {
|
||||
DrawerItem di = rightItems[position];
|
||||
handleDrawerSelection(di.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2279,24 +2239,9 @@ public class DroidFish extends Activity
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.option_new_game);
|
||||
builder.setMessage(R.string.start_new_game);
|
||||
builder.setNeutralButton(R.string.yes, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startNewGame(2);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.white, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startNewGame(0);
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(R.string.black, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startNewGame(1);
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(R.string.yes, (dialog, which) -> startNewGame(2));
|
||||
builder.setNegativeButton(R.string.white, (dialog, which) -> startNewGame(0));
|
||||
builder.setPositiveButton(R.string.black, (dialog, which) -> startNewGame(1));
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
@ -2326,11 +2271,7 @@ public class DroidFish extends Activity
|
|||
};
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.promote_pawn_to);
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
ctrl.reportPromotePiece(item);
|
||||
}
|
||||
});
|
||||
builder.setItems(items, (dialog, item) -> ctrl.reportPromotePiece(item));
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
@ -2347,8 +2288,7 @@ public class DroidFish extends Activity
|
|||
lst.add(getString(R.string.paste)); actions.add(PASTE);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.tools_menu);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case COPY_GAME: {
|
||||
String pgn = ctrl.getPGN();
|
||||
|
@ -2383,7 +2323,6 @@ public class DroidFish extends Activity
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2415,8 +2354,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.tools_menu);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case CLIPBOARD:
|
||||
showDialog(CLIPBOARD_DIALOG);
|
||||
|
@ -2441,7 +2379,6 @@ public class DroidFish extends Activity
|
|||
ctrl.repeatLastMove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2536,8 +2473,7 @@ public class DroidFish extends Activity
|
|||
lst.add(getString(R.string.save_game)); actions.add(SAVE_GAME);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.load_save_menu);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case LOAD_LAST_FILE:
|
||||
loadLastFile();
|
||||
|
@ -2558,7 +2494,6 @@ public class DroidFish extends Activity
|
|||
selectScidFile();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2605,15 +2540,12 @@ public class DroidFish extends Activity
|
|||
}
|
||||
|
||||
private Dialog selectBookDialog() {
|
||||
String[] fileNames = findFilesInDirectory(bookDir, new FileNameFilter() {
|
||||
@Override
|
||||
public boolean accept(String filename) {
|
||||
String[] fileNames = findFilesInDirectory(bookDir, filename -> {
|
||||
int dotIdx = filename.lastIndexOf(".");
|
||||
if (dotIdx < 0)
|
||||
return false;
|
||||
String ext = filename.substring(dotIdx+1);
|
||||
return ("ctg".equals(ext) || "bin".equals(ext));
|
||||
}
|
||||
});
|
||||
final int numFiles = fileNames.length;
|
||||
final String[] items = new String[numFiles + 3];
|
||||
|
@ -2635,8 +2567,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.select_opening_book_file);
|
||||
builder.setSingleChoiceItems(items, defaultItem, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setSingleChoiceItems(items, defaultItem, (dialog, item) -> {
|
||||
Editor editor = settings.edit();
|
||||
final String bookFile;
|
||||
if (item == numFiles)
|
||||
|
@ -2652,7 +2583,6 @@ public class DroidFish extends Activity
|
|||
bookOptions.filename = bookFile;
|
||||
setBookOptions();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2683,24 +2613,14 @@ public class DroidFish extends Activity
|
|||
engine.getName()));
|
||||
}
|
||||
}
|
||||
Collections.sort(oexEngines, new Comparator<Pair<String,String>>() {
|
||||
@Override
|
||||
public int compare(Pair<String, String> lhs, Pair<String, String> rhs) {
|
||||
return lhs.second.compareTo(rhs.second);
|
||||
}
|
||||
});
|
||||
Collections.sort(oexEngines, (lhs, rhs) -> lhs.second.compareTo(rhs.second));
|
||||
for (Pair<String,String> eng : oexEngines) {
|
||||
ids.add(base + EngineUtil.openExchangeDir + sep + eng.first);
|
||||
items.add(eng.second);
|
||||
}
|
||||
}
|
||||
|
||||
String[] fileNames = findFilesInDirectory(engineDir, new FileNameFilter() {
|
||||
@Override
|
||||
public boolean accept(String filename) {
|
||||
return !reservedEngineName(filename);
|
||||
}
|
||||
});
|
||||
String[] fileNames = findFilesInDirectory(engineDir, filename -> !reservedEngineName(filename));
|
||||
for (String file : fileNames) {
|
||||
ids.add(base + file);
|
||||
items.add(file);
|
||||
|
@ -2719,8 +2639,7 @@ public class DroidFish extends Activity
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.select_chess_engine);
|
||||
builder.setSingleChoiceItems(items.toArray(new String[0]), defaultItem,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
(dialog, item) -> {
|
||||
if ((item < 0) || (item >= nEngines))
|
||||
return;
|
||||
Editor editor = settings.edit();
|
||||
|
@ -2731,14 +2650,10 @@ public class DroidFish extends Activity
|
|||
int strength = settings.getInt("strength", 1000);
|
||||
setEngineOptions(false);
|
||||
setEngineStrength(engine, strength);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
builder.setOnCancelListener(dialog -> {
|
||||
if (!abortOnCancel)
|
||||
reShowDialog(MANAGE_ENGINES_DIALOG);
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2749,22 +2664,12 @@ public class DroidFish extends Activity
|
|||
|
||||
private Dialog selectPgnFileDialog() {
|
||||
return selectFileDialog(pgnDir, R.string.select_pgn_file, R.string.no_pgn_files,
|
||||
"currentPGNFile", new Loader() {
|
||||
@Override
|
||||
public void load(String pathName) {
|
||||
loadPGNFromFile(pathName);
|
||||
}
|
||||
});
|
||||
"currentPGNFile", pathName -> loadPGNFromFile(pathName));
|
||||
}
|
||||
|
||||
private Dialog selectFenFileDialog() {
|
||||
return selectFileDialog(fenDir, R.string.select_fen_file, R.string.no_fen_files,
|
||||
"currentFENFile", new Loader() {
|
||||
@Override
|
||||
public void load(String pathName) {
|
||||
loadFENFromFile(pathName);
|
||||
}
|
||||
});
|
||||
"currentFENFile", pathName -> loadFENFromFile(pathName));
|
||||
}
|
||||
|
||||
private Dialog selectFileDialog(final String defaultDir, int selectFileMsg, int noFilesMsg,
|
||||
|
@ -2788,14 +2693,12 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(selectFileMsg);
|
||||
builder.setSingleChoiceItems(fileNames, defaultItem, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setSingleChoiceItems(fileNames, defaultItem, (dialog, item) -> {
|
||||
dialog.dismiss();
|
||||
String sep = File.separator;
|
||||
String fn = fileNames[item].toString();
|
||||
String pathName = Environment.getExternalStorageDirectory() + sep + defaultDir + sep + fn;
|
||||
loader.load(pathName);
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2819,8 +2722,7 @@ public class DroidFish extends Activity
|
|||
items[numFiles] = getString(R.string.new_file);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.select_pgn_file_save);
|
||||
builder.setSingleChoiceItems(items, defaultItem, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setSingleChoiceItems(items, defaultItem, (dialog, item) -> {
|
||||
String pgnFile;
|
||||
if (item >= numFiles) {
|
||||
dialog.dismiss();
|
||||
|
@ -2832,7 +2734,6 @@ public class DroidFish extends Activity
|
|||
String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile;
|
||||
savePGNToFile(pathName);
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2845,33 +2746,25 @@ public class DroidFish extends Activity
|
|||
builder.setTitle(R.string.select_pgn_file_save);
|
||||
final EditText fileNameView = content.findViewById(R.id.create_pgn_filename);
|
||||
fileNameView.setText("");
|
||||
final Runnable savePGN = new Runnable() {
|
||||
public void run() {
|
||||
final Runnable savePGN = () -> {
|
||||
String pgnFile = fileNameView.getText().toString();
|
||||
if ((pgnFile.length() > 0) && !pgnFile.contains("."))
|
||||
pgnFile += ".pgn";
|
||||
String sep = File.separator;
|
||||
String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile;
|
||||
savePGNToFile(pathName);
|
||||
}
|
||||
};
|
||||
builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
savePGN.run();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> savePGN.run());
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
|
||||
final Dialog dialog = builder.create();
|
||||
fileNameView.setOnKeyListener(new OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
fileNameView.setOnKeyListener((v, keyCode, event) -> {
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||
savePGN.run();
|
||||
dialog.cancel();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
@ -2882,8 +2775,7 @@ public class DroidFish extends Activity
|
|||
String[] themeNames = new String[ColorTheme.themeNames.length];
|
||||
for (int i = 0; i < themeNames.length; i++)
|
||||
themeNames[i] = getString(ColorTheme.themeNames[i]);
|
||||
builder.setSingleChoiceItems(themeNames, -1, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setSingleChoiceItems(themeNames, -1, (dialog, item) -> {
|
||||
ColorTheme.instance().setTheme(settings, item);
|
||||
PieceSet.instance().readPrefs(settings);
|
||||
cb.setColors();
|
||||
|
@ -2891,7 +2783,6 @@ public class DroidFish extends Activity
|
|||
ctrl.prefsChanged(false);
|
||||
dialog.dismiss();
|
||||
overrideViewAttribs();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2907,8 +2798,7 @@ public class DroidFish extends Activity
|
|||
};
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.select_game_mode);
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(items, (dialog, item) -> {
|
||||
int gameModeType = -1;
|
||||
boolean matchPlayerNames = false;
|
||||
switch (item) {
|
||||
|
@ -2925,7 +2815,6 @@ public class DroidFish extends Activity
|
|||
newGameMode(gameModeType);
|
||||
setBoardFlip(matchPlayerNames);
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -2964,8 +2853,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.edit_game);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case EDIT_HEADERS:
|
||||
editHeaders();
|
||||
|
@ -2990,7 +2878,6 @@ public class DroidFish extends Activity
|
|||
break;
|
||||
}
|
||||
moveListMenuDlg = null;
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
moveListMenuDlg = alert;
|
||||
|
@ -3032,8 +2919,7 @@ public class DroidFish extends Activity
|
|||
gameResult.setSelection(Arrays.asList(items).indexOf(headers.get("Result")));
|
||||
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
headers.put("Event", event.getText().toString().trim());
|
||||
headers.put("Site", site .getText().toString().trim());
|
||||
headers.put("Date", date .getText().toString().trim());
|
||||
|
@ -3046,7 +2932,6 @@ public class DroidFish extends Activity
|
|||
headers.put("Result", res);
|
||||
ctrl.setHeaders(headers);
|
||||
setBoardFlip(true);
|
||||
}
|
||||
});
|
||||
|
||||
builder.show();
|
||||
|
@ -3076,18 +2961,16 @@ public class DroidFish extends Activity
|
|||
nag.setText(nagStr);
|
||||
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
String pre = preComment.getText().toString().trim();
|
||||
String post = postComment.getText().toString().trim();
|
||||
int nagVal = Node.strToNag(nag.getText().toString());
|
||||
|
||||
DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo();
|
||||
commInfo.preComment = pre;
|
||||
commInfo.postComment = post;
|
||||
commInfo.nag = nagVal;
|
||||
ctrl.setComments(commInfo);
|
||||
}
|
||||
DroidChessController.CommentInfo commInfo1 = new DroidChessController.CommentInfo();
|
||||
commInfo1.preComment = pre;
|
||||
commInfo1.postComment = post;
|
||||
commInfo1.nag = nagVal;
|
||||
ctrl.setComments(commInfo1);
|
||||
});
|
||||
|
||||
builder.show();
|
||||
|
@ -3127,8 +3010,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.analysis);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case ADD_ANALYSIS: {
|
||||
ArrayList<ArrayList<Move>> pvMovesTmp = pvMoves;
|
||||
|
@ -3175,7 +3057,6 @@ public class DroidFish extends Activity
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -3270,12 +3151,10 @@ public class DroidFish extends Activity
|
|||
});
|
||||
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
int p = seekBar.getProgress();
|
||||
int nPV = progressToNumPV(p, maxPV);
|
||||
setMultiPVMode(nPV);
|
||||
}
|
||||
});
|
||||
|
||||
builder.show();
|
||||
|
@ -3306,8 +3185,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.go_back);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case GOTO_START_GAME: ctrl.gotoMove(0); break;
|
||||
case GOTO_START_VAR: ctrl.gotoStartOfVariation(); break;
|
||||
|
@ -3319,7 +3197,6 @@ public class DroidFish extends Activity
|
|||
setAutoMode(AutoMode.BACKWARD);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -3346,8 +3223,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.go_forward);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case GOTO_END_VAR: ctrl.gotoMove(Integer.MAX_VALUE); break;
|
||||
case GOTO_NEXT_VAR: ctrl.changeVariation(1); break;
|
||||
|
@ -3358,7 +3234,6 @@ public class DroidFish extends Activity
|
|||
setAutoMode(AutoMode.FORWARD);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -3377,11 +3252,9 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(buttonActions.getMenuTitle());
|
||||
builder.setItems(names.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(names.toArray(new String[0]), (dialog, item) -> {
|
||||
UIAction a = actions.get(item);
|
||||
a.run();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -3400,8 +3273,7 @@ public class DroidFish extends Activity
|
|||
lst.add(getString(R.string.configure_network_engine)); actions.add(CONFIG_NET_ENGINE);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.option_manage_engines);
|
||||
builder.setItems(lst.toArray(new String[0]), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setItems(lst.toArray(new String[0]), (dialog, item) -> {
|
||||
switch (actions.get(item)) {
|
||||
case SELECT_ENGINE:
|
||||
reShowDialog(SELECT_ENGINE_DIALOG);
|
||||
|
@ -3413,7 +3285,6 @@ public class DroidFish extends Activity
|
|||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -3443,13 +3314,10 @@ public class DroidFish extends Activity
|
|||
}
|
||||
|
||||
private Dialog networkEngineDialog() {
|
||||
String[] fileNames = findFilesInDirectory(engineDir, new FileNameFilter() {
|
||||
@Override
|
||||
public boolean accept(String filename) {
|
||||
String[] fileNames = findFilesInDirectory(engineDir, filename -> {
|
||||
if (reservedEngineName(filename))
|
||||
return false;
|
||||
return EngineUtil.isNetEngine(filename);
|
||||
}
|
||||
});
|
||||
final int numItems = fileNames.length + 1;
|
||||
final String[] items = new String[numItems];
|
||||
|
@ -3472,8 +3340,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.configure_network_engine);
|
||||
builder.setSingleChoiceItems(items, defaultItem, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
builder.setSingleChoiceItems(items, defaultItem, (dialog, item) -> {
|
||||
if ((item < 0) || (item >= numItems))
|
||||
return;
|
||||
dialog.dismiss();
|
||||
|
@ -3483,14 +3350,8 @@ public class DroidFish extends Activity
|
|||
networkEngineToConfig = ids[item];
|
||||
reShowDialog(NETWORK_ENGINE_CONFIG_DIALOG);
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new Dialog.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
reShowDialog(MANAGE_ENGINES_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(dialog -> reShowDialog(MANAGE_ENGINES_DIALOG));
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
@ -3505,8 +3366,7 @@ public class DroidFish extends Activity
|
|||
builder.setTitle(R.string.create_network_engine);
|
||||
final EditText engineNameView = content.findViewById(R.id.create_network_engine);
|
||||
engineNameView.setText("");
|
||||
final Runnable createEngine = new Runnable() {
|
||||
public void run() {
|
||||
final Runnable createEngine = () -> {
|
||||
String engineName = engineNameView.getText().toString();
|
||||
String sep = File.separator;
|
||||
String pathName = Environment.getExternalStorageDirectory() + sep + engineDir + sep + engineName;
|
||||
|
@ -3527,36 +3387,19 @@ public class DroidFish extends Activity
|
|||
}
|
||||
networkEngineToConfig = pathName;
|
||||
reShowDialog(NETWORK_ENGINE_CONFIG_DIALOG);
|
||||
}
|
||||
};
|
||||
builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
createEngine.run();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new Dialog.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> createEngine.run());
|
||||
builder.setNegativeButton(R.string.cancel, (dialog, which) -> reShowDialog(NETWORK_ENGINE_DIALOG));
|
||||
builder.setOnCancelListener(dialog -> reShowDialog(NETWORK_ENGINE_DIALOG));
|
||||
|
||||
final Dialog dialog = builder.create();
|
||||
engineNameView.setOnKeyListener(new OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
engineNameView.setOnKeyListener((v, keyCode, event) -> {
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||
createEngine.run();
|
||||
dialog.cancel();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
@ -3583,51 +3426,30 @@ public class DroidFish extends Activity
|
|||
}
|
||||
hostNameView.setText(hostName);
|
||||
portView.setText(port);
|
||||
final Runnable writeConfig = new Runnable() {
|
||||
public void run() {
|
||||
String hostName = hostNameView.getText().toString();
|
||||
String port = portView.getText().toString();
|
||||
final Runnable writeConfig = () -> {
|
||||
String hostName1 = hostNameView.getText().toString();
|
||||
String port1 = portView.getText().toString();
|
||||
try {
|
||||
FileWriter fw = new FileWriter(new File(networkEngineToConfig), false);
|
||||
fw.write("NETE\n");
|
||||
fw.write(hostName); fw.write("\n");
|
||||
fw.write(port); fw.write("\n");
|
||||
fw.write(hostName1); fw.write("\n");
|
||||
fw.write(port1); fw.write("\n");
|
||||
fw.close();
|
||||
setEngineOptions(true);
|
||||
} catch (IOException e) {
|
||||
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
};
|
||||
builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
writeConfig.run();
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new Dialog.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
reShowDialog(DELETE_NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, (dialog, which) -> reShowDialog(NETWORK_ENGINE_DIALOG));
|
||||
builder.setOnCancelListener(dialog -> reShowDialog(NETWORK_ENGINE_DIALOG));
|
||||
builder.setNeutralButton(R.string.delete, (dialog, which) -> reShowDialog(DELETE_NETWORK_ENGINE_DIALOG));
|
||||
|
||||
final Dialog dialog = builder.create();
|
||||
portView.setOnKeyListener(new OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
portView.setOnKeyListener((v, keyCode, event) -> {
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||
writeConfig.run();
|
||||
dialog.cancel();
|
||||
|
@ -3635,7 +3457,6 @@ public class DroidFish extends Activity
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
@ -3647,8 +3468,7 @@ public class DroidFish extends Activity
|
|||
if (msg.lastIndexOf('/') >= 0)
|
||||
msg = msg.substring(msg.lastIndexOf('/')+1);
|
||||
builder.setMessage(getString(R.string.network_engine) + ": " + msg);
|
||||
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
builder.setPositiveButton(R.string.yes, (dialog, id) -> {
|
||||
new File(networkEngineToConfig).delete();
|
||||
String engine = settings.getString("engine", "stockfish");
|
||||
if (engine.equals(networkEngineToConfig)) {
|
||||
|
@ -3663,20 +3483,12 @@ public class DroidFish extends Activity
|
|||
}
|
||||
dialog.cancel();
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
builder.setNegativeButton(R.string.no, (dialog, id) -> {
|
||||
dialog.cancel();
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new Dialog.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(dialog -> reShowDialog(NETWORK_ENGINE_DIALOG));
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
@ -3777,12 +3589,10 @@ public class DroidFish extends Activity
|
|||
File extDir = Environment.getExternalStorageDirectory();
|
||||
String sep = File.separator;
|
||||
File dir = new File(extDir.getAbsolutePath() + sep + dirName);
|
||||
File[] files = dir.listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
File[] files = dir.listFiles(pathname -> {
|
||||
if (!pathname.isFile())
|
||||
return false;
|
||||
return (filter == null) || filter.accept(pathname.getAbsolutePath());
|
||||
}
|
||||
});
|
||||
if (files == null)
|
||||
files = new File[0];
|
||||
|
@ -3976,11 +3786,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
|
||||
private Handler handlerTimer = new Handler();
|
||||
private Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
ctrl.updateRemainingTime();
|
||||
}
|
||||
};
|
||||
private Runnable r = () -> ctrl.updateRemainingTime();
|
||||
|
||||
@Override
|
||||
public void setRemainingTime(int wTime, int bTime, int nextUpdate) {
|
||||
|
@ -3999,9 +3805,7 @@ public class DroidFish extends Activity
|
|||
}
|
||||
|
||||
private Handler autoModeTimer = new Handler();
|
||||
private Runnable amRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
private Runnable amRunnable = () -> {
|
||||
switch (autoMode) {
|
||||
case BACKWARD:
|
||||
ctrl.undoMove();
|
||||
|
@ -4014,7 +3818,6 @@ public class DroidFish extends Activity
|
|||
case OFF:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** Set automatic move forward/backward mode. */
|
||||
|
|
|
@ -65,9 +65,7 @@ public class Speech {
|
|||
initialized = true;
|
||||
if (initialized)
|
||||
return;
|
||||
tts = new TextToSpeech(context, new OnInitListener() {
|
||||
@Override
|
||||
public void onInit(int status) {
|
||||
tts = new TextToSpeech(context, status -> {
|
||||
initialized = true;
|
||||
int toast = -1;
|
||||
if (status == TextToSpeech.SUCCESS) {
|
||||
|
@ -100,7 +98,6 @@ public class Speech {
|
|||
}
|
||||
if (toast != -1)
|
||||
DroidFishApp.toast(toast, Toast.LENGTH_LONG);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
okButton.setOnClickListener(v -> sendBackResult());
|
||||
cancelButton.setOnClickListener(v -> {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
status.setFocusable(false);
|
||||
|
@ -294,10 +283,7 @@ 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) {
|
||||
leftDrawer.setOnItemClickListener((parent, view, position, id) -> {
|
||||
drawerLayout.closeDrawer(Gravity.LEFT);
|
||||
leftDrawer.clearChoices();
|
||||
DrawerItem di = leftItems.get(position);
|
||||
|
@ -369,7 +355,6 @@ public class EditBoard extends Activity {
|
|||
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -519,9 +504,8 @@ 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
|
||||
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();
|
||||
|
@ -530,7 +514,6 @@ public class EditBoard extends Activity {
|
|||
checkValidAndUpdateMaterialDiff();
|
||||
dialog.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -545,9 +528,7 @@ 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) {
|
||||
builder.setMultiChoiceItems(items, checkedItems, (dialog, which, isChecked) -> {
|
||||
Position pos = new Position(cb.pos);
|
||||
boolean a1Castle = pos.a1Castle();
|
||||
boolean h1Castle = pos.h1Castle();
|
||||
|
@ -567,7 +548,6 @@ public class EditBoard extends Activity {
|
|||
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) {
|
||||
builder.setSingleChoiceItems(items, getEPFile(), (dialog, item) -> {
|
||||
setEPFile(item);
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -595,8 +573,7 @@ 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() {
|
||||
final Runnable setCounters = () -> {
|
||||
try {
|
||||
int halfClock = Integer.parseInt(halfMoveClock.getText().toString());
|
||||
int fullCount = Integer.parseInt(fullMoveCounter.getText().toString());
|
||||
|
@ -605,26 +582,19 @@ public class EditBoard extends Activity {
|
|||
} 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) {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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,22 +204,12 @@ 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();
|
||||
}
|
||||
});
|
||||
cancelButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
okButton.setOnClickListener(v -> sendBackResult());
|
||||
cancelButton.setOnClickListener(v -> {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
resetButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
resetButton.setOnClickListener(v -> {
|
||||
if (uciOpts != null) {
|
||||
boolean modified = false;
|
||||
for (String name : uciOpts.getOptionNames()) {
|
||||
|
@ -268,7 +248,6 @@ public class EditOptions extends Activity {
|
|||
if (modified)
|
||||
initUI();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
workThread = new Thread(() -> {
|
||||
if (!readFile())
|
||||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
lpgn.showList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
workThread.start();
|
||||
} else if ("org.petero.droidfish.loadFileNextGame".equals(action) ||
|
||||
|
@ -138,12 +134,10 @@ public abstract class EditPGN extends ListActivity {
|
|||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
workThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
workThread = new Thread(() -> {
|
||||
if (!readFile())
|
||||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (loadItem >= gamesInFile.size()) {
|
||||
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
|
||||
setResult(RESULT_CANCELED);
|
||||
|
@ -152,9 +146,7 @@ public abstract class EditPGN extends ListActivity {
|
|||
defaultItem = loadItem;
|
||||
sendBackResult(gamesInFile.get(loadItem));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
workThread.start();
|
||||
}
|
||||
|
@ -170,12 +162,10 @@ 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() {
|
||||
workThread = new Thread(() -> {
|
||||
if (!readFile())
|
||||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
|
@ -185,9 +175,7 @@ public abstract class EditPGN extends ListActivity {
|
|||
} else {
|
||||
lpgn.showList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
workThread.start();
|
||||
}
|
||||
|
@ -266,9 +254,7 @@ 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) {
|
||||
lv.setOnItemClickListener((parent, view, pos, id) -> {
|
||||
selectedGi = aa.getItem(pos);
|
||||
if (selectedGi == null)
|
||||
return;
|
||||
|
@ -278,16 +264,12 @@ public abstract class EditPGN extends ListActivity {
|
|||
} else {
|
||||
reShowDialog(SAVE_GAME_DIALOG);
|
||||
}
|
||||
}
|
||||
});
|
||||
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) {
|
||||
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) {
|
||||
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) {
|
||||
builder.setPositiveButton(R.string.yes, (dialog, id14) -> {
|
||||
deleteGame(gi);
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.no, (dialog, id13) -> dialog.cancel());
|
||||
return builder.create();
|
||||
}
|
||||
case SAVE_GAME_DIALOG: {
|
||||
|
@ -379,8 +352,7 @@ 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) {
|
||||
builder.setItems(items, (dialog, item) -> {
|
||||
GameInfo giToReplace;
|
||||
switch (item) {
|
||||
case 0: giToReplace = new GameInfo().setNull(gi.startPos); break;
|
||||
|
@ -391,7 +363,6 @@ public abstract class EditPGN extends ListActivity {
|
|||
}
|
||||
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) {
|
||||
builder.setPositiveButton(R.string.yes, (dialog, id12) -> {
|
||||
pgnFile.delete();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
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:
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -105,8 +105,7 @@ public class LoadFEN extends ListActivity {
|
|||
progressLatch = new CountDownLatch(1);
|
||||
showProgressDialog();
|
||||
final LoadFEN lfen = this;
|
||||
workThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
workThread = new Thread(() -> {
|
||||
try {
|
||||
progressLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -116,17 +115,14 @@ public class LoadFEN extends ListActivity {
|
|||
}
|
||||
if (!readFile())
|
||||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
lfen.showList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
workThread.start();
|
||||
} else if ("org.petero.droidfish.loadNextFen".equals(action) ||
|
||||
|
@ -139,12 +135,10 @@ public class LoadFEN extends ListActivity {
|
|||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
workThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
workThread = new Thread(() -> {
|
||||
if (!readFile())
|
||||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (loadItem >= fensInFile.size()) {
|
||||
DroidFishApp.toast(R.string.no_next_fen, Toast.LENGTH_SHORT);
|
||||
setResult(RESULT_CANCELED);
|
||||
|
@ -153,9 +147,7 @@ public class LoadFEN extends ListActivity {
|
|||
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) {
|
||||
okButton.setOnClickListener(v -> {
|
||||
if (selectedFi != null)
|
||||
sendBackResult(selectedFi, false);
|
||||
}
|
||||
});
|
||||
cancelButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
cancelButton.setOnClickListener(v -> {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
Util.overrideViewAttribs(findViewById(android.R.id.content));
|
||||
|
@ -235,9 +223,7 @@ 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) {
|
||||
lv.setOnItemClickListener((parent, view, pos, id) -> {
|
||||
selectedFi = aa.getItem(pos);
|
||||
if (selectedFi == null)
|
||||
return;
|
||||
|
@ -252,11 +238,8 @@ public class LoadFEN extends ListActivity {
|
|||
cb.setPosition(chessPos);
|
||||
okButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) {
|
||||
lv.setOnItemLongClickListener((parent, view, pos, id) -> {
|
||||
selectedFi = aa.getItem(pos);
|
||||
if (selectedFi == null)
|
||||
return false;
|
||||
|
@ -270,7 +253,6 @@ public class LoadFEN extends ListActivity {
|
|||
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();
|
||||
|
|
|
@ -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,9 +135,7 @@ public class LoadScid extends ListActivity {
|
|||
progressLatch = new CountDownLatch(1);
|
||||
showProgressDialog();
|
||||
final LoadScid lpgn = this;
|
||||
startReadFile(new OnCursorReady() {
|
||||
@Override
|
||||
public void run(Cursor cursor) {
|
||||
startReadFile(cursor -> {
|
||||
try {
|
||||
progressLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -151,17 +145,14 @@ public class LoadScid extends ListActivity {
|
|||
}
|
||||
if (!readFile(cursor))
|
||||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
lpgn.showList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if ("org.petero.droidfish.loadScidNextGame".equals(action) ||
|
||||
"org.petero.droidfish.loadScidPrevGame".equals(action)) {
|
||||
|
@ -172,13 +163,10 @@ public class LoadScid extends ListActivity {
|
|||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
startReadFile(new OnCursorReady() {
|
||||
@Override
|
||||
public void run(Cursor cursor) {
|
||||
startReadFile(cursor -> {
|
||||
if (!readFile(cursor))
|
||||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (loadItem >= gamesInFile.size()) {
|
||||
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
|
||||
setResult(RESULT_CANCELED);
|
||||
|
@ -187,9 +175,7 @@ public class LoadScid extends ListActivity {
|
|||
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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -64,12 +64,9 @@ public class Preferences extends PreferenceActivity {
|
|||
currentItem = firstVisibleItem;
|
||||
}
|
||||
});
|
||||
lv.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lv.post(() -> {
|
||||
if (initialItem >= 0)
|
||||
lv.setSelection(initialItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -127,9 +127,7 @@ 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) {
|
||||
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);
|
||||
|
@ -143,36 +141,27 @@ public class SeekBarPreference extends Preference
|
|||
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() {
|
||||
final Runnable selectValue = () -> {
|
||||
try {
|
||||
String txt = valueView.getText().toString();
|
||||
int value = (int)(Double.parseDouble(txt) * 10 + 0.5);
|
||||
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) {
|
||||
valueView.setOnKeyListener((v1, keyCode, 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.setPositiveButton("Ok", (dialog, which) -> selectValue.run());
|
||||
builder.setNegativeButton("Cancel", null);
|
||||
|
||||
builder.create().show();
|
||||
}
|
||||
});
|
||||
|
||||
return layout;
|
||||
|
|
|
@ -135,15 +135,14 @@ public final class DroidBook {
|
|||
}
|
||||
|
||||
if (bookMoves != null) {
|
||||
Collections.sort(bookMoves, new Comparator<BookEntry>() {
|
||||
public int compare(BookEntry arg0, BookEntry arg1) {
|
||||
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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -648,22 +648,15 @@ public class DroidComputerPlayer {
|
|||
engineName = "Computer";
|
||||
uciEngine = UCIEngineBase.getEngine(searchRequest.engine,
|
||||
engineOptions,
|
||||
new UCIEngine.Report() {
|
||||
@Override
|
||||
public void reportError(String 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();
|
||||
|
|
|
@ -80,9 +80,7 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
}
|
||||
reNice();
|
||||
|
||||
startupThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startupThread = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -90,13 +88,10 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
}
|
||||
if (startedOk && isRunning && !isUCI)
|
||||
report.reportError(context.getString(R.string.uci_protocol_error));
|
||||
}
|
||||
});
|
||||
startupThread.start();
|
||||
|
||||
exitThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
exitThread = new Thread(() -> {
|
||||
try {
|
||||
Process ep = engineProc;
|
||||
if (ep != null)
|
||||
|
@ -109,14 +104,11 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
}
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
}
|
||||
});
|
||||
exitThread.start();
|
||||
|
||||
// Start a thread to read stdin
|
||||
stdInThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
stdInThread = new Thread(() -> {
|
||||
Process ep = engineProc;
|
||||
if (ep == null)
|
||||
return;
|
||||
|
@ -141,14 +133,11 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
} catch (IOException ignore) {
|
||||
}
|
||||
inLines.close();
|
||||
}
|
||||
});
|
||||
stdInThread.start();
|
||||
|
||||
// Start a thread to ignore stderr
|
||||
stdErrThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
stdErrThread = new Thread(() -> {
|
||||
byte[] buffer = new byte[128];
|
||||
while (true) {
|
||||
Process ep = engineProc;
|
||||
|
@ -162,7 +151,6 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
stdErrThread.start();
|
||||
} catch (IOException ex) {
|
||||
|
|
|
@ -112,9 +112,7 @@ 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() {
|
||||
startupThread = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -124,14 +122,11 @@ public class NetworkEngine extends UCIEngineBase {
|
|||
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() {
|
||||
stdInThread = new Thread(() -> {
|
||||
connect();
|
||||
try {
|
||||
InputStream is = socket.getInputStream();
|
||||
|
@ -163,14 +158,11 @@ public class NetworkEngine extends UCIEngineBase {
|
|||
}
|
||||
}
|
||||
engineToGui.close();
|
||||
}
|
||||
});
|
||||
stdInThread.start();
|
||||
|
||||
// Start a thread to write data to engine
|
||||
stdOutThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
stdOutThread = new Thread(() -> {
|
||||
try {
|
||||
connect();
|
||||
String line;
|
||||
|
@ -194,7 +186,6 @@ public class NetworkEngine extends UCIEngineBase {
|
|||
try { socket.getOutputStream().write("quit\n".getBytes()); } catch (IOException ignore) {}
|
||||
try { socket.close(); } catch (IOException ignore) {}
|
||||
}
|
||||
}
|
||||
});
|
||||
stdOutThread.start();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -240,8 +240,7 @@ public class DroidEngineControl {
|
|||
}
|
||||
tt.nextGeneration();
|
||||
final int srchmaxDepth = maxDepth;
|
||||
Runnable run = new Runnable() {
|
||||
public void run() {
|
||||
Runnable run = () -> {
|
||||
Move m = null;
|
||||
if (ownBook && !analyseMode) {
|
||||
Book book = new Book(false);
|
||||
|
@ -269,7 +268,6 @@ public class DroidEngineControl {
|
|||
engineThread = null;
|
||||
sc = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
ThreadGroup tg = new ThreadGroup("searcher");
|
||||
engineThread = new Thread(tg, run, "searcher", 32768);
|
||||
|
|
|
@ -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() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
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();
|
||||
|
|
|
@ -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() {
|
||||
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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.setOnTouchListener((view, motionEvent) -> {
|
||||
mViewHole.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} else if (mMotionType!=null && mMotionType == TourGuide.MotionType.SwipeOnly) {
|
||||
Log.d("tourguide","enforceMotionType 4");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 -> {});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user