AbstractPopupItem.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package de.tudarmstadt.informatik.hostage.ui.popup;
  2. import android.content.Context;
  3. import android.view.LayoutInflater;
  4. import android.view.MotionEvent;
  5. import android.view.View;
  6. import java.util.HashMap;
  7. /**
  8. * Created by Julien on 13.02.14.
  9. */
  10. public abstract class AbstractPopupItem {
  11. private int itemId;
  12. private String title;
  13. private View rootView;
  14. private LayoutInflater lInf;
  15. public HashMap<Object, Object> data;
  16. /**
  17. * Override to return the layout id.
  18. * @return int layoutID
  19. */
  20. abstract public int getLayoutId();
  21. /**
  22. * Override to do additional stuff with the rootview.
  23. *
  24. * @param View rootview
  25. */
  26. abstract public void configureItemView(View view);
  27. public void setValue(String key, Object value){
  28. if (key != null && value != null){
  29. this.data.put(key, value);
  30. if (this.rootView != null) this.configureItemView(this.rootView);
  31. }
  32. }
  33. /**
  34. * Add other data to the item.
  35. * @param HashMap<Object, Object> data
  36. */
  37. public void setMultipleData(HashMap<Object, Object> map){
  38. if (map != null){
  39. for(Object key : map.keySet()){
  40. this.data.put(key, map.get(key));
  41. }
  42. if (this.rootView != null) this.configureItemView(this.rootView);
  43. }
  44. }
  45. public void setTitle(String title){
  46. this.title = title;
  47. if (this.rootView != null) this.configureItemView(this.rootView);
  48. }
  49. public String getTitle(){
  50. return this.title;
  51. }
  52. /**
  53. * Set a specific item ID to identify it.
  54. * @param int id
  55. */
  56. public void setItemId(int id){
  57. this.itemId = id;
  58. if (this.rootView != null) this.configureItemView(this.rootView);
  59. }
  60. /**
  61. * Returns the item ID.
  62. * @return int ID
  63. */
  64. public int getItemId() {
  65. return this.itemId;
  66. }
  67. /**
  68. * Constructor
  69. * @param Context context
  70. */
  71. public AbstractPopupItem(Context context) {
  72. super();
  73. this.lInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  74. this.data = new HashMap<Object, Object>();
  75. }
  76. /**
  77. * Returns the rootview.
  78. * This method calls everytime the ConfigureItemView methode.
  79. * @return View rootview
  80. */
  81. public View getRootView(){
  82. if (this.rootView == null){
  83. this.rootView = this.lInf.inflate(this.getLayoutId(), null);
  84. }
  85. this.configureItemView(this.rootView);
  86. return this.rootView;
  87. }
  88. /**
  89. * The method is called if the user clicks the rootview.
  90. * @param MotionEvent event
  91. * @return Object object
  92. */
  93. public Object onClickedResult(MotionEvent event){
  94. return this;
  95. }
  96. /**
  97. * Will be called if the user selected the view.
  98. * @param MotionEvent event
  99. */
  100. public void onItemSelect(MotionEvent event){
  101. }
  102. /**
  103. * Will be called if the user deselects the view.
  104. * @param MotionEvent event
  105. */
  106. public void onItemDeselect(MotionEvent event){
  107. }
  108. }