more work on color prefs. Add a list pref at the same level as colors

for setting "scheme".  Implement that as changing potentially several
colors but only empty cell color for now.  Remove prefs for whether
cell letters follow user colors (they always will) and the new one for
frame color -- it'll always be dark grey.
This commit is contained in:
Andy2 2011-01-18 18:42:25 -08:00
parent 8d52149c28
commit bce4a11595
6 changed files with 86 additions and 56 deletions

View file

@ -25,8 +25,7 @@
<string name="key_tile_back">key_clr_tile_back</string>
<string name="key_empty">key_clr_empty</string>
<string name="key_clr_crosshairs">key_clr_crosshairs</string>
<string name="key_clr_frames">key_clr_frames</string>
<string name="key_hilite_whiteonblack">key_hilite_whiteonblack</string>
<string name="key_board_theme">key_board_theme</string>
<string name="key_relay_host">key_relay_host</string>
<string name="key_relay_port">key_relay_port2</string>
<string name="key_proxy_port">key_proxy_port</string>
@ -83,6 +82,11 @@
<item>@string/robot_smart</item>
</string-array>
<string-array name="board_themes">
<item>@string/black_on_white</item>
<item>@string/white_on_black</item>
</string-array>
<string-array name="connect_frequencies">
<item>@string/connect_thirty_seconds</item>
<item>@string/connect_five_mins</item>

View file

@ -268,7 +268,7 @@
<string name="manage_dicts">Choose</string>
<string name="prefs_colors">Colors</string>
<string name="prefs_colors">Individual colors</string>
<string name="prefs_colors_summary">Edit colors used on the board</string>
<string name="player0">First player</string>
<string name="player1">Second player</string>
@ -287,10 +287,9 @@
<string name="tile_back">Tile background</string>
<string name="empty">Empty cell/background</string>
<string name="clr_crosshairs">Crosshairs color</string>
<string name="clr_frames">Border color</string>
<string name="hilite_whiteonblack">Last play white-on-black</string>
<string name="hilite_whiteonblack_summary">Toggle recent move
contrast colors</string>
<string name="board_themes">Board color schemes</string>
<string name="white_on_black">Dark background</string>
<string name="black_on_white">Light background</string>
<string name="advanced">Advanced</string>
<string name="advanced_summary">You may never need these...</string>

View file

@ -49,11 +49,11 @@
<PreferenceScreen android:title="@string/prefs_appearance"
android:summary="@string/prefs_appearance_summary"
>
<CheckBoxPreference android:key="@string/key_color_tiles"
android:title="@string/color_tiles"
android:summary="@string/color_tiles_summary"
android:defaultValue="true"
/>
<!-- <CheckBoxPreference android:key="@string/key_color_tiles" -->
<!-- android:title="@string/color_tiles" -->
<!-- android:summary="@string/color_tiles_summary" -->
<!-- android:defaultValue="true" -->
<!-- /> -->
<CheckBoxPreference android:key="@string/key_show_arrow"
android:title="@string/show_arrow"
android:summary="@string/show_arrow_summary"
@ -69,14 +69,16 @@
android:summary="@string/show_bonussum_summary"
android:defaultValue="true"
/>
<ListPreference android:key="@string/key_board_theme"
android:title="@string/board_themes"
android:entries="@array/board_themes"
android:entryValues="@array/board_themes"
android:defaultValue="@string/white_on_black"
/>
<PreferenceScreen android:title="@string/prefs_colors"
android:summary="@string/prefs_colors_summary"
>
<CheckBoxPreference android:key="@string/key_hilite_whiteonblack"
android:title="@string/hilite_whiteonblack"
android:summary="@string/hilite_whiteonblack_summary"
android:defaultValue="true"
/>
<org.eehouse.android.xw4.EditColorPreference
android:key="@string/key_player0"
android:title="@string/player0"
@ -117,20 +119,16 @@
android:title="@string/bonus_w3x"
android:defaultValue="0xAFAFAF"
/>
<org.eehouse.android.xw4.EditColorPreference
android:key="@string/key_tile_back"
android:title="@string/tile_back"
android:defaultValue="0xFFFF99"
/>
<org.eehouse.android.xw4.EditColorPreference
android:key="@string/key_clr_crosshairs"
android:title="@string/clr_crosshairs"
android:defaultValue="0x7070FF"
/>
<org.eehouse.android.xw4.EditColorPreference
android:key="@string/key_clr_frames"
android:title="@string/clr_frames"
android:defaultValue="0x101010"
android:key="@string/key_tile_back"
android:title="@string/tile_back"
android:defaultValue="0xFFFF99"
/>
<org.eehouse.android.xw4.EditColorPreference
android:key="@string/key_empty"

View file

