From a5c3c7e548fbc9df65c7f8f6d6d8b188ab11957b Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 18 Jul 2012 07:07:53 -0700 Subject: [PATCH] fix layout on wider screens (e.g. 768x1024): rather than draw the board so wide that scrolling's required, reduce width enough that it's not. --- xwords4/android/XWords4/res/layout/board.xml | 6 +- .../org/eehouse/android/xw4/BoardDims.java | 1 - .../org/eehouse/android/xw4/BoardView.java | 140 ++++++++++-------- 3 files changed, 85 insertions(+), 62 deletions(-) diff --git a/xwords4/android/XWords4/res/layout/board.xml b/xwords4/android/XWords4/res/layout/board.xml index 0c6629b78..b15f6505b 100644 --- a/xwords4/android/XWords4/res/layout/board.xml +++ b/xwords4/android/XWords4/res/layout/board.xml @@ -8,13 +8,15 @@ > + android:drawSelectorOnTop="false" + android:layout_gravity="center_vertical|center_horizontal" + /> maxCellSize ) { - cellSize = maxCellSize; - - int boardWidth = nCells * cellSize; - result.left = (width - boardWidth) / 2; - result.width = boardWidth; - } - result.maxCellSize = maxCellSize; - - // Now determine if vertical scrolling will be necessary. - // There's a minimum tray and scoreboard height. If we can - // fit them and all cells no scrolling's needed. Otherwise - // determine the minimum number that must be hidden to fit. - // Finally grow scoreboard and tray to use whatever's left. - int trayHt = 2 * cellSize; - int scoreHt = (cellSize * 3) / 2; - int wantHt = trayHt + scoreHt + (cellSize * nCells); + int trayHt; + int scoreHt; + int wantHt; int nToScroll; - if ( wantHt <= height ) { - nToScroll = 0; - } else { - nToScroll = nCells - ((height - trayHt - scoreHt) / cellSize); - } - int heightUsed = trayHt + scoreHt + (nCells - nToScroll) * cellSize; - int heightLeft = height - heightUsed; - if ( 0 < heightLeft ) { - if ( heightLeft > (cellSize * 3 / 2) ) { - heightLeft = cellSize * 3 / 2; + for ( boolean firstPass = true; ; ) { + result.width = width; + + int cellSize = width / nCells; + if ( cellSize > maxCellSize ) { + cellSize = maxCellSize; + + int boardWidth = nCells * cellSize; + result.width = boardWidth; } - heightLeft /= 3; - trayHt += heightLeft * 2; - scoreHt += heightLeft; - heightUsed = trayHt + scoreHt + ((nCells - nToScroll) * cellSize); - } + result.maxCellSize = maxCellSize; - result.trayHt = trayHt; - result.scoreHt = scoreHt; + // Now determine if vertical scrolling will be necessary. + // There's a minimum tray and scoreboard height. If we can + // fit them and all cells no scrolling's needed. Otherwise + // determine the minimum number that must be hidden to fit. + // Finally grow scoreboard and tray to use whatever's left. + trayHt = 2 * cellSize; + scoreHt = (cellSize * 3) / 2; + wantHt = trayHt + scoreHt + (cellSize * nCells); + if ( wantHt <= height ) { + nToScroll = 0; + } else { + // Scrolling's required if we use cell width sufficient to + // fill the screen. But perhaps we don't need to. + int cellWidth = 2 * (height / ( 4 + 3 + (2*nCells))); + if ( firstPass && cellWidth >= m_defaultFontHt ) { + firstPass = false; + width = nCells * cellWidth; + continue; + } else { + nToScroll = nCells - ((height - trayHt - scoreHt) / cellSize); + } + } - result.boardHt = cellSize * nCells; - result.trayTop = scoreHt + (cellSize * (nCells-nToScroll)); - result.height = heightUsed; - result.cellSize = cellSize; + int heightUsed = trayHt + scoreHt + (nCells - nToScroll) * cellSize; + int heightLeft = height - heightUsed; + if ( 0 < heightLeft ) { + if ( heightLeft > (cellSize * 3 / 2) ) { + heightLeft = cellSize * 3 / 2; + } + heightLeft /= 3; + trayHt += heightLeft * 2; + scoreHt += heightLeft; + heightUsed = trayHt + scoreHt + ((nCells - nToScroll) * cellSize); + } - if ( m_gi.timerEnabled ) { - Paint paint = new Paint(); - paint.setTextSize( m_mediumFontHt ); - paint.getTextBounds( "-00:00", 0, 6, m_boundsScratch ); - result.timerWidth = m_boundsScratch.width(); + result.trayHt = trayHt; + result.scoreHt = scoreHt; + + result.boardHt = cellSize * nCells; + result.trayTop = scoreHt + (cellSize * (nCells-nToScroll)); + result.height = heightUsed; + result.cellSize = cellSize; + + if ( m_gi.timerEnabled ) { + Paint paint = new Paint(); + paint.setTextSize( m_mediumFontHt ); + paint.getTextBounds( "-00:00", 0, 6, m_boundsScratch ); + result.timerWidth = m_boundsScratch.width(); + } + break; } return result; @@ -404,8 +421,6 @@ public class BoardView extends View implements DrawCtx, BoardHandler, m_valRect = null; BoardDims dims = figureBoardDims( width, height ); - m_left = dims.left; - m_top = dims.top; if ( null == s_bitmap ) { s_bitmap = Bitmap.createBitmap( 1 + dims.width, @@ -877,9 +892,16 @@ public class BoardView extends View implements DrawCtx, BoardHandler, public void objFinished( /*BoardObjectType*/int typ, Rect rect ) { - // if ( DrawCtx.OBJ_SCORE == typ ) { - // m_canvas.restoreToCount(1); // in case new canvas... - // } + if ( DrawCtx.OBJ_BOARD == typ ) { + // On squat screens, where I can't use the full width for + // the board (without scrolling), the right-most cells + // don't draw their right borders due to clipping, so draw + // for them. + m_strokePaint.setColor( adjustColor(FRAME_GREY) ); + int xx = rect.left + rect.width() - 1; + m_canvas.drawLine( xx, rect.top, xx, rect.top + rect.height(), + m_strokePaint ); + } } public void dictChanged( int dictPtr )