AbstractPopupItem.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package de.tudarmstadt.informatik.hostage.ui2.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 the root view
  25. */
  26. abstract public void configureItemView(View view);
  27. /**
  28. * Set different types of data. Calls {@link #configureItemView(android.view.View)}
  29. * @param key String
  30. * @param value Object
  31. */
  32. public void setValue(String key, Object value){
  33. if (key != null && value != null){
  34. this.data.put(key, value);
  35. if (this.rootView != null) this.configureItemView(this.rootView);
  36. }
  37. }
  38. /**
  39. * Add other data to the item.
  40. * @param map HashMap<Object, Object> optional data.
  41. */
  42. public void setMultipleData(HashMap<Object, Object> map){
  43. if (map != null){
  44. for(Object key : map.keySet()){
  45. this.data.put(key, map.get(key));
  46. }
  47. if (this.rootView != null) this.configureItemView(this.rootView);
  48. }
  49. }
  50. public void setTitle(String title){
  51. this.title = title;
  52. if (this.rootView != null) this.configureItemView(this.rootView);
  53. }
  54. public String getTitle(){
  55. return this.title;
  56. }
  57. /**
  58. * Set a specific item ID to identify it.
  59. * @param id int
  60. */
  61. public void setItemId(int id){
  62. this.itemId = id;
  63. if (this.rootView != null) this.configureItemView(this.rootView);
  64. }
  65. /**
  66. * Returns the item ID.
  67. * @return int ID
  68. */
  69. public int getItemId() {
  70. return this.itemId;
  71. }
  72. /**
  73. * Constructor
  74. * @param context Context
  75. */
  76. public AbstractPopupItem(Context context) {
  77. super();
  78. this.lInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  79. this.data = new HashMap<Object, Object>();
  80. }
  81. /**
  82. * Returns the rootview.
  83. * This method calls everytime the ConfigureItemView methode.
  84. * @return View rootview
  85. */
  86. public View getRootView(){
  87. if (this.rootView == null){
  88. this.rootView = this.lInf.inflate(this.getLayoutId(), null);
  89. }
  90. this.configureItemView(this.rootView);
  91. return this.rootView;
  92. }
  93. /**
  94. * The method is called if the user clicks the rootview.
  95. * @param event MotionEvent
  96. * @return Object object
  97. */
  98. public Object onClickedResult(MotionEvent event){
  99. return this;
  100. }
  101. /**
  102. * Will be called if the user selected the view.
  103. * @param event MotionEvent
  104. */
  105. public void onItemSelect(MotionEvent event){
  106. }
  107. /**
  108. * Will be called if the user deselects the view.
  109. * @param event MotionEvent
  110. */
  111. public void onItemDeselect(MotionEvent event){
  112. }
  113. }