toggle image when clicked

This commit is contained in:
Eric House 2014-03-26 21:12:43 -07:00
parent 84698273a5
commit 64d0e0c867

View file

@ -25,11 +25,13 @@ import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ImageButton;
import org.eehouse.android.xw4.DBUtils.GameGroupInfo; import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
public class GameListGroup extends LinearLayout public class GameListGroup extends LinearLayout
implements SelectableItem.LongClickHandler, implements SelectableItem.LongClickHandler,
View.OnClickListener,
View.OnLongClickListener View.OnLongClickListener
{ {
private int m_groupPosition; private int m_groupPosition;
@ -39,6 +41,7 @@ public class GameListGroup extends LinearLayout
private ExpiringTextView m_etv; private ExpiringTextView m_etv;
private boolean m_selected; private boolean m_selected;
private DrawSelDelegate m_dsdel; private DrawSelDelegate m_dsdel;
private ImageButton m_expandButton;
public static GameListGroup makeForPosition( Context context, public static GameListGroup makeForPosition( Context context,
int groupPosition, int groupPosition,
@ -63,8 +66,11 @@ public class GameListGroup extends LinearLayout
{ {
super.onFinishInflate(); super.onFinishInflate();
m_etv = (ExpiringTextView)findViewById( R.id.game_name ); m_etv = (ExpiringTextView)findViewById( R.id.game_name );
m_expandButton = (ImageButton)findViewById( R.id.expander );
m_expandButton.setOnClickListener( this );
m_dsdel = new DrawSelDelegate( this ); m_dsdel = new DrawSelDelegate( this );
setOnLongClickListener( this ); setOnLongClickListener( this );
setButton();
} }
public void setGroupPosition( int groupPosition ) public void setGroupPosition( int groupPosition )
@ -122,4 +128,22 @@ public class GameListGroup extends LinearLayout
longClicked(); longClicked();
return true; return true;
} }
//////////////////////////////////////////////////
// View.OnClickListener interface
//////////////////////////////////////////////////
public void onClick( View view )
{
m_expanded = !m_expanded;
DBUtils.setGroupExpanded( getContext(), m_groupID, m_expanded );
setButton();
}
private void setButton()
{
m_expandButton.setImageResource( m_expanded ?
R.drawable.expander_ic_maximized :
R.drawable.expander_ic_minimized);
}
} }