@ -67,6 +67,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
private boolean m_blackArrow;
// m_backgroundUsed: alpha not set ensures inequality
private int m_backgroundUsed = 0x00000000;
private boolean m_darkOnLight;
private Drawable m_origin;
private int m_left, m_top;
private JNIThread m_jniThread;
@ -115,6 +116,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private static final int FRAME_GREY = 0xFF101010;
private static final int GREY = 0xFF7F7F7F;
private int[] m_bonusColors;
private int[] m_playerColors;
@ -476,7 +478,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
}
} else if ( pending ) {
if ( CommonPrefs.getHiliteWhiteOnBlack( m_context ) ) {
if ( darkOnLight() ) {
foreColor = WHITE;
backColor = BLACK;
} else {
@ -509,7 +511,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
// frame the cell
m_strokePaint.setColor( m_otherColors[CommonPrefs.COLOR_FRAMES] );
m_strokePaint.setColor( FRAME_GREY );
m_canvas.drawRect( rect, m_strokePaint );
drawCrosshairs( rect, flags );
@ -521,32 +523,21 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
public void drawBoardArrow( Rect rect, int bonus, boolean vert,
int hintAtts, int flags )
{
Drawable arrow ;
// figure out if the background is more dark than light
int sum = 0;
int background = m_otherColors[ CommonPrefs.COLOR_BKGND ];
if ( background != m_backgroundUsed ) {
m_backgroundUsed = background;
for ( int ii = 0; ii < 3; ++ii ) {
sum += background & 0xFF;
background >>= 8;
}
boolean blackArrow = sum > (127 * 3);
if ( m_blackArrow != blackArrow ) {
m_blackArrow = blackArrow;
m_downArrow = m_rightArrow = null;
}
boolean useDark = darkOnLight();
if ( m_blackArrow != useDark ) {
m_blackArrow = useDark;
m_downArrow = m_rightArrow = null;
}
Drawable arrow;
if ( vert ) {
if ( null == m_downArrow ) {
m_downArrow = loadAndRecolor( R.drawable.downarrow );
m_downArrow = loadAndRecolor( R.drawable.downarrow, useDark );
}
arrow = m_downArrow;
} else {
if ( null == m_rightArrow ) {
m_rightArrow = loadAndRecolor( R.drawable.rightarrow );
m_rightArrow = loadAndRecolor( R.drawable.rightarrow, useDark );
}
arrow = m_rightArrow;
}
@ -940,12 +931,28 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
}
private Drawable loadAndRecolor( int resID )
private boolean darkOnLight()
{
int background = m_otherColors[ CommonPrefs.COLOR_BKGND ];
if ( background != m_backgroundUsed ) {
m_backgroundUsed = background;
int sum = 0;
for ( int ii = 0; ii < 3; ++ii ) {
sum += background & 0xFF;
background >>= 8;
}
m_darkOnLight = sum > (127*3);
}
return m_darkOnLight;
}
private Drawable loadAndRecolor( int resID, boolean useDark )
{
Resources res = getResources();
Drawable arrow = res.getDrawable( resID );
if ( ! m_blackArrow ) {
if ( !useDark ) {
Bitmap src = ((BitmapDrawable)arrow).getBitmap();
Bitmap bitmap = src.copy( Bitmap.Config.ARGB_8888, true );
for ( int xx = 0; xx < bitmap.getWidth(); ++xx ) {

View file

@ -39,6 +39,10 @@ public class PrefsActivity extends PreferenceActivity
private static final int REVERT_ALL = 2;
private String[] m_keys;
private String m_boardThemeKey;
private String m_keyEmpty;
private String m_whiteOnBlack;
private String m_blackOnWhite;
@Override
protected Dialog onCreateDialog( int id )
@ -118,6 +122,7 @@ public class PrefsActivity extends PreferenceActivity
R.string.key_initial_player_minutes,
R.string.key_default_dict,
R.string.key_default_phonies,
R.string.key_board_theme,
};
SharedPreferences sp
@ -129,6 +134,10 @@ public class PrefsActivity extends PreferenceActivity
setSummary( sp, key );
m_keys[ii] = key;
}
m_boardThemeKey = getString( R.string.key_board_theme );
m_keyEmpty = getString( R.string.key_empty );
m_whiteOnBlack = getString( R.string.white_on_black );
m_blackOnWhite = getString( R.string.black_on_white );
}
@Override
@ -149,12 +158,33 @@ public class PrefsActivity extends PreferenceActivity
public void onSharedPreferenceChanged( SharedPreferences sp, String key )
{
// This would search faster if it were a hash set...
for ( String akey : m_keys ) {
if ( akey.equals( key ) ) {
setSummary( sp, key );
break;
}
}
// Change those color elements that follow the "themes" --
// currently only key_empty
while ( m_boardThemeKey.equals( key ) ) { // while allows break
String newValue = sp.getString( key, "" );
int color;
if ( m_whiteOnBlack.equals( newValue ) ) {
color = 0xFF000000;
} else if ( m_blackOnWhite.equals( newValue ) ) {
color = 0xFFFFFFFF;
} else {
break;
}
SharedPreferences.Editor editor = sp.edit();
editor.putInt( m_keyEmpty, color );
editor.commit();
break;
}
}
@Override

View file

@ -35,8 +35,7 @@ public class CommonPrefs {
public static final int COLOR_TILE_BACK = 0;
public static final int COLOR_BKGND = 1;
public static final int COLOR_FOCUS = 2;
public static final int COLOR_FRAMES = 3;
public static final int COLOR_LAST = 4;
public static final int COLOR_LAST = 3;
private static CommonPrefs s_cp = null;
@ -104,7 +103,6 @@ public class CommonPrefs {
int idsOther[] = { R.string.key_tile_back,
R.string.key_empty,
R.string.key_clr_crosshairs,
R.string.key_clr_frames,
};
for ( int ii = 0; ii < idsOther.length; ++ii ) {
otherColors[ii] = prefToColor( context, sp, idsOther[ii] );
@ -255,12 +253,6 @@ public class CommonPrefs {
return getPrefsBoolean( context, R.string.key_show_bonussum, false );
}
public static boolean getHiliteWhiteOnBlack( Context context )
{
return getPrefsBoolean( context, R.string.key_hilite_whiteonblack,
true );
}
public static boolean getPrefsBoolean( Context context, int keyID,
boolean defaultValue )
{