Merge branch 'android_branch' into android_invite

Conflicts:
	xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java
This commit is contained in:
Andy2 2011-07-19 18:34:39 -07:00
commit 785a64123f
8 changed files with 315 additions and 221 deletions

View file

@ -11,23 +11,27 @@
android:summary="@string/prefs_names_summary" android:summary="@string/prefs_names_summary"
> >
<EditTextPreference android:key="@string/key_player1_name" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_player1_name"
android:title="@string/pref_player1_name" android:title="@string/pref_player1_name"
android:defaultValue="" android:defaultValue=""
/> />
<EditTextPreference android:key="@string/key_player2_name" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_player2_name"
android:title="@string/pref_player2_name" android:title="@string/pref_player2_name"
android:defaultValue="ignored" android:defaultValue="ignored"
android:summary="@string/tell_unused" android:summary="@string/tell_unused"
android:enabled="false" android:enabled="false"
/> />
<EditTextPreference android:key="@string/key_player3_name" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_player3_name"
android:title="@string/pref_player3_name" android:title="@string/pref_player3_name"
android:defaultValue="" android:defaultValue=""
android:summary="@string/tell_unused" android:summary="@string/tell_unused"
android:enabled="false" android:enabled="false"
/> />
<EditTextPreference android:key="@string/key_player4_name" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_player4_name"
android:title="@string/pref_player4_name" android:title="@string/pref_player4_name"
android:defaultValue="" android:defaultValue=""
android:summary="@string/tell_unused" android:summary="@string/tell_unused"
@ -63,7 +67,8 @@
android:defaultValue="false" android:defaultValue="false"
/> />
<ListPreference android:key="@string/key_default_phonies" <org.eehouse.android.xw4.XWListPreference
android:key="@string/key_default_phonies"
android:title="@string/default_phonies" android:title="@string/default_phonies"
android:entries="@array/phony_names" android:entries="@array/phony_names"
android:entryValues="@array/phony_names" android:entryValues="@array/phony_names"
@ -75,13 +80,15 @@
android:defaultValue="false" android:defaultValue="false"
/> />
<EditTextPreference android:key="@string/key_initial_player_minutes" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_initial_player_minutes"
android:title="@string/initial_player_minutes" android:title="@string/initial_player_minutes"
android:defaultValue="25" android:defaultValue="25"
android:numeric="decimal" android:numeric="decimal"
/> />
<ListPreference android:key="@string/key_board_size" <org.eehouse.android.xw4.XWListPreference
android:key="@string/key_board_size"
android:title="@string/board_size" android:title="@string/board_size"
android:entries="@array/board_sizes" android:entries="@array/board_sizes"
android:entryValues="@array/board_sizes" android:entryValues="@array/board_sizes"
@ -244,31 +251,31 @@
<PreferenceScreen android:title="@string/advanced" <PreferenceScreen android:title="@string/advanced"
android:summary="@string/advanced_summary" android:summary="@string/advanced_summary"
> >
<EditTextPreference android:key="@string/key_relay_host" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_relay_host"
android:title="@string/relay_host" android:title="@string/relay_host"
android:defaultValue="@string/default_host" android:defaultValue="@string/default_host"
/> />
<EditTextPreference android:key="@string/key_relay_port" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_relay_port"
android:title="@string/relay_port" android:title="@string/relay_port"
android:defaultValue="10997" android:defaultValue="10997"
android:numeric="decimal" android:numeric="decimal"
/> />
<EditTextPreference android:key="@string/key_proxy_port" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_proxy_port"
android:title="@string/proxy_port" android:title="@string/proxy_port"
android:defaultValue="10998" android:defaultValue="10998"
android:numeric="decimal" android:numeric="decimal"
/> />
<EditTextPreference android:key="@string/key_redir_host" <org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_redir_host"
android:title="@string/redir_host" android:title="@string/redir_host"
android:defaultValue="@string/default_host" android:defaultValue="@string/default_host"
/> />
<!-- <EditTextPreference android:key="@string/key_sms_port" --> <org.eehouse.android.xw4.XWEditTextPreference
<!-- android:title="@string/sms_port" --> android:key="@string/key_dict_host"
<!-- android:defaultValue="5432" -->
<!-- android:numeric="decimal" -->
<!-- /> -->
<EditTextPreference android:key="@string/key_dict_host"
android:title="@string/dict_host" android:title="@string/dict_host"
android:defaultValue="@string/dict_url" android:defaultValue="@string/dict_url"
/> />

