move more knowledge from Board Activity to Toolbar

This commit is contained in:
Andy2 2010-07-01 18:45:33 -07:00
parent 7895325f74
commit 0d2ba57186
2 changed files with 77 additions and 87 deletions

View file

@ -720,87 +720,58 @@ public class BoardActivity extends Activity implements UtilCtxt {
}
} // loadGame
private void bindButtons( View.OnClickListener listener, int... ids )
{
for ( int id : ids ) {
ImageButton button = (ImageButton)findViewById( id );
if ( null == listener ) {
button.setVisibility( View.GONE );
} else {
button.setVisibility( View.VISIBLE );
button.setOnClickListener( listener );
}
}
}
private void populateToolbar()
{
View.OnClickListener listener;
if ( m_gi.hintsNotAllowed ) {
listener = null;
} else {
listener = new View.OnClickListener() {
@Override
public void onClick( View view ) {
Utils.notImpl( BoardActivity.this );
}
};
}
bindButtons( listener, R.id.prevhint_button_horizontal,
R.id.prevhint_button_vertical );
if ( m_gi.hintsNotAllowed ) {
listener = null;
} else {
listener = new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_NEXT_HINT );
}
};
}
bindButtons( listener, R.id.nexthint_button_horizontal,
R.id.nexthint_button_vertical );
listener = new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_JUGGLE );
}
};
bindButtons( listener, R.id.shuffle_button_horizontal,
R.id.shuffle_button_vertical );
listener = new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_FLIP );
}
};
bindButtons( listener, R.id.flip_button_horizontal,
R.id.flip_button_vertical );
listener = new View.OnClickListener() {
private boolean m_goIn = true;
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_ZOOM,
m_goIn? 8 : -8 );
m_goIn = !m_goIn;
}
};
bindButtons( listener, R.id.zoom_button_horizontal,
R.id.zoom_button_vertical );
listener = new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_UNDO_CUR );
}
};
bindButtons( listener, R.id.undo_button_horizontal,
R.id.undo_button_vertical );
m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV,
new View.OnClickListener() {
@Override
public void onClick( View view ) {
Utils.notImpl( BoardActivity.this );
}
} );
m_toolbar.setListener( Toolbar.BUTTON_HINT_NEXT,
new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd
.CMD_NEXT_HINT );
}
} );
m_toolbar.setListener( Toolbar.BUTTON_JUGGLE,
new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd
.CMD_JUGGLE );
}
} );
m_toolbar.setListener( Toolbar.BUTTON_FLIP,
new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd
.CMD_FLIP );
}
} );
m_toolbar.setListener( Toolbar.BUTTON_ZOOM,
new View.OnClickListener() {
private boolean m_goIn = true;
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd
.CMD_ZOOM,
m_goIn? 8 : -8 );
m_goIn = !m_goIn;
}
} );
m_toolbar.setListener( Toolbar.BUTTON_UNDO,
new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_jniThread.handle( JNIThread.JNICmd
.CMD_UNDO_CUR );
}
}) ;
} // populateToolbar
private DialogInterface.OnDismissListener makeODLforBlocking()

View file

@ -36,16 +36,17 @@ public class Toolbar {
private static class TBButtonInfo {
public TBButtonInfo( int horID, int vertID ) {
m_horID = horID;
m_vertID = vertID;
m_ids = new int[] { horID, vertID };
}
public int m_horID;
public int m_vertID;
public int m_ids[];
}
public static final int BUTTON_HINT_PREV = 0;
public static final int BUTTON_HINT_NEXT = 1;
public static final int BUTTON_FLIP = 2;
public static final int BUTTON_JUGGLE = 3;
public static final int BUTTON_ZOOM = 4;
public static final int BUTTON_UNDO = 5;
private static TBButtonInfo[] s_buttonInfo = {
// BUTTON_HINT_PREV
@ -57,6 +58,15 @@ public class Toolbar {
// BUTTON_FLIP
new TBButtonInfo(R.id.flip_button_horizontal,
R.id.flip_button_vertical),
// BUTTON_JUGGLE
new TBButtonInfo( R.id.shuffle_button_horizontal,
R.id.shuffle_button_vertical ),
// BUTTON_ZOOM
new TBButtonInfo( R.id.zoom_button_horizontal,
R.id.zoom_button_vertical ),
// BUTTON_UNDO
new TBButtonInfo( R.id.undo_button_horizontal,
R.id.undo_button_vertical ),
};
private Activity m_activity;
@ -76,6 +86,15 @@ public class Toolbar {
m_vertLayout = (LinearLayout)vertLayout;
}
public void setListener( int index, View.OnClickListener listener )
{
TBButtonInfo info = s_buttonInfo[index];
for ( int id : info.m_ids ) {
ImageButton button = (ImageButton)m_activity.findViewById( id );
button.setOnClickListener( listener );
}
}
public void orientChanged( boolean landscape )
{
if ( landscape && m_curOrient == ORIENTATION.ORIENT_LANDSCAPE ) {
@ -106,10 +125,10 @@ public class Toolbar {
int vis = enable != 0 ? View.VISIBLE : View.GONE;
ImageButton button;
button = (ImageButton)m_activity.findViewById( info.m_horID );
button.setVisibility( vis );
button = (ImageButton)m_activity.findViewById( info.m_vertID );
button.setVisibility( vis );
for ( int id : info.m_ids ) {
button = (ImageButton)m_activity.findViewById( id );
button.setVisibility( vis );
}
}
}