AbstractPopupItem.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 itemView;
  14. private LayoutInflater lInf;
  15. public HashMap<Object, Object> data;
  16. abstract public int getLayoutId();
  17. abstract public void configureItemView(View view);
  18. public void setValue(String key, Object value){
  19. if (key != null && value != null){
  20. this.data.put(key, value);
  21. if (this.itemView != null) this.configureItemView(this.itemView);
  22. }
  23. }
  24. public void setMultipleData(HashMap<Object, Object> map){
  25. if (map != null){
  26. for(Object key : map.keySet()){
  27. this.data.put(key, map.get(key));
  28. }
  29. if (this.itemView != null) this.configureItemView(this.itemView);
  30. }
  31. }
  32. public void setTitle(String title){
  33. this.title = title;
  34. if (this.itemView != null) this.configureItemView(this.itemView);
  35. }
  36. public String getTitle(){
  37. return this.title;
  38. }
  39. public void setItemId(int id){
  40. this.itemId = id;
  41. if (this.itemView != null) this.configureItemView(this.itemView);
  42. }
  43. public int getItemId() {
  44. return this.itemId;
  45. }
  46. public AbstractPopupItem(Context context) {
  47. super();
  48. this.lInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  49. this.data = new HashMap<Object, Object>();
  50. }
  51. public View getItemView(){
  52. if (this.itemView == null){
  53. this.itemView = this.lInf.inflate(this.getLayoutId(), null);
  54. }
  55. this.configureItemView(this.itemView);
  56. return this.itemView;
  57. }
  58. public Object onClickedResult(MotionEvent event){
  59. return this;
  60. }
  61. public void onItemSelect(MotionEvent event){
  62. }
  63. public void onItemDeselect(MotionEvent event){
  64. }
  65. }