Merge branch 'android_branch' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_branch

This commit is contained in:
Eric House 2011-08-29 20:36:53 -07:00
commit 8c811c3d5a
9 changed files with 170 additions and 152 deletions

View file

@ -63,6 +63,7 @@
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_marginRight="4dip"
/> <!-- end players column -->
<!-- holds right column. Could hold more... -->

View file

@ -75,11 +75,22 @@ public class BoardActivity extends XWActivity
private static final int UNDO_LAST_ACTION = 1;
private static final int LAUNCH_INVITE_ACTION = 2;
private static final int SYNC_ACTION = 3;
private static final int COMMIT_ACTION = 4;
private static final int SHOW_EXPL_ACTION = 5;
private static final int PREV_HINT_ACTION = 6;
private static final int NEXT_HINT_ACTION = 7;
private static final int JUGGLE_ACTION = 8;
private static final int FLIP_ACTION = 9;
private static final int ZOOM_ACTION = 10;
private static final int UNDO_ACTION = 11;
private static final int CHAT_ACTION = 12;
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 static final String TOASTSTR = "TOASTSTR";
private BoardView m_view;
private int m_jniGamePtr;
@ -114,6 +125,7 @@ public class BoardActivity extends XWActivity
private boolean m_blockingDlgPosted = false;
private String m_room;
private String m_toastStr;
private int m_missing;
private boolean m_haveInvited = false;
@ -364,6 +376,7 @@ public class BoardActivity extends XWActivity
outState.putString( DLG_TITLESTR, m_dlgTitleStr );
outState.putString( DLG_BYTES, m_dlgBytes );
outState.putString( ROOM, m_room );
outState.putString( TOASTSTR, m_toastStr );
}
private void getBundledData( Bundle bundle )
@ -373,6 +386,7 @@ public class BoardActivity extends XWActivity
m_dlgTitle = bundle.getInt( DLG_TITLE );
m_dlgBytes = bundle.getString( DLG_BYTES );
m_room = bundle.getString( ROOM );
m_toastStr = bundle.getString( TOASTSTR );
}
}
@ -481,13 +495,8 @@ public class BoardActivity extends XWActivity
int id = item.getItemId();
switch ( id ) {
case R.id.board_menu_done:
proc = new Runnable() {
public void run() {
checkAndHandle( JNIThread.JNICmd.CMD_COMMIT );
}
};
showNotAgainDlgThen( R.string.not_again_done,
R.string.key_notagain_done, proc );
R.string.key_notagain_done, COMMIT_ACTION );
break;
// case R.id.board_menu_juggle:
// cmd = JNIThread.JNICmd.CMD_JUGGLE;
@ -541,7 +550,9 @@ public class BoardActivity extends XWActivity
break;
case R.id.gamel_menu_checkmoves:
doSyncMenuitem();
showNotAgainDlgThen( R.string.not_again_sync,
R.string.key_notagain_sync,
SYNC_ACTION );
break;
case R.id.board_menu_file_prefs:
@ -570,13 +581,7 @@ public class BoardActivity extends XWActivity
@Override
public void dlgButtonClicked( int id, int which )
{
switch ( id ) {
case UNDO_LAST_ACTION:
if ( AlertDialog.BUTTON_POSITIVE == which ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_LAST );
}
break;
case LAUNCH_INVITE_ACTION:
if ( LAUNCH_INVITE_ACTION == id ) {
if ( DlgDelegate.DISMISS_BUTTON != which ) {
GameUtils.launchInviteActivity( BoardActivity.this,
DlgDelegate.TEXT_BTN == which,
@ -584,9 +589,46 @@ public class BoardActivity extends XWActivity
m_gi.dictLang,
m_gi.nPlayers );
}
break;
default:
Assert.fail();
} else if ( AlertDialog.BUTTON_POSITIVE == which ) {
switch ( id ) {
case UNDO_LAST_ACTION:
m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_LAST );
break;
case SYNC_ACTION:
doSyncMenuitem();
break;
case COMMIT_ACTION:
checkAndHandle( JNIThread.JNICmd.CMD_COMMIT );
break;
case SHOW_EXPL_ACTION:
Toast.makeText( BoardActivity.this, m_toastStr,
Toast.LENGTH_SHORT).show();
m_toastStr = null;
break;
case PREV_HINT_ACTION:
checkAndHandle( JNIThread.JNICmd.CMD_PREV_HINT );
break;
case NEXT_HINT_ACTION:
checkAndHandle( JNIThread.JNICmd.CMD_NEXT_HINT );
break;
case JUGGLE_ACTION:
checkAndHandle( JNIThread.JNICmd.CMD_JUGGLE );
break;
case FLIP_ACTION:
checkAndHandle( JNIThread.JNICmd.CMD_FLIP );
break;
case ZOOM_ACTION:
checkAndHandle( JNIThread.JNICmd.CMD_TOGGLEZOOM );
break;
case UNDO_ACTION:
checkAndHandle( JNIThread.JNICmd.CMD_UNDO_CUR );
break;
case CHAT_ACTION:
startChatActivity();
break;
default:
Assert.fail();
}
}
}
@ -777,17 +819,12 @@ public class BoardActivity extends XWActivity
}
if ( null != str ) {
final String fstr = str;
Runnable proc = new Runnable() {
public void run() {
Toast.makeText( BoardActivity.this, fstr,
Toast.LENGTH_SHORT).show();
}
};
m_toastStr = str;
if ( naMsg == 0 ) {
proc.run();
dlgButtonClicked( SHOW_EXPL_ACTION,
AlertDialog.BUTTON_POSITIVE );
} else {
showNotAgainDlgThen( naMsg, naKey, proc );
showNotAgainDlgThen( naMsg, naKey, SHOW_EXPL_ACTION );
}
}
} // handleConndMessage
@ -894,8 +931,7 @@ public class BoardActivity extends XWActivity
post( new Runnable() {
public void run() {
showNotAgainDlgThen( R.string.not_again_turnchanged,
R.string.key_notagain_turnchanged,
null );
R.string.key_notagain_turnchanged );
}
} );
m_jniThread.handle( JNIThread.JNICmd. CMD_ZOOM, -8 );
@ -1165,71 +1201,31 @@ public class BoardActivity extends XWActivity
m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV,
R.string.not_again_hintprev,
R.string.key_notagain_hintprev,
new Runnable() {
public void run() {
checkAndHandle( JNIThread.JNICmd.
CMD_PREV_HINT );
}
} );
PREV_HINT_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_HINT_NEXT,
R.string.not_again_hintnext,
R.string.key_notagain_hintnext,
new Runnable() {
@Override
public void run() {
checkAndHandle( JNIThread.JNICmd
.CMD_NEXT_HINT );
}
} );
NEXT_HINT_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_JUGGLE,
R.string.not_again_juggle,
R.string.key_notagain_juggle,
new Runnable() {
@Override
public void run() {
checkAndHandle( JNIThread.JNICmd
.CMD_JUGGLE );
}
} );
JUGGLE_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_FLIP,
R.string.not_again_flip,
R.string.key_notagain_flip,
new Runnable() {
@Override
public void run() {
checkAndHandle( JNIThread.JNICmd
.CMD_FLIP );
}
} );
FLIP_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_ZOOM,
R.string.not_again_zoom,
R.string.key_notagain_zoom,
new Runnable() {
@Override
public void run() {
checkAndHandle( JNIThread.JNICmd
.CMD_TOGGLEZOOM );
}
} );
ZOOM_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_UNDO,
R.string.not_again_undo,
R.string.key_notagain_undo,
new Runnable() {
@Override
public void run() {
checkAndHandle( JNIThread.JNICmd
.CMD_UNDO_CUR );
}
});
UNDO_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_CHAT,
R.string.not_again_chat,
R.string.key_notagain_chat,
new Runnable() {
@Override
public void run() {
startChatActivity();
}
});
CHAT_ACTION );
} // populateToolbar
private OnDismissListener makeODLforBlocking( final int id )

