From b2e69acea9f33b3916cbb8ea9e3fa15ecbc4ba09 Mon Sep 17 00:00:00 2001 From: Tim Tennyson Date: Mon, 30 May 2016 12:05:12 -0700 Subject: [PATCH 01/13] Updated Examine View. Updated landscape mode. Fixed Bugs. --- .../jwtc/android/chess/ics/ICSChessView.java | 92 +++++++++++++----- .../jwtc/android/chess/ics/ICSClient.java | 22 ++--- .../android/chess/ics/ICSGameOverDlg.java | 21 +++- .../main/res/drawable/navigation_revert.png | Bin 0 -> 601 bytes app/src/main/res/layout-land/icsclient.xml | 86 ++++++++++++---- app/src/main/res/layout/ics_over.xml | 11 ++- app/src/main/res/layout/icsclient.xml | 65 +++++++++---- app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 223 insertions(+), 77 deletions(-) create mode 100644 app/src/main/res/drawable/navigation_revert.png diff --git a/app/src/main/java/jwtc/android/chess/ics/ICSChessView.java b/app/src/main/java/jwtc/android/chess/ics/ICSChessView.java index ac33a37d..76fe9f47 100644 --- a/app/src/main/java/jwtc/android/chess/ics/ICSChessView.java +++ b/app/src/main/java/jwtc/android/chess/ics/ICSChessView.java @@ -33,13 +33,14 @@ public class ICSChessView extends ChessViewBase { private JNI _jni; //private Button _butAction; private TextView _tvPlayerTop, _tvPlayerBottom, _tvPlayerTopRating, _tvPlayerBottomRating, - _tvClockTop, _tvClockBottom, _tvBoardNum, _tvLastMove; + _tvClockTop, _tvClockBottom, _tvBoardNum, _tvLastMove, _tvTimePerMove, _tvMoveNumber; //private EditText _editChat; + protected ImageButton _butImageBackward, _butImageForward, _butImageRevert; private Button _butConfirmMove, _butCancelMove; private ViewSwitcher _viewSwitchConfirm; private String _opponent, _whitePlayer, _blackPlayer, _playerMe; - private int m_iFrom, _iWhiteRemaining, _iBlackRemaining, _iGameNum, _iTurn, m_iTo; + private int m_iFrom, _iWhiteRemaining, _iBlackRemaining, _iGameNum, _iMe, _iTurn, m_iTo; private ICSClient _parent; private boolean _bHandleClick, _bOngoingGame, _bConfirmMove, _bCanPreMove, _bfirst; private Timer _timer; @@ -53,13 +54,16 @@ public class ICSChessView extends ChessViewBase { /** Gets called on every message that is received */ // @Override public void handleMessage(Message msg) { + if(_viewMode == VIEW_EXAMINE){ // No ticks during EXAMINE mode + return; + } if (msg.what == MSG_TOP_TIME) { _tvClockTop.setText(parseTime(msg.getData().getInt("ticks"))); } else { _tvClockBottom.setText(parseTime(msg.getData().getInt("ticks"))); } - if((msg.what == MSG_TOP_TIME && (_tvPlayerTop.getText()).equals(_playerMe)) + if((msg.what == MSG_TOP_TIME && (_tvPlayerTop.getText()).equals(_playerMe)) // Time Low Warning || (msg.what == MSG_BOTTOM_TIME && (_tvPlayerBottom.getText()).equals(_playerMe))){ if (_parent.is_bTimeWarning() && (msg.getData().getInt("ticks") <= _parent.get_TimeWarning()) && (msg.getData().getInt("ticks") > 0)) { try { @@ -104,6 +108,8 @@ public ICSChessView(Activity activity) { _tvBoardNum = (TextView) _activity.findViewById(R.id.TextViewICSBoardNum); //_tvViewMode = (TextView)_activity.findViewById(R.id.TextViewICSBoardViewMode); _tvLastMove = (TextView) _activity.findViewById(R.id.TextViewICSBoardLastMove); + _tvTimePerMove = (TextView) _activity.findViewById(R.id.TextViewICSTimePerMove); + _tvMoveNumber = (TextView) _activity.findViewById(R.id.TextViewMoveNumber); _butCancelMove = (Button) _activity.findViewById(R.id.ButtonCancelMove); _butCancelMove.setOnClickListener(new OnClickListener() { @@ -132,21 +138,28 @@ public void onClick(View arg0) { _viewSwitchConfirm = (ViewSwitcher) _activity.findViewById(R.id.ViewSitcherConfirmAndText); - /* - ImageButton butPrev = (ImageButton)_activity.findViewById((R.id.ButtonICSExamineRew)); - butPrev.setOnClickListener(new OnClickListener() { + _butImageBackward = (ImageButton)_activity.findViewById(R.id.ButtonICSExamineBackward); + _butImageBackward.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { _parent.sendString("backward"); } }); - ImageButton butNext = (ImageButton)_activity.findViewById((R.id.ButtonICSExamineFf)); - butNext.setOnClickListener(new OnClickListener() { + _butImageForward = (ImageButton)_activity.findViewById(R.id.ButtonICSExamineForward); + _butImageForward.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { _parent.sendString("forward"); } }); - */ + + _butImageRevert = (ImageButton)_activity.findViewById(R.id.ButtonICSRevert); + _butImageRevert.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View arg0) { + _parent.sendString("revert"); + } + }); + _timer = new Timer(true); _timer.schedule(new TimerTask() { @@ -233,6 +246,7 @@ public void setViewMode(final int iMode) { public void updateViewMode() { switch (_viewMode) { case VIEW_NONE: + setButtonExamineVisibility(false); Log.i(TAG, "Idle"); break; case VIEW_PLAY: @@ -254,6 +268,7 @@ public void updateViewMode() { Log.i(TAG, "Watch"); break; case VIEW_EXAMINE: + setButtonExamineVisibility(true); Log.i(TAG, "Examine"); break; case VIEW_PUZZLE: @@ -303,6 +318,16 @@ public void stopGame() { //paint(); } + public void setButtonExamineVisibility(boolean status){ + _butImageBackward.setVisibility(status ? View.VISIBLE : View.GONE); + _butImageForward.setVisibility(status ? View.VISIBLE : View.GONE); + _butImageRevert.setVisibility(status ? View.VISIBLE : View.GONE); + _tvTimePerMove.setVisibility(status ? View.VISIBLE : View.GONE); + + _tvPlayerTopRating.setVisibility(status ? View.GONE : View.VISIBLE); // EXAMINE pattern doesn't have ratings plus + _tvPlayerBottomRating.setVisibility(status ? View.GONE : View.VISIBLE); //it allows enough room for examine buttons in landscape mode + } + public synchronized boolean preParseGame(final String fLine) { try { // 64 fields + 8 spaces = 72 @@ -340,7 +365,9 @@ public synchronized boolean preParseGame(final String fLine) { } public synchronized boolean parseGame(String line, String sMe) { - //Log.i("parseGame", line); + //Log.i(TAG, "parseGame" + line); + + String _sNumberOfMove; try { //<12> rnbqkb-r pppppppp -----n-- -------- ----P--- -------- PPPPKPPP RNBQ-BNR B -1 0 0 1 1 0 7 Newton Einstein 1 2 12 39 39 119 122 2 K/e1-e2 (0:06) Ke2 0 @@ -387,8 +414,9 @@ public synchronized boolean parseGame(String line, String sMe) { //_flippedBoard = false; //B 0 0 1 1 0 7 Newton Einstein 1 2 12 39 39 119 122 2 K/e1-e2 (0:06) Ke2 0 StringTokenizer st = new StringTokenizer(line); - _iTurn = BoardConstants.WHITE; - if (st.nextToken().equals("B")) { + String _sTurn = st.nextToken(); // _sTurn is "W" or "B" + _iTurn = BoardConstants.WHITE; // _iTurn is 1 or 0 + if (_sTurn.equals("B")) { _jni.setTurn(BoardConstants.BLACK); _iTurn = BoardConstants.BLACK; } @@ -432,16 +460,29 @@ public synchronized boolean parseGame(String line, String sMe) { } _bfirst = false; } - int iMe = Integer.parseInt(st.nextToken()); + _iMe = Integer.parseInt(st.nextToken()); // my relation number to this game + /* + -3 isolated position, such as for "ref 3" or the "sposition" command + -2 I am observing game being examined + 2 I am the examiner of this game + -1 I am playing, it is my opponent's move + 1 I am playing and it is my move + 0 I am observing a game being played + */ + if (_iMe == 2 && _viewMode != VIEW_EXAMINE){ // I am the examiner of this game + //initiate textviews in examine mode + _tvMoveNumber.setText("1"); + this.setViewMode(VIEW_EXAMINE); + } //_bHandleClick = (iMe == 1); _bHandleClick = true; - //Log.i("parseGame", "setting handleclick " + iMe + ":" + _whitePlayer + ":" + _blackPlayer); + //Log.i(TAG, "parseGame setting handleclick " + iMe + ":" + _whitePlayer + ":" + _blackPlayer); //_bInTheGame = iMe == 1 || iMe == -1; _bCanPreMove = false; if (_viewMode == VIEW_PLAY) { _opponent = _blackPlayer.equals(sMe) ? _whitePlayer : _blackPlayer; - if (iMe == 1) { + if (_iMe == 1) { if (m_iFrom != -1 && m_iTo != -1) { _tvLastMove.setText("..."); @@ -461,10 +502,15 @@ public synchronized boolean parseGame(String line, String sMe) { int iTime = Integer.parseInt(st.nextToken()); int iIncrement = Integer.parseInt(st.nextToken()); - st.nextToken(); - st.nextToken(); + int iWhiteMaterialStrength = Integer.parseInt(st.nextToken()); + int iBlackMaterialStrength = Integer.parseInt(st.nextToken()); _iWhiteRemaining = Integer.parseInt(st.nextToken()); _iBlackRemaining = Integer.parseInt(st.nextToken()); + _sNumberOfMove = st.nextToken(); // the number of the move about to be made + String sMove = st.nextToken(); // machine notation move + String _sTimePerMove = st.nextToken(); // time it took to make a move + String sLastMoveDisplay = st.nextToken(); // algebraic notation move + int iFlipBoardOrientation = Integer.parseInt(st.nextToken()); //0 = White on Bottom / 1 = Black on bottom if (_flippedBoard) { _tvPlayerTop.setText(_whitePlayer); @@ -489,16 +535,14 @@ public synchronized boolean parseGame(String line, String sMe) { _tvClockTop.setText(parseTime(_iBlackRemaining)); _tvClockBottom.setText(parseTime(_iWhiteRemaining)); } - - st.nextToken(); - String sMove = st.nextToken(); // machine notation move - st.nextToken(); // time per move - String sLastMoveDisplay = st.nextToken(); // algebraic notation move //int iFrom = -1; if (false == sMove.equals("none") && sMove.length() > 2) { - _tvLastMove.setText(_iTurn==1 ? ".." + sLastMoveDisplay: sLastMoveDisplay); // display last move + _tvLastMove.setText(_iTurn==1 ? "." + sLastMoveDisplay: sLastMoveDisplay); // display last move + _tvTimePerMove.setText(_sTimePerMove); + // The about to be move is converted to the current move + _tvMoveNumber.setText(_iTurn==0 ? _sNumberOfMove : Integer.toString(Integer.parseInt(_sNumberOfMove)-1)); if (sMove.equals("o-o")) { if (_iTurn == BoardConstants.WHITE) @@ -580,7 +624,7 @@ else if (_jni.pieceAt(_jni.getTurn(), index) == BoardConstants.FIELD) { if (_bCanPreMove) { m_iTo = index; - Log.i("ICSChessView", "pre move:" + m_iFrom + "-" + m_iTo); + Log.i(TAG, "pre move:" + m_iFrom + "-" + m_iTo); paint(); return; } diff --git a/app/src/main/java/jwtc/android/chess/ics/ICSClient.java b/app/src/main/java/jwtc/android/chess/ics/ICSClient.java index 8e4ca6c7..068c0129 100644 --- a/app/src/main/java/jwtc/android/chess/ics/ICSClient.java +++ b/app/src/main/java/jwtc/android/chess/ics/ICSClient.java @@ -538,8 +538,6 @@ public boolean onCreateOptionsMenu(Menu menu) { menu.add(Menu.NONE, R.string.ics_menu_console, Menu.NONE, R.string.ics_menu_console); menu.add("tell puzzlebot hint"); - menu.add("forward"); - menu.add("backward"); menu.add("unexamine"); menu.add("tell endgamebot hint"); menu.add("tell endgamebot move"); @@ -601,10 +599,6 @@ public boolean onPrepareOptionsMenu(Menu menu) { String title = item.getTitle().toString(); if (title.equals("tell puzzlebot hint")) { item.setVisible(isConnected && viewMode == ICSChessView.VIEW_PUZZLE); - } else if (title.equals("forward")) { - item.setVisible(isConnected && viewMode == ICSChessView.VIEW_EXAMINE); - } else if (title.equals("backward")) { - item.setVisible(isConnected && viewMode == ICSChessView.VIEW_EXAMINE); } else if (title.equals("unexamine")) { item.setVisible(isConnected && viewMode == ICSChessView.VIEW_EXAMINE); } else if (title.equals("tell endgamebot hint")) { @@ -706,9 +700,9 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } - // check menu for ending tag of , then delete tag and allow a command with no return + // check menu for ending tag of , then delete tag and allow a command with no return String itemTitle = item.getTitle().toString(); - if(itemTitle.substring(itemTitle.length()-4).equals("")){ + if(itemTitle.length() > 4 && itemTitle.substring(itemTitle.length()-4).equals("")){ if(_viewAnimatorLobby.getDisplayedChild() == VIEW_SUB_CONSOLE){ _editConsole.setText(itemTitle.substring(0, itemTitle.length()-4)); _editConsole.requestFocus(); @@ -986,6 +980,7 @@ public void run() { sendString("-channel 4"); // guest sendString("-channel 53"); // guest chat sendString("set kibitz 1"); // for puzzlebot + sendString("set gin 0"); // current server game results - turn off - some clients turn it on sendString("set tzone " + tz.getDisplayName(false, TimeZone.SHORT)); // sets timezone // sendMessage("set interface "+ getPreferences().getString(APP_NAME)); @@ -1419,8 +1414,8 @@ else if ((false == get_view().isUserPlaying()) && _pattStoredRow.matcher(line).m // shouts, tshouts etc... // any other data we haven't matched, put it on prompt else if (line.length() > 0) { - Log.i("ICSClient", "lines[" + i + "] " + line); - //Log.i("ICSClient", "lines[" + i + "][last] " + (int)(line.charAt(line.length()-1))); + Log.i(TAG, "lines[" + i + "] " + line); + //Log.i(TAG, "lines[" + i + "][last] " + (int)(line.charAt(line.length()-1))); sRaw += "\n" + line; } @@ -1504,7 +1499,7 @@ protected void makeGamePGN(String sEnd){ saveGameSDCard(); - _dlgOver.updateGRtext(_matgame.group(11)); // game result message sent to dialog + _dlgOver.updateGameResultText(_matgame.group(11)); // game result message sent to dialog _dlgOver.setWasPlaying(get_view().getOpponent().length() > 0); _dlgOver.show(); @@ -1870,6 +1865,11 @@ public int get_gameStartSound(){ return _gameStartSound; } + public String get_whiteHandle(){ + Log.d(TAG,"get_whiteHandle ->" + _matgame.group(1)); + return _matgame.group(1); + } + public String get_whiteRating(){ return _whiteRating == null ? "" : _whiteRating; } diff --git a/app/src/main/java/jwtc/android/chess/ics/ICSGameOverDlg.java b/app/src/main/java/jwtc/android/chess/ics/ICSGameOverDlg.java index baee8578..93bb51ab 100644 --- a/app/src/main/java/jwtc/android/chess/ics/ICSGameOverDlg.java +++ b/app/src/main/java/jwtc/android/chess/ics/ICSGameOverDlg.java @@ -4,6 +4,7 @@ import android.app.Dialog; import android.content.Context; +import android.util.Log; import android.view.Gravity; import android.view.View; import android.widget.Button; @@ -12,8 +13,10 @@ public class ICSGameOverDlg extends Dialog { + public static final String TAG = "ICSGameOverDlg"; + private ICSClient _parent; - private Button _butGoodGame, _butRematch, _butClipBoard, _butSend, _butExit; + private Button _butGoodGame, _butRematch, _butExamine, _butClipBoard, _butSend, _butExit; private TextView _tvGameResult, _tvSendMessagesTitle; @@ -57,6 +60,20 @@ public void onClick(View view) { } }); + _butExamine = (Button)findViewById(R.id.ButtonGameExamine); + _butExamine.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + _parent.sendString("examine " + _parent.get_whiteHandle() + " -1"); + } catch (Exception e){ + _parent.doToast(e.toString()); + Log.e(TAG, "Exception error ->" + e.toString()); + } + + } + }); + _butClipBoard = (Button)findViewById(R.id.ButtonGameClipBoard); _butClipBoard.setOnClickListener(new View.OnClickListener() { @Override @@ -80,7 +97,7 @@ public void setWasPlaying(boolean bWasPlaying){ _butRematch.setVisibility(bWasPlaying ? View.VISIBLE : View.GONE); } - public void updateGRtext(String GRText){ + public void updateGameResultText(String GRText){ _tvGameResult.setText(GRText); } } diff --git a/app/src/main/res/drawable/navigation_revert.png b/app/src/main/res/drawable/navigation_revert.png new file mode 100644 index 0000000000000000000000000000000000000000..5e7df440a1c980f762a11ff57fa31ab17f97090b GIT binary patch literal 601 zcmV-f0;c_mP)|W zK~#9!?b=I@!ypU*P-Epb>20cHGOy!9i=qas$;0<_@YB48dtDU6;}N z!6X+JTCL`}u|5(`&-+bh0fXAAbgj{ad#c{SioSYYv5uk&HEdy6z&g#N0;?e5j5Vv^ z6ow*w$N|@uqHKMhO8?aRMfNZ?;HBC-oHd=Nn8Ffh*JY_Milx@AEzjeAermlHTr$GF zUXCNmkYa>2EV#Y0&z`KU z6;jR3aaHSpxjoklC~ZY?L{v22P_;V@+eaWGDk6$5nj)eK@-B>Mim6AM#bZQMUa5nD zlvfX8AmtU!7)W_L3zKK0lC2jEBu7xak<3p$4j{8oQnzTPQE}Yu9&p_9GaXS{fYd^1 n15ydqg4Fw<)ns}gar*oV0@~UBm9GOl00000NkvXXu0mjfDFy{j literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout-land/icsclient.xml b/app/src/main/res/layout-land/icsclient.xml index 03a01d3c..8f7f60ed 100644 --- a/app/src/main/res/layout-land/icsclient.xml +++ b/app/src/main/res/layout-land/icsclient.xml @@ -28,15 +28,15 @@ - - + - + + + @@ -100,11 +121,36 @@ /> + + + + + + + + android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginTop="20dp" + android:layout_above="@id/RelativeExamineButtons" android:layout_below="@id/TablePlayerTop"> +