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,6 +251,20 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
private BoardDims figureBoardDims( int width, int height )
{
BoardDims result = new BoardDims();
boolean squareTiles = XWPrefs.getSquareTiles( m_context );
Paint paint = new Paint();
paint.setTextSize( m_mediumFontHt );
paint.getTextBounds( "-00:00", 0, 6, m_boundsScratch );
int timerWidth = m_boundsScratch.width();
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;
@ -299,8 +317,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
scoreHt += heightLeft;
trayHt += heightLeft * 2;
if ( XWPrefs.getSquareTiles( m_context )
&& trayHt > (width / 7) ) {
if ( squareTiles && trayHt > (width / 7) ) {
trayHt = width / 7;
}
heightUsed = trayHt + scoreHt + ((nCells - nToScroll) * cellSize);
@ -315,13 +332,11 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
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();
result.timerWidth = timerWidth;
}
break;
}
}
return result;
} // figureBoardDims
@ -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,8 +230,11 @@ 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 )
{
if ( useCommon ) {
XwJNI.board_applyLayout( m_jniGamePtr, dims );
} else {
int scoreWidth = dims.width - dims.cellSize;
ConnStatusHandler.setRect( scoreWidth, 0, scoreWidth + dims.cellSize,
dims.scoreHt );
@ -257,6 +260,7 @@ public class JNIThread extends Thread {
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 );