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 \ -DHASH_STREAM \
-DXWFEATURE_BASE64 \ -DXWFEATURE_BASE64 \
-DXWFEATURE_DEVID \ -DXWFEATURE_DEVID \
-DCOMMON_LAYOUT \
-DINITIAL_CLIENT_VERS=${INITIAL_CLIENT_VERS} \ -DINITIAL_CLIENT_VERS=${INITIAL_CLIENT_VERS} \
-DRELAY_ROOM_DEFAULT=\"\" \ -DRELAY_ROOM_DEFAULT=\"\" \
-D__LITTLE_ENDIAN \ -D__LITTLE_ENDIAN \

View file

@ -107,7 +107,7 @@ getInts( JNIEnv* env, void* cobj, jobject jobj, const SetInfo* sis, XP_U16 nSis
*ptr = val; *ptr = val;
break; 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 ); */ /* __func__, si->name, si->siz, val, si->offset ); */
} }
} }

View file

@ -158,6 +158,36 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
} }
} /* setJGI */ } /* 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 static void
destroyGI( MPFORMAL CurGameInfo** gip ) destroyGI( MPFORMAL CurGameInfo** gip )
{ {
@ -601,6 +631,47 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1draw
return result; 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 JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setPos Java_org_eehouse_android_xw4_jni_XwJNI_board_1setPos
(JNIEnv *env, jclass C, jint gamePtr, jint left, jint top, jint width, (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_browseall">key_na_browseall</string>
<string name="key_na_values">key_na_values</string> <string name="key_na_values">key_na_values</string>
<string name="key_enable_debug">key_enable_debug</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> <string name="key_download_path">key_download_path</string>
<!-- Nor is my email address --> <!-- Nor is my email address -->

View file

@ -299,6 +299,11 @@
android:summary="Menuitems etc." android:summary="Menuitems etc."
android:defaultValue="false" 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 <!-- For broken devices like my Blaze 4G that report a download
directory that doesn't exist, allow users to set it. Mine: 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... // Why does this have to be its own class...
public class BoardDims { public class BoardDims {
public int left, top;
public int width, height; // of the bitmap public int width, height; // of the bitmap
public int scoreHt; public int scoreHt;
public int boardHt; public int boardHt;

View file

@ -73,6 +73,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
private int m_lastSecsLeft; private int m_lastSecsLeft;
private int m_lastTimerPlayer; private int m_lastTimerPlayer;
private int m_pendingScore; private int m_pendingScore;
private boolean m_useCommon;
private CommsAddrRec.CommsConnType m_connType = private CommsAddrRec.CommsConnType m_connType =
CommsAddrRec.CommsConnType.COMMS_CONN_NONE; CommsAddrRec.CommsConnType.COMMS_CONN_NONE;
@ -188,6 +189,9 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
int heightMode = View.MeasureSpec.getMode( heightMeasureSpec ); int heightMode = View.MeasureSpec.getMode( heightMeasureSpec );
// printMode( "heightMode", heightMode ); // printMode( "heightMode", heightMode );
m_useCommon =
XWPrefs.getPrefsBoolean( m_context,
R.string.key_enable_commlayt, false );
BoardDims dims = figureBoardDims( width, height ); BoardDims dims = figureBoardDims( width, height );
// If I let the spec tell me whether I can reduce the width // 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 // 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 ) private BoardDims figureBoardDims( int width, int height )
{ {
BoardDims result = new BoardDims(); BoardDims result = new BoardDims();
int nCells = m_gi.boardSize; boolean squareTiles = XWPrefs.getSquareTiles( m_context );
int maxCellSize = 4 * m_defaultFontHt;
int trayHt;
int scoreHt;
int wantHt;
int nToScroll;
for ( boolean firstPass = true; ; ) { Paint paint = new Paint();
result.width = width; paint.setTextSize( m_mediumFontHt );
paint.getTextBounds( "-00:00", 0, 6, m_boundsScratch );
int timerWidth = m_boundsScratch.width();
int cellSize = width / nCells; if ( m_useCommon ) {
if ( cellSize > maxCellSize ) { Rect bounds = new Rect( 0, 0, width, height );
cellSize = maxCellSize; 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; for ( boolean firstPass = true; ; ) {
result.width = boardWidth; result.width = width;
}
result.maxCellSize = maxCellSize;
// Now determine if vertical scrolling will be necessary. int cellSize = width / nCells;
// There's a minimum tray and scoreboard height. If we can if ( cellSize > maxCellSize ) {
// fit them and all cells no scrolling's needed. Otherwise cellSize = maxCellSize;
// determine the minimum number that must be hidden to fit.
// Finally grow scoreboard and tray to use whatever's left. int boardWidth = nCells * cellSize;
trayHt = 2 * cellSize; result.width = boardWidth;
scoreHt = (cellSize * 3) / 2; }
wantHt = trayHt + scoreHt + (cellSize * nCells); result.maxCellSize = maxCellSize;
if ( wantHt <= height ) {
nToScroll = 0; // Now determine if vertical scrolling will be necessary.
} else { // There's a minimum tray and scoreboard height. If we can
// Scrolling's required if we use cell width sufficient to // fit them and all cells no scrolling's needed. Otherwise
// fill the screen. But perhaps we don't need to. // determine the minimum number that must be hidden to fit.
int cellWidth = 2 * (height / ( 4 + 3 + (2*nCells))); // Finally grow scoreboard and tray to use whatever's left.
if ( firstPass && cellWidth >= m_defaultFontHt ) { trayHt = 2 * cellSize;
firstPass = false; scoreHt = (cellSize * 3) / 2;
width = nCells * cellWidth; wantHt = trayHt + scoreHt + (cellSize * nCells);
continue; if ( wantHt <= height ) {
nToScroll = 0;
} else { } 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 heightUsed = trayHt + scoreHt + (nCells - nToScroll) * cellSize;
int heightLeft = height - heightUsed; int heightLeft = height - heightUsed;
if ( 0 < heightLeft ) { if ( 0 < heightLeft ) {
if ( heightLeft > (cellSize * 3 / 2) ) { if ( heightLeft > (cellSize * 3 / 2) ) {
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; result.trayHt = trayHt;
if ( XWPrefs.getSquareTiles( m_context ) result.scoreHt = scoreHt;
&& trayHt > (width / 7) ) {
trayHt = width / 7; 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; return result;
@ -362,7 +377,8 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
XwJNI.board_setDraw( m_jniGamePtr, m_canvas ); XwJNI.board_setDraw( m_jniGamePtr, m_canvas );
// need to synchronize?? // 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 ); m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
layoutDone = true; layoutDone = true;
} }

View file

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

View file

@ -20,6 +20,9 @@
package org.eehouse.android.xw4.jni; package org.eehouse.android.xw4.jni;
import android.graphics.Rect;
import org.eehouse.android.xw4.BoardDims;
// Collection of native methods // Collection of native methods
public class XwJNI { 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_setDraw( int gamePtr, DrawCtx draw );
public static native void board_invalAll( int gamePtr ); public static native void board_invalAll( int gamePtr );
public static native boolean board_draw( 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, public static native void board_setPos( int gamePtr, int left, int top,
int width, int height, int width, int height,
int maxCellHt, boolean lefty ); int maxCellHt, boolean lefty );