Merge branch 'android_branch' into send_in_background

This commit is contained in:
eehouse@eehouse.org 2011-08-24 22:44:40 -07:00 committed by Andy2
commit e592ea8559
8 changed files with 201 additions and 142 deletions

View file

@ -74,10 +74,12 @@ public class BoardActivity extends XWActivity
private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins
private static final int UNDO_LAST_ACTION = 1;
private static final int LAUNCH_INVITE_ACTION = 2;
private static final String DLG_TITLE = "DLG_TITLE";
private static final String DLG_TITLESTR = "DLG_TITLESTR";
private static final String DLG_BYTES = "DLG_BYTES";
private static final String ROOM = "ROOM";
private BoardView m_view;
private int m_jniGamePtr;
@ -268,10 +270,7 @@ public class BoardActivity extends XWActivity
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog,
int item ) {
GameUtils.launchInviteActivity( BoardActivity.this,
m_room,
m_gi.dictLang,
m_gi.nPlayers );
showTextOrHtmlThen( LAUNCH_INVITE_ACTION );
}
};
dialog = new AlertDialog.Builder( this )
@ -364,6 +363,7 @@ public class BoardActivity extends XWActivity
outState.putInt( DLG_TITLESTR, m_dlgTitle );
outState.putString( DLG_TITLESTR, m_dlgTitleStr );
outState.putString( DLG_BYTES, m_dlgBytes );
outState.putString( ROOM, m_room );
}
private void getBundledData( Bundle bundle )
@ -372,6 +372,7 @@ public class BoardActivity extends XWActivity
m_dlgTitleStr = bundle.getString( DLG_TITLESTR );
m_dlgTitle = bundle.getInt( DLG_TITLE );
m_dlgBytes = bundle.getString( DLG_BYTES );
m_room = bundle.getString( ROOM );
}
}
@ -566,15 +567,24 @@ public class BoardActivity extends XWActivity
//////////////////////////////////////////////////
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////
public void buttonClicked( int id, boolean cancelled )
@Override
public void dlgButtonClicked( int id, int which )
{
switch ( id ) {
case UNDO_LAST_ACTION:
if ( !cancelled ) {
if ( AlertDialog.BUTTON_POSITIVE == which ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_LAST );
}
break;
case LAUNCH_INVITE_ACTION:
if ( DlgDelegate.DISMISS_BUTTON != which ) {
GameUtils.launchInviteActivity( BoardActivity.this,
DlgDelegate.TEXT_BTN == which,
m_room,
m_gi.dictLang,
m_gi.nPlayers );
}
break;
default:
Assert.fail();
}

View file

@ -551,11 +551,11 @@ public class DictsActivity extends ExpandableListActivity
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, boolean cancelled )
public void dlgButtonClicked( int id, int which )
{
switch( id ) {
case DELETE_DICT_ACTION:
if ( !cancelled ) {
if ( DialogInterface.BUTTON_POSITIVE == which ) {
deleteDict( m_deleteDict );
}
break;

View file

@ -45,16 +45,21 @@ public class DlgDelegate {
public static final int DLG_DICTGONE = 6;
public static final int DIALOG_LAST = DLG_DICTGONE;
public static final String MSG = "msg";
public static final String CALLBACK = "callback";
public static final String MSGID = "msgid";
public static final int TEXT_BTN = AlertDialog.BUTTON_POSITIVE;
public static final int HTML_BTN = AlertDialog.BUTTON_NEGATIVE;
public static final int DISMISS_BUTTON = 0;
private static final String MSG = "msg";
private static final String CALLBACK = "callback";
private static final String MSGID = "msgid";
public interface DlgClickNotify {
void dlgButtonClicked( int id, boolean cancelled );
void dlgButtonClicked( int id, int button );
}
private int m_msgID;
private int m_cbckID;
private int m_cbckID = 0; // if this can be set twice I have a
// problem. See asserts below.
private String m_msg;
private Runnable m_proc = null;
private int m_prefsKey;
@ -126,17 +131,6 @@ public class DlgDelegate {
break;
case CONFIRM_THEN:
ad.setMessage( m_msg );
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
boolean cancelled =
button == DialogInterface.BUTTON_NEGATIVE;
m_clickCallback.dlgButtonClicked( m_cbckID, cancelled );
}
};
ad.setButton( AlertDialog.BUTTON_POSITIVE,
m_activity.getString( R.string.button_ok ), lstnr );
ad.setButton( AlertDialog.BUTTON_NEGATIVE,
m_activity.getString( R.string.button_ok ), lstnr );
break;
}
}
@ -176,12 +170,16 @@ public class DlgDelegate {
public void showConfirmThen( String msg, int callbackID )
{
m_msg = msg;
Assert.assertTrue( 0 != callbackID );
Assert.assertTrue( 0 == m_cbckID );
m_cbckID = callbackID;
m_activity.showDialog( CONFIRM_THEN );
}
public void showTextOrHtmlThen( int callbackID )
{
Assert.assertTrue( 0 != callbackID );
Assert.assertTrue( 0 == m_cbckID );
m_cbckID = callbackID;
m_activity.showDialog( TEXT_OR_HTML_THEN );
}
@ -275,31 +273,29 @@ public class DlgDelegate {
private Dialog createConfirmThenDialog()
{
DialogInterface.OnClickListener lstnr = mkCallbackClickListener();
Dialog dialog = new AlertDialog.Builder( m_activity )
.setTitle( R.string.query_title )
.setMessage( "" )
.setPositiveButton( R.string.button_ok, null ) // will change
.setNegativeButton( R.string.button_cancel, null )
.setPositiveButton( R.string.button_ok, lstnr )
.setNegativeButton( R.string.button_cancel, lstnr )
.create();
return dialog;
return setCallbackDismissListener( dialog );
}
private Dialog createHtmlThenDialog()
{
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
boolean cancelled =
button == DialogInterface.BUTTON_NEGATIVE;
m_clickCallback.dlgButtonClicked( m_cbckID, cancelled );
}
};
return new AlertDialog.Builder( m_activity )
DialogInterface.OnClickListener lstnr = mkCallbackClickListener();
Dialog dialog = new AlertDialog.Builder( m_activity )
.setTitle( R.string.query_title )
.setMessage( R.string.text_or_html )
.setPositiveButton( R.string.button_text, lstnr )
.setNegativeButton( R.string.button_html, lstnr )
.create();
return setCallbackDismissListener( dialog );
}
private Dialog createDictGoneDialog()
@ -319,4 +315,31 @@ public class DlgDelegate {
return dialog;
}
private DialogInterface.OnClickListener mkCallbackClickListener()
{
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
Assert.assertTrue( 0 != m_cbckID );
m_clickCallback.dlgButtonClicked( m_cbckID, button );
}
};
return lstnr;
}
private Dialog setCallbackDismissListener( Dialog dialog )
{
DialogInterface.OnDismissListener lstnr =
new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
Assert.assertTrue( 0 != m_cbckID );
m_clickCallback.dlgButtonClicked( m_cbckID,
DISMISS_BUTTON );
m_cbckID = 0;
}
};
dialog.setOnDismissListener( lstnr );
return dialog;
}
}

