mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 11:31:33 +01:00
Use Java 8 in CuckooChessApp
This commit is contained in:
parent
ec36bfb123
commit
2e1227eed5
|
@ -35,6 +35,10 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = '1.8'
|
||||||
|
targetCompatibility = '1.8'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
|
@ -88,12 +88,9 @@ public class CuckooChess extends Activity implements GUIInterface {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
settings = PreferenceManager.getDefaultSharedPreferences(this);
|
settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
|
settings.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> {
|
||||||
@Override
|
readPrefs();
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
ctrl.setHumanWhite(playerWhite);
|
||||||
readPrefs();
|
|
||||||
ctrl.setHumanWhite(playerWhite);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
binding = ((MainBinding) DataBindingUtil.setContentView(this, R.layout.main)).content;
|
binding = ((MainBinding) DataBindingUtil.setContentView(this, R.layout.main)).content;
|
||||||
|
@ -140,19 +137,16 @@ public class CuckooChess extends Activity implements GUIInterface {
|
||||||
}
|
}
|
||||||
ctrl.startGame();
|
ctrl.startGame();
|
||||||
|
|
||||||
binding.chessboard.setOnTouchListener(new OnTouchListener() {
|
binding.chessboard.setOnTouchListener((v, event) -> {
|
||||||
@Override
|
if (ctrl.humansTurn() && (event.getAction() == MotionEvent.ACTION_UP)) {
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
int sq = binding.chessboard.eventToSquare(event);
|
||||||
if (ctrl.humansTurn() && (event.getAction() == MotionEvent.ACTION_UP)) {
|
Move m = binding.chessboard.mousePressed(sq);
|
||||||
int sq = binding.chessboard.eventToSquare(event);
|
if (m != null) {
|
||||||
Move m = binding.chessboard.mousePressed(sq);
|
ctrl.humanMove(m);
|
||||||
if (m != null) {
|
|
||||||
ctrl.humanMove(m);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
binding.chessboard.setOnTrackballListener(new ChessBoard.OnTrackballListener() {
|
binding.chessboard.setOnTrackballListener(new ChessBoard.OnTrackballListener() {
|
||||||
|
@ -165,13 +159,10 @@ public class CuckooChess extends Activity implements GUIInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
binding.chessboard.setOnLongClickListener(new OnLongClickListener() {
|
binding.chessboard.setOnLongClickListener(v -> {
|
||||||
@Override
|
if (!ctrl.computerThinking())
|
||||||
public boolean onLongClick(View v) {
|
showDialog(CLIPBOARD_DIALOG);
|
||||||
if (!ctrl.computerThinking())
|
return true;
|
||||||
showDialog(CLIPBOARD_DIALOG);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,44 +280,38 @@ public class CuckooChess extends Activity implements GUIInterface {
|
||||||
final CharSequence[] items = {"Queen", "Rook", "Bishop", "Knight"};
|
final CharSequence[] items = {"Queen", "Rook", "Bishop", "Knight"};
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle("Promote pawn to?");
|
builder.setTitle("Promote pawn to?");
|
||||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
builder.setItems(items, (dialog, item) -> ctrl.reportPromotePiece(item));
|
||||||
public void onClick(DialogInterface dialog, int item) {
|
|
||||||
ctrl.reportPromotePiece(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
case CLIPBOARD_DIALOG: {
|
case CLIPBOARD_DIALOG: {
|
||||||
final CharSequence[] items = {"Copy Game", "Copy Position", "Paste"};
|
final CharSequence[] items = {"Copy Game", "Copy Position", "Paste"};
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle("Clipboard");
|
builder.setTitle("Clipboard");
|
||||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
builder.setItems(items, (dialog, item) -> {
|
||||||
public void onClick(DialogInterface dialog, int item) {
|
switch (item) {
|
||||||
switch (item) {
|
case 0: {
|
||||||
case 0: {
|
String pgn = ctrl.getPGN();
|
||||||
String pgn = ctrl.getPGN();
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
clipboard.setText(pgn);
|
||||||
clipboard.setText(pgn);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
case 1: {
|
||||||
case 1: {
|
String fen = ctrl.getFEN() + "\n";
|
||||||
String fen = ctrl.getFEN() + "\n";
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
clipboard.setText(fen);
|
||||||
clipboard.setText(fen);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
case 2: {
|
||||||
case 2: {
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
if (clipboard.hasText()) {
|
||||||
if (clipboard.hasText()) {
|
String fenPgn = clipboard.getText().toString();
|
||||||
String fenPgn = clipboard.getText().toString();
|
try {
|
||||||
try {
|
ctrl.setFENOrPGN(fenPgn);
|
||||||
ctrl.setFENOrPGN(fenPgn);
|
} catch (ChessParseError e) {
|
||||||
} catch (ChessParseError e) {
|
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -338,11 +323,7 @@ public class CuckooChess extends Activity implements GUIInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestPromotePiece() {
|
public void requestPromotePiece() {
|
||||||
runOnUIThread(new Runnable() {
|
runOnUIThread(() -> showDialog(PROMOTE_DIALOG));
|
||||||
public void run() {
|
|
||||||
showDialog(PROMOTE_DIALOG);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user