add and honor preference for board background color (e.g. scoreboard

and tray when no tile present).  This may allow a light-on-dark theme.
This commit is contained in:
Andy2 2011-04-01 07:17:11 -07:00
parent a64bad0b73
commit 6584c69df1
5 changed files with 28 additions and 12 deletions

View file

@ -23,6 +23,7 @@
<string name="key_bonus_w3x">key_clr_bonus_w3x</string> <string name="key_bonus_w3x">key_clr_bonus_w3x</string>
<string name="key_tile_back">key_clr_tile_back</string> <string name="key_tile_back">key_clr_tile_back</string>
<string name="key_empty">key_clr_empty</string> <string name="key_empty">key_clr_empty</string>
<string name="key_background">key_clr_background</string>
<string name="key_clr_crosshairs">key_clr_crosshairs</string> <string name="key_clr_crosshairs">key_clr_crosshairs</string>
<string name="key_relay_host">key_relay_host</string> <string name="key_relay_host">key_relay_host</string>
<string name="key_relay_port">key_relay_port2</string> <string name="key_relay_port">key_relay_port2</string>

View file

@ -293,6 +293,7 @@
<string name="tile_back">Tile background</string> <string name="tile_back">Tile background</string>
<string name="empty">Empty cell/background</string> <string name="empty">Empty cell/background</string>
<string name="clr_crosshairs">Crosshairs color</string> <string name="clr_crosshairs">Crosshairs color</string>
<string name="background">Board background</string>
<string name="advanced">For debugging</string> <string name="advanced">For debugging</string>
<string name="advanced_summary">You should never need these...</string> <string name="advanced_summary">You should never need these...</string>

View file

@ -129,6 +129,12 @@
android:title="@string/empty" android:title="@string/empty"
android:defaultValue="0xFFFFFF" android:defaultValue="0xFFFFFF"
/> />
<org.eehouse.android.xw4.EditColorPreference
android:key="@string/key_background"
android:title="@string/background"
android:defaultValue="0xFFFFFF"
/>
</PreferenceScreen> </PreferenceScreen>
</PreferenceScreen> </PreferenceScreen>

View file

