don't create toolbar unless required widgets are present in layout,

then test for null toolbar before use. Fixes NPEs on small screens.
This commit is contained in:
Eric House 2014-07-30 07:07:00 -07:00
parent f01d12035b
commit 7f880627ec

View file

@ -519,11 +519,15 @@ public class BoardDelegate extends DelegateBase
m_view = (BoardView)findViewById( R.id.board_view );
if ( ! ABUtils.haveActionBar() ) {
m_tradeButtons = findViewById( R.id.exchange_buttons );
m_exchCommmitButton = (Button)findViewById( R.id.exchange_commit );
if ( null != m_tradeButtons ) {
m_exchCommmitButton = (Button)
findViewById( R.id.exchange_commit );
m_exchCommmitButton.setOnClickListener( this );
m_exchCancelButton = (Button)findViewById( R.id.exchange_cancel );
m_exchCancelButton = (Button)
findViewById( R.id.exchange_cancel );
m_exchCancelButton.setOnClickListener( this );
}
}
m_volKeysZoom = XWPrefs.getVolKeysZoom( m_activity );
Intent intent = getIntent();
@ -1855,9 +1859,11 @@ public class BoardDelegate extends DelegateBase
setTitle( GameUtils.getName( m_activity, m_rowid ) );
}
if ( null != findViewById( R.id.tbar_parent_hor ) ) {
int orient = m_activity.getResources().getConfiguration().orientation;
boolean isLandscape = Configuration.ORIENTATION_LANDSCAPE == orient;
m_toolbar = new Toolbar( m_activity, this, isLandscape );
}
populateToolbar();
adjustTradeVisibility();
@ -1907,6 +1913,7 @@ public class BoardDelegate extends DelegateBase
private void populateToolbar()
{
if ( null != m_toolbar ) {
m_toolbar.setListener( Toolbar.BUTTON_BROWSE_DICT,
R.string.not_again_browseall,
R.string.key_na_browseall,
@ -1949,6 +1956,7 @@ public class BoardDelegate extends DelegateBase
R.string.key_notagain_chat,
Action.CHAT_ACTION );
}
}
} // populateToolbar
private OnDismissListener makeODLforBlocking( final int id )
@ -2134,6 +2142,7 @@ 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 );
@ -2145,10 +2154,13 @@ public class BoardDelegate extends DelegateBase
m_toolbar.update( Toolbar.BUTTON_BROWSE_DICT,
null != m_gi.dictName( m_view.getCurPlayer() ) );
}
}
private void adjustTradeVisibility()
{
if ( null != m_toolbar ) {
m_toolbar.setVisible( !m_inTrade );
}
if ( null != m_tradeButtons ) {
m_tradeButtons.setVisibility( m_inTrade? View.VISIBLE : View.GONE );
}