mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 11:31:33 +01:00
Use binding in LoadFEN and EditPGN
This commit is contained in:
parent
0324409feb
commit
31d8ebab0e
|
@ -18,27 +18,12 @@
|
||||||
|
|
||||||
package org.petero.droidfish.activities;
|
package org.petero.droidfish.activities;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.petero.droidfish.ColorTheme;
|
|
||||||
import org.petero.droidfish.DroidFishApp;
|
|
||||||
import org.petero.droidfish.ObjectCache;
|
|
||||||
import org.petero.droidfish.R;
|
|
||||||
import org.petero.droidfish.Util;
|
|
||||||
import org.petero.droidfish.activities.PGNFile.GameInfo;
|
|
||||||
import org.petero.droidfish.activities.PGNFile.GameInfoResult;
|
|
||||||
import org.petero.droidfish.gamelogic.Pair;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.DialogInterface.OnCancelListener;
|
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -49,14 +34,26 @@ import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
import android.widget.AdapterView.OnItemLongClickListener;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
|
import org.petero.droidfish.ColorTheme;
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
|
import org.petero.droidfish.ObjectCache;
|
||||||
|
import org.petero.droidfish.R;
|
||||||
|
import org.petero.droidfish.Util;
|
||||||
|
import org.petero.droidfish.activities.PGNFile.GameInfo;
|
||||||
|
import org.petero.droidfish.activities.PGNFile.GameInfoResult;
|
||||||
|
import org.petero.droidfish.databinding.SelectGameBinding;
|
||||||
|
import org.petero.droidfish.gamelogic.Pair;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public abstract class EditPGN extends ListActivity {
|
public abstract class EditPGN extends ListActivity {
|
||||||
static ArrayList<GameInfo> gamesInFile = new ArrayList<>();
|
static ArrayList<GameInfo> gamesInFile = new ArrayList<>();
|
||||||
|
@ -65,8 +62,6 @@ public abstract class EditPGN extends ListActivity {
|
||||||
ProgressDialog progress;
|
ProgressDialog progress;
|
||||||
private GameInfo selectedGi = null;
|
private GameInfo selectedGi = null;
|
||||||
ArrayAdapter<GameInfo> aa = null;
|
ArrayAdapter<GameInfo> aa = null;
|
||||||
TextView hintText = null;
|
|
||||||
EditText filterText = null;
|
|
||||||
|
|
||||||
SharedPreferences settings;
|
SharedPreferences settings;
|
||||||
int defaultItem = 0;
|
int defaultItem = 0;
|
||||||
|
@ -80,6 +75,8 @@ public abstract class EditPGN extends ListActivity {
|
||||||
boolean loadGame; // True when loading game, false when saving
|
boolean loadGame; // True when loading game, false when saving
|
||||||
String pgnToSave;
|
String pgnToSave;
|
||||||
|
|
||||||
|
private SelectGameBinding binding;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -124,7 +121,7 @@ public abstract class EditPGN extends ListActivity {
|
||||||
});
|
});
|
||||||
workThread.start();
|
workThread.start();
|
||||||
} else if ("org.petero.droidfish.loadFileNextGame".equals(action) ||
|
} else if ("org.petero.droidfish.loadFileNextGame".equals(action) ||
|
||||||
"org.petero.droidfish.loadFilePrevGame".equals(action)) {
|
"org.petero.droidfish.loadFilePrevGame".equals(action)) {
|
||||||
pgnFile = new PGNFile(fileName);
|
pgnFile = new PGNFile(fileName);
|
||||||
loadGame = true;
|
loadGame = true;
|
||||||
boolean next = action.equals("org.petero.droidfish.loadFileNextGame");
|
boolean next = action.equals("org.petero.droidfish.loadFileNextGame");
|
||||||
|
@ -227,9 +224,9 @@ public abstract class EditPGN extends ListActivity {
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.item_delete_file:
|
case R.id.item_delete_file:
|
||||||
reShowDialog(DELETE_PGN_FILE_DIALOG);
|
reShowDialog(DELETE_PGN_FILE_DIALOG);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -237,7 +234,7 @@ public abstract class EditPGN extends ListActivity {
|
||||||
private void showList() {
|
private void showList() {
|
||||||
progress = null;
|
progress = null;
|
||||||
removeDialog(PROGRESS_DIALOG);
|
removeDialog(PROGRESS_DIALOG);
|
||||||
setContentView(R.layout.select_game);
|
binding = DataBindingUtil.setContentView(this, R.layout.select_game);
|
||||||
Util.overrideViewAttribs(findViewById(android.R.id.content));
|
Util.overrideViewAttribs(findViewById(android.R.id.content));
|
||||||
aa = new ArrayAdapter<GameInfo>(this, R.layout.select_game_list_item, gamesInFile) {
|
aa = new ArrayAdapter<GameInfo>(this, R.layout.select_game_list_item, gamesInFile) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -272,24 +269,26 @@ public abstract class EditPGN extends ListActivity {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
filterText = findViewById(R.id.select_game_filter);
|
binding.selectGameFilter.addTextChangedListener(new TextWatcher() {
|
||||||
filterText.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) { }
|
public void afterTextChanged(Editable s) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
aa.getFilter().filter(s);
|
aa.getFilter().filter(s);
|
||||||
lastSearchString = s.toString();
|
lastSearchString = s.toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
filterText.setText(lastSearchString);
|
binding.selectGameFilter.setText(lastSearchString);
|
||||||
hintText = findViewById(R.id.select_game_hint);
|
|
||||||
if (loadGame) {
|
if (loadGame) {
|
||||||
hintText.setVisibility(View.GONE);
|
binding.selectGameHint.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
hintText.setText(R.string.save_game_hint);
|
binding.selectGameHint.setText(R.string.save_game_hint);
|
||||||
}
|
}
|
||||||
lv.requestFocus();
|
lv.requestFocus();
|
||||||
}
|
}
|
||||||
|
@ -304,7 +303,9 @@ public abstract class EditPGN extends ListActivity {
|
||||||
final static int SAVE_GAME_DIALOG = 2;
|
final static int SAVE_GAME_DIALOG = 2;
|
||||||
final static int DELETE_PGN_FILE_DIALOG = 3;
|
final static int DELETE_PGN_FILE_DIALOG = 3;
|
||||||
|
|
||||||
/** Remove and show a dialog. */
|
/**
|
||||||
|
* Remove and show a dialog.
|
||||||
|
*/
|
||||||
private void reShowDialog(int id) {
|
private void reShowDialog(int id) {
|
||||||
removeDialog(id);
|
removeDialog(id);
|
||||||
showDialog(id);
|
showDialog(id);
|
||||||
|
@ -313,74 +314,81 @@ public abstract class EditPGN extends ListActivity {
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case PROGRESS_DIALOG:
|
case PROGRESS_DIALOG:
|
||||||
progress = new ProgressDialog(this);
|
progress = new ProgressDialog(this);
|
||||||
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
progress.setTitle(R.string.reading_pgn_file);
|
progress.setTitle(R.string.reading_pgn_file);
|
||||||
progress.setOnCancelListener(dialog -> {
|
progress.setOnCancelListener(dialog -> {
|
||||||
canceled = true;
|
canceled = true;
|
||||||
Thread thr = workThread;
|
Thread thr = workThread;
|
||||||
if (thr != null)
|
if (thr != null)
|
||||||
thr.interrupt();
|
thr.interrupt();
|
||||||
});
|
});
|
||||||
return progress;
|
return progress;
|
||||||
case DELETE_GAME_DIALOG: {
|
case DELETE_GAME_DIALOG: {
|
||||||
final GameInfo gi = selectedGi;
|
final GameInfo gi = selectedGi;
|
||||||
selectedGi = null;
|
selectedGi = null;
|
||||||
if (gi == null)
|
if (gi == null)
|
||||||
|
return null;
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setTitle(R.string.delete_game);
|
||||||
|
String msg = gi.toString();
|
||||||
|
builder.setMessage(msg);
|
||||||
|
builder.setPositiveButton(R.string.yes, (dialog, id14) -> {
|
||||||
|
deleteGame(gi);
|
||||||
|
dialog.cancel();
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.no, (dialog, id13) -> dialog.cancel());
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
case SAVE_GAME_DIALOG: {
|
||||||
|
final GameInfo gi = selectedGi;
|
||||||
|
selectedGi = null;
|
||||||
|
if (gi == null)
|
||||||
|
return null;
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setTitle(R.string.save_game_question);
|
||||||
|
final CharSequence[] items = {
|
||||||
|
getString(R.string.before_selected),
|
||||||
|
getString(R.string.after_selected),
|
||||||
|
getString(R.string.replace_selected),
|
||||||
|
};
|
||||||
|
builder.setItems(items, (dialog, item) -> {
|
||||||
|
GameInfo giToReplace;
|
||||||
|
switch (item) {
|
||||||
|
case 0:
|
||||||
|
giToReplace = new GameInfo().setNull(gi.startPos);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
giToReplace = new GameInfo().setNull(gi.endPos);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
giToReplace = gi;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pgnFile.replacePGN(pgnToSave, giToReplace);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
case DELETE_PGN_FILE_DIALOG: {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setTitle(R.string.delete_file_question);
|
||||||
|
String name = new File(pgnFile.getName()).getName();
|
||||||
|
String msg = String.format(Locale.US, getString(R.string.delete_named_file), name);
|
||||||
|
builder.setMessage(msg);
|
||||||
|
builder.setPositiveButton(R.string.yes, (dialog, id12) -> {
|
||||||
|
pgnFile.delete();
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.no, (dialog, id1) -> dialog.cancel());
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
default:
|
||||||
return null;
|
return null;
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
builder.setTitle(R.string.delete_game);
|
|
||||||
String msg = gi.toString();
|
|
||||||
builder.setMessage(msg);
|
|
||||||
builder.setPositiveButton(R.string.yes, (dialog, id14) -> {
|
|
||||||
deleteGame(gi);
|
|
||||||
dialog.cancel();
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(R.string.no, (dialog, id13) -> dialog.cancel());
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
case SAVE_GAME_DIALOG: {
|
|
||||||
final GameInfo gi = selectedGi;
|
|
||||||
selectedGi = null;
|
|
||||||
if (gi == null)
|
|
||||||
return null;
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
builder.setTitle(R.string.save_game_question);
|
|
||||||
final CharSequence[] items = {
|
|
||||||
getString(R.string.before_selected),
|
|
||||||
getString(R.string.after_selected),
|
|
||||||
getString(R.string.replace_selected),
|
|
||||||
};
|
|
||||||
builder.setItems(items, (dialog, item) -> {
|
|
||||||
GameInfo giToReplace;
|
|
||||||
switch (item) {
|
|
||||||
case 0: giToReplace = new GameInfo().setNull(gi.startPos); break;
|
|
||||||
case 1: giToReplace = new GameInfo().setNull(gi.endPos); break;
|
|
||||||
case 2: giToReplace = gi; break;
|
|
||||||
default:
|
|
||||||
finish(); return;
|
|
||||||
}
|
|
||||||
pgnFile.replacePGN(pgnToSave, giToReplace);
|
|
||||||
finish();
|
|
||||||
});
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
case DELETE_PGN_FILE_DIALOG: {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
builder.setTitle(R.string.delete_file_question);
|
|
||||||
String name = new File(pgnFile.getName()).getName();
|
|
||||||
String msg = String.format(Locale.US, getString(R.string.delete_named_file), name);
|
|
||||||
builder.setMessage(msg);
|
|
||||||
builder.setPositiveButton(R.string.yes, (dialog, id12) -> {
|
|
||||||
pgnFile.delete();
|
|
||||||
finish();
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(R.string.no, (dialog, id1) -> dialog.cancel());
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,15 +403,15 @@ public abstract class EditPGN extends ListActivity {
|
||||||
if (p.first != GameInfoResult.OK) {
|
if (p.first != GameInfoResult.OK) {
|
||||||
gamesInFile = new ArrayList<>();
|
gamesInFile = new ArrayList<>();
|
||||||
switch (p.first) {
|
switch (p.first) {
|
||||||
case OUT_OF_MEMORY:
|
case OUT_OF_MEMORY:
|
||||||
runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT));
|
runOnUiThread(() -> DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT));
|
||||||
break;
|
break;
|
||||||
case NOT_PGN:
|
case NOT_PGN:
|
||||||
runOnUiThread(() -> DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT));
|
runOnUiThread(() -> DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT));
|
||||||
break;
|
break;
|
||||||
case CANCEL:
|
case CANCEL:
|
||||||
case OK:
|
case OK:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
|
@ -431,10 +439,10 @@ public abstract class EditPGN extends ListActivity {
|
||||||
private void deleteGame(GameInfo gi) {
|
private void deleteGame(GameInfo gi) {
|
||||||
if (pgnFile.deleteGame(gi, gamesInFile)) {
|
if (pgnFile.deleteGame(gi, gamesInFile)) {
|
||||||
ListView lv = getListView();
|
ListView lv = getListView();
|
||||||
int pos = lv.pointToPosition(0,0);
|
int pos = lv.pointToPosition(0, 0);
|
||||||
aa = new ArrayAdapter<>(this, R.layout.select_game_list_item, gamesInFile);
|
aa = new ArrayAdapter<>(this, R.layout.select_game_list_item, gamesInFile);
|
||||||
setListAdapter(aa);
|
setListAdapter(aa);
|
||||||
String s = filterText.getText().toString();
|
String s = binding.selectGameFilter.getText().toString();
|
||||||
aa.getFilter().filter(s);
|
aa.getFilter().filter(s);
|
||||||
lv.setSelection(pos);
|
lv.setSelection(pos);
|
||||||
// Update lastModTime, since current change has already been handled
|
// Update lastModTime, since current change has already been handled
|
||||||
|
|
|
@ -18,22 +18,6 @@
|
||||||
|
|
||||||
package org.petero.droidfish.activities;
|
package org.petero.droidfish.activities;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
import org.petero.droidfish.ChessBoardPlay;
|
|
||||||
import org.petero.droidfish.ColorTheme;
|
|
||||||
import org.petero.droidfish.DroidFishApp;
|
|
||||||
import org.petero.droidfish.R;
|
|
||||||
import org.petero.droidfish.Util;
|
|
||||||
import org.petero.droidfish.activities.FENFile.FenInfo;
|
|
||||||
import org.petero.droidfish.activities.FENFile.FenInfoResult;
|
|
||||||
import org.petero.droidfish.gamelogic.ChessParseError;
|
|
||||||
import org.petero.droidfish.gamelogic.Pair;
|
|
||||||
import org.petero.droidfish.gamelogic.Position;
|
|
||||||
import org.petero.droidfish.gamelogic.TextIO;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
|
@ -48,16 +32,30 @@ import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
import android.widget.AdapterView.OnItemLongClickListener;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
|
import org.petero.droidfish.ColorTheme;
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
|
import org.petero.droidfish.R;
|
||||||
|
import org.petero.droidfish.Util;
|
||||||
|
import org.petero.droidfish.activities.FENFile.FenInfo;
|
||||||
|
import org.petero.droidfish.activities.FENFile.FenInfoResult;
|
||||||
|
import org.petero.droidfish.databinding.LoadFenBinding;
|
||||||
|
import org.petero.droidfish.gamelogic.ChessParseError;
|
||||||
|
import org.petero.droidfish.gamelogic.Pair;
|
||||||
|
import org.petero.droidfish.gamelogic.Position;
|
||||||
|
import org.petero.droidfish.gamelogic.TextIO;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class LoadFEN extends ListActivity {
|
public class LoadFEN extends ListActivity {
|
||||||
private static ArrayList<FenInfo> fensInFile = new ArrayList<>();
|
private static ArrayList<FenInfo> fensInFile = new ArrayList<>();
|
||||||
|
@ -76,8 +74,7 @@ public class LoadFEN extends ListActivity {
|
||||||
private CountDownLatch progressLatch = null;
|
private CountDownLatch progressLatch = null;
|
||||||
private boolean canceled = false;
|
private boolean canceled = false;
|
||||||
|
|
||||||
private ChessBoardPlay cb;
|
LoadFenBinding binding;
|
||||||
private Button okButton;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -126,7 +123,7 @@ public class LoadFEN extends ListActivity {
|
||||||
});
|
});
|
||||||
workThread.start();
|
workThread.start();
|
||||||
} else if ("org.petero.droidfish.loadNextFen".equals(action) ||
|
} else if ("org.petero.droidfish.loadNextFen".equals(action) ||
|
||||||
"org.petero.droidfish.loadPrevFen".equals(action)) {
|
"org.petero.droidfish.loadPrevFen".equals(action)) {
|
||||||
fenFile = new FENFile(fileName);
|
fenFile = new FENFile(fileName);
|
||||||
boolean next = action.equals("org.petero.droidfish.loadNextFen");
|
boolean next = action.equals("org.petero.droidfish.loadNextFen");
|
||||||
final int loadItem = defaultItem + (next ? 1 : -1);
|
final int loadItem = defaultItem + (next ? 1 : -1);
|
||||||
|
@ -192,17 +189,13 @@ public class LoadFEN extends ListActivity {
|
||||||
progress = null;
|
progress = null;
|
||||||
removeProgressDialog();
|
removeProgressDialog();
|
||||||
setContentView(R.layout.load_fen);
|
setContentView(R.layout.load_fen);
|
||||||
|
binding = DataBindingUtil.setContentView(this, R.layout.load_fen);
|
||||||
cb = findViewById(R.id.loadfen_chessboard);
|
binding.loadfenOk.setEnabled(false);
|
||||||
okButton = findViewById(R.id.loadfen_ok);
|
binding.loadfenOk.setOnClickListener(v -> {
|
||||||
Button cancelButton = findViewById(R.id.loadfen_cancel);
|
|
||||||
|
|
||||||
okButton.setEnabled(false);
|
|
||||||
okButton.setOnClickListener(v -> {
|
|
||||||
if (selectedFi != null)
|
if (selectedFi != null)
|
||||||
sendBackResult(selectedFi, false);
|
sendBackResult(selectedFi, false);
|
||||||
});
|
});
|
||||||
cancelButton.setOnClickListener(v -> {
|
binding.loadfenCancel.setOnClickListener(v -> {
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
|
@ -235,8 +228,8 @@ public class LoadFEN extends ListActivity {
|
||||||
chessPos = e2.pos;
|
chessPos = e2.pos;
|
||||||
}
|
}
|
||||||
if (chessPos != null) {
|
if (chessPos != null) {
|
||||||
cb.setPosition(chessPos);
|
binding.loadfenChessboard.setPosition(chessPos);
|
||||||
okButton.setEnabled(true);
|
binding.loadfenOk.setEnabled(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
lv.setOnItemLongClickListener((parent, view, pos, id) -> {
|
lv.setOnItemLongClickListener((parent, view, pos, id) -> {
|
||||||
|
@ -260,18 +253,18 @@ public class LoadFEN extends ListActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
if (cb != null) {
|
if (binding.loadfenChessboard != null) {
|
||||||
Position pos = cb.pos;
|
Position pos = binding.loadfenChessboard.pos;
|
||||||
showList();
|
showList();
|
||||||
cb.setPosition(pos);
|
binding.loadfenChessboard.setPosition(pos);
|
||||||
okButton.setEnabled(selectedFi != null);
|
binding.loadfenOk.setEnabled(selectedFi != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ProgressFragment extends DialogFragment {
|
public static class ProgressFragment extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
LoadFEN a = (LoadFEN)getActivity();
|
LoadFEN a = (LoadFEN) getActivity();
|
||||||
ProgressDialog progress = new ProgressDialog(a);
|
ProgressDialog progress = new ProgressDialog(a);
|
||||||
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
progress.setTitle(R.string.reading_fen_file);
|
progress.setTitle(R.string.reading_fen_file);
|
||||||
|
@ -279,12 +272,13 @@ public class LoadFEN extends ListActivity {
|
||||||
a.progressLatch.countDown();
|
a.progressLatch.countDown();
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
super.onCancel(dialog);
|
super.onCancel(dialog);
|
||||||
Activity a = getActivity();
|
Activity a = getActivity();
|
||||||
if (a instanceof LoadFEN) {
|
if (a instanceof LoadFEN) {
|
||||||
LoadFEN lf = (LoadFEN)a;
|
LoadFEN lf = (LoadFEN) a;
|
||||||
lf.canceled = true;
|
lf.canceled = true;
|
||||||
Thread thr = lf.workThread;
|
Thread thr = lf.workThread;
|
||||||
if (thr != null)
|
if (thr != null)
|
||||||
|
@ -301,7 +295,7 @@ public class LoadFEN extends ListActivity {
|
||||||
private void removeProgressDialog() {
|
private void removeProgressDialog() {
|
||||||
Fragment f = getFragmentManager().findFragmentByTag("progress");
|
Fragment f = getFragmentManager().findFragmentByTag("progress");
|
||||||
if (f instanceof DialogFragment)
|
if (f instanceof DialogFragment)
|
||||||
((DialogFragment)f).dismiss();
|
((DialogFragment) f).dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean readFile() {
|
private boolean readFile() {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical" />
|
android:orientation="vertical" />
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -44,6 +45,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@android:string/ok" />
|
android:text="@android:string/ok" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -1,54 +1,63 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
<LinearLayout
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:baselineAligned="false"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
<ListView
|
|
||||||
android:id="@android:id/list"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:focusable="false">
|
android:baselineAligned="false"
|
||||||
</ListView>
|
android:orientation="horizontal">
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
<ListView
|
||||||
android:layout_weight="2"
|
android:id="@android:id/list"
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:baselineAligned="false">
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<view
|
|
||||||
class="org.petero.droidfish.ChessBoardPlay"
|
|
||||||
android:id="@+id/loadfen_chessboard"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
</view>
|
|
||||||
</LinearLayout>
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent"
|
||||||
<Button
|
android:layout_weight="1"
|
||||||
android:id="@+id/loadfen_cancel"
|
android:focusable="false" />
|
||||||
android:text="@string/cancel"
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<org.petero.droidfish.ChessBoardPlay
|
||||||
|
android:id="@+id/loadfen_chessboard"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent"
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
android:id="@+id/loadfen_ok"
|
|
||||||
android:text="@android:string/ok"
|
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_width="fill_parent"
|
android:orientation="horizontal">
|
||||||
android:layout_height="fill_parent">
|
|
||||||
</Button>
|
<Button
|
||||||
|
android:id="@+id/loadfen_cancel"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/loadfen_ok"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@android:string/ok" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
|
||||||
|
</layout>
|
||||||
|
|
|
@ -1,49 +1,58 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:baselineAligned="false">
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<view
|
|
||||||
class="org.petero.droidfish.ChessBoardPlay"
|
|
||||||
android:id="@+id/loadfen_chessboard"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
</view>
|
|
||||||
</LinearLayout>
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<Button
|
|
||||||
android:id="@+id/loadfen_cancel"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/cancel">
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
android:text="@android:string/ok"
|
|
||||||
android:id="@+id/loadfen_ok"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
</Button>
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
<ListView
|
|
||||||
android:id="@android:id/list"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:focusable="false">
|
android:orientation="vertical">
|
||||||
</ListView>
|
|
||||||
</LinearLayout>
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<org.petero.droidfish.ChessBoardPlay
|
||||||
|
android:id="@+id/loadfen_chessboard"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/loadfen_cancel"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/loadfen_ok"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@android:string/ok" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@android:id/list"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:focusable="false" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</layout>
|
||||||
|
|
|
@ -1,28 +1,32 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
<LinearLayout
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/select_game_hint"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:includeFontPadding="true">
|
|
||||||
</TextView>
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/select_game_filter"
|
|
||||||
android:hint="@string/filter_text"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:inputType="text"
|
|
||||||
android:layout_margin="10dp">
|
|
||||||
</EditText>
|
|
||||||
<ListView
|
|
||||||
android:id="@android:id/list"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:focusable="false">
|
android:orientation="vertical">
|
||||||
</ListView>
|
|
||||||
</LinearLayout>
|
<TextView
|
||||||
|
android:id="@+id/select_game_hint"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:includeFontPadding="true" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/select_game_filter"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:hint="@string/filter_text"
|
||||||
|
android:inputType="text"
|
||||||
|
android:maxLines="1" />
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@android:id/list"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:focusable="false" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</layout>
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="Default Description"
|
android:text="Default Description"
|
||||||
android:textColor="@color/White" />
|
android:textColor="@color/White" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user