add game time to board and jni; clean up hide/show on check events.

This commit is contained in:
eehouse 2010-02-18 04:44:30 +00:00
parent 74140ccaad
commit de58f33b4c
12 changed files with 183 additions and 71 deletions

View file

@ -207,6 +207,17 @@ and_draw_score_drawPlayer( DrawCtx* dctx,
(*env)->CallVoidMethod( env, draw->jdraw, mid, jrinner, jrouter, jdsi );
} /* and_draw_score_drawPlayer */
static void
and_draw_drawTimer( DrawCtx* dctx, const XP_Rect* rect, XP_U16 player,
XP_S16 secondsLeft )
{
DRAW_CBK_HEADER("drawTimer", "(Landroid/graphics/Rect;II)V" );
jobject jrect = makeJRect( draw, JCACHE_RECT0, rect );
(*env)->CallVoidMethod( env, draw->jdraw, mid,
jrect, player, secondsLeft );
}
static XP_Bool
and_draw_boardBegin( DrawCtx* dctx, const XP_Rect* rect, DrawFocusState dfs )
{
@ -442,6 +453,8 @@ makeDraw( MPFORMAL JNIEnv** envp, jobject jdraw )
SET_PROC(measureScoreText);
SET_PROC(drawRemText);
SET_PROC(score_drawPlayer);
SET_PROC(drawTimer);
SET_PROC(drawCell);
SET_PROC(drawBoardArrow);
SET_PROC(vertScrollBoard);

View file

@ -25,6 +25,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
XP_UCHAR buf[256]; /* in case needs whole path */
gi->nPlayers = getInt( env, j_gi, "nPlayers");
gi->gameSeconds = getInt( env, j_gi, "gameSeconds");
gi->boardSize = getInt( env, j_gi, "boardSize" );
gi->gameID = getInt( env, j_gi, "gameID" );
gi->robotSmartness = getInt( env, j_gi, "robotSmartness" );
@ -78,6 +79,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
{
// set fields
setInt( env, jgi, "nPlayers", gi->nPlayers );
setInt( env, jgi, "gameSeconds", gi->gameSeconds );
setInt( env, jgi, "boardSize", gi->boardSize );
setInt( env, jgi, "gameID", gi->gameID );
setInt( env, jgi, "robotSmartness", gi->robotSmartness );
@ -491,6 +493,19 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScoreboardLoc
XWJNI_END();
}
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTimerLoc
( JNIEnv* env, jclass C, jint gamePtr, jint timerLeft, jint timerTop,
jint timerWidth, jint timerHeight )
{
XWJNI_START();
XP_LOGF( "%s(%d,%d,%d,%d)", __func__, timerLeft, timerTop,
timerWidth, timerHeight );
board_setTimerLoc( state->game.board, timerLeft, timerTop,
timerWidth, timerHeight );
XWJNI_END();
}
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTrayLoc
( JNIEnv *env, jclass C, jint gamePtr, jint left, jint top,

View file

@ -113,6 +113,36 @@
android:text="@string/use_timer"
/>
<LinearLayout android:id="@+id/timer_set"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="@string/minutes_label"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/timer_minutes_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:numeric="decimal"
android:hint="25"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
<CheckBox android:id="@+id/color_tiles"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

View file

@ -30,56 +30,67 @@
android:text="@string/remote_label"
/>
<TextView android:id="@+id/player_name_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="@string/player_label"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/player_name_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<!-- Use a layout to group elems we want to show/hide as a set -->
<LinearLayout android:id="@+id/local_player_set"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<CheckBox android:id="@+id/robot_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/robot_label"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="@string/player_label"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/player_name_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView android:id="@+id/password_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="@string/password_label"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/password_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:password="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<CheckBox android:id="@+id/robot_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/robot_label"
/>
<LinearLayout android:id="@+id/password_set"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="@string/password_label"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/password_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:password="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -156,6 +156,7 @@
<string name="configure_role">Configure connection</string>
<string name="phonies_label">Phonies</string>
<string name="minutes_label">Minutes in game</string>
<string name="download_dicts">Download more...</string>

View file

@ -373,6 +373,9 @@ public class BoardActivity extends Activity implements UtilCtxt {
case UtilCtxt.TIMER_COMMS:
inHowLong = when * 1000;
break;
case UtilCtxt.TIMER_TIMERTICK:
inHowLong = 1000; // when is 0 for TIMER_TIMERTICK
break;
default:
inHowLong = 500;
}

View file

@ -41,6 +41,7 @@ public class BoardView extends View implements DrawCtx,
private Rect m_boundsScratch;
private String m_remText;
private int m_dictPtr = 0;
private int m_lastSecsLeft;
private class FontDims {
FontDims( int topRow, int bottomRow, int width ) {
m_topRow = topRow;
@ -268,6 +269,26 @@ public class BoardView extends View implements DrawCtx,
drawCentered( text, rOuter );
}
public void drawTimer( Rect rect, int player, int secondsLeft )
{
if ( null != m_canvas && m_lastSecsLeft != secondsLeft ) {
m_lastSecsLeft = secondsLeft;
String negSign = secondsLeft < 0? "-":"";
secondsLeft = Math.abs( secondsLeft );
String time = String.format( "%s%d:%02d", negSign, secondsLeft/60,
secondsLeft%60 );
clearToBack( rect );
m_fillPaint.setTextSize( rect.bottom - rect.top );
m_fillPaint.setColor( m_playerColors[player] );
drawCentered( time, rect );
m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
}
}
public boolean drawCell( Rect rect, String text, BitmapDrawable[] bitmaps,
int tile, int owner, int bonus, int hintAtts,
int flags )

View file

@ -170,9 +170,7 @@ public class GameConfig extends Activity implements View.OnClickListener {
CurGameInfo.DeviceRole.SERVER_ISSERVER == curRole();
LocalPlayer lp = m_gi.players[m_whichPlayer];
EditText player = (EditText)
m_curDialog.findViewById( R.id.player_name_edit );
player.setText( lp.name );
Utils.setText( m_curDialog, R.id.player_name_edit, lp.name );
CheckBox check = (CheckBox)
m_curDialog.findViewById( R.id.remote_check );
@ -181,16 +179,9 @@ public class GameConfig extends Activity implements View.OnClickListener {
new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView,
boolean checked ) {
int ids[] = { R.id.player_name_label,
R.id.player_name_edit,
R.id.robot_check,
R.id.password_label,
R.id.password_edit };
int vis = checked ? View.GONE : View.VISIBLE;
for ( int id : ids ) {
View view = m_curDialog.findViewById( id );
view.setVisibility( vis );
}
View view
= m_curDialog.findViewById( R.id.local_player_set );
view.setVisibility( checked ? View.GONE : View.VISIBLE );
}
};
check.setOnCheckedChangeListener( lstnr );
@ -203,13 +194,8 @@ public class GameConfig extends Activity implements View.OnClickListener {
new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView,
boolean checked ) {
int ids[] = { R.id.password_label,
R.id.password_edit };
int vis = checked ? View.GONE : View.VISIBLE;
for ( int id : ids ) {
View view = m_curDialog.findViewById( id );
view.setVisibility( vis );
}
View view = m_curDialog.findViewById( R.id.password_set );
view.setVisibility( checked ? View.GONE : View.VISIBLE );
}
};
check.setOnCheckedChangeListener( lstnr );
@ -394,7 +380,20 @@ public class GameConfig extends Activity implements View.OnClickListener {
m_phoniesSpinner.setSelection( m_gi.phoniesAction.ordinal() );
Utils.setChecked( this, R.id.hints_allowed, !m_gi.hintsNotAllowed );
Utils.setInt( this, R.id.timer_minutes_edit, m_gi.gameSeconds/60 );
CheckBox check = (CheckBox)findViewById( R.id.use_timer );
CompoundButton.OnCheckedChangeListener lstnr =
new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView,
boolean checked ) {
View view = findViewById( R.id.timer_set );
view.setVisibility( checked ? View.VISIBLE : View.GONE );
}
};
check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
Utils.setChecked( this, R.id.color_tiles, m_gi.showColors );
Utils.setChecked( this, R.id.smart_robot, 0 < m_gi.robotSmartness );
@ -663,6 +662,7 @@ public class GameConfig extends Activity implements View.OnClickListener {
{
m_gi.hintsNotAllowed = !Utils.getChecked( this, R.id.hints_allowed );
m_gi.timerEnabled = Utils.getChecked( this, R.id.use_timer );
m_gi.gameSeconds = 60 * Utils.getInt( this, R.id.timer_minutes_edit );
m_gi.showColors = Utils.getChecked( this, R.id.color_tiles );
m_gi.robotSmartness
= Utils.getChecked( this, R.id.smart_robot ) ? 1 : 0;

View file

@ -17,6 +17,7 @@ public class CurGameInfo {
public String dictName;
public LocalPlayer[] players;
public int gameID;
public int gameSeconds;
public int nPlayers;
public int boardSize;
public DeviceRole serverRole;

View file

@ -30,6 +30,7 @@ public interface DrawCtx {
void measureScoreText( Rect r, DrawScoreInfo dsi, int[] width, int[] height );
void drawRemText( Rect rInner, Rect rOuter, int nTilesLeft, boolean focussed );
void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi );
void drawTimer( Rect rect, int player, int secondsLeft );
boolean drawCell( Rect rect, String text, BitmapDrawable[] bitmaps, int tile,
int owner, int bonus, int hintAtts, int flags );

View file

@ -1,4 +1,4 @@
/* -*- compile-command: "cd ../../../../../../; ant reinstall"; -*- */
/* -*- compile-command: "cd ../../../../../../; ant install"; -*- */
package org.eehouse.android.xw4.jni;
@ -9,6 +9,8 @@ import java.lang.InterruptedException;
import java.util.concurrent.LinkedBlockingQueue;
import android.os.Handler;
import android.os.Message;
import android.graphics.Paint;
import android.graphics.Rect;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
@ -125,8 +127,18 @@ public class JNIThread extends Thread {
trayHt = height - (cellSize * (1 + (nCells-nToScroll)));
}
XwJNI.board_setScoreboardLoc( m_jniGamePtr, 0, 0,
nCells * cellSize, // width
int scoreWidth = nCells * cellSize;
if ( m_gi.timerEnabled ) {
Paint paint = new Paint();
paint.setTextSize( scoreHt );
Rect rect = new Rect();
paint.getTextBounds( "-00:00", 0, 6, rect );
int timerWidth = rect.right;
scoreWidth -= timerWidth;
XwJNI.board_setTimerLoc( m_jniGamePtr, scoreWidth, 0, timerWidth,
scoreHt );
}
XwJNI.board_setScoreboardLoc( m_jniGamePtr, 0, 0, scoreWidth,
scoreHt, true );
XwJNI.board_setPos( m_jniGamePtr, 0, scoreHt, false );

View file

@ -83,6 +83,10 @@ public class XwJNI {
public static native void board_setTrayLoc( int gamePtr, int left,
int top, int width,
int height, int minDividerWidth );
public static native void board_setTimerLoc( int gamePtr,
int timerLeft, int timerTop,
int timerWidth, int timerHeight );
public static native boolean board_handlePenDown( int gamePtr,
int xx, int yy,
boolean[] handled );