View file

@ -77,7 +77,7 @@ public class BoardActivity extends XWActivity
private GameUtils.GameLock m_gameLock; private GameUtils.GameLock m_gameLock;
private CurGameInfo m_gi; private CurGameInfo m_gi;
CommsTransport m_xport; CommsTransport m_xport;
private Handler m_handler; private Handler m_handler = null;
private TimerRunnable[] m_timers; private TimerRunnable[] m_timers;
private Runnable m_screenTimer; private Runnable m_screenTimer;
private String m_name; private String m_name;
@ -324,7 +324,6 @@ public class BoardActivity extends XWActivity
m_utils = new BoardUtilCtxt(); m_utils = new BoardUtilCtxt();
m_jniu = JNIUtilsImpl.get(); m_jniu = JNIUtilsImpl.get();
setContentView( R.layout.board ); setContentView( R.layout.board );
m_handler = new Handler();
m_timers = new TimerRunnable[4]; // needs to be in sync with m_timers = new TimerRunnable[4]; // needs to be in sync with
// XWTimerReason // XWTimerReason
m_gi = new CurGameInfo( this ); m_gi = new CurGameInfo( this );
@ -343,6 +342,7 @@ public class BoardActivity extends XWActivity
@Override @Override
protected void onPause() protected void onPause()
{ {
m_handler = null;
waitCloseGame( true ); waitCloseGame( true );
super.onPause(); super.onPause();
} }
@ -351,6 +351,7 @@ public class BoardActivity extends XWActivity
protected void onResume() protected void onResume()
{ {
super.onResume(); super.onResume();
m_handler = new Handler();
setKeepScreenOn(); setKeepScreenOn();
loadGame(); loadGame();
} }
@ -558,7 +559,7 @@ public class BoardActivity extends XWActivity
public void tpmRelayConnd( final String room, final int devOrder, public void tpmRelayConnd( final String room, final int devOrder,
final boolean allHere, final int nMissing ) final boolean allHere, final int nMissing )
{ {
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
handleConndMessage( room, devOrder, allHere, nMissing ); handleConndMessage( room, devOrder, allHere, nMissing );
} }
@ -612,7 +613,7 @@ public class BoardActivity extends XWActivity
} else if ( dlgID >= 0 ) { } else if ( dlgID >= 0 ) {
final int strIDf = strID; final int strIDf = strID;
final int dlgIDf = dlgID; final int dlgIDf = dlgID;
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
m_dlgBytes = getString( strIDf ); m_dlgBytes = getString( strIDf );
m_dlgTitle = R.string.relay_alert; m_dlgTitle = R.string.relay_alert;
@ -762,7 +763,7 @@ public class BoardActivity extends XWActivity
public void requestTime() public void requestTime()
{ {
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
if ( null != m_jniThread ) { if ( null != m_jniThread ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_DO, false ); m_jniThread.handle( JNIThread.JNICmd.CMD_DO, false );
@ -795,7 +796,7 @@ public class BoardActivity extends XWActivity
public void setTimer( int why, int when, int handle ) public void setTimer( int why, int when, int handle )
{ {
if ( null != m_timers[why] ) { if ( null != m_timers[why] ) {
m_handler.removeCallbacks( m_timers[why] ); removeCallbacks( m_timers[why] );
} }
m_timers[why] = new TimerRunnable( why, when, handle ); m_timers[why] = new TimerRunnable( why, when, handle );
@ -811,13 +812,13 @@ public class BoardActivity extends XWActivity
default: default:
inHowLong = 500; inHowLong = 500;
} }
m_handler.postDelayed( m_timers[why], inHowLong ); postDelayed( m_timers[why], inHowLong );
} }
public void clearTimer( int why ) public void clearTimer( int why )
{ {
if ( null != m_timers[why] ) { if ( null != m_timers[why] ) {
m_handler.removeCallbacks( m_timers[why] ); removeCallbacks( m_timers[why] );
m_timers[why] = null; m_timers[why] = null;
} }
} }
@ -852,7 +853,7 @@ public class BoardActivity extends XWActivity
public void turnChanged() public void turnChanged()
{ {
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
showNotAgainDlgThen( R.string.not_again_turnchanged, showNotAgainDlgThen( R.string.not_again_turnchanged,
R.string.key_notagain_turnchanged, R.string.key_notagain_turnchanged,
@ -870,7 +871,7 @@ public class BoardActivity extends XWActivity
public void engineStarting( int nBlanks ) public void engineStarting( int nBlanks )
{ {
if ( nBlanks > 0 ) { if ( nBlanks > 0 ) {
m_handler.post( new Runnable() { post( new Runnable() {
// Need to keep this from running after activity dies!! // Need to keep this from running after activity dies!!
public void run() { public void run() {
if ( m_isVisible ) { if ( m_isVisible ) {
@ -888,7 +889,7 @@ public class BoardActivity extends XWActivity
public void engineStopping() public void engineStopping()
{ {
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
if ( null != m_progress ) { if ( null != m_progress ) {
m_progress.cancel(); m_progress.cancel();
@ -1037,7 +1038,7 @@ public class BoardActivity extends XWActivity
// chat-messages. // chat-messages.
public void showChat( final String msg ) public void showChat( final String msg )
{ {
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
DBUtils.appendChatHistory( BoardActivity.this, DBUtils.appendChatHistory( BoardActivity.this,
m_name, msg, false ); m_name, msg, false );
@ -1235,7 +1236,7 @@ public class BoardActivity extends XWActivity
} else { } else {
setBlockingThread(); setBlockingThread();
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
showDialog( dlgID ); // crash showDialog( dlgID ); // crash
m_blockingDlgPosted = true; m_blockingDlgPosted = true;
@ -1273,7 +1274,7 @@ public class BoardActivity extends XWActivity
} }
m_dlgBytes = txt; m_dlgBytes = txt;
m_handler.post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
showDialog( dlgID ); showDialog( dlgID );
} }
@ -1367,9 +1368,36 @@ public class BoardActivity extends XWActivity
} }
}; };
} }
m_handler.removeCallbacks( m_screenTimer ); // needed? removeCallbacks( m_screenTimer ); // needed?
m_handler.postDelayed( m_screenTimer, SCREEN_ON_TIME ); postDelayed( m_screenTimer, SCREEN_ON_TIME );
} }
} }
private void post( Runnable runnable )
{
if ( null != m_handler ) {
m_handler.post( runnable );
} else {
Utils.logf( "post: dropping because handler null" );
}
}
private void postDelayed( Runnable runnable, int when )
{
if ( null != m_handler ) {
m_handler.postDelayed( runnable, when );
} else {
Utils.logf( "postDelayed: dropping %d because handler null", when );
}
}
private void removeCallbacks( Runnable which )
{
if ( null != m_handler ) {
m_handler.removeCallbacks( which );
} else {
Utils.logf( "removeCallbacks: dropping %h because handler null",
which );
}
}
} // class BoardActivity } // class BoardActivity

View file

@ -26,7 +26,7 @@ import android.util.AttributeSet;
import junit.framework.Assert; import junit.framework.Assert;
public class DictListPreference extends ListPreference { public class DictListPreference extends XWListPreference {
public DictListPreference( Context context, AttributeSet attrs ) public DictListPreference( Context context, AttributeSet attrs )
{ {

View file

@ -39,7 +39,6 @@ public class PrefsActivity extends PreferenceActivity
private static final int REVERT_COLORS = 1; private static final int REVERT_COLORS = 1;
private static final int REVERT_ALL = 2; private static final int REVERT_ALL = 2;
private HashSet<String> m_keys;
private String m_keyEmpty; private String m_keyEmpty;
private String m_keyLogging; private String m_keyLogging;
@ -114,31 +113,6 @@ public class PrefsActivity extends PreferenceActivity
// Load the preferences from an XML resource // Load the preferences from an XML resource
addPreferencesFromResource( R.xml.xwprefs ); addPreferencesFromResource( R.xml.xwprefs );
int[] textKeyIds = { R.string.key_relay_host,
R.string.key_redir_host,
R.string.key_relay_port,
R.string.key_proxy_port,
R.string.key_dict_host,
R.string.key_board_size,
R.string.key_initial_player_minutes,
R.string.key_default_dict,
R.string.key_default_robodict,
R.string.key_default_phonies,
R.string.key_player1_name,
R.string.key_player2_name,
R.string.key_player3_name,
R.string.key_player4_name,
};
SharedPreferences sp
= PreferenceManager.getDefaultSharedPreferences( this );
m_keys = new HashSet<String>( textKeyIds.length );
for ( int ii = 0; ii < textKeyIds.length; ++ii ) {
int id = textKeyIds[ii];
String key = getString( id );
setSummary( sp, key );
m_keys.add( key );
}
m_keyEmpty = getString( R.string.key_empty ); m_keyEmpty = getString( R.string.key_empty );
m_keyLogging = getString( R.string.key_logging_on ); m_keyLogging = getString( R.string.key_logging_on );
} }
@ -161,9 +135,6 @@ public class PrefsActivity extends PreferenceActivity
public void onSharedPreferenceChanged( SharedPreferences sp, String key ) public void onSharedPreferenceChanged( SharedPreferences sp, String key )
{ {
if ( m_keys.contains( key ) ) {
setSummary( sp, key );
}
if ( key.equals( m_keyLogging ) ) { if ( key.equals( m_keyLogging ) ) {
Utils.logEnable( sp.getBoolean( key, false ) ); Utils.logEnable( sp.getBoolean( key, false ) );
} }
@ -197,18 +168,6 @@ public class PrefsActivity extends PreferenceActivity
return handled; return handled;
} }
private void setSummary( SharedPreferences sp, String key )
{
Preference pref = getPreferenceScreen().findPreference( key );
String value = sp.getString( key, "" );
// if ( pref instanceof android.preference.ListPreference ) {
// Utils.logf( "%s: want to do lookup of user string here",
// key );
// }
pref.setSummary( value );
}
private void relaunch() private void relaunch()
{ {
PreferenceManager.setDefaultValues( this, R.xml.xwprefs, PreferenceManager.setDefaultValues( this, R.xml.xwprefs,

View file

@ -34,7 +34,7 @@ public class XWApp extends Application {
public void onCreate() public void onCreate()
{ {
Utils.logEnable( this ); Utils.logEnable( this );
Utils.logf( "XWApp.onCreate()" ); Utils.logf( "XWApp.onCreate(); svn_rev=%s", getString(R.string.git_rev_gen) );
super.onCreate(); super.onCreate();
} }

View file

@ -0,0 +1,48 @@
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
/*
* Copyright 2010 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.preference.EditTextPreference;
import android.content.Context;
import android.util.AttributeSet;
import junit.framework.Assert;
public class XWEditTextPreference extends EditTextPreference {
public XWEditTextPreference( Context context, AttributeSet attrs )
{
super( context, attrs );
}
protected void onAttachedToActivity()
{
super.onAttachedToActivity();
setSummary( getPersistedString( "" ) );
}
protected boolean persistString( String value )
{
setSummary( value );
return super.persistString( value );
}
}

View file

@ -0,0 +1,47 @@
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
/*
* Copyright 2010 - 2011 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.preference.ListPreference;
import android.content.Context;
import android.util.AttributeSet;
import junit.framework.Assert;
public class XWListPreference extends ListPreference {
public XWListPreference( Context context, AttributeSet attrs )
{
super( context, attrs );
}
protected void onAttachedToActivity()
{
super.onAttachedToActivity();
setSummary( getPersistedString( "" ) );
}
protected boolean persistString( String value )
{
setSummary( value );
return super.persistString( value );
}
}

View file

@ -271,7 +271,12 @@ public class JNIThread extends Thread {
if ( nextSame( JNICmd.CMD_SAVE ) ) { if ( nextSame( JNICmd.CMD_SAVE ) ) {
continue; continue;
} }
// If server has any work to do, e.g. clean up after
// showing a remote- or robot-moved dialog, let it do
// so before saving state. In some cases it'll
// otherwise drop the move.
XwJNI.server_do( m_jniGamePtr ); XwJNI.server_do( m_jniGamePtr );
XwJNI.game_getGi( m_jniGamePtr, m_gi ); XwJNI.game_getGi( m_jniGamePtr, m_gi );
GameSummary summary = new GameSummary( m_gi ); GameSummary summary = new GameSummary( m_gi );
XwJNI.game_summarize( m_jniGamePtr, summary ); XwJNI.game_summarize( m_jniGamePtr, summary );