View file

@ -68,6 +68,8 @@ public class GameConfig extends XWActivity
private static final int CONFIRM_CHANGE_PLAY = PLAYER_EDIT + 3;
private static final int NO_NAME_FOUND = PLAYER_EDIT + 4;
private static final String WHICH_PLAYER = "WHICH_PLAYER";
private CheckBox m_joinPublicCheck;
private CheckBox m_gameLockedCheck;
private boolean m_isLocked;
@ -202,7 +204,7 @@ public class GameConfig extends XWActivity
.create();
dialog.setOnDismissListener( new DialogInterface.OnDismissListener() {
@Override
public void onDismiss( DialogInterface di )
public void onDismiss( DialogInterface di )
{
if ( m_gi.forceRemoteConsistent() ) {
Toast.makeText( GameConfig.this,
@ -358,6 +360,7 @@ public class GameConfig extends XWActivity
public void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
getBundledData( savedInstanceState );
// 1.5 doesn't have SDK_INT. So parse the string version.
// int sdk_int = 0;
@ -391,97 +394,19 @@ public class GameConfig extends XWActivity
setTitle();
} // onCreate
@Override
protected void onStart()
{
super.onStart();
loadGame();
}
@Override
protected void onResume()
{
super.onResume();
m_giOrig = new CurGameInfo( this );
// Lock in case we're going to config. We *could* re-get the
// lock once the user decides to make changes. PENDING.
m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock();
int gamePtr = GameUtils.loadMakeGame( this, m_giOrig, m_gameLock );
if ( 0 == gamePtr ) {
showDictGoneFinish();
} else {
m_gameStarted = XwJNI.model_getNMoves( gamePtr ) > 0
|| XwJNI.comms_isConnected( gamePtr );
if ( m_gameStarted ) {
if ( null == m_gameLockedCheck ) {
m_gameLockedCheck =
(CheckBox)findViewById( R.id.game_locked_check );
m_gameLockedCheck.setVisibility( View.VISIBLE );
m_gameLockedCheck.setChecked( true );
m_gameLockedCheck.setOnClickListener( this );
}
handleLockedChange();
}
m_gi = new CurGameInfo( this, m_giOrig );
m_carOrig = new CommsAddrRec( this );
if ( XwJNI.game_hasComms( gamePtr ) ) {
XwJNI.comms_getAddr( gamePtr, m_carOrig );
} else {
String relayName = CommonPrefs.getDefaultRelayHost( this );
int relayPort = CommonPrefs.getDefaultRelayPort( this );
XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort );
}
XwJNI.game_dispose( gamePtr );
m_car = new CommsAddrRec( m_carOrig );
m_notNetworkedGame = DeviceRole.SERVER_STANDALONE == m_gi.serverRole;
setTitle();
if ( !m_notNetworkedGame ) {
m_joinPublicCheck =
(CheckBox)findViewById(R.id.join_public_room_check);
m_joinPublicCheck.setOnClickListener( this );
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
Utils.setChecked( this, R.id.advertise_new_room_check,
m_car.ip_relay_advertiseRoom );
m_publicRoomsSet =
(LinearLayout)findViewById(R.id.public_rooms_set );
m_privateRoomsSet =
(LinearLayout)findViewById(R.id.private_rooms_set );
Utils.setText( this, R.id.room_edit, m_car.ip_relay_invite );
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
m_refreshRoomsButton =
(ImageButton)findViewById( R.id.refresh_button );
m_refreshRoomsButton.setOnClickListener( this );
adjustConnectStuff();
}
loadPlayers();
configLangSpinner();
m_phoniesSpinner.setSelection( m_gi.phoniesAction.ordinal() );
setSmartnessSpinner();
Utils.setChecked( this, R.id.hints_allowed, !m_gi.hintsNotAllowed );
Utils.setInt( this, R.id.timer_minutes_edit,
m_gi.gameSeconds/60/m_gi.nPlayers );
CheckBox check = (CheckBox)findViewById( R.id.use_timer );
CompoundButton.OnCheckedChangeListener lstnr =
new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView,
boolean checked ) {
View view = findViewById( R.id.timer_set );
view.setVisibility( checked ? View.VISIBLE : View.GONE );
}
};
check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
}
} // onResume
loadGame();
}
@Override
protected void onPause()
@ -490,9 +415,116 @@ public class GameConfig extends XWActivity
m_gameLock.unlock();
m_gameLock = null;
}
m_giOrig = null; // flag for onStart and onResume
super.onPause();
}
@Override
protected void onSaveInstanceState( Bundle outState )
{
super.onSaveInstanceState( outState );
outState.putInt( WHICH_PLAYER, m_whichPlayer );
}
private void loadGame()
{
if ( null == m_giOrig ) {
m_giOrig = new CurGameInfo( this );
// Lock in case we're going to config. We *could* re-get the
// lock once the user decides to make changes. PENDING.
m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock();
int gamePtr = GameUtils.loadMakeGame( this, m_giOrig, m_gameLock );
if ( 0 == gamePtr ) {
showDictGoneFinish();
} else {
m_gameStarted = XwJNI.model_getNMoves( gamePtr ) > 0
|| XwJNI.comms_isConnected( gamePtr );
if ( m_gameStarted ) {
if ( null == m_gameLockedCheck ) {
m_gameLockedCheck =
(CheckBox)findViewById( R.id.game_locked_check );
m_gameLockedCheck.setVisibility( View.VISIBLE );
m_gameLockedCheck.setChecked( true );
m_gameLockedCheck.setOnClickListener( this );
}
handleLockedChange();
}
m_gi = new CurGameInfo( this, m_giOrig );
m_carOrig = new CommsAddrRec( this );
if ( XwJNI.game_hasComms( gamePtr ) ) {
XwJNI.comms_getAddr( gamePtr, m_carOrig );
} else {
String relayName = CommonPrefs.getDefaultRelayHost( this );
int relayPort = CommonPrefs.getDefaultRelayPort( this );
XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort );
}
XwJNI.game_dispose( gamePtr );
m_car = new CommsAddrRec( m_carOrig );
m_notNetworkedGame = DeviceRole.SERVER_STANDALONE == m_gi.serverRole;
setTitle();
if ( !m_notNetworkedGame ) {
m_joinPublicCheck =
(CheckBox)findViewById(R.id.join_public_room_check);
m_joinPublicCheck.setOnClickListener( this );
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
Utils.setChecked( this, R.id.advertise_new_room_check,
m_car.ip_relay_advertiseRoom );
m_publicRoomsSet =
(LinearLayout)findViewById(R.id.public_rooms_set );
m_privateRoomsSet =
(LinearLayout)findViewById(R.id.private_rooms_set );
Utils.setText( this, R.id.room_edit, m_car.ip_relay_invite );
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
m_refreshRoomsButton =
(ImageButton)findViewById( R.id.refresh_button );
m_refreshRoomsButton.setOnClickListener( this );
adjustConnectStuff();
}
loadPlayers();
configLangSpinner();
m_phoniesSpinner.setSelection( m_gi.phoniesAction.ordinal() );
setSmartnessSpinner();
Utils.setChecked( this, R.id.hints_allowed, !m_gi.hintsNotAllowed );
Utils.setInt( this, R.id.timer_minutes_edit,
m_gi.gameSeconds/60/m_gi.nPlayers );
CheckBox check = (CheckBox)findViewById( R.id.use_timer );
CompoundButton.OnCheckedChangeListener lstnr =
new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView,
boolean checked ) {
View view = findViewById( R.id.timer_set );
view.setVisibility( checked ? View.VISIBLE : View.GONE );
}
};
check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
}
}
} // loadGame
private void getBundledData( Bundle bundle )
{
if ( null != bundle ) {
m_whichPlayer = bundle.getInt( WHICH_PLAYER );
}
}
// DeleteCallback interface
public void deleteCalled( int myPosition, final String name )
{

View file

@ -404,9 +404,10 @@ public class GamesList extends XWListActivity
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, boolean cancelled )
@Override
public void dlgButtonClicked( int id, int which )
{
if ( !cancelled ) {
if ( AlertDialog.BUTTON_POSITIVE == which ) {
switch( id ) {
case NEW_NET_GAME_ACTION:
long rowid = GameUtils.makeNewNetGame( this, m_netLaunchInfo );

View file

@ -87,11 +87,15 @@ public class NewGameActivity extends XWActivity {
}
public void dlgButtonClicked( int id, boolean cancelled )
// DlgDelegate.DlgClickNotify interface
@Override
public void dlgButtonClicked( int id, int which )
{
switch( id ) {
case NEW_GAME_ACTION:
makeNewGame( true, true, !cancelled );
if ( DlgDelegate.DISMISS_BUTTON != which ) {
makeNewGame( true, true, DlgDelegate.TEXT_BTN == which );
}
break;
default:
Assert.fail();

View file

@ -147,7 +147,7 @@ public class XWActivity extends Activity
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, boolean cancelled )
public void dlgButtonClicked( int id, int which )
{
Assert.fail();
}

View file

@ -95,17 +95,6 @@ public class XWListActivity extends ListActivity
if ( null == dialog ) {
dialog = super.onCreateDialog( id );
}
if ( null != dialog ) {
DialogInterface.OnDismissListener lstnr =
new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
Utils.logf( "%s.onDismiss() called",
getClass().getName() );
removeDialog( id );
}
};
dialog.setOnDismissListener( lstnr );
}
return dialog;
}
@ -154,7 +143,7 @@ public class XWListActivity extends ListActivity
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, boolean cancelled )
public void dlgButtonClicked( int id, int which )
{
Assert.fail();
}