@ -318,7 +318,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
synchronized( this ) { synchronized( this ) {
if ( null != m_canvas ) { if ( null != m_canvas ) {
if ( 0 == resID ) { if ( 0 == resID ) {
fillRect( rect, m_otherColors[CommonPrefs.COLOR_BKGND] ); fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
} else { } else {
Drawable icon = getResources().getDrawable( resID ); Drawable icon = getResources().getDrawable( resID );
icon.setBounds( rect ); icon.setBounds( rect );
@ -332,7 +332,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
public boolean scoreBegin( Rect rect, int numPlayers, int[] scores, public boolean scoreBegin( Rect rect, int numPlayers, int[] scores,
int remCount, int dfs ) int remCount, int dfs )
{ {
fillRect( rect, WHITE ); fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
m_canvas.save( Canvas.CLIP_SAVE_FLAG ); m_canvas.save( Canvas.CLIP_SAVE_FLAG );
m_canvas.clipRect(rect); m_canvas.clipRect(rect);
m_scores = new String[numPlayers][]; m_scores = new String[numPlayers][];
@ -365,7 +365,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
{ {
int indx = focussed ? CommonPrefs.COLOR_FOCUS int indx = focussed ? CommonPrefs.COLOR_FOCUS
: CommonPrefs.COLOR_TILE_BACK; : CommonPrefs.COLOR_TILE_BACK;
fillRect( rOuter, m_otherColors[indx] ); fillRectOther( rOuter, indx );
m_fillPaint.setColor( BLACK ); m_fillPaint.setColor( BLACK );
drawCentered( m_remText, rInner, null ); drawCentered( m_remText, rInner, null );
@ -416,7 +416,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
public void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi ) public void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi )
{ {
if ( 0 != (dsi.flags & CELL_ISCURSOR) ) { if ( 0 != (dsi.flags & CELL_ISCURSOR) ) {
fillRect( rOuter, m_otherColors[CommonPrefs.COLOR_FOCUS] ); fillRectOther( rOuter, CommonPrefs.COLOR_FOCUS );
} }
String[] texts = m_scores[dsi.playerNum]; String[] texts = m_scores[dsi.playerNum];
m_fillPaint.setColor( m_playerColors[dsi.playerNum] ); m_fillPaint.setColor( m_playerColors[dsi.playerNum] );
@ -440,7 +440,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
String time = String.format( "%s%d:%02d", negSign, secondsLeft/60, String time = String.format( "%s%d:%02d", negSign, secondsLeft/60,
secondsLeft%60 ); secondsLeft%60 );
fillRect( rect, WHITE ); fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
m_fillPaint.setColor( m_playerColors[player] ); m_fillPaint.setColor( m_playerColors[player] );
Rect shorter = new Rect( rect ); Rect shorter = new Rect( rect );
@ -476,7 +476,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
backColor = m_otherColors[CommonPrefs.COLOR_FOCUS]; backColor = m_otherColors[CommonPrefs.COLOR_FOCUS];
} else if ( empty ) { } else if ( empty ) {
if ( 0 == bonus ) { if ( 0 == bonus ) {
backColor = m_otherColors[CommonPrefs.COLOR_BKGND]; backColor = m_otherColors[CommonPrefs.COLOR_NOTILE];
} else { } else {
backColor = m_bonusColors[bonus]; backColor = m_bonusColors[bonus];
bonusStr = m_bonusSummaries[bonus]; bonusStr = m_bonusSummaries[bonus];
@ -606,9 +606,10 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
int flags ) int flags )
{ {
String text = score >= 0? String.format( "%d", score ) : "??"; String text = score >= 0? String.format( "%d", score ) : "??";
int otherIndx = (0 == (flags & CELL_ISCURSOR))
? CommonPrefs.COLOR_BACKGRND : CommonPrefs.COLOR_FOCUS;
++rect.top; ++rect.top;
fillRect( rect, (0 == (flags & CELL_ISCURSOR)) fillRectOther( rect, otherIndx );
? WHITE : m_otherColors[CommonPrefs.COLOR_FOCUS] );
m_fillPaint.setColor( m_playerColors[playerNum] ); m_fillPaint.setColor( m_playerColors[playerNum] );
rect.bottom -= rect.height() / 2; rect.bottom -= rect.height() / 2;
@ -727,7 +728,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
m_canvas.clipRect( rect ); m_canvas.clipRect( rect );
if ( clearBack ) { if ( clearBack ) {
fillRect( rect, WHITE ); fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
} }
if ( isCursor || notEmpty ) { if ( isCursor || notEmpty ) {
@ -844,6 +845,11 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
} }
} }
private void fillRectOther( Rect rect, int index )
{
fillRect( rect, m_otherColors[index] );
}
private void fillRect( Rect rect, int color ) private void fillRect( Rect rect, int color )
{ {
m_fillPaint.setColor( color ); m_fillPaint.setColor( color );
@ -937,7 +943,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
private boolean darkOnLight() private boolean darkOnLight()
{ {
int background = m_otherColors[ CommonPrefs.COLOR_BKGND ]; int background = m_otherColors[ CommonPrefs.COLOR_NOTILE ];
if ( background != m_backgroundUsed ) { if ( background != m_backgroundUsed ) {
m_backgroundUsed = background; m_backgroundUsed = background;

View file

@ -33,9 +33,10 @@ import org.eehouse.android.xw4.GameUtils;
public class CommonPrefs { public class CommonPrefs {
public static final int COLOR_TILE_BACK = 0; public static final int COLOR_TILE_BACK = 0;
public static final int COLOR_BKGND = 1; public static final int COLOR_NOTILE = 1;
public static final int COLOR_FOCUS = 2; public static final int COLOR_FOCUS = 2;
public static final int COLOR_LAST = 3; public static final int COLOR_BACKGRND = 3;
public static final int COLOR_LAST = 4;
private static CommonPrefs s_cp = null; private static CommonPrefs s_cp = null;
@ -99,6 +100,7 @@ public class CommonPrefs {
int idsOther[] = { R.string.key_tile_back, int idsOther[] = { R.string.key_tile_back,
R.string.key_empty, R.string.key_empty,
R.string.key_clr_crosshairs, R.string.key_clr_crosshairs,
R.string.key_background,
}; };
for ( int ii = 0; ii < idsOther.length; ++ii ) { for ( int ii = 0; ii < idsOther.length; ++ii ) {
otherColors[ii] = prefToColor( context, sp, idsOther[ii] ); otherColors[ii] = prefToColor( context, sp, idsOther[ii] );