SplitPopupItem.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package de.tudarmstadt.informatik.hostage.ui.popup;
  2. import android.content.Context;
  3. import android.view.MotionEvent;
  4. import android.view.View;
  5. import android.widget.TextView;
  6. import de.tudarmstadt.informatik.hostage.R;
  7. /**
  8. * Created by Julien on 16.02.14.
  9. */
  10. public class SplitPopupItem extends AbstractPopupItem {
  11. public final static String LEFT_TITLE = "LEFT_TITLE";
  12. public final static String RIGHT_TITLE = "RIGHT_TITLE";
  13. public final static String LEFT_SUBTITLE = "LEFT_SUBTITLE";
  14. public final static String RIGHT_SUBTITLE = "RIGHT_SUBTITLE";
  15. public boolean wasRightTouch;
  16. private Context context;
  17. private View left_container;
  18. private View right_container;
  19. /**
  20. * Constructor
  21. *
  22. * @param Context context
  23. */
  24. public SplitPopupItem(Context context){
  25. super(context);
  26. this.context = context;
  27. }
  28. public int getLayoutId(){
  29. return R.layout.split_popup_item;
  30. }
  31. public void configureItemView(View view){
  32. String leftTitle = (String) this.data.get(LEFT_TITLE);
  33. String rightTitle = (String) this.data.get(RIGHT_TITLE);
  34. String leftSubtitle = (String) this.data.get(LEFT_SUBTITLE);
  35. String rightSubtitle = (String) this.data.get(RIGHT_SUBTITLE);
  36. TextView leftTitleView = (TextView)view.findViewById(R.id.left_title_text_view);
  37. leftTitleView.setText(leftTitle);
  38. TextView leftSubtitleView = (TextView)view.findViewById(R.id.left_subtitle_text_view);
  39. if (leftSubtitle != null){
  40. leftSubtitleView.setText(leftSubtitle);
  41. } else {
  42. leftSubtitleView.setText("-");
  43. }
  44. TextView rightTitleView = (TextView)view.findViewById(R.id.right_title_text_view);
  45. rightTitleView.setText(rightTitle);
  46. TextView rightSubtilteView = (TextView)view.findViewById(R.id.right_subtitle_text_view);
  47. if (rightSubtitle != null){
  48. rightSubtilteView.setText(rightSubtitle);
  49. } else {
  50. rightSubtilteView.setText("-");
  51. }
  52. }
  53. public Object onClickedResult(MotionEvent event){
  54. this.wasRightTouch = isRightTouch(event);
  55. return this;
  56. }
  57. /**
  58. * Returns true if the user touched the right side of the view.
  59. * @return boolean isRightTouch
  60. */
  61. private boolean isRightTouch(MotionEvent event){
  62. return event.getX() > this.getRootView().getX() + (this.getRootView().getWidth() / 2);
  63. }
  64. /**
  65. * Returns the left view.
  66. * @return View the left view
  67. */
  68. private View getLeftContainer(){
  69. if(left_container == null){
  70. left_container = this.getRootView().findViewById(R.id.popup_left_container);
  71. }
  72. return left_container;
  73. }
  74. /**
  75. * Returns the right view.
  76. * @return View the right view
  77. */
  78. private View getRightContainer(){
  79. if(right_container == null){
  80. right_container = this.getRootView().findViewById(R.id.popup_right_container);
  81. }
  82. return right_container;
  83. }
  84. public void onItemSelect(MotionEvent event){
  85. int blue_color = context.getResources().getColor(android.R.color.holo_blue_light);
  86. int trans_color = context.getResources().getColor(android.R.color.transparent);
  87. if(!isRightTouch(event)){
  88. getLeftContainer().setBackgroundColor(blue_color);
  89. getRightContainer().setBackgroundColor(trans_color);
  90. } else {
  91. getLeftContainer().setBackgroundColor(trans_color);
  92. getRightContainer().setBackgroundColor(blue_color);
  93. }
  94. }
  95. public void onItemDeselect(MotionEvent event){
  96. int trans_color = context.getResources().getColor(android.R.color.transparent);
  97. getLeftContainer().setBackgroundColor(trans_color);
  98. getRightContainer().setBackgroundColor(trans_color);
  99. }
  100. }