Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarolus committed Apr 17, 2016
2 parents 1f7a727 + a419c0c commit d9cf223
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
}
}
compileSdkVersion 23
buildToolsVersion "23.0.0"
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "jwtc.android.chess"
minSdkVersion 11
Expand All @@ -28,7 +28,7 @@ android {
dependencies {
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:mediarouter-v7:22.2.1'
compile 'com.android.support:mediarouter-v7:23.1.1'
compile 'com.google.android.gms:play-services-cast:8.3.0'
compile 'com.google.android.gms:play-services-analytics:8.3.0'
compile files('libs/play-hub-support.jar')
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jwtc.android.chess"
android:versionCode="137"
android:versionName="8.6.9"
android:versionCode="138"
android:versionName="8.6.10"
android:installLocation="auto"
>
<application android:name=".MyApplication" android:icon="@drawable/icon" android:label="@string/app_name"
Expand Down
83 changes: 51 additions & 32 deletions app/src/main/java/jwtc/android/chess/ics/ICSClient.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package jwtc.android.chess.ics;

import android.Manifest;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.media.MediaPlayer;
Expand All @@ -16,6 +18,8 @@
import android.os.PowerManager;
import android.os.Vibrator;
import android.preference.PreferenceActivity;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.ClipboardManager;
import android.util.Log;
import android.view.*;
Expand Down Expand Up @@ -56,9 +60,9 @@ public class ICSClient extends MyBaseActivity implements OnItemClickListener {
private TelnetSocket _socket;
private Thread _workerTelnet;
private String _server, _handle, _pwd, _prompt, _waitFor, _buffer, _ficsHandle, _ficsPwd,
_sFile, _FEN = "", _whiteRating, _blackRating, _whiteHandle, _blackHandle, _resultMessage, _resultNumerical;
private int _port, _serverType, _TimeWarning, _gameStartSound;
private boolean _bIsGuest, _bInICS, _bAutoSought, _bTimeWarning, _bEndBuf, _bEndGameDialog,
_sFile, _FEN = "", _whiteRating, _blackRating, _whiteHandle, _blackHandle;
private int _port, _serverType, _TimeWarning, _gameStartSound, _iConsoleCharacterSize;
private boolean _bIsGuest, _bInICS, _bAutoSought, _bTimeWarning, _bEndGameDialog,
_gameStartFront, _bConsoleText;
private Button _butLogin;
private TextView _tvHeader, _tvConsole, _tvPlayConsole;
Expand Down Expand Up @@ -109,6 +113,9 @@ public class ICSClient extends MyBaseActivity implements OnItemClickListener {

//1269.allko ++++.kaspalesweb(U)
private Pattern _pattPlayerRow = Pattern.compile("(\\s+)?(.{4})([\\.\\:\\^\\ ])(\\w+)(\\(\\w+\\))?");
private Pattern _pattEndGame = Pattern.compile("(\\w+) \\((\\w+)\\) vs. (\\w+) \\((\\w+)\\) --- \\w+ (\\w+\\s+\\d{1,2}, )\\w.*(\\d{4})\\s(\\w.+)\\," +
" initial time: (\\d{1,3}) minutes, increment: (\\d{1,3})(.|\\n)*\\{(.*)\\} (.*)");
private Matcher _matgame;

private ArrayList<HashMap<String, String>> _mapChallenges = new ArrayList<HashMap<String, String>>();
private ArrayList<HashMap<String, String>> _mapPlayers = new ArrayList<HashMap<String, String>>();
Expand Down Expand Up @@ -235,8 +242,6 @@ public void onCreate(Bundle savedInstanceState) {
_dlgConfirm = new ICSConfirmDlg(this);
_dlgChat = new ICSChatDlg(this);
_dlgOver = new ICSGameOverDlg(this);
_resultMessage = "";
_resultNumerical = "";

_handle = null;
_pwd = null;
Expand All @@ -250,6 +255,7 @@ public void onCreate(Bundle savedInstanceState) {
_bIsGuest = true;
_serverType = SERVER_FICS;
_bInICS = false;
_iConsoleCharacterSize = 10;
_bAutoSought = true;
_bTimeWarning = true;
_bEndGameDialog = true;
Expand Down Expand Up @@ -469,13 +475,30 @@ public void onClick(View arg0) {
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.freechess.org/Register/index.html"));
startActivity(i);
} catch(Exception ex){
} catch (Exception ex) {

doToast("Could not go to registration page");
}
}
});
}

final int REQUEST_CODE_ASK_PERMISSIONS = 123; // Ask permission to write to external storage for android 6 and above
int hasWritePermission =
ContextCompat.checkSelfPermission(ICSClient.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if(hasWritePermission != PackageManager.PERMISSION_GRANTED){

if(!ActivityCompat.shouldShowRequestPermissionRationale(ICSClient.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
ActivityCompat.requestPermissions(ICSClient.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_ASK_PERMISSIONS);
} else {
globalToast("NEED PERMISSION TO WRITE GAMES TO SD CARD"); // Show toast if user denied permission
ActivityCompat.requestPermissions(ICSClient.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_ASK_PERMISSIONS);
}
}


_ringNotification = null;

switchToLoginView();
Expand Down Expand Up @@ -612,7 +635,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.string.ics_menu_abort:
sendString("abort");
get_view().stopGame();
// game will stop by way of toast
return true;
case R.string.ics_menu_adjourn:
sendString("adjourn");
Expand Down Expand Up @@ -1085,12 +1108,8 @@ else if(lines.length > 3 && _buffer.indexOf("Stored games for " + _handle + ":")
}
}
if (mat3.matches()){ // mat3 is the endgame result
_resultMessage = mat3.group(4);
_resultNumerical = mat3.group(5);

_bEndBuf = true;

sendString("oldmoves " + _whiteHandle);
sendString("oldmoves " + _whiteHandle); // send moves at end of game
Log.d(TAG, "oldmoves " + _whiteHandle);
}
}
Expand Down Expand Up @@ -1231,7 +1250,7 @@ else if (line.contains("{Game ") && (line.contains("} 1-0") || line.contains("}
else if (line.contains("} 1/2-1/2")){ // draw
gameToast(String.format(getString(R.string.ics_game_over_format), getString(R.string.state_draw)), true);
}
_dlgOver.updateGRtext(_resultMessage);

gameToast(String.format(getString(R.string.ics_game_over_format), text), true);

get_view().setViewMode(ICSChessView.VIEW_NONE);
Expand Down Expand Up @@ -1417,12 +1436,13 @@ else if (line.length() > 0) {
addConsoleText(sRaw);
}

if(_bEndBuf && _bEndGameDialog){
if (_bEndGameDialog){
sEnd += sRaw;
Log.d(TAG, "sEnd = " + sEnd);
if(sRaw.contains("---- ---------------- ----------------")){
//Log.d(TAG, "sEnd ->" + sEnd);

_matgame = _pattEndGame.matcher(sEnd);

_bEndBuf = false;
if(_matgame.matches()){

sEnd = sEnd.trim().replaceAll(" +", " ");
sEnd = sEnd.replaceAll("\\{.*\\}", "");
Expand All @@ -1431,15 +1451,6 @@ else if (line.length() > 0) {
event = event.replace("\n", "");
String site = "FICS";

DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
Date date1 = new Date();
String date = dateFormat.format(date1);

// Pattern variables
//White is _whitehandle - Black is _blackhandle
//Result is _resultMessage and _resultNumerical
//WhiteElo is _whiteRating - BlackElo is _blackRating

String timeControl = sEnd.substring(sEnd.indexOf("time:")+6, sEnd.indexOf(".", sEnd.indexOf("time:")));
String _FEN1, _FEN2;

Expand All @@ -1449,12 +1460,12 @@ else if (line.length() > 0) {
PGN = new StringBuilder("");
PGN.append("[Event \"" + event + "\"]\n");
PGN.append("[Site \"" + site + "\"]\n");
PGN.append("[Date \"" + date + "\"]\n");
PGN.append("[White \"" + _whiteHandle + "\"]\n");
PGN.append("[Black \"" + _blackHandle + "\"]\n");
PGN.append("[Result \"" + _resultNumerical + "\"]\n");
PGN.append("[WhiteElo \"" + _whiteRating + "\"]\n");
PGN.append("[BlackElo \"" + _blackRating + "\"]\n");
PGN.append("[Date \"" + _matgame.group(5) + _matgame.group(6) + "\"]\n");
PGN.append("[White \"" + _matgame.group(1) + "\"]\n");
PGN.append("[Black \"" + _matgame.group(3) + "\"]\n");
PGN.append("[Result \"" + _matgame.group(12) + "\"]\n");
PGN.append("[WhiteElo \"" + _matgame.group(2) + "\"]\n");
PGN.append("[BlackElo \"" + _matgame.group(4) + "\"]\n");
PGN.append("[TimeControl \"" + timeControl + "\"]\n");

if(!_FEN.equals("")) { // As for now, used for Chess960 FEN.
Expand All @@ -1470,6 +1481,8 @@ else if (line.length() > 0) {

saveGameSDCard();

_dlgOver.updateGRtext(_matgame.group(11)); // game result message sent to dialog

_dlgOver.setWasPlaying(get_view().getOpponent().length() > 0);
_dlgOver.show();
//_dlgOver.prepare();
Expand Down Expand Up @@ -1546,6 +1559,10 @@ public void addConsoleText(final String s) {
_tvConsole.setTypeface(Typeface.MONOSPACE); // Monospace gives each character the same width
_tvPlayConsole.setTypeface(Typeface.MONOSPACE);

_tvConsole.setTextSize(_iConsoleCharacterSize); // sets console text size
_tvPlayConsole.setTextSize(_iConsoleCharacterSize);


final String s2 = _tvConsole.getText() + "\n\n" + s;
if (s2.length() > 8192) {
_tvConsole.setText(s2.substring(s2.length() - 4096));
Expand Down Expand Up @@ -1600,6 +1617,8 @@ protected void onResume() {
_ficsHandle = prefs.getString("ics_handle", null);
_ficsPwd = prefs.getString("ics_password", null);

_iConsoleCharacterSize = Integer.parseInt(prefs.getString("ICSConsoleCharacterSize", "10"));

_bAutoSought = prefs.getBoolean("ICSAutoSought", true);

_bTimeWarning = prefs.getBoolean("ICSTimeWarning", true);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
<string name="pref_icsconfirmmove_desc">Confirmar manualmente un movimiento</string>
<string name="pref_icscustomcommand">Los comandos personalizados</string>
<string name="pref_icscustomcommand_desc">Crea tus propios comandos personalizados</string>
<string name="pref_icsconsolecharactersize">CONSOLA tamaño de la fuente</string>
<string name="pref_icsconsolecharactersize_desc">Regolare la dimensione dei caratteri in consolle</string>
<string name="pref_icsautosought">Buscado auto</string>
<string name="pref_icsautosought_desc">Refresque la pantalla desafíos automáticamente</string>
<string name="pref_icstimewarning">Advertencia de tiempo de baja</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
<string name="pref_icsconfirmmove_desc">Conferma manuale della mossa</string>
<string name="pref_icscustomcommand">Comandi personalizzati</string>
<string name="pref_icscustomcommand_desc">Crea i tuoi comandi personalizzati</string>
<string name="pref_icsconsolecharactersize">dimensione del carattere CONSOLE</string>
<string name="pref_icsconsolecharactersize_desc">Regolare la dimensione dei caratteri in consolle</string>
<string name="pref_icsautosought">Ricerca automatica</string>
<string name="pref_icsautosought_desc">Aggiorna automaticamente la finestra delle sfide</string>
<string name="pref_icstimewarning">Basso ora Avvertenza</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
<item>White</item>
<item>Black</item>
</string-array>
<string-array name="console_character_size">
<item>6</item><item>8</item><item>10</item><item>12</item>
<item>14</item><item>16</item><item>18</item>
</string-array>
<string-array name="console_character_size_values">
<item>6</item><item>8</item><item>10</item><item>12</item>
<item>14</item><item>16</item><item>18</item>
</string-array>
<string-array name="time_warning">
<item>5 seconds</item><item>10 seconds</item><item>25 seconds</item>
<item>45 seconds</item><item>1 minute</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
<string name="pref_icsconfirmmove_desc">Manually confirm a move</string>
<string name="pref_icscustomcommand">Custom commands</string>
<string name="pref_icscustomcommand_desc">Create your own custom commands</string>
<string name="pref_icsconsolecharactersize">CONSOLE character size</string>
<string name="pref_icsconsolecharactersize_desc">Adjust the size of characters in CONSOLE</string>
<string name="pref_icsautosought">Auto sought</string>
<string name="pref_icsautosought_desc">Refresh the challenges screen automatically</string>
<string name="pref_icstimewarning">Time Low Warning</string>
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/icsprefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
android:summary="@string/pref_icscustomcommand_desc"
android:key="icscustomcommandHandle" />

<ListPreference
android:title="@string/pref_icsconsolecharactersize"
android:key="ICSConsoleCharacterSize"
android:summary="@string/pref_icsconsolecharactersize_desc"
android:entries="@array/console_character_size"
android:entryValues="@array/console_character_size_values"
android:defaultValue="10"
/>

<CheckBoxPreference
android:title="@string/pref_icsautosought"
android:defaultValue="true"
Expand Down

0 comments on commit d9cf223

Please sign in to comment.