From bce4a1159569c300370603389de3da6eb354b7ac Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 18 Jan 2011 18:42:25 -0800 Subject: [PATCH] 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. --- .../XWords4/res/values/common_rsrc.xml | 8 ++- .../android/XWords4/res/values/strings.xml | 9 ++-- xwords4/android/XWords4/res/xml/xwprefs.xml | 34 ++++++------- .../org/eehouse/android/xw4/BoardView.java | 51 +++++++++++-------- .../eehouse/android/xw4/PrefsActivity.java | 30 +++++++++++ .../eehouse/android/xw4/jni/CommonPrefs.java | 10 +--- 6 files changed, 86 insertions(+), 56 deletions(-) diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index d0271a566..529248ac1 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -25,8 +25,7 @@ key_clr_tile_back key_clr_empty key_clr_crosshairs - key_clr_frames - key_hilite_whiteonblack + key_board_theme key_relay_host key_relay_port2 key_proxy_port @@ -83,6 +82,11 @@ @string/robot_smart + + @string/black_on_white + @string/white_on_black + + @string/connect_thirty_seconds @string/connect_five_mins diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 5a86c102c..9b964e1c1 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -268,7 +268,7 @@ Choose - Colors + Individual colors Edit colors used on the board First player Second player @@ -287,10 +287,9 @@ Tile background Empty cell/background Crosshairs color - Border color - Last play white-on-black - Toggle recent move - contrast colors + Board color schemes + Dark background + Light background Advanced You may never need these... diff --git a/xwords4/android/XWords4/res/xml/xwprefs.xml b/xwords4/android/XWords4/res/xml/xwprefs.xml index 260f0713e..d0872209d 100644 --- a/xwords4/android/XWords4/res/xml/xwprefs.xml +++ b/xwords4/android/XWords4/res/xml/xwprefs.xml @@ -49,11 +49,11 @@ - + + + + + + + - - + >= 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 ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java index ab6965b2b..ddfaa1064 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java @@ -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 diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java index a337c045f..1d1d7feb4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java @@ -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 ) {