View file

@ -562,8 +562,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
public void run() {
m_parent.
showNotAgainDlgThen( R.string.not_again_arrow,
R.string.key_notagain_arrow,
null );
R.string.key_notagain_arrow );
}
} );
}

View file

@ -48,10 +48,12 @@ public class DlgDelegate {
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;
public static final int SKIP_CALLBACK = -1;
private static final String MSG = "msg";
private static final String CALLBACK = "callback";
private static final String MSGID = "msgid";
private static final String PREFSKEY = "prefskey";
// Cache a couple of callback implementations that never change:
private DialogInterface.OnClickListener m_cbkOnClickLstnr = null;
@ -65,7 +67,6 @@ public class DlgDelegate {
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;
private Activity m_activity;
private DlgClickNotify m_clickCallback;
@ -81,6 +82,7 @@ public class DlgDelegate {
m_msg = bundle.getString( MSG );
m_cbckID = bundle.getInt( CALLBACK );
m_msgID = bundle.getInt( MSGID );
m_prefsKey = bundle.getInt( PREFSKEY );
}
}
@ -89,6 +91,7 @@ public class DlgDelegate {
outState.putString( MSG, m_msg );
outState.putInt( CALLBACK, m_cbckID );
outState.putInt( MSGID, m_msgID );
outState.putInt( PREFSKEY, m_prefsKey );
}
public Dialog onCreateDialog( int id )
@ -156,21 +159,31 @@ public class DlgDelegate {
}
public void showNotAgainDlgThen( int msgID, int prefsKey,
Runnable proc )
int callbackID )
{
boolean set = CommonPrefs.getPrefsBoolean( m_activity, prefsKey, false );
if ( set ) {
if ( null != proc ) {
proc.run();
}
if ( set || 0 != m_cbckID ) {
// If it's set, do the action without bothering with the
// dialog
if ( SKIP_CALLBACK != callbackID ) {
m_clickCallback.dlgButtonClicked( callbackID,
AlertDialog.BUTTON_POSITIVE );
}
} else {
m_msgID = msgID;
m_proc = proc;
Assert.assertTrue( 0 != callbackID );
Assert.assertTrue( 0 == m_cbckID ); // fired
m_cbckID = callbackID;
m_prefsKey = prefsKey;
m_activity.showDialog( DIALOG_NOTAGAIN );
}
}
public void showNotAgainDlgThen( int msgID, int prefsKey )
{
showNotAgainDlgThen( msgID, prefsKey, SKIP_CALLBACK );
}
public void showConfirmThen( String msg, int callbackID )
{
m_msg = msg;
@ -243,36 +256,29 @@ public class DlgDelegate {
private Dialog createNotAgainDialog()
{
Dialog dialog = null;
if ( 0 != m_msgID ) {
DialogInterface.OnClickListener lstnr_p =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
if ( null != m_proc ) {
m_proc.run();
}
}
};
DialogInterface.OnClickListener lstnr_p = mkCallbackClickListener();
DialogInterface.OnClickListener lstnr_n =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
CommonPrefs.setPrefsBoolean( m_activity, m_prefsKey,
true );
if ( null != m_proc ) {
m_proc.run();
}
DialogInterface.OnClickListener lstnr_n =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
CommonPrefs.setPrefsBoolean( m_activity, m_prefsKey,
true );
if ( SKIP_CALLBACK != m_cbckID ) {
m_clickCallback.
dlgButtonClicked( m_cbckID,
AlertDialog.BUTTON_POSITIVE );
}
};
}
};
dialog = new AlertDialog.Builder( m_activity )
.setTitle( R.string.newbie_title )
.setMessage( m_msgID )
.setPositiveButton( R.string.button_ok, lstnr_p )
.setNegativeButton( R.string.button_notagain, lstnr_n )
.create();
}
return dialog;
Dialog dialog = new AlertDialog.Builder( m_activity )
.setTitle( R.string.newbie_title )
.setMessage( m_msgID )
.setPositiveButton( R.string.button_ok, lstnr_p )
.setNegativeButton( R.string.button_notagain, lstnr_n )
.create();
return setCallbackDismissListener( dialog );
} // createNotAgainDialog
private Dialog createConfirmThenDialog()
@ -324,8 +330,10 @@ public class DlgDelegate {
if ( null == m_cbkOnClickLstnr ) {
m_cbkOnClickLstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
Assert.assertTrue( 0 != m_cbckID );
m_clickCallback.dlgButtonClicked( m_cbckID, button );
if ( SKIP_CALLBACK != m_cbckID ) {
m_clickCallback.dlgButtonClicked( m_cbckID,
button );
}
}
};
}
@ -337,9 +345,10 @@ public class DlgDelegate {
if ( null == m_cbkOnDismissLstnr ) {
m_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
Assert.assertTrue( 0 != m_cbckID );
m_clickCallback.dlgButtonClicked( m_cbckID,
DISMISS_BUTTON );
if ( SKIP_CALLBACK != m_cbckID ) {
m_clickCallback.dlgButtonClicked( m_cbckID,
DISMISS_BUTTON );
}
m_cbckID = 0;
}
};

