mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
do app prefs the way they're supposed to be done
This commit is contained in:
parent
338a39e8b4
commit
4db8750ec0
7 changed files with 86 additions and 69 deletions
|
@ -183,4 +183,18 @@
|
|||
<string name="port_label">Port</string>
|
||||
<string name="role_edit_title">Connection</string>
|
||||
|
||||
<string name="general_prefs">Preferences</string>
|
||||
<string name="prefs_colors">Colors</string>
|
||||
<string name="player0">First player</string>
|
||||
<string name="player1">Second player</string>
|
||||
|
||||
<!-- These do not require localization -->
|
||||
<string name="key_color_tiles">key_color_tiles</string>
|
||||
<string name="key_show_arrow">key_show_arrow</string>
|
||||
<string name="key_explain_robot">key_explain_robot</string>
|
||||
<string name="key_skip_confirm">key_skip_confirm</string>
|
||||
<string name="key_hide_values">key_hide_values</string>
|
||||
<string name="key_player0">key_player0</string>
|
||||
<string name="key_player1">key_player1</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -50,6 +50,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
private String m_dlgBytes = null;
|
||||
private int m_dlgTitle;
|
||||
private boolean m_dlgResult;
|
||||
private CommonPrefs m_cp;
|
||||
|
||||
// call startActivityForResult synchronously
|
||||
private Semaphore m_forResultWait = new Semaphore(0);
|
||||
|
@ -111,6 +112,8 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
{
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
m_cp = new CommonPrefs( this );
|
||||
|
||||
setContentView( R.layout.board );
|
||||
m_handler = new Handler();
|
||||
m_timers = new TimerRunnable[4]; // needs to be in sync with
|
||||
|
@ -144,10 +147,9 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
if ( null == stream ||
|
||||
! XwJNI.game_makeFromStream( m_jniGamePtr, stream,
|
||||
m_gi, dictBytes, this,
|
||||
m_view, Utils.getCP(),
|
||||
m_xport ) ) {
|
||||
m_view, m_cp, m_xport ) ) {
|
||||
XwJNI.game_makeNewGame( m_jniGamePtr, m_gi, this, m_view,
|
||||
Utils.getCP(), m_xport, dictBytes );
|
||||
m_cp, m_xport, dictBytes );
|
||||
}
|
||||
|
||||
m_jniThread = new
|
||||
|
@ -177,11 +179,17 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
}
|
||||
} // onCreate
|
||||
|
||||
// protected void onPause() {
|
||||
// // save state here
|
||||
// saveGame();
|
||||
// super.onPause();
|
||||
// }
|
||||
@Override
|
||||
public void onWindowFocusChanged( boolean hasFocus )
|
||||
{
|
||||
super.onWindowFocusChanged( hasFocus );
|
||||
if ( hasFocus )
|
||||
if ( null == m_cp ) {
|
||||
m_cp = new CommonPrefs( this );
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_PREFS_CHANGE, m_cp );
|
||||
}
|
||||
onContentChanged();
|
||||
}
|
||||
|
||||
protected void onDestroy()
|
||||
{
|
||||
|
@ -275,6 +283,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
Utils.notImpl(this);
|
||||
break;
|
||||
case R.id.board_menu_file_prefs:
|
||||
m_cp = null; // mark so we'll reset it later
|
||||
startActivity( new Intent( this, PrefsActivity.class ) );
|
||||
break;
|
||||
case R.id.board_menu_file_about:
|
||||
|
|
|
@ -52,6 +52,8 @@ public class GamesList extends ListActivity implements View.OnClickListener {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
CommonPrefs.setContext( this );
|
||||
|
||||
setContentView(R.layout.game_list);
|
||||
|
||||
// setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.content.Intent;
|
||||
|
@ -14,7 +15,7 @@ import android.widget.Button;
|
|||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
|
||||
public class PrefsActivity extends Activity implements View.OnClickListener {
|
||||
public class PrefsActivity extends PreferenceActivity {
|
||||
|
||||
private Button m_doneB;
|
||||
private CommonPrefs m_cp;
|
||||
|
@ -22,36 +23,9 @@ public class PrefsActivity extends Activity implements View.OnClickListener {
|
|||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
Utils.logf( "PrefsActivity::onCreate() called" );
|
||||
super.onCreate( savedInstanceState );
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
m_cp = new CommonPrefs( Utils.getCP() );
|
||||
|
||||
setContentView( R.layout.prefs );
|
||||
|
||||
Utils.setChecked( this, R.id.color_tiles, m_cp.showColors );
|
||||
Utils.setChecked( this, R.id.show_arrow, m_cp.showBoardArrow );
|
||||
Utils.setChecked( this, R.id.explain_robot, m_cp.showRobotScores );
|
||||
Utils.setChecked( this, R.id.skip_confirm_turn, m_cp.skipCommitConfirm );
|
||||
Utils.setChecked( this, R.id.hide_values, m_cp.hideTileValues );
|
||||
|
||||
m_doneB = (Button)findViewById(R.id.prefs_done);
|
||||
m_doneB.setOnClickListener( this );
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource( R.xml.xwprefs );
|
||||
}
|
||||
|
||||
public void onClick( View view )
|
||||
{
|
||||
if ( m_doneB == view ) {
|
||||
|
||||
m_cp.showColors = Utils.getChecked( this, R.id.color_tiles );
|
||||
m_cp.showBoardArrow = Utils.getChecked( this, R.id.show_arrow );
|
||||
m_cp.showRobotScores = Utils.getChecked( this, R.id.explain_robot );
|
||||
m_cp.skipCommitConfirm = Utils.getChecked( this, R.id.skip_confirm_turn );
|
||||
m_cp.hideTileValues = Utils.getChecked( this, R.id.hide_values );
|
||||
|
||||
Utils.setCP( m_cp );
|
||||
|
||||
finish();
|
||||
}
|
||||
} // onClick
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.eehouse.android.xw4.jni.JNIThread.*;
|
|||
|
||||
public class Utils {
|
||||
static final String TAG = "EJAVA";
|
||||
private static CommonPrefs m_cp;
|
||||
private static JNIThread s_jniThread = null;
|
||||
|
||||
private Utils() {}
|
||||
|
@ -249,25 +248,4 @@ public class Utils {
|
|||
return Integer.parseInt( str );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
if ( null != s_jniThread ) {
|
||||
s_jniThread.handle( JNICmd.CMD_PREFS_CHANGE, m_cp );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,22 +1,50 @@
|
|||
/* -*- compile-command: "cd ../../../../../../; ant reinstall"; -*- */
|
||||
|
||||
package org.eehouse.android.xw4.jni;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import org.eehouse.android.xw4.R;
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class CommonPrefs {
|
||||
private static Context s_context = null;
|
||||
|
||||
public boolean showBoardArrow;
|
||||
public boolean showRobotScores;
|
||||
public boolean hideTileValues;
|
||||
public boolean skipCommitConfirm;
|
||||
public boolean showColors;
|
||||
|
||||
public CommonPrefs() {
|
||||
showBoardArrow = true;
|
||||
showRobotScores = false;
|
||||
hideTileValues = false;
|
||||
skipCommitConfirm = false;
|
||||
showColors = true;
|
||||
public CommonPrefs( Context context )
|
||||
{
|
||||
if ( s_context == null ) {
|
||||
s_context = context;
|
||||
}
|
||||
|
||||
SharedPreferences sp =
|
||||
PreferenceManager.getDefaultSharedPreferences( s_context );
|
||||
String str;
|
||||
|
||||
str = s_context.getString( R.string.key_show_arrow );
|
||||
showBoardArrow = sp.getBoolean( str, true );
|
||||
|
||||
str = s_context.getString( R.string.key_explain_robot );
|
||||
showRobotScores = sp.getBoolean( str, false );
|
||||
|
||||
str = s_context.getString( R.string.key_hide_values );
|
||||
hideTileValues = sp.getBoolean( str, false );
|
||||
|
||||
str = s_context.getString( R.string.key_skip_confirm );
|
||||
skipCommitConfirm = sp.getBoolean( str, false );
|
||||
|
||||
str = s_context.getString( R.string.key_color_tiles );
|
||||
showColors = sp.getBoolean( str, true );
|
||||
}
|
||||
|
||||
public CommonPrefs( CommonPrefs src ) {
|
||||
this();
|
||||
public CommonPrefs( Context context, CommonPrefs src ) {
|
||||
this( context );
|
||||
copyFrom( src );
|
||||
}
|
||||
|
||||
|
@ -28,4 +56,10 @@ public class CommonPrefs {
|
|||
skipCommitConfirm = src.skipCommitConfirm;
|
||||
showColors = src.showColors;
|
||||
}
|
||||
|
||||
public static void setContext( Context context )
|
||||
{
|
||||
Assert.assertTrue( s_context == null );
|
||||
s_context = context;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,12 @@ for XML_FILE in $(find res/menu -name '*.xml'); do
|
|||
done
|
||||
done
|
||||
|
||||
for XML_FILE in $(find res/xml -name '*.xml'); do
|
||||
for STRING in $(grep 'android:.*="@string/' $XML_FILE | sed 's,^.*"@string/\(.*\)".*$,\1,'); do
|
||||
check_add $STRING
|
||||
done
|
||||
done
|
||||
|
||||
for JAVA_FILE in $(find src -name '*.java'); do
|
||||
for STRING in $(grep -E 'R\.string\.' $JAVA_FILE | sed 's/^.*R\.string\.\([a-z_]*\).*$/\1/'); do
|
||||
check_add $STRING
|
||||
|
|
Loading…
Add table
Reference in a new issue