cleanup: constants + parallel array => enum

I didn't always know enums could have constructors
This commit is contained in:
Eric House 2016-08-15 16:01:30 -07:00
parent 71ac6062f1
commit ab24140813
2 changed files with 43 additions and 59 deletions

View file

@ -46,6 +46,7 @@ import junit.framework.Assert;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.Toolbar.Buttons;
import org.eehouse.android.xw4.jni.CommonPrefs;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
@ -1033,7 +1034,7 @@ public class BoardDelegate extends DelegateBase
case BUTTON_BROWSEALL_ACTION:
case BUTTON_BROWSE_ACTION:
String curDict = m_gi.dictName( m_view.getCurPlayer() );
View button = m_toolbar.getViewFor( Toolbar.BUTTON_BROWSE_DICT );
View button = m_toolbar.getViewFor( Buttons.BUTTON_BROWSE_DICT );
if ( Action.BUTTON_BROWSEALL_ACTION == action &&
DictsDelegate.handleDictsPopup( getDelegator(), button,
curDict, m_gi.dictLang ) ){
@ -2225,43 +2226,43 @@ public class BoardDelegate extends DelegateBase
private void populateToolbar()
{
if ( null != m_toolbar ) {
m_toolbar.setListener( Toolbar.BUTTON_BROWSE_DICT,
m_toolbar.setListener( Buttons.BUTTON_BROWSE_DICT,
R.string.not_again_browseall,
R.string.key_na_browseall,
Action.BUTTON_BROWSEALL_ACTION );
m_toolbar.setLongClickListener( Toolbar.BUTTON_BROWSE_DICT,
m_toolbar.setLongClickListener( Buttons.BUTTON_BROWSE_DICT,
R.string.not_again_browse,
R.string.key_na_browse,
Action.BUTTON_BROWSE_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV,
m_toolbar.setListener( Buttons.BUTTON_HINT_PREV,
R.string.not_again_hintprev,
R.string.key_notagain_hintprev,
Action.PREV_HINT_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_HINT_NEXT,
m_toolbar.setListener( Buttons.BUTTON_HINT_NEXT,
R.string.not_again_hintnext,
R.string.key_notagain_hintnext,
Action.NEXT_HINT_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_JUGGLE,
m_toolbar.setListener( Buttons.BUTTON_JUGGLE,
R.string.not_again_juggle,
R.string.key_notagain_juggle,
Action.JUGGLE_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_FLIP,
m_toolbar.setListener( Buttons.BUTTON_FLIP,
R.string.not_again_flip,
R.string.key_notagain_flip,
Action.FLIP_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_ZOOM,
m_toolbar.setListener( Buttons.BUTTON_ZOOM,
R.string.not_again_zoom,
R.string.key_notagain_zoom,
Action.ZOOM_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_VALUES,
m_toolbar.setListener( Buttons.BUTTON_VALUES,
R.string.not_again_values,
R.string.key_na_values,
Action.VALUES_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_UNDO,
m_toolbar.setListener( Buttons.BUTTON_UNDO,
R.string.not_again_undo,
R.string.key_notagain_undo,
Action.UNDO_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_CHAT,
m_toolbar.setListener( Buttons.BUTTON_CHAT,
R.string.not_again_chat,
R.string.key_notagain_chat,
Action.CHAT_ACTION );
@ -2496,14 +2497,14 @@ public class BoardDelegate extends DelegateBase
private void updateToolbar()
{
if ( null != m_toolbar ) {
m_toolbar.update( Toolbar.BUTTON_FLIP, m_gsi.visTileCount >= 1 );
m_toolbar.update( Toolbar.BUTTON_VALUES, m_gsi.visTileCount >= 1 );
m_toolbar.update( Toolbar.BUTTON_JUGGLE, m_gsi.canShuffle );
m_toolbar.update( Toolbar.BUTTON_UNDO, m_gsi.canRedo );
m_toolbar.update( Toolbar.BUTTON_HINT_PREV, m_gsi.canHint );
m_toolbar.update( Toolbar.BUTTON_HINT_NEXT, m_gsi.canHint );
m_toolbar.update( Toolbar.BUTTON_CHAT, m_gsi.canChat );
m_toolbar.update( Toolbar.BUTTON_BROWSE_DICT,
m_toolbar.update( Buttons.BUTTON_FLIP, m_gsi.visTileCount >= 1 );
m_toolbar.update( Buttons.BUTTON_VALUES, m_gsi.visTileCount >= 1 );
m_toolbar.update( Buttons.BUTTON_JUGGLE, m_gsi.canShuffle );
m_toolbar.update( Buttons.BUTTON_UNDO, m_gsi.canRedo );
m_toolbar.update( Buttons.BUTTON_HINT_PREV, m_gsi.canHint );
m_toolbar.update( Buttons.BUTTON_HINT_NEXT, m_gsi.canHint );
m_toolbar.update( Buttons.BUTTON_CHAT, m_gsi.canChat );
m_toolbar.update( Buttons.BUTTON_BROWSE_DICT,
null != m_gi.dictName( m_view.getCurPlayer() ) );
}
}

View file

@ -34,35 +34,21 @@ import org.eehouse.android.xw4.DlgDelegate.HasDlgDelegate;
import org.eehouse.android.xw4.loc.LocUtils;
public class Toolbar {
public static final int BUTTON_BROWSE_DICT = 0;
public static final int BUTTON_HINT_PREV = 1;
public static final int BUTTON_HINT_NEXT = 2;
public static final int BUTTON_FLIP = 3;
public static final int BUTTON_JUGGLE = 4;
public static final int BUTTON_ZOOM = 5;
public static final int BUTTON_UNDO = 6;
public static final int BUTTON_CHAT = 7;
public static final int BUTTON_VALUES = 8;
public enum Buttons {
BUTTON_BROWSE_DICT(R.id.dictlist_button),
BUTTON_HINT_PREV(R.id.prevhint_button),
BUTTON_HINT_NEXT(R.id.nexthint_button),
BUTTON_FLIP(R.id.flip_button),
BUTTON_JUGGLE(R.id.shuffle_button),
BUTTON_ZOOM(R.id.zoom_button),
BUTTON_UNDO(R.id.undo_button),
BUTTON_CHAT(R.id.chat_button),
BUTTON_VALUES(R.id.values_button)
;
private static int[] s_buttonInfo = {
// BUTTON_BROWSE_DICT
R.id.dictlist_button,
// BUTTON_HINT_PREV
R.id.prevhint_button,
// BUTTON_HINT_NEXT
R.id.nexthint_button,
// BUTTON_FLIP
R.id.flip_button,
// BUTTON_JUGGLE
R.id.shuffle_button,
// BUTTON_ZOOM
R.id.zoom_button,
// BUTTON_UNDO
R.id.undo_button,
// BUTTON_CHAT
R.id.chat_button,
// BUTTON_VALUES
R.id.values_button,
private int m_id;
private Buttons(int id) { m_id = id; }
public int getResId() { return m_id; }
};
private Activity m_activity;
@ -85,14 +71,12 @@ public class Toolbar {
}
}
public ImageButton getViewFor( int index )
public ImageButton getViewFor( Buttons index )
{
int id = s_buttonInfo[index];
ImageButton button = (ImageButton)m_activity.findViewById( id );
return button;
return (ImageButton)m_activity.findViewById( index.getResId() );
}
public void setListener( int index, final int msgID, final int prefsKey,
public void setListener( Buttons index, final int msgID, final int prefsKey,
final Action action )
{
View.OnClickListener listener = new View.OnClickListener() {
@ -104,7 +88,7 @@ public class Toolbar {
setListener( index, listener );
}
public void setLongClickListener( int index, final int msgID,
public void setLongClickListener( Buttons index, final int msgID,
final int prefsKey, final Action action )
{
View.OnLongClickListener listener = new View.OnLongClickListener() {
@ -125,13 +109,12 @@ public class Toolbar {
}
}
public void update( int index, boolean enable )
public void update( Buttons index, boolean enable )
{
int vis = enable ? View.VISIBLE : View.GONE;
int id = s_buttonInfo[index];
int id = index.getResId();
ImageButton button = (ImageButton)m_activity.findViewById( id );
if ( null != button ) {
button.setVisibility( vis );
button.setVisibility( enable ? View.VISIBLE : View.GONE );
}
}
@ -157,7 +140,7 @@ public class Toolbar {
m_layout.setVisibility( m_visible? View.VISIBLE : View.GONE );
}
private void setListener( int index, View.OnClickListener listener )
private void setListener( Buttons index, View.OnClickListener listener )
{
ImageButton button = getViewFor( index );
if ( null != button ) {
@ -165,7 +148,7 @@ public class Toolbar {
}
}
private void setLongClickListener( int index,
private void setLongClickListener( Buttons index,
View.OnLongClickListener listener )
{
ImageButton button = getViewFor( index );