View file

@ -69,6 +69,7 @@ public class GameConfig extends XWActivity
private static final int NO_NAME_FOUND = PLAYER_EDIT + 4;
private static final String WHICH_PLAYER = "WHICH_PLAYER";
private static final int LOCKED_CHANGE_ACTION = 1;
private CheckBox m_joinPublicCheck;
private CheckBox m_gameLockedCheck;
@ -539,6 +540,20 @@ public class GameConfig extends XWActivity
showDialog( NO_NAME_FOUND );
}
@Override
public void dlgButtonClicked( int id, int button )
{
switch( id ) {
case LOCKED_CHANGE_ACTION:
if ( AlertDialog.BUTTON_POSITIVE == button ) {
handleLockedChange();
}
break;
default:
Assert.fail();
}
}
public void onClick( View view )
{
if ( m_addPlayerButton == view ) {
@ -555,11 +570,7 @@ public class GameConfig extends XWActivity
} else if ( m_gameLockedCheck == view ) {
showNotAgainDlgThen( R.string.not_again_unlock,
R.string.key_notagain_unlock,
new Runnable() {
public void run() {
handleLockedChange();
}
});
LOCKED_CHANGE_ACTION );
} else if ( m_refreshRoomsButton == view ) {
refreshNames();
} else if ( m_playButton == view ) {

View file

@ -67,6 +67,8 @@ public class GamesList extends XWListActivity
private static final int RESET_GAME_ACTION = 2;
private static final int DELETE_GAME_ACTION = 3;
private static final int DELETE_ALL_ACTION = 4;
private static final int SYNC_MENU_ACTION = 5;
private static final int DUPE_GAME_ACTION = 6;
private GameListAdapter m_adapter;
private String m_missingDict;
@ -426,6 +428,15 @@ public class GamesList extends XWListActivity
m_adapter.inval( games[ii] );
}
break;
case SYNC_MENU_ACTION:
doSyncMenuitem();
break;
case DUPE_GAME_ACTION:
long newid = GameUtils.dupeGame( GamesList.this, m_rowid );
if ( null != m_adapter ) {
m_adapter.inval( newid );
}
break;
default:
Assert.fail();
}
@ -520,11 +531,7 @@ public class GamesList extends XWListActivity
case R.id.gamel_menu_checkmoves:
showNotAgainDlgThen( R.string.not_again_sync,
R.string.key_notagain_sync,
new Runnable() {
public void run() {
doSyncMenuitem();
}
} );
SYNC_MENU_ACTION );
break;
case R.id.gamel_menu_prefs:
@ -551,46 +558,36 @@ public class GamesList extends XWListActivity
boolean handled = true;
DialogInterface.OnClickListener lstnr;
final long rowid = DBUtils.gamesList( this )[position];
m_rowid = DBUtils.gamesList( this )[position];
if ( R.id.list_item_delete == menuID ) {
m_rowid = rowid;
showConfirmThen( R.string.confirm_delete, DELETE_GAME_ACTION );
} else {
if ( checkWarnNoDict( rowid ) ) {
if ( checkWarnNoDict( m_rowid ) ) {
switch ( menuID ) {
case R.id.list_item_reset:
m_rowid = rowid;
showConfirmThen( R.string.confirm_reset, RESET_GAME_ACTION );
break;
case R.id.list_item_config:
GameUtils.doConfig( this, rowid, GameConfig.class );
GameUtils.doConfig( this, m_rowid, GameConfig.class );
break;
case R.id.list_item_rename:
m_rowid = rowid;
showDialog( RENAME_GAME );
break;
case R.id.list_item_new_from:
Runnable proc = new Runnable() {
public void run() {
long newid =
GameUtils.dupeGame( GamesList.this, rowid );
if ( null != m_adapter ) {
m_adapter.inval( newid );
}
}
};
showNotAgainDlgThen( R.string.not_again_newfrom,
R.string.key_notagain_newfrom, proc );
R.string.key_notagain_newfrom,
DUPE_GAME_ACTION );
break;
case R.id.list_item_copy:
GameSummary summary = DBUtils.getSummary( this, rowid, true );
GameSummary summary = DBUtils.getSummary( this,
m_rowid, true );
if ( summary.inNetworkGame() ) {
showOKOnlyDialog( R.string.no_copy_network );
} else {
byte[] stream = GameUtils.savedGame( this, rowid );
byte[] stream = GameUtils.savedGame( this, m_rowid );
GameUtils.GameLock lock =
GameUtils.saveNewGame( this, stream );
DBUtils.saveSummary( this, lock, summary );

View file

@ -85,11 +85,11 @@ public class Toolbar {
}
public void setListener( int index, final int msgID, final int prefsKey,
final Runnable proc )
final int callback )
{
View.OnClickListener listener = new View.OnClickListener() {
public void onClick( View view ) {
m_activity.showNotAgainDlgThen( msgID, prefsKey, proc );
m_activity.showNotAgainDlgThen( msgID, prefsKey, callback );
}
};
setListener( index, listener );

View file

@ -116,9 +116,14 @@ public class XWActivity extends Activity
}
protected void showNotAgainDlgThen( int msgID, int prefsKey,
Runnable proc )
int action )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey, proc );
m_delegate.showNotAgainDlgThen( msgID, prefsKey, action );
}
protected void showNotAgainDlgThen( int msgID, int prefsKey )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey );
}
protected void showOKOnlyDialog( int msgID )

View file

@ -112,14 +112,14 @@ public class XWListActivity extends ListActivity
}
protected void showNotAgainDlgThen( int msgID, int prefsKey,
Runnable proc )
int action )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey, proc );
m_delegate.showNotAgainDlgThen( msgID, prefsKey, action );
}
protected void showNotAgainDlg( int msgID, int prefsKey )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey, null );
m_delegate.showNotAgainDlgThen( msgID, prefsKey );
}
protected void showOKOnlyDialog( int msgID )