From ec085d89440b7a5e3d5ff3649ce6395f855c0b68 Mon Sep 17 00:00:00 2001 From: ehouse Date: Tue, 26 Jan 2010 14:48:37 +0000 Subject: [PATCH] lots of little changes toward making prefs (per-game and global) work, which they more-or-less do. Some still not captured. --- .../XWords4/res/layout/player_view.xml | 11 +++++ .../XWords4/res/menu/game_config_menu.xml | 3 ++ .../XWords4/res/menu/games_list_menu.xml | 3 ++ .../android/XWords4/res/values/strings.xml | 22 ++++++++- .../eehouse/android/xw4/BoardActivity.java | 6 +-- .../org/eehouse/android/xw4/BoardView.java | 3 ++ .../org/eehouse/android/xw4/GamesList.java | 12 ++++- .../org/eehouse/android/xw4/PlayerView.java | 19 ++++++++ .../src/org/eehouse/android/xw4/Utils.java | 47 +++++++++++++++++++ .../eehouse/android/xw4/jni/CommonPrefs.java | 16 +++++++ .../eehouse/android/xw4/jni/CurGameInfo.java | 14 +++++- 11 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 xwords4/android/XWords4/res/layout/player_view.xml create mode 100644 xwords4/android/XWords4/src/org/eehouse/android/xw4/PlayerView.java diff --git a/xwords4/android/XWords4/res/layout/player_view.xml b/xwords4/android/XWords4/res/layout/player_view.xml new file mode 100644 index 000000000..e8ad4a279 --- /dev/null +++ b/xwords4/android/XWords4/res/layout/player_view.xml @@ -0,0 +1,11 @@ + + + diff --git a/xwords4/android/XWords4/res/menu/game_config_menu.xml b/xwords4/android/XWords4/res/menu/game_config_menu.xml index f401fc9c5..f52466c51 100644 --- a/xwords4/android/XWords4/res/menu/game_config_menu.xml +++ b/xwords4/android/XWords4/res/menu/game_config_menu.xml @@ -1,6 +1,9 @@ + diff --git a/xwords4/android/XWords4/res/menu/games_list_menu.xml b/xwords4/android/XWords4/res/menu/games_list_menu.xml index 5b8be1807..4d18fd606 100644 --- a/xwords4/android/XWords4/res/menu/games_list_menu.xml +++ b/xwords4/android/XWords4/res/menu/games_list_menu.xml @@ -4,6 +4,9 @@ + diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 7eca3616d..5c9f7d28e 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -146,14 +146,34 @@ Players Add player - Juggle + Juggle players Up one Down one Dictionary + Role + Phonies + Download more... http://eehouse.org/and_dicts + Allow hints + Enable timer + Color tiles + Smart robot + Show board arrow + Explain robot moves + Skip confirming turn + Hide values + + Standalone + Host + Guest + + Ignore + Warn + Disallow + Preferences diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index 4777df4c2..ce1347d40 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -40,7 +40,6 @@ public class BoardActivity extends Activity implements UtilCtxt, Runnable { private BoardView m_view; private int m_jniGamePtr; private CurGameInfo m_gi; - private CommonPrefs m_prefs; private Handler m_handler; private TimerRunnable[] m_timers; private String m_path; @@ -114,7 +113,6 @@ public class BoardActivity extends Activity implements UtilCtxt, Runnable { m_handler = new Handler(); m_timers = new TimerRunnable[4]; // needs to be in sync with // XWTimerReason - m_prefs = new CommonPrefs(); m_gi = new CurGameInfo(); m_view = (BoardView)findViewById( R.id.board_view ); @@ -140,10 +138,10 @@ public class BoardActivity extends Activity implements UtilCtxt, Runnable { if ( null == stream || ! XwJNI.game_makeFromStream( m_jniGamePtr, stream, m_gi, dictBytes, this, - m_view, m_prefs, + m_view, Utils.getCP(), null ) ) { XwJNI.game_makeNewGame( m_jniGamePtr, m_gi, this, m_view, 0, - m_prefs, null, dictBytes ); + Utils.getCP(), null, dictBytes ); } m_jniThread = new diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index ce739afb7..5cbf7b2f2 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -275,6 +275,9 @@ public class BoardView extends View implements DrawCtx, backColor = BLACK; } else { backColor = TILE_BACK; + if ( owner < 0 ) { + owner = 0; + } foreColor = m_playerColors[owner]; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 65ea6635c..1a684a2cc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -177,10 +177,20 @@ public class GamesList extends ListActivity implements View.OnClickListener { setListAdapter( m_adapter ); handled = true; break; + + case R.id.gamel_menu_prefs: + Intent intent = new Intent( this, PrefsActivity.class ); + intent.setAction( Intent.ACTION_EDIT ); + startActivity( intent ); + break; + case R.id.gamel_menu_view_hidden: Utils.notImpl( this ); break; + default: + handled = false; } + return handled; } @@ -208,7 +218,7 @@ public class GamesList extends ListActivity implements View.OnClickListener { Uri uri = Uri.fromFile( new File(path) ); Intent intent = new Intent( Intent.ACTION_EDIT, uri, - GamesList.this, GameConfig.class ); + this, GameConfig.class ); startActivity( intent ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PlayerView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PlayerView.java new file mode 100644 index 000000000..f230c5d99 --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PlayerView.java @@ -0,0 +1,19 @@ +/* -*- compile-command: "cd ../../../../../; ant reinstall"; -*- */ + +package org.eehouse.android.xw4; + +import android.widget.TextView; +import android.app.Activity; +import android.content.Context; +import android.util.AttributeSet; + +public class PlayerView extends TextView { + private int m_position; + + public PlayerView( Context cx, AttributeSet as ) { + super( cx, as ); + } + + public int getPosition() { return m_position; } + public void setPosition( int indx ) { m_position = indx; } +} diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index f118fa633..8a95e9f4a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -14,9 +14,15 @@ import java.util.ArrayList; import android.content.res.AssetManager; import android.os.Environment; import java.io.InputStream; +import android.widget.CheckBox; +import android.app.Activity; +import android.app.Dialog; + +import org.eehouse.android.xw4.jni.*; public class Utils { static final String TAG = "EJAVA"; + private static CommonPrefs m_cp; private Utils() {} @@ -176,4 +182,45 @@ public class Utils { return bytes; } + public static void setChecked( Activity activity, int id, boolean value ) + { + CheckBox cbx = (CheckBox)activity.findViewById( id ); + cbx.setChecked( value ); + } + + public static void setChecked( Dialog dialog, int id, boolean value ) + { + CheckBox cbx = (CheckBox)dialog.findViewById( id ); + cbx.setChecked( value ); + } + + public static boolean getChecked( Activity activity, int id ) + { + CheckBox cbx = (CheckBox)activity.findViewById( id ); + return cbx.isChecked(); + } + + public static boolean getChecked( Dialog dialog, int id ) + { + CheckBox cbx = (CheckBox)dialog.findViewById( id ); + return cbx.isChecked(); + } + + public static CommonPrefs getCP() + { + if ( null == m_cp ) { + m_cp = new CommonPrefs(); + } + return m_cp; + } + + public static void setCP( CommonPrefs cp ) + { + if ( null == m_cp ) { + m_cp = new CommonPrefs( cp ); + } else { + m_cp.copyFrom( cp ); + } + } + } 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 bad8270d1..7a500cc91 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 @@ -5,11 +5,27 @@ public class CommonPrefs { public boolean showRobotScores; public boolean hideTileValues; public boolean skipCommitConfirm; + public boolean showColors; public CommonPrefs() { showBoardArrow = true; showRobotScores = true; hideTileValues = false; skipCommitConfirm = false; + showColors = true; + } + + public CommonPrefs( CommonPrefs src ) { + this(); + copyFrom( src ); + } + + public void copyFrom( CommonPrefs src ) + { + showBoardArrow = src.showBoardArrow; + showRobotScores = src.showRobotScores; + hideTileValues = src.hideTileValues; + skipCommitConfirm = src.skipCommitConfirm; + showColors = src.showColors; } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java index 6d08e4491..0942a25b5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java @@ -16,7 +16,6 @@ public class CurGameInfo { public String dictName; public LocalPlayer[] players; public int gameID; - public int gameSeconds; /* for timer */ public int nPlayers; public int boardSize; public DeviceRole serverRole; @@ -25,6 +24,7 @@ public class CurGameInfo { public boolean timerEnabled; public boolean allowPickTiles; public boolean allowHintRect; + public boolean showColors; public int robotSmartness; public XWPhoniesChoice phoniesAction; public boolean confirmBTConnect; /* only used for BT */ @@ -36,6 +36,12 @@ public class CurGameInfo { serverRole = DeviceRole.SERVER_STANDALONE; dictName = BUILTIN_DICT; hintsNotAllowed = false; + phoniesAction = XWPhoniesChoice.PHONIES_IGNORE; + timerEnabled = false; + allowPickTiles = false; + allowHintRect = false; + showColors = true; + robotSmartness = 1; // Always create MAX_NUM_PLAYERS so jni code doesn't ever have // to cons up a LocalPlayer instance. @@ -52,6 +58,12 @@ public class CurGameInfo { serverRole = src.serverRole; dictName = src.dictName; hintsNotAllowed = src.hintsNotAllowed; + phoniesAction = src.phoniesAction; + timerEnabled = src.timerEnabled; + allowPickTiles = src.allowPickTiles; + allowHintRect = src.allowHintRect; + showColors = src.showColors; + robotSmartness = src.robotSmartness; int ii; for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {