AbstractPopupItem.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package de.tudarmstadt.informatik.hostage.ui2.popup;
  2. import android.content.Context;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import java.util.HashMap;
  6. /**
  7. * Created by Julien on 13.02.14.
  8. */
  9. public abstract class AbstractPopupItem {
  10. private int itemId;
  11. private String title;
  12. private View itemView;
  13. private LayoutInflater lInf;
  14. public HashMap<Object, Object> data;
  15. abstract public int getLayoutId();
  16. abstract public void configureItemView(View view);
  17. public void setValue(String key, Object value){
  18. if (key != null && value != null){
  19. this.data.put(key, value);
  20. if (this.itemView != null) this.configureItemView(this.itemView);
  21. }
  22. }
  23. public void setMultipleData(HashMap<Object, Object> map){
  24. if (map != null){
  25. for(Object key : map.keySet()){
  26. this.data.put(key, map.get(key));
  27. }
  28. if (this.itemView != null) this.configureItemView(this.itemView);
  29. }
  30. }
  31. public void setTitle(String title){
  32. this.title = title;
  33. if (this.itemView != null) this.configureItemView(this.itemView);
  34. }
  35. public String getTitle(){
  36. return this.title;
  37. }
  38. public void setItemId(int id){
  39. this.itemId = id;
  40. if (this.itemView != null) this.configureItemView(this.itemView);
  41. }
  42. public int getItemId() {
  43. return this.itemId;
  44. }
  45. public AbstractPopupItem(Context context) {
  46. super();
  47. lInf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  48. this.data = new HashMap<Object, Object>();
  49. }
  50. public View getItemView(){
  51. if (this.itemView == null){
  52. this.itemView = lInf.inflate(this.getLayoutId(), null);
  53. }
  54. this.configureItemView(this.itemView);
  55. return this.itemView;
  56. }
  57. }