mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-12 00:52:40 +01:00
DroidFish: Cancel old toast before showing new.
This commit is contained in:
@@ -157,7 +157,7 @@ public class ChessBoardPlay extends ChessBoard {
|
|||||||
int pieceType = (pgnOptions == null) ? PGNOptions.PT_LOCAL
|
int pieceType = (pgnOptions == null) ? PGNOptions.PT_LOCAL
|
||||||
: pgnOptions.view.pieceType;
|
: pgnOptions.view.pieceType;
|
||||||
msg += ": " + TextIO.pieceAndSquareToString(pieceType, p, sq);
|
msg += ": " + TextIO.pieceAndSquareToString(pieceType, p, sq);
|
||||||
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(msg, Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setSelection(anyMatch ? sq : -1);
|
setSelection(anyMatch ? sq : -1);
|
||||||
|
|||||||
@@ -758,11 +758,9 @@ public class DroidFish extends Activity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data,
|
DroidFishApp.toast(R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(),
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
return new Pair<String,String>(pgnOrFen,filename);
|
return new Pair<String,String>(pgnOrFen,filename);
|
||||||
}
|
}
|
||||||
@@ -1666,7 +1664,7 @@ public class DroidFish extends Activity
|
|||||||
if (ctrl.claimDrawIfPossible())
|
if (ctrl.claimDrawIfPossible())
|
||||||
ctrl.stopPonder();
|
ctrl.stopPonder();
|
||||||
else
|
else
|
||||||
Toast.makeText(getApplicationContext(), R.string.offer_draw, Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(R.string.offer_draw, Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ITEM_SELECT_BOOK:
|
case ITEM_SELECT_BOOK:
|
||||||
@@ -1732,7 +1730,7 @@ public class DroidFish extends Activity
|
|||||||
ctrl.setFENOrPGN(pgn);
|
ctrl.setFENOrPGN(pgn);
|
||||||
setBoardFlip(true);
|
setBoardFlip(true);
|
||||||
} catch (ChessParseError e) {
|
} catch (ChessParseError e) {
|
||||||
Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(getParseErrString(e), Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -2294,7 +2292,7 @@ public class DroidFish extends Activity
|
|||||||
ctrl.setFENOrPGN(fenPgn.toString());
|
ctrl.setFENOrPGN(fenPgn.toString());
|
||||||
setBoardFlip(true);
|
setBoardFlip(true);
|
||||||
} catch (ChessParseError e) {
|
} catch (ChessParseError e) {
|
||||||
Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(getParseErrString(e), Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -2385,7 +2383,7 @@ public class DroidFish extends Activity
|
|||||||
ow.close();
|
ow.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String authority = "org.petero.droidfish.fileprovider";
|
String authority = "org.petero.droidfish.fileprovider";
|
||||||
@@ -2418,7 +2416,7 @@ public class DroidFish extends Activity
|
|||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3487,7 +3485,7 @@ public class DroidFish extends Activity
|
|||||||
errMsg = R.string.engine_name_in_use;
|
errMsg = R.string.engine_name_in_use;
|
||||||
}
|
}
|
||||||
if (!nameOk) {
|
if (!nameOk) {
|
||||||
Toast.makeText(getApplicationContext(), errMsg, Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(errMsg, Toast.LENGTH_LONG);
|
||||||
reShowDialog(NETWORK_ENGINE_DIALOG);
|
reShowDialog(NETWORK_ENGINE_DIALOG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3561,7 +3559,7 @@ public class DroidFish extends Activity
|
|||||||
fw.close();
|
fw.close();
|
||||||
setEngineOptions(true);
|
setEngineOptions(true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -3686,7 +3684,7 @@ public class DroidFish extends Activity
|
|||||||
try {
|
try {
|
||||||
startActivityForResult(intent, RESULT_SELECT_SCID);
|
startActivityForResult(intent, RESULT_SELECT_SCID);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3703,7 +3701,7 @@ public class DroidFish extends Activity
|
|||||||
try {
|
try {
|
||||||
startActivityForResult(i, RESULT_GET_FEN);
|
startActivityForResult(i, RESULT_GET_FEN);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3829,21 +3827,21 @@ public class DroidFish extends Activity
|
|||||||
String msg = String.format(Locale.US, "%s %s-%s",
|
String msg = String.format(Locale.US, "%s %s-%s",
|
||||||
getString(R.string.invalid_move),
|
getString(R.string.invalid_move),
|
||||||
TextIO.squareToString(m.from), TextIO.squareToString(m.to));
|
TextIO.squareToString(m.from), TextIO.squareToString(m.to));
|
||||||
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(msg, Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportEngineName(String engine) {
|
public void reportEngineName(String engine) {
|
||||||
String msg = String.format(Locale.US, "%s: %s",
|
String msg = String.format(Locale.US, "%s: %s",
|
||||||
getString(R.string.engine), engine);
|
getString(R.string.engine), engine);
|
||||||
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(msg, Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportEngineError(String errMsg) {
|
public void reportEngineError(String errMsg) {
|
||||||
String msg = String.format(Locale.US, "%s: %s",
|
String msg = String.format(Locale.US, "%s: %s",
|
||||||
getString(R.string.engine_error), errMsg);
|
getString(R.string.engine_error), errMsg);
|
||||||
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(msg, Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initialize text to speech if enabled in settings. */
|
/** Initialize text to speech if enabled in settings. */
|
||||||
@@ -3855,8 +3853,7 @@ public class DroidFish extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void movePlayed(Position pos, Move move, boolean computerMove) {
|
public void movePlayed(Position pos, Move move, boolean computerMove) {
|
||||||
if (move == null) {
|
if (move == null) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.engine_error,
|
DroidFishApp.toast(R.string.engine_error, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
newGameMode(GameMode.EDIT_GAME);
|
newGameMode(GameMode.EDIT_GAME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ package org.petero.droidfish;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class DroidFishApp extends Application {
|
public class DroidFishApp extends Application {
|
||||||
private static Context appContext;
|
private static Context appContext;
|
||||||
|
private static Toast toast;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
@@ -33,4 +36,28 @@ public class DroidFishApp extends Application {
|
|||||||
public static Context getContext() {
|
public static Context getContext() {
|
||||||
return appContext;
|
return appContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Show a toast after canceling current toast. */
|
||||||
|
public static void toast(int resId, int duration) {
|
||||||
|
if (toast != null) {
|
||||||
|
toast.cancel();
|
||||||
|
toast = null;
|
||||||
|
}
|
||||||
|
if (appContext != null) {
|
||||||
|
toast = Toast.makeText(appContext, resId, duration);
|
||||||
|
toast.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Show a toast after canceling current toast. */
|
||||||
|
public static void toast(CharSequence text, int duration) {
|
||||||
|
if (toast != null) {
|
||||||
|
toast.cancel();
|
||||||
|
toast = null;
|
||||||
|
}
|
||||||
|
if (appContext != null) {
|
||||||
|
toast = Toast.makeText(appContext, text, duration);
|
||||||
|
toast.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class Speech {
|
|||||||
toast = R.string.tts_failed_to_init;
|
toast = R.string.tts_failed_to_init;
|
||||||
}
|
}
|
||||||
if (toast != -1)
|
if (toast != -1)
|
||||||
Toast.makeText(context, toast, Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(toast, Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.petero.droidfish.DroidFish;
|
import org.petero.droidfish.DroidFish;
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.Util;
|
import org.petero.droidfish.Util;
|
||||||
import org.petero.droidfish.Util.MaterialDiff;
|
import org.petero.droidfish.Util.MaterialDiff;
|
||||||
@@ -367,7 +368,7 @@ public class EditBoard extends Activity {
|
|||||||
try {
|
try {
|
||||||
startActivityForResult(i, RESULT_GET_FEN);
|
startActivityForResult(i, RESULT_GET_FEN);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
DroidFishApp.toast(e.getMessage(), Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -607,7 +608,7 @@ public class EditBoard extends Activity {
|
|||||||
cb.pos.halfMoveClock = halfClock;
|
cb.pos.halfMoveClock = halfClock;
|
||||||
cb.pos.fullMoveCounter = fullCount;
|
cb.pos.fullMoveCounter = fullCount;
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.invalid_number_format, Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(R.string.invalid_number_format, Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -645,7 +646,7 @@ public class EditBoard extends Activity {
|
|||||||
} catch (ChessParseError e) {
|
} catch (ChessParseError e) {
|
||||||
if (e.pos != null)
|
if (e.pos != null)
|
||||||
cb.setPosition(e.pos);
|
cb.setPosition(e.pos);
|
||||||
Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(getParseErrString(e), Toast.LENGTH_SHORT);
|
||||||
}
|
}
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValidAndUpdateMaterialDiff();
|
checkValidAndUpdateMaterialDiff();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.petero.droidfish.ColorTheme;
|
import org.petero.droidfish.ColorTheme;
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
import org.petero.droidfish.ObjectCache;
|
import org.petero.droidfish.ObjectCache;
|
||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.Util;
|
import org.petero.droidfish.Util;
|
||||||
@@ -133,8 +134,7 @@ public class EditPGN extends ListActivity {
|
|||||||
boolean next = action.equals("org.petero.droidfish.loadFileNextGame");
|
boolean next = action.equals("org.petero.droidfish.loadFileNextGame");
|
||||||
final int loadItem = defaultItem + (next ? 1 : -1);
|
final int loadItem = defaultItem + (next ? 1 : -1);
|
||||||
if (loadItem < 0) {
|
if (loadItem < 0) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.no_prev_game,
|
DroidFishApp.toast(R.string.no_prev_game, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
@@ -145,8 +145,7 @@ public class EditPGN extends ListActivity {
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (loadItem >= gamesInFile.size()) {
|
if (loadItem >= gamesInFile.size()) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.no_next_game,
|
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
@@ -166,7 +165,7 @@ public class EditPGN extends ListActivity {
|
|||||||
boolean silent = i.getBooleanExtra("org.petero.droidfish.silent", false);
|
boolean silent = i.getBooleanExtra("org.petero.droidfish.silent", false);
|
||||||
if (silent) { // Silently append to file
|
if (silent) { // Silently append to file
|
||||||
PGNFile pgnFile2 = new PGNFile(fileName);
|
PGNFile pgnFile2 = new PGNFile(fileName);
|
||||||
pgnFile2.appendPGN(pgnToSave, null);
|
pgnFile2.appendPGN(pgnToSave);
|
||||||
} else {
|
} else {
|
||||||
pgnFile = new PGNFile(fileName);
|
pgnFile = new PGNFile(fileName);
|
||||||
showDialog(PROGRESS_DIALOG);
|
showDialog(PROGRESS_DIALOG);
|
||||||
@@ -181,7 +180,7 @@ public class EditPGN extends ListActivity {
|
|||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
} else if (gamesInFile.size() == 0) {
|
} else if (gamesInFile.size() == 0) {
|
||||||
pgnFile.appendPGN(pgnToSave, getApplicationContext());
|
pgnFile.appendPGN(pgnToSave);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
lpgn.showList();
|
lpgn.showList();
|
||||||
@@ -391,7 +390,7 @@ public class EditPGN extends ListActivity {
|
|||||||
default:
|
default:
|
||||||
finish(); return;
|
finish(); return;
|
||||||
}
|
}
|
||||||
pgnFile.replacePGN(pgnToSave, giToReplace, getApplicationContext());
|
pgnFile.replacePGN(pgnToSave, giToReplace);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -437,16 +436,14 @@ public class EditPGN extends ListActivity {
|
|||||||
case OUT_OF_MEMORY:
|
case OUT_OF_MEMORY:
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(getApplicationContext(), R.string.file_too_large,
|
DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case NOT_PGN:
|
case NOT_PGN:
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(getApplicationContext(), R.string.not_a_pgn_file,
|
DroidFishApp.toast(R.string.not_a_pgn_file, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -478,7 +475,7 @@ public class EditPGN extends ListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final void deleteGame(GameInfo gi) {
|
private final void deleteGame(GameInfo gi) {
|
||||||
if (pgnFile.deleteGame(gi, getApplicationContext(), 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<GameInfo>(this, R.layout.select_game_list_item, gamesInFile);
|
aa = new ArrayAdapter<GameInfo>(this, R.layout.select_game_list_item, gamesInFile);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
|
|
||||||
import org.petero.droidfish.ChessBoardPlay;
|
import org.petero.droidfish.ChessBoardPlay;
|
||||||
import org.petero.droidfish.ColorTheme;
|
import org.petero.droidfish.ColorTheme;
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.Util;
|
import org.petero.droidfish.Util;
|
||||||
import org.petero.droidfish.activities.FENFile.FenInfo;
|
import org.petero.droidfish.activities.FENFile.FenInfo;
|
||||||
@@ -135,8 +136,7 @@ public class LoadFEN extends ListActivity {
|
|||||||
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);
|
||||||
if (loadItem < 0) {
|
if (loadItem < 0) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.no_prev_fen,
|
DroidFishApp.toast(R.string.no_prev_fen, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
@@ -147,8 +147,7 @@ public class LoadFEN extends ListActivity {
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (loadItem >= fensInFile.size()) {
|
if (loadItem >= fensInFile.size()) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.no_next_fen,
|
DroidFishApp.toast(R.string.no_next_fen, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
@@ -338,8 +337,7 @@ public class LoadFEN extends ListActivity {
|
|||||||
if (p.first == FenInfoResult.OUT_OF_MEMORY) {
|
if (p.first == FenInfoResult.OUT_OF_MEMORY) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(getApplicationContext(), R.string.file_too_large,
|
DroidFishApp.toast(R.string.file_too_large, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.util.Vector;
|
|||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import org.petero.droidfish.ColorTheme;
|
import org.petero.droidfish.ColorTheme;
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
import org.petero.droidfish.ObjectCache;
|
import org.petero.droidfish.ObjectCache;
|
||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.Util;
|
import org.petero.droidfish.Util;
|
||||||
@@ -167,8 +168,7 @@ public class LoadScid extends ListActivity {
|
|||||||
boolean next = action.equals("org.petero.droidfish.loadScidNextGame");
|
boolean next = action.equals("org.petero.droidfish.loadScidNextGame");
|
||||||
final int loadItem = defaultItem + (next ? 1 : -1);
|
final int loadItem = defaultItem + (next ? 1 : -1);
|
||||||
if (loadItem < 0) {
|
if (loadItem < 0) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.no_prev_game,
|
DroidFishApp.toast(R.string.no_prev_game, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
@@ -180,8 +180,7 @@ public class LoadScid extends ListActivity {
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (loadItem >= gamesInFile.size()) {
|
if (loadItem >= gamesInFile.size()) {
|
||||||
Toast.makeText(getApplicationContext(), R.string.no_next_game,
|
DroidFishApp.toast(R.string.no_next_game, Toast.LENGTH_SHORT);
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.io.InputStream;
|
|||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.gamelogic.Pair;
|
import org.petero.droidfish.gamelogic.Pair;
|
||||||
|
|
||||||
@@ -398,20 +399,19 @@ public class PGNFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Append PGN to the end of this PGN file. */
|
/** Append PGN to the end of this PGN file. */
|
||||||
public final void appendPGN(String pgn, Context context) {
|
public final void appendPGN(String pgn) {
|
||||||
try {
|
try {
|
||||||
mkDirs();
|
mkDirs();
|
||||||
FileWriter fw = new FileWriter(fileName, true);
|
FileWriter fw = new FileWriter(fileName, true);
|
||||||
fw.write(pgn);
|
fw.write(pgn);
|
||||||
fw.close();
|
fw.close();
|
||||||
Toast.makeText(context, R.string.game_saved, Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(R.string.game_saved, Toast.LENGTH_SHORT);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (context != null)
|
DroidFishApp.toast(R.string.failed_to_save_game, Toast.LENGTH_SHORT);
|
||||||
Toast.makeText(context, R.string.failed_to_save_game, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean deleteGame(GameInfo gi, Context context, ArrayList<GameInfo> gamesInFile) {
|
final boolean deleteGame(GameInfo gi, ArrayList<GameInfo> gamesInFile) {
|
||||||
try {
|
try {
|
||||||
File tmpFile = new File(fileName + ".tmp_delete");
|
File tmpFile = new File(fileName + ".tmp_delete");
|
||||||
RandomAccessFile fileReader = new RandomAccessFile(fileName, "r");
|
RandomAccessFile fileReader = new RandomAccessFile(fileName, "r");
|
||||||
@@ -439,13 +439,12 @@ public class PGNFile {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (context != null)
|
DroidFishApp.toast(R.string.failed_to_delete_game, Toast.LENGTH_SHORT);
|
||||||
Toast.makeText(context, R.string.failed_to_delete_game, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean replacePGN(String pgnToSave, GameInfo gi, Context context) {
|
final boolean replacePGN(String pgnToSave, GameInfo gi) {
|
||||||
try {
|
try {
|
||||||
File tmpFile = new File(fileName + ".tmp_delete");
|
File tmpFile = new File(fileName + ".tmp_delete");
|
||||||
RandomAccessFile fileReader = new RandomAccessFile(fileName, "r");
|
RandomAccessFile fileReader = new RandomAccessFile(fileName, "r");
|
||||||
@@ -458,11 +457,10 @@ public class PGNFile {
|
|||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
if (!tmpFile.renameTo(fileName))
|
if (!tmpFile.renameTo(fileName))
|
||||||
throw new IOException();
|
throw new IOException();
|
||||||
Toast.makeText(context, R.string.game_saved, Toast.LENGTH_SHORT).show();
|
DroidFishApp.toast(R.string.game_saved, Toast.LENGTH_SHORT);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (context != null)
|
DroidFishApp.toast(R.string.failed_to_save_game, Toast.LENGTH_SHORT);
|
||||||
Toast.makeText(context, R.string.failed_to_save_game, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package org.petero.droidfish.activities;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.petero.droidfish.DroidFishApp;
|
||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -200,8 +201,7 @@ public class SeekBarPreference extends Preference
|
|||||||
if ("stockfish".equals(engine)) {
|
if ("stockfish".equals(engine)) {
|
||||||
showStrengthHint = false;
|
showStrengthHint = false;
|
||||||
if (getKey().equals("strength"))
|
if (getKey().equals("strength"))
|
||||||
Toast.makeText(getContext(), R.string.strength_cuckoo_hint,
|
DroidFishApp.toast(R.string.strength_cuckoo_hint, Toast.LENGTH_LONG);
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user