build with COMMON_LAYOUT defined, and when off-by-default debug pref

is on use it instead of java-side layout.
This commit is contained in:
Eric House 2013-11-03 12:17:20 -08:00
parent 184ac28ebc
commit e01af60dab
9 changed files with 198 additions and 87 deletions

View file

@ -37,6 +37,7 @@ LOCAL_DEFINES += \
-DHASH_STREAM \
-DXWFEATURE_BASE64 \
-DXWFEATURE_DEVID \
-DCOMMON_LAYOUT \
-DINITIAL_CLIENT_VERS=${INITIAL_CLIENT_VERS} \
-DRELAY_ROOM_DEFAULT=\"\" \
-D__LITTLE_ENDIAN \

View file

@ -107,7 +107,7 @@ getInts( JNIEnv* env, void* cobj, jobject jobj, const SetInfo* sis, XP_U16 nSis
*ptr = val;
break;
}
/* XP_LOGF( "%s: wrote int %s of size %dwith val %d at offset %d", */
/* XP_LOGF( "%s: wrote int %s of size %d with val %d at offset %d", */
/* __func__, si->name, si->siz, val, si->offset ); */
}
}

View file

@ -158,6 +158,36 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
}
} /* setJGI */
#ifdef COMMON_LAYOUT
static const SetInfo bd_ints[] = {
ARR_MEMBER( BoardDims, left )
,ARR_MEMBER( BoardDims, top )
,ARR_MEMBER( BoardDims, width )
,ARR_MEMBER( BoardDims, height )
,ARR_MEMBER( BoardDims, scoreHt )
,ARR_MEMBER( BoardDims, boardHt )
,ARR_MEMBER( BoardDims, trayTop )
,ARR_MEMBER( BoardDims, trayHt )
,ARR_MEMBER( BoardDims, cellSize )
,ARR_MEMBER( BoardDims, maxCellSize )
,ARR_MEMBER( BoardDims, timerWidth )
};
static void
dimsJToC( JNIEnv* env, BoardDims* out, jobject jdims )
{
getInts( env, (void*)out, jdims, bd_ints, VSIZE(bd_ints) );
}
static void
dimsCtoJ( JNIEnv* env, jobject jdims, const BoardDims* in )
{
LOG_FUNC();
setInts( env, jdims, (void*)in, bd_ints, VSIZE(bd_ints) );
LOG_RETURN_VOID();
}
#endif
static void
destroyGI( MPFORMAL CurGameInfo** gip )
{
@ -601,6 +631,47 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1draw
return result;
}
#ifdef COMMON_LAYOUT
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1figureLayout
( JNIEnv* env, jclass C, jint gamePtr, jobject jgi, jint fontHt, jint fontWidth,
jboolean squareTiles, jobject jbounds, jobject jdims )
{
LOG_FUNC();
XWJNI_START();
CurGameInfo* gi = makeGI( MPPARM(mpool) env, jgi );
XP_Rect bounds;
bounds.left = getInt( env, jbounds, "left" );
bounds.top = getInt( env, jbounds, "top" );
bounds.width = getInt( env, jbounds, "right" ) - bounds.left;
bounds.height = getInt( env, jbounds, "bottom" ) - bounds.top;
BoardDims dims;
board_figureLayout( state->game.board, gi, fontHt, fontWidth,
squareTiles, &bounds, ((!!jdims) ? &dims : NULL) );
destroyGI( MPPARM(mpool) &gi );
if ( !!jdims ) {
dimsCtoJ( env, jdims, &dims );
}
XWJNI_END();
LOG_RETURN_VOID();
}
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1applyLayout
( JNIEnv* env, jclass C, jint gamePtr, jobject jdims )
{
XWJNI_START();
BoardDims dims;
dimsJToC( env, &dims, jdims );
board_applyLayout( state->game.board, &dims );
XWJNI_END();
}
#endif
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setPos
(JNIEnv *env, jclass C, jint gamePtr, jint left, jint top, jint width,

View file

@ -103,6 +103,7 @@
<string name="key_na_browseall">key_na_browseall</string>
<string name="key_na_values">key_na_values</string>
<string name="key_enable_debug">key_enable_debug</string>
<string name="key_enable_commlayt">key_enable_commlayt</string>
<string name="key_download_path">key_download_path</string>
<!-- Nor is my email address -->

View file

@ -299,6 +299,11 @@
android:summary="Menuitems etc."
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_enable_commlayt"
android:title="Use common layout"
android:summary="(rather than android-specific)"
android:defaultValue="false"
/>
<!-- For broken devices like my Blaze 4G that report a download
directory that doesn't exist, allow users to set it. Mine:

View file

@ -23,6 +23,7 @@ package org.eehouse.android.xw4;
// Why does this have to be its own class...
public class BoardDims {
public int left, top;
public int width, height; // of the bitmap
public int scoreHt;
public int boardHt;

View file

@ -73,6 +73,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
private int m_lastSecsLeft;
private int m_lastTimerPlayer;
private int m_pendingScore;
private boolean m_useCommon;
private CommsAddrRec.CommsConnType m_connType =
CommsAddrRec.CommsConnType.COMMS_CONN_NONE;
@ -188,6 +189,9 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
int heightMode = View.MeasureSpec.getMode( heightMeasureSpec );
// printMode( "heightMode", heightMode );
m_useCommon =
XWPrefs.getPrefsBoolean( m_context,
R.string.key_enable_commlayt, false );
BoardDims dims = figureBoardDims( width, height );
// If I let the spec tell me whether I can reduce the width
// then I don't change it on the second pass, but if I ignore
@ -247,80 +251,91 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
private BoardDims figureBoardDims( int width, int height )
{
BoardDims result = new BoardDims();
int nCells = m_gi.boardSize;
int maxCellSize = 4 * m_defaultFontHt;
int trayHt;
int scoreHt;
int wantHt;
int nToScroll;
boolean squareTiles = XWPrefs.getSquareTiles( m_context );
for ( boolean firstPass = true; ; ) {
result.width = width;
Paint paint = new Paint();
paint.setTextSize( m_mediumFontHt );
paint.getTextBounds( "-00:00", 0, 6, m_boundsScratch );
int timerWidth = m_boundsScratch.width();
int cellSize = width / nCells;
if ( cellSize > maxCellSize ) {
cellSize = maxCellSize;
if ( m_useCommon ) {
Rect bounds = new Rect( 0, 0, width, height );
int fontWidth = timerWidth / 6;
XwJNI.board_figureLayout( m_jniGamePtr, m_gi, m_defaultFontHt,
fontWidth, squareTiles, bounds, result );
} else {
int nCells = m_gi.boardSize;
int maxCellSize = 4 * m_defaultFontHt;
int trayHt;
int scoreHt;
int wantHt;
int nToScroll;
int boardWidth = nCells * cellSize;
result.width = boardWidth;
}
result.maxCellSize = maxCellSize;
for ( boolean firstPass = true; ; ) {
result.width = width;
// 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;
int cellSize = width / nCells;
if ( cellSize > maxCellSize ) {
cellSize = maxCellSize;
int boardWidth = nCells * cellSize;
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.
trayHt = 2 * cellSize;
scoreHt = (cellSize * 3) / 2;
wantHt = trayHt + scoreHt + (cellSize * nCells);
if ( wantHt <= height ) {
nToScroll = 0;
} else {
nToScroll = nCells - ((height - trayHt - scoreHt) / cellSize);
// 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);
}
}
}
int heightUsed = trayHt + scoreHt + (nCells - nToScroll) * cellSize;
int heightLeft = height - heightUsed;
if ( 0 < heightLeft ) {
if ( heightLeft > (cellSize * 3 / 2) ) {
heightLeft = cellSize * 3 / 2;
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;
scoreHt += heightLeft;
trayHt += heightLeft * 2;
if ( squareTiles && trayHt > (width / 7) ) {
trayHt = width / 7;
}
heightUsed = trayHt + scoreHt + ((nCells - nToScroll) * cellSize);
}
heightLeft /= 3;
scoreHt += heightLeft;
trayHt += heightLeft * 2;
if ( XWPrefs.getSquareTiles( m_context )
&& trayHt > (width / 7) ) {
trayHt = width / 7;
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 ) {
result.timerWidth = timerWidth;
}
heightUsed = trayHt + scoreHt + ((nCells - nToScroll) * cellSize);
break;
}
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;
@ -362,7 +377,8 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
XwJNI.board_setDraw( m_jniGamePtr, m_canvas );
// need to synchronize??
m_jniThread.handle( JNIThread.JNICmd.CMD_LAYOUT, dims );
m_jniThread.handle( JNIThread.JNICmd.CMD_LAYOUT, dims,
m_useCommon );
m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
layoutDone = true;
}

View file

@ -230,32 +230,36 @@ public class JNIThread extends Thread {
Message.obtain( m_handler, DIALOG, titleArg, 0, text ).sendToTarget();
}
private void doLayout( BoardDims dims )
private void doLayout( BoardDims dims, boolean useCommon )
{
int scoreWidth = dims.width - dims.cellSize;
ConnStatusHandler.setRect( scoreWidth, 0, scoreWidth + dims.cellSize,
dims.scoreHt );
if ( useCommon ) {
XwJNI.board_applyLayout( m_jniGamePtr, dims );
} else {
int scoreWidth = dims.width - dims.cellSize;
ConnStatusHandler.setRect( scoreWidth, 0, scoreWidth + dims.cellSize,
dims.scoreHt );
if ( m_gi.timerEnabled ) {
scoreWidth -= dims.timerWidth;
XwJNI.board_setTimerLoc( m_jniGamePtr, scoreWidth, 0,
dims.timerWidth, dims.scoreHt );
}
XwJNI.board_setScoreboardLoc( m_jniGamePtr, 0, 0, scoreWidth,
dims.scoreHt, true );
if ( m_gi.timerEnabled ) {
scoreWidth -= dims.timerWidth;
XwJNI.board_setTimerLoc( m_jniGamePtr, scoreWidth, 0,
dims.timerWidth, dims.scoreHt );
}
XwJNI.board_setScoreboardLoc( m_jniGamePtr, 0, 0, scoreWidth,
dims.scoreHt, true );
// Have no idea why I was doing -1 below, but it breaks layout
// for small (QVGA) boards. If it needs to be done, do it
// early in figureBoardDims so the calculations that follow
// are consistent.
XwJNI.board_setPos( m_jniGamePtr, 0, dims.scoreHt,
dims.width/*-1*/, dims.boardHt, dims.maxCellSize,
false );
// Have no idea why I was doing -1 below, but it breaks layout
// for small (QVGA) boards. If it needs to be done, do it
// early in figureBoardDims so the calculations that follow
// are consistent.
XwJNI.board_setPos( m_jniGamePtr, 0, dims.scoreHt,
dims.width/*-1*/, dims.boardHt, dims.maxCellSize,
false );
XwJNI.board_setTrayLoc( m_jniGamePtr, 0, dims.trayTop,
dims.width/*-1*/, dims.trayHt, kMinDivWidth );
XwJNI.board_setTrayLoc( m_jniGamePtr, 0, dims.trayTop,
dims.width/*-1*/, dims.trayHt, kMinDivWidth );
XwJNI.board_invalAll( m_jniGamePtr );
XwJNI.board_invalAll( m_jniGamePtr );
}
}
private boolean nextSame( JNICmd cmd )
@ -354,7 +358,7 @@ public class JNIThread extends Thread {
break;
case CMD_LAYOUT:
doLayout( (BoardDims)args[0] );
doLayout( (BoardDims)args[0], (Boolean)args[1] );
draw = true;
// check and disable zoom button at limit
handle( JNICmd.CMD_ZOOM, 0 );

View file

@ -20,6 +20,9 @@
package org.eehouse.android.xw4.jni;
import android.graphics.Rect;
import org.eehouse.android.xw4.BoardDims;
// Collection of native methods
public class XwJNI {
@ -145,6 +148,15 @@ public class XwJNI {
public static native void board_setDraw( int gamePtr, DrawCtx draw );
public static native void board_invalAll( int gamePtr );
public static native boolean board_draw( int gamePtr );
// Only if COMMON_LAYOUT defined
public static native void board_figureLayout( int gamePtr, CurGameInfo gi,
int fontHt, int fontWidth,
boolean squareTiles,
Rect bounds, BoardDims dims );
// Only if COMMON_LAYOUT defined
public static native void board_applyLayout( int gamePtr, BoardDims dims );
public static native void board_setPos( int gamePtr, int left, int top,
int width, int height,
int maxCellHt, boolean lefty );