use a global enum for DlgDelegate actions -- should be no real code change

This commit is contained in:
Eric House 2014-03-18 06:06:21 -07:00
parent 12e77e8c47
commit c333e561af
14 changed files with 220 additions and 187 deletions

View file

@ -57,6 +57,7 @@ import java.util.HashSet;
import java.util.concurrent.Semaphore;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.jni.*;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
@ -77,27 +78,6 @@ 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 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 int START_TRADE_ACTION = 13;
private static final int LOOKUP_ACTION = 14;
private static final int BUTTON_BROWSE_ACTION = 15;
private static final int VALUES_ACTION = 16;
private static final int BT_PICK_ACTION = 17;
private static final int SMS_PICK_ACTION = 18;
private static final int SMS_CONFIG_ACTION = 19;
private static final int BUTTON_BROWSEALL_ACTION = 20;
private static final String DLG_TITLE = "DLG_TITLE";
private static final String DLG_TITLESTR = "DLG_TITLESTR";
private static final String DLG_BYTES = "DLG_BYTES";
@ -394,7 +374,7 @@ public class BoardActivity extends XWActivity
not_again_lookup,
R.string.
key_na_lookup,
LOOKUP_ACTION );
Action.LOOKUP_ACTION );
}
};
ab.setNegativeButton( buttonTxt, lstnr );
@ -488,7 +468,7 @@ public class BoardActivity extends XWActivity
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog,
int item ) {
showInviteChoicesThen( LAUNCH_INVITE_ACTION );
showInviteChoicesThen( Action.LAUNCH_INVITE_ACTION );
}
};
dialog = new AlertDialog.Builder( this )
@ -812,9 +792,10 @@ public class BoardActivity extends XWActivity
m_view.getCurPlayer() );
if ( XWApp.MAX_TRAY_TILES > nTiles ) {
showNotAgainDlgThen( R.string.not_again_done,
R.string.key_notagain_done, COMMIT_ACTION );
R.string.key_notagain_done,
Action.COMMIT_ACTION );
} else {
dlgButtonClicked( COMMIT_ACTION, AlertDialog.BUTTON_POSITIVE, null );
dlgButtonClicked( Action.COMMIT_ACTION, AlertDialog.BUTTON_POSITIVE, null );
}
break;
@ -853,7 +834,7 @@ public class BoardActivity extends XWActivity
: R.string. not_again_trading_buttons;
msg += getString( strID );
showNotAgainDlgThen( msg, R.string.key_notagain_trading,
START_TRADE_ACTION );
Action.START_TRADE_ACTION );
break;
case R.id.board_menu_tray:
@ -869,7 +850,7 @@ public class BoardActivity extends XWActivity
cmd = JNICmd.CMD_UNDO_CUR;
break;
case R.id.board_menu_undo_last:
showConfirmThen( R.string.confirm_undo_last, UNDO_LAST_ACTION );
showConfirmThen( R.string.confirm_undo_last, Action.UNDO_LAST_ACTION );
break;
case R.id.board_menu_invite:
showDialog( DlgID.DLG_INVITE.ordinal() );
@ -904,7 +885,7 @@ public class BoardActivity extends XWActivity
case R.id.gamel_menu_checkmoves:
showNotAgainDlgThen( R.string.not_again_sync,
R.string.key_notagain_sync,
SYNC_ACTION );
Action.SYNC_ACTION );
break;
case R.id.board_menu_file_prefs:
@ -931,9 +912,9 @@ public class BoardActivity extends XWActivity
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////
@Override
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
if ( LAUNCH_INVITE_ACTION == id ) {
if ( Action.LAUNCH_INVITE_ACTION == action ) {
if ( DlgDelegate.DISMISS_BUTTON != which ) {
if ( DlgDelegate.NFC_BTN == which ) {
if ( NFCUtils.nfcAvail( this )[1] ) {
@ -952,7 +933,7 @@ public class BoardActivity extends XWActivity
}
} else if ( AlertDialog.BUTTON_POSITIVE == which ) {
JNICmd cmd = JNICmd.CMD_NONE;
switch ( id ) {
switch ( action ) {
case UNDO_LAST_ACTION:
cmd = JNICmd.CMD_UNDO_LAST;
break;
@ -982,7 +963,7 @@ public class BoardActivity extends XWActivity
case BUTTON_BROWSE_ACTION:
String curDict = m_gi.dictName( m_view.getCurPlayer() );
View button = m_toolbar.getViewFor( Toolbar.BUTTON_BROWSE_DICT );
if ( BUTTON_BROWSEALL_ACTION == id &&
if ( Action.BUTTON_BROWSEALL_ACTION == action &&
DictsActivity.handleDictsPopup( this, button, curDict ) ) {
break;
}
@ -1370,10 +1351,10 @@ public class BoardActivity extends XWActivity
if ( null != toastStr ) {
m_toastStr = toastStr;
if ( naMsg == 0 ) {
dlgButtonClicked( SHOW_EXPL_ACTION,
dlgButtonClicked( Action.SHOW_EXPL_ACTION,
AlertDialog.BUTTON_POSITIVE, null );
} else {
showNotAgainDlgThen( naMsg, naKey, SHOW_EXPL_ACTION );
showNotAgainDlgThen( naMsg, naKey, Action.SHOW_EXPL_ACTION );
}
}
@ -1670,20 +1651,20 @@ public class BoardActivity extends XWActivity
{
m_connType = connType;
int action = 0;
Action action = null;
if ( 0 < nMissingPlayers && isServer && !m_haveInvited ) {
switch( connType ) {
case COMMS_CONN_BT:
action = BT_PICK_ACTION;
action = Action.BT_PICK_ACTION;
break;
case COMMS_CONN_SMS:
action = SMS_PICK_ACTION;
action = Action.SMS_PICK_ACTION;
break;
}
}
if ( 0 != action ) {
if ( null != action ) {
m_haveInvited = true;
final int faction = action;
final Action faction = action;
final String fmsg = getString( R.string.invite_msgf,
nMissingPlayers );
post( new Runnable() {
@ -1955,44 +1936,44 @@ public class BoardActivity extends XWActivity
m_toolbar.setListener( Toolbar.BUTTON_BROWSE_DICT,
R.string.not_again_browseall,
R.string.key_na_browseall,
BUTTON_BROWSEALL_ACTION );
Action.BUTTON_BROWSEALL_ACTION );
m_toolbar.setLongClickListener( Toolbar.BUTTON_BROWSE_DICT,
R.string.not_again_browse,
R.string.key_na_browse,
BUTTON_BROWSE_ACTION );
Action.BUTTON_BROWSE_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV,
R.string.not_again_hintprev,
R.string.key_notagain_hintprev,
PREV_HINT_ACTION );
Action.PREV_HINT_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_HINT_NEXT,
R.string.not_again_hintnext,
R.string.key_notagain_hintnext,
NEXT_HINT_ACTION );
Action.NEXT_HINT_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_JUGGLE,
R.string.not_again_juggle,
R.string.key_notagain_juggle,
JUGGLE_ACTION );
Action.JUGGLE_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_FLIP,
R.string.not_again_flip,
R.string.key_notagain_flip,
FLIP_ACTION );
Action.FLIP_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_ZOOM,
R.string.not_again_zoom,
R.string.key_notagain_zoom,
ZOOM_ACTION );
Action.ZOOM_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_VALUES,
R.string.not_again_values,
R.string.key_na_values,
VALUES_ACTION );
Action.VALUES_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_UNDO,
R.string.not_again_undo,
R.string.key_notagain_undo,
UNDO_ACTION );
Action.UNDO_ACTION );
if ( BuildConstants.CHAT_SUPPORTED ) {
m_toolbar.setListener( Toolbar.BUTTON_CHAT,
R.string.not_again_chat,
R.string.key_notagain_chat,
CHAT_ACTION );
Action.CHAT_ACTION );
}
} // populateToolbar
@ -2128,7 +2109,7 @@ public class BoardActivity extends XWActivity
if ( XWApp.SMSSUPPORTED && !XWPrefs.getSMSEnabled( this ) ) {
showConfirmThen( R.string.warn_sms_disabled,
R.string.newgame_enable_sms,
SMS_CONFIG_ACTION );
Action.SMS_CONFIG_ACTION );
}
break;
}

View file

@ -42,6 +42,7 @@ import java.util.Arrays;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.jni.JNIUtilsImpl;
import org.eehouse.android.xw4.jni.XwJNI;
@ -52,7 +53,6 @@ public class DictBrowseActivity extends XWListActivity
private static final String DICT_LOC = "DICT_LOC";
private static final int MIN_LEN = 2;
private static final int FINISH_ACTION = 1;
private int m_dictClosure = 0;
private int m_lang;
@ -194,7 +194,7 @@ public class DictBrowseActivity extends XWListActivity
// search/minmax stuff.
String msg = Utils.format( this, R.string.alert_empty_dictf,
name );
showOKOnlyDialogThen( msg, FINISH_ACTION );
showOKOnlyDialogThen( msg, Action.FINISH_ACTION );
} else {
figureMinMax( m_browseState.m_counts );
if ( newState ) {
@ -307,9 +307,9 @@ public class DictBrowseActivity extends XWListActivity
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////
@Override
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
Assert.assertTrue( FINISH_ACTION == id );
Assert.assertTrue( Action.FINISH_ACTION == action );
finish();
}

View file

@ -54,6 +54,7 @@ import java.util.Iterator;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.DictUtils.DictAndLoc;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.jni.JNIUtilsImpl;
@ -77,10 +78,6 @@ public class DictsActivity extends XWExpandableListActivity
private HashSet<String> m_closedLangs;
// For new callback alternative
private static final int DELETE_DICT_ACTION = 1;
private static final int DOWNLOAD_DICT_ACTION = 2;
// I can't provide a subclass of MenuItem to hold DictAndLoc, so
// settle for a hash on the side.
private static HashMap<MenuItem, DictAndLoc> s_itemData;
@ -608,7 +605,7 @@ public class DictsActivity extends XWExpandableListActivity
}
}
showConfirmThen( msg, R.string.button_delete, DELETE_DICT_ACTION,
showConfirmThen( msg, R.string.button_delete, Action.DELETE_DICT_ACTION,
(Object)items );
} // deleteSelected
@ -627,9 +624,9 @@ public class DictsActivity extends XWExpandableListActivity
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
switch( id ) {
switch( action ) {
case DELETE_DICT_ACTION:
if ( DialogInterface.BUTTON_POSITIVE == which ) {
XWListItem[] items = (XWListItem[])params[0];
@ -668,7 +665,7 @@ public class DictsActivity extends XWExpandableListActivity
Intent intent = mkDownloadIntent( this, lang, name );
showNotAgainDlgThen( R.string.not_again_firefox,
R.string.key_na_firefox,
DOWNLOAD_DICT_ACTION, intent );
Action.DOWNLOAD_DICT_ACTION, intent );
}
private void startDownload( Intent downloadIntent )

View file

@ -39,17 +39,78 @@ import junit.framework.Assert;
public class DlgDelegate {
public static enum Action {
SKIP_CALLBACK,
// GameListDelegate
RESET_GAMES,
SYNC_MENU,
NEW_FROM,
DELETE_GAMES,
DELETE_GROUPS,
OPEN_GAME,
CLEAR_SELS,
NEW_NET_GAME,
// BoardDelegate
UNDO_LAST_ACTION,
LAUNCH_INVITE_ACTION,
SYNC_ACTION,
COMMIT_ACTION,
SHOW_EXPL_ACTION,
PREV_HINT_ACTION,
NEXT_HINT_ACTION,
JUGGLE_ACTION,
FLIP_ACTION,
ZOOM_ACTION,
UNDO_ACTION,
CHAT_ACTION,
START_TRADE_ACTION,
LOOKUP_ACTION,
BUTTON_BROWSE_ACTION,
VALUES_ACTION,
BT_PICK_ACTION,
SMS_PICK_ACTION,
SMS_CONFIG_ACTION,
BUTTON_BROWSEALL_ACTION,
// Dict Browser
FINISH_ACTION,
DELETE_DICT_ACTION,
DOWNLOAD_DICT_ACTION,
// Game configs
LOCKED_CHANGE_ACTION,
// New Game
NEW_GAME_ACTION,
// SMS invite
CLEAR_ACTION,
USE_IMMOBILE_ACTION,
POST_WARNING_ACTION,
// Study list
SL_CLEAR_ACTION,
SL_COPY_ACTION,
__LAST
}
public static final int SMS_BTN = AlertDialog.BUTTON_POSITIVE;
public static final int EMAIL_BTN = AlertDialog.BUTTON_NEGATIVE;
public static final int NFC_BTN = AlertDialog.BUTTON_NEUTRAL;
public static final int DISMISS_BUTTON = 0;
public static final int SKIP_CALLBACK = -1;
private static final String IDS = "IDS";
private static final String STATE_KEYF = "STATE_%d";
public interface DlgClickNotify {
void dlgButtonClicked( int id, int button, Object[] params );
void dlgButtonClicked( Action action, int button, Object[] params );
}
public interface DlgClickRegisterer {
void registerClickNotify( DlgClickNotify cb );
void unregisterClickNotify( DlgClickNotify cb );
}
public interface HasDlgDelegate {
void showOKOnlyDialog( int msgID );
@ -132,20 +193,20 @@ public class DlgDelegate {
public void showOKOnlyDialog( String msg )
{
showOKOnlyDialog( msg, SKIP_CALLBACK );
showOKOnlyDialog( msg, Action.SKIP_CALLBACK );
}
public void showOKOnlyDialog( String msg, int callbackID )
public void showOKOnlyDialog( String msg, Action action )
{
// Assert.assertNull( m_dlgStates );
DlgState state = new DlgState( DlgID.DIALOG_OKONLY, msg, callbackID );
DlgState state = new DlgState( DlgID.DIALOG_OKONLY, msg, action );
addState( state );
m_activity.showDialog( DlgID.DIALOG_OKONLY.ordinal() );
}
public void showOKOnlyDialog( int msgID )
{
showOKOnlyDialog( m_activity.getString( msgID ), SKIP_CALLBACK );
showOKOnlyDialog( m_activity.getString( msgID ), Action.SKIP_CALLBACK );
}
public void showDictGoneFinish()
@ -159,25 +220,25 @@ public class DlgDelegate {
}
public void showNotAgainDlgThen( int msgID, int prefsKey,
final int callbackID,
final Action action,
final Object[] params )
{
showNotAgainDlgThen( m_activity.getString( msgID ), prefsKey,
callbackID, params );
action, params );
}
public void showNotAgainDlgThen( String msg, int prefsKey,
final int callbackID,
final Action action,
final Object[] params )
{
if ( XWPrefs.getPrefsBoolean( m_activity, prefsKey, false ) ) {
// If it's set, do the action without bothering with the
// dialog
if ( SKIP_CALLBACK != callbackID ) {
if ( Action.SKIP_CALLBACK != action ) {
post( new Runnable() {
public void run() {
m_clickCallback
.dlgButtonClicked( callbackID,
.dlgButtonClicked( action,
AlertDialog.BUTTON_POSITIVE,
params );
}
@ -185,7 +246,7 @@ public class DlgDelegate {
}
} else {
DlgState state =
new DlgState( DlgID.DIALOG_NOTAGAIN, msg, callbackID, prefsKey,
new DlgState( DlgID.DIALOG_NOTAGAIN, msg, action, prefsKey,
params );
addState( state );
m_activity.showDialog( DlgID.DIALOG_NOTAGAIN.ordinal() );
@ -193,51 +254,51 @@ public class DlgDelegate {
}
public void showNotAgainDlgThen( int msgID, int prefsKey,
int callbackID )
Action action)
{
showNotAgainDlgThen( msgID, prefsKey, callbackID, null );
showNotAgainDlgThen( msgID, prefsKey, action, null );
}
public void showNotAgainDlgThen( int msgID, int prefsKey )
{
showNotAgainDlgThen( msgID, prefsKey, SKIP_CALLBACK );
showNotAgainDlgThen( msgID, prefsKey, Action.SKIP_CALLBACK );
}
public void showConfirmThen( String msg, int callbackID )
public void showConfirmThen( String msg, Action action )
{
showConfirmThen( msg, R.string.button_ok, callbackID, null );
showConfirmThen( msg, R.string.button_ok, action, null );
}
public void showConfirmThen( String msg, int callbackID, Object[] params )
public void showConfirmThen( String msg, Action action, Object[] params )
{
showConfirmThen( msg, R.string.button_ok, callbackID, params );
showConfirmThen( msg, R.string.button_ok, action, params );
}
public void showConfirmThen( String msg, int posButton, int callbackID )
public void showConfirmThen( String msg, int posButton, Action action )
{
showConfirmThen( msg, posButton, callbackID, null );
showConfirmThen( msg, posButton, action, null );
}
public void showConfirmThen( String msg, int posButton, int callbackID,
public void showConfirmThen( String msg, int posButton, Action action,
Object[] params )
{
DlgState state = new DlgState( DlgID.CONFIRM_THEN, msg, posButton,
callbackID, 0, params );
action, 0, params );
addState( state );
m_activity.showDialog( DlgID.CONFIRM_THEN.ordinal() );
}
public void showInviteChoicesThen( final int callbackID )
public void showInviteChoicesThen( final Action action )
{
if ( Utils.deviceSupportsSMS( m_activity )
|| NFCUtils.nfcAvail( m_activity )[0] ) {
DlgState state = new DlgState( DlgID.INVITE_CHOICES_THEN, callbackID );
DlgState state = new DlgState( DlgID.INVITE_CHOICES_THEN, action );
addState( state );
m_activity.showDialog( DlgID.INVITE_CHOICES_THEN.ordinal() );
} else {
post( new Runnable() {
public void run() {
m_clickCallback.dlgButtonClicked( callbackID, EMAIL_BTN,
m_clickCallback.dlgButtonClicked( action, EMAIL_BTN,
null );
}
});
@ -314,7 +375,7 @@ public class DlgDelegate {
post( new Runnable() {
public void run() {
if ( asDlg ) {
showOKOnlyDialog( fmsg, SKIP_CALLBACK );
showOKOnlyDialog( fmsg, Action.SKIP_CALLBACK );
} else {
DbgUtils.showf( m_activity, fmsg );
}
@ -385,9 +446,9 @@ public class DlgDelegate {
public void onClick( DialogInterface dlg, int item ) {
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
true );
if ( SKIP_CALLBACK != state.m_cbckID ) {
if ( Action.SKIP_CALLBACK != state.m_action ) {
m_clickCallback.
dlgButtonClicked( state.m_cbckID,
dlgButtonClicked( state.m_action,
AlertDialog.BUTTON_POSITIVE,
state.m_params );
}
@ -470,8 +531,8 @@ public class DlgDelegate {
OnClickListener cbkOnClickLstnr;
cbkOnClickLstnr = new OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
if ( SKIP_CALLBACK != state.m_cbckID ) {
m_clickCallback.dlgButtonClicked( state.m_cbckID,
if ( Action.SKIP_CALLBACK != state.m_action ) {
m_clickCallback.dlgButtonClicked( state.m_action,
button,
state.m_params );
}
@ -489,8 +550,8 @@ public class DlgDelegate {
= new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
dropState( state );
if ( SKIP_CALLBACK != state.m_cbckID ) {
m_clickCallback.dlgButtonClicked( state.m_cbckID,
if ( Action.SKIP_CALLBACK != state.m_action ) {
m_clickCallback.dlgButtonClicked( state.m_action,
DISMISS_BUTTON,
state.m_params );
}

View file

@ -20,6 +20,8 @@
package org.eehouse.android.xw4;
import org.eehouse.android.xw4.DlgDelegate.Action;
import android.os.Parcelable;
import android.os.Parcel;
@ -27,52 +29,52 @@ public class DlgState implements Parcelable {
public DlgID m_id;
public String m_msg;
public int m_posButton;
public int m_cbckID = 0;
public Action m_action = null;
public int m_prefsKey;
public Object[] m_params;
public DlgState( DlgID dlgID, String msg, int cbckID )
public DlgState( DlgID dlgID, String msg, Action action )
{
this( dlgID, msg, R.string.button_ok, cbckID, 0 );
this( dlgID, msg, R.string.button_ok, action, 0 );
}
public DlgState( DlgID dlgID, String msg, int cbckID, int prefsKey )
public DlgState( DlgID dlgID, String msg, Action action, int prefsKey )
{
this( dlgID, msg, R.string.button_ok, cbckID, prefsKey );
this( dlgID, msg, R.string.button_ok, action, prefsKey );
}
public DlgState( DlgID dlgID, String msg, int cbckID, int prefsKey,
public DlgState( DlgID dlgID, String msg, Action action, int prefsKey,
Object[] params )
{
this( dlgID, msg, R.string.button_ok, cbckID, prefsKey );
this( dlgID, msg, R.string.button_ok, action, prefsKey );
m_params = params;
}
public DlgState( DlgID dlgID, String msg, int posButton,
int cbckID, int prefsKey )
Action action, int prefsKey )
{
this( dlgID, msg, posButton, cbckID, prefsKey, null );
this( dlgID, msg, posButton, action, prefsKey, null );
}
public DlgState( DlgID dlgID, String msg, int posButton,
int cbckID, int prefsKey, Object[] params )
Action action, int prefsKey, Object[] params )
{
m_id = dlgID;
m_msg = msg;
m_posButton = posButton;
m_cbckID = cbckID;
m_action = action;
m_prefsKey = prefsKey;
m_params = params;
}
public DlgState( DlgID dlgID, int cbckID )
public DlgState( DlgID dlgID, Action action )
{
this( dlgID, null, 0, cbckID, 0 );
this( dlgID, null, 0, action, 0 );
}
public DlgState( DlgID dlgID, Object[] params )
{
this( dlgID, null, 0, 0, 0, params );
this( dlgID, null, 0, null, 0, params );
}
public int describeContents() {
@ -82,7 +84,7 @@ public class DlgState implements Parcelable {
public void writeToParcel( Parcel out, int flags ) {
out.writeInt( m_id.ordinal() );
out.writeInt( m_posButton );
out.writeInt( m_cbckID );
out.writeInt( m_action.ordinal() );
out.writeInt( m_prefsKey );
out.writeString( m_msg );
}
@ -92,10 +94,10 @@ public class DlgState implements Parcelable {
public DlgState createFromParcel(Parcel in) {
DlgID id = DlgID.values()[in.readInt()];
int posButton = in.readInt();
int cbckID = in.readInt();
Action action = Action.values()[in.readInt()];
int prefsKey = in.readInt();
String msg = in.readString();
return new DlgState( id, msg, posButton, cbckID, prefsKey );
return new DlgState( id, msg, posButton, action, prefsKey );
}
public DlgState[] newArray(int size) {

View file

@ -54,6 +54,7 @@ import android.widget.Toast;
import android.database.DataSetObserver;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.jni.*;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
@ -64,7 +65,6 @@ public class GameConfig extends XWActivity
,RefreshNamesTask.NoNameFound {
private static final String WHICH_PLAYER = "WHICH_PLAYER";
private static final int LOCKED_CHANGE_ACTION = 1;
private CheckBox m_joinPublicCheck;
private CheckBox m_gameLockedCheck;
@ -596,9 +596,9 @@ public class GameConfig extends XWActivity
}
@Override
public void dlgButtonClicked( int id, int button, Object[] params )
public void dlgButtonClicked( Action action, int button, Object[] params )
{
switch( id ) {
switch( action ) {
case LOCKED_CHANGE_ACTION:
if ( AlertDialog.BUTTON_POSITIVE == button ) {
handleLockedChange();
@ -627,7 +627,7 @@ public class GameConfig extends XWActivity
} else if ( m_gameLockedCheck == view ) {
showNotAgainDlgThen( R.string.not_again_unlock,
R.string.key_notagain_unlock,
LOCKED_CHANGE_ACTION );
Action.LOCKED_CHANGE_ACTION );
} else if ( m_refreshRoomsButton == view ) {
refreshNames();
} else if ( m_playButton == view ) {

View file

@ -55,6 +55,7 @@ import java.util.Set;
// import android.telephony.TelephonyManager;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.jni.*;
public class GamesList extends XWExpandableListActivity
@ -73,16 +74,6 @@ public class GamesList extends XWExpandableListActivity
private static final String REMATCH_ROWID_EXTRA = "rowid_rm";
private static final String ALERT_MSG = "alert_msg";
private static enum GamesActions { NEW_NET_GAME
,RESET_GAMES
,SYNC_MENU
,NEW_FROM
,DELETE_GAMES
,DELETE_GROUPS
,OPEN_GAME
,CLEAR_SELS
};
private static final int[] DEBUG_ITEMS = {
// R.id.games_menu_loaddb,
R.id.games_menu_storedb,
@ -500,8 +491,7 @@ public class GamesList extends XWExpandableListActivity
long rowid = ((GameListItem)clicked).getRowID();
showNotAgainDlgThen( R.string.not_again_newselect,
R.string.key_notagain_newselect,
GamesActions.OPEN_GAME.ordinal(),
rowid, summary );
Action.OPEN_GAME, rowid, summary );
}
}
}
@ -568,10 +558,9 @@ public class GamesList extends XWExpandableListActivity
// DlgDelegate.DlgClickNotify interface
@Override
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
if ( AlertDialog.BUTTON_POSITIVE == which ) {
GamesActions action = GamesActions.values()[id];
switch( action ) {
case NEW_NET_GAME:
if ( checkWarnNoDict( m_netLaunchInfo ) ) {
@ -636,7 +625,7 @@ public class GamesList extends XWExpandableListActivity
} else {
showNotAgainDlgThen( R.string.not_again_backclears,
R.string.key_notagain_backclears,
GamesActions.CLEAR_SELS.ordinal() );
Action.CLEAR_SELS );
}
}
@ -767,7 +756,7 @@ public class GamesList extends XWExpandableListActivity
case R.id.games_menu_checkmoves:
showNotAgainDlgThen( R.string.not_again_sync,
R.string.key_notagain_sync,
GamesActions.SYNC_MENU.ordinal() );
Action.SYNC_MENU );
break;
case R.id.games_menu_checkupdates:
@ -815,7 +804,7 @@ public class GamesList extends XWExpandableListActivity
String msg = Utils.format( this, R.string.confirm_seldeletesf,
selRowIDs.length );
showConfirmThen( msg, R.string.button_delete,
GamesActions.DELETE_GAMES.ordinal(), selRowIDs );
Action.DELETE_GAMES, selRowIDs );
break;
case R.id.games_game_move:
@ -830,8 +819,7 @@ public class GamesList extends XWExpandableListActivity
dropSels = true; // will select the new game instead
showNotAgainDlgThen( R.string.not_again_newfrom,
R.string.key_notagain_newfrom,
GamesActions.NEW_FROM.ordinal(),
selRowIDs[0] );
Action.NEW_FROM, selRowIDs[0] );
break;
case R.id.games_game_copy:
final GameSummary smry = DBUtils.getSummary( this, selRowIDs[0] );
@ -860,7 +848,7 @@ public class GamesList extends XWExpandableListActivity
case R.id.games_game_reset:
msg = getString( R.string.confirm_resetf, selRowIDs.length );
showConfirmThen( msg, R.string.button_reset,
GamesActions.RESET_GAMES.ordinal(), selRowIDs );
Action.RESET_GAMES, selRowIDs );
break;
case R.id.games_game_rename:
@ -887,8 +875,7 @@ public class GamesList extends XWExpandableListActivity
if ( 0 < nGames ) {
msg += getString( R.string.groups_confirm_del_gamesf, nGames );
}
showConfirmThen( msg, GamesActions.DELETE_GROUPS.ordinal(),
groupIDs );
showConfirmThen( msg, Action.DELETE_GROUPS, groupIDs );
}
break;
case R.id.games_group_default:
@ -1094,7 +1081,7 @@ public class GamesList extends XWExpandableListActivity
String msg = getString( R.string.dup_game_queryf,
create.toString() );
m_netLaunchInfo = nli;
showConfirmThen( msg, GamesActions.NEW_NET_GAME.ordinal(), nli );
showConfirmThen( msg, Action.NEW_NET_GAME, nli );
} else {
showOKOnlyDialog( R.string.dropped_dupe );
}

View file

@ -46,7 +46,6 @@ import org.eehouse.android.xw4.jni.XwJNI;
public class NewGameActivity extends XWActivity {
private static final int NEW_GAME_ACTION = 1;
// private static final String SAVE_DEVNAMES = "DEVNAMES";
private static final String SAVE_REMOTEGAME = "REMOTEGAME";
private static final String SAVE_GAMEID = "GAMEID";
@ -150,9 +149,9 @@ public class NewGameActivity extends XWActivity {
// DlgDelegate.DlgClickNotify interface
@Override
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( DlgDelegate.Action action, int which, Object[] params )
{
switch( id ) {
switch( action ) {
case NEW_GAME_ACTION:
if ( DlgDelegate.DISMISS_BUTTON != which ) {
makeNewGame( true, true, which );
@ -310,7 +309,7 @@ public class NewGameActivity extends XWActivity {
{
if ( launch && networked ) {
// Let 'em cancel before we make the game
showInviteChoicesThen( NEW_GAME_ACTION );
showInviteChoicesThen( DlgDelegate.Action.NEW_GAME_ACTION );
} else {
makeNewGame( networked, launch, DlgDelegate.SMS_BTN );
}

View file

@ -40,16 +40,14 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import org.eehouse.android.xw4.DlgDelegate.Action;
public class SMSInviteActivity extends InviteActivity {
private static final int GET_CONTACT = 1;
private static final String SAVE_NAME = "SAVE_NAME";
private static final String SAVE_NUMBER = "SAVE_NUMBER";
private static final int CLEAR_ACTION = 1;
private static final int USE_IMMOBILE_ACTION = 2;
private static final int POST_WARNING_ACTION = 3;
private ArrayList<PhoneRec> m_phoneRecs;
private SMSPhonesAdapter m_adapter;
private ImageButton m_addButton;
@ -137,7 +135,7 @@ public class SMSInviteActivity extends InviteActivity {
m_pendingName = null;
showConfirmThen( R.string.warn_unlimited,
R.string.button_yes,
POST_WARNING_ACTION );
Action.POST_WARNING_ACTION );
}
};
dialog = new AlertDialog.Builder( this )
@ -162,7 +160,7 @@ public class SMSInviteActivity extends InviteActivity {
protected void clearSelected()
{
showConfirmThen( R.string.confirm_clear, CLEAR_ACTION );
showConfirmThen( R.string.confirm_clear, Action.CLEAR_ACTION );
}
protected String[] listSelected()
@ -190,11 +188,11 @@ public class SMSInviteActivity extends InviteActivity {
// DlgDelegate.DlgClickNotify interface
@Override
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
switch( which ) {
case AlertDialog.BUTTON_POSITIVE:
switch( id ) {
switch( action ) {
case CLEAR_ACTION:
clearSelectedImpl();
break;
@ -208,10 +206,10 @@ public class SMSInviteActivity extends InviteActivity {
}
break;
case DlgDelegate.DISMISS_BUTTON:
if ( USE_IMMOBILE_ACTION == id && m_immobileConfirmed ) {
if ( Action.USE_IMMOBILE_ACTION == action && m_immobileConfirmed ) {
showConfirmThen( R.string.warn_unlimited,
R.string.button_yes,
POST_WARNING_ACTION );
Action.POST_WARNING_ACTION );
}
break;
}
@ -259,14 +257,14 @@ public class SMSInviteActivity extends InviteActivity {
if ( Phone.TYPE_MOBILE == type ) {
showConfirmThen( R.string.warn_unlimited,
R.string.button_yes,
POST_WARNING_ACTION );
Action.POST_WARNING_ACTION );
} else {
m_immobileConfirmed = false;
String msg =
Utils.format( this, R.string.warn_nomobilef,
number, name );
showConfirmThen( msg, R.string.button_yes,
USE_IMMOBILE_ACTION );
Action.USE_IMMOBILE_ACTION );
}
}
}

View file

@ -37,13 +37,13 @@ import android.widget.Spinner;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
public class StudyList extends XWListActivity
implements OnItemSelectedListener {
public static final int NO_LANG = -1;
private static final int CLEAR_ACTION = 1;
private static final int COPY_ACTION = 2;
private static final String START_LANG = "START_LANG";
private Spinner m_spinner;
@ -84,10 +84,11 @@ public class StudyList extends XWListActivity
case R.id.copy_all:
showNotAgainDlgThen( R.string.not_again_studycopy,
R.string.key_na_studycopy,
COPY_ACTION );
Action.SL_COPY_ACTION );
break;
case R.id.clear_all:
showConfirmThen( R.string.confirm_studylist_clear, CLEAR_ACTION );
showConfirmThen( R.string.confirm_studylist_clear,
Action.SL_CLEAR_ACTION );
break;
default:
handled = false;
@ -99,15 +100,15 @@ public class StudyList extends XWListActivity
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////
@Override
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
if ( AlertDialog.BUTTON_POSITIVE == which ) {
switch ( id ) {
case CLEAR_ACTION:
switch ( action ) {
case SL_CLEAR_ACTION:
DBUtils.studyListClear( this, m_langCodes[m_position] );
initOrFinish( null );
break;
case COPY_ACTION:
case SL_COPY_ACTION:
ClipboardManager clipboard = (ClipboardManager)
getSystemService( Context.CLIPBOARD_SERVICE );
clipboard.setText( TextUtils.join( "\n", m_words ) );

View file

@ -28,6 +28,7 @@ import android.view.View;
import android.widget.LinearLayout;
import android.widget.ImageButton;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.jni.*;
public class Toolbar {
@ -117,22 +118,22 @@ public class Toolbar {
}
public void setListener( int index, final int msgID, final int prefsKey,
final int callback )
final Action action )
{
View.OnClickListener listener = new View.OnClickListener() {
public void onClick( View view ) {
m_activity.showNotAgainDlgThen( msgID, prefsKey, callback );
m_activity.showNotAgainDlgThen( msgID, prefsKey, action );
}
};
setListener( index, listener );
}
public void setLongClickListener( int index, final int msgID,
final int prefsKey, final int callback )
final int prefsKey, final Action action )
{
View.OnLongClickListener listener = new View.OnLongClickListener() {
public boolean onLongClick( View view ) {
m_activity.showNotAgainDlgThen( msgID, prefsKey, callback );
m_activity.showNotAgainDlgThen( msgID, prefsKey, action );
return true;
}
};

View file

@ -30,6 +30,8 @@ import android.view.View;
import android.widget.TextView;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
public class XWActivity extends Activity
implements DlgDelegate.DlgClickNotify, DlgDelegate.HasDlgDelegate,
MultiService.MultiEventListener {
@ -113,13 +115,13 @@ public class XWActivity extends Activity
}
protected void showNotAgainDlgThen( String msg, int prefsKey,
int action )
Action action )
{
m_delegate.showNotAgainDlgThen( msg, prefsKey, action, null );
}
protected void showNotAgainDlgThen( int msgID, int prefsKey,
int action )
Action action )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey, action );
}
@ -144,22 +146,22 @@ public class XWActivity extends Activity
m_delegate.showDictGoneFinish();
}
protected void showConfirmThen( int msgID, int action )
protected void showConfirmThen( int msgID, Action action )
{
m_delegate.showConfirmThen( getString(msgID), action );
}
protected void showConfirmThen( String msg, int action )
protected void showConfirmThen( String msg, Action action )
{
m_delegate.showConfirmThen( msg, action );
}
protected void showConfirmThen( int msg, int posButton, int action )
protected void showConfirmThen( int msg, int posButton, Action action )
{
m_delegate.showConfirmThen( getString(msg), posButton, action );
}
public void showInviteChoicesThen( int action )
public void showInviteChoicesThen( Action action )
{
m_delegate.showInviteChoicesThen( action );
}
@ -190,7 +192,7 @@ public class XWActivity extends Activity
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
Assert.fail();
}

View file

@ -27,6 +27,7 @@ import android.os.Bundle;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
public class XWExpandableListActivity extends ExpandableListActivity
implements DlgDelegate.DlgClickNotify, DlgDelegate.HasDlgDelegate,
@ -86,13 +87,13 @@ public class XWExpandableListActivity extends ExpandableListActivity
}
protected void showNotAgainDlgThen( int msgID, int prefsKey,
int action, Object... params )
Action action, Object... params )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey, action, params );
}
protected void showNotAgainDlgThen( int msgID, int prefsKey,
int action )
Action action )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey, action );
}
@ -118,25 +119,26 @@ public class XWExpandableListActivity extends ExpandableListActivity
m_delegate.showOKOnlyDialog( msg );
}
protected void showConfirmThen( String msg, int action, Object... params )
protected void showConfirmThen( String msg, Action action, Object... params )
{
m_delegate.showConfirmThen( msg, action, params );
}
protected void showConfirmThen( String msg, int posButton, int action,
protected void showConfirmThen( String msg, int posButton, Action action,
Object... params )
{
m_delegate.showConfirmThen( msg, posButton, action, params );
}
protected void showConfirmThen( int msg, int posButton, int action,
protected void showConfirmThen( int msg, int posButton, Action action,
Object... params )
{
m_delegate.showConfirmThen( getString(msg), posButton, action, params );
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( DlgDelegate.Action action, int which,
Object[] params )
{
Assert.fail();
}

View file

@ -25,6 +25,8 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import org.eehouse.android.xw4.DlgDelegate.Action;
import junit.framework.Assert;
public class XWListActivity extends ListActivity
@ -97,7 +99,7 @@ public class XWListActivity extends ListActivity
}
protected void showNotAgainDlgThen( int msgID, int prefsKey,
int action )
Action action )
{
m_delegate.showNotAgainDlgThen( msgID, prefsKey, action );
}
@ -107,7 +109,7 @@ public class XWListActivity extends ListActivity
m_delegate.showNotAgainDlgThen( msgID, prefsKey );
}
protected void showOKOnlyDialogThen( String msg, int action )
protected void showOKOnlyDialogThen( String msg, Action action )
{
m_delegate.showOKOnlyDialog( msg, action );
}
@ -122,22 +124,22 @@ public class XWListActivity extends ListActivity
m_delegate.showOKOnlyDialog( msgID );
}
protected void showConfirmThen( String msg, int action )
protected void showConfirmThen( String msg, Action action )
{
m_delegate.showConfirmThen( msg, action );
}
protected void showConfirmThen( int msg, int action )
protected void showConfirmThen( int msg, Action action )
{
showConfirmThen( getString(msg), action );
}
protected void showConfirmThen( String msg, int posButton, int action )
protected void showConfirmThen( String msg, int posButton, Action action )
{
m_delegate.showConfirmThen( msg, posButton, action );
}
protected void showConfirmThen( int msg, int posButton, int action )
protected void showConfirmThen( int msg, int posButton, Action action )
{
m_delegate.showConfirmThen( getString(msg), posButton, action );
}
@ -163,7 +165,7 @@ public class XWListActivity extends ListActivity
}
// DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( int id, int which, Object[] params )
public void dlgButtonClicked( Action action, int which, Object[] params )
{
Assert.fail();
}