SimplePopupItem.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package de.tudarmstadt.informatik.hostage.ui2.popup;
  2. import android.content.Context;
  3. import android.view.MotionEvent;
  4. import android.view.View;
  5. import android.widget.RadioButton;
  6. import android.widget.TextView;
  7. import de.tudarmstadt.informatik.hostage.R;
  8. /**
  9. * Created by Julien on 13.02.14.
  10. */
  11. public class SimplePopupItem extends AbstractPopupItem {
  12. public boolean selected;
  13. private Context context;
  14. private View container;
  15. /**
  16. * Constructor
  17. * @param context the context
  18. */
  19. public SimplePopupItem(Context context) {
  20. super(context);
  21. this.context = context;
  22. }
  23. @Override
  24. public int getLayoutId(){
  25. return R.layout.simple_popup_item;
  26. }
  27. @Override
  28. public void configureItemView(View view){
  29. TextView titleView = (TextView) view.findViewById(R.id.title_text_view);
  30. RadioButton cbox = (RadioButton) view.findViewById(R.id.isSelectedButton);
  31. titleView.setText(this.getTitle());
  32. if (this.isSelected()){
  33. cbox.setVisibility(View.VISIBLE);
  34. } else {
  35. cbox.setVisibility(View.INVISIBLE);
  36. }
  37. }
  38. /**
  39. * Set the selection state.
  40. * @param selected boolean
  41. */
  42. public void setSelected(boolean selected){
  43. this.selected = selected;
  44. if (this.getRootView() != null) this.configureItemView(this.getRootView());
  45. }
  46. /**
  47. * Return the background view.
  48. * @return view the background view
  49. */
  50. private View getContainer(){
  51. if(container == null){
  52. container = this.getRootView().findViewById(R.id.popup_item_container);
  53. }
  54. return container;
  55. }
  56. /**
  57. * Returns true if the item is selected, otherwise false.
  58. * @return boolean
  59. */
  60. public boolean isSelected(){
  61. return this.selected;
  62. }
  63. @Override
  64. public void onItemSelect(MotionEvent event){
  65. getContainer().setBackgroundColor(
  66. context.getResources().getColor(android.R.color.holo_blue_light));
  67. }
  68. @Override
  69. public void onItemDeselect(MotionEvent event){
  70. getContainer().setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
  71. }
  72. }