moonlightcheese

voodoo

Aug 18th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.69 KB | None | 0 0
  1.     class CustomExpandableListAdapter extends SimpleExpandableListAdapter {
  2.         Context mCtx;
  3.         LayoutInflater vi;
  4.         public List<List<Boolean>> checkData;
  5.         String[] mChildFrom;
  6.         int[] mChildTo;
  7.        
  8.         public CustomExpandableListAdapter(Context ctx, List<? extends Map<String, ?>> groupData, int groupLayout, String[] groupFrom, int[] groupTo, List<? extends List<? extends Map<String, ?>>>childData, int childLayout, String[] childFrom, int[] childTo, List<List<Boolean>> checkData) {
  9.             super(ctx, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo);
  10.             this.mCtx=ctx;
  11.             this.vi = (LayoutInflater)mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  12.             this.checkData = checkData;
  13.             this.mChildFrom = childFrom;
  14.             this.mChildTo = childTo;
  15.         }
  16.        
  17.         public boolean updateChecked(List<List<Boolean>> newData) {
  18.             checkData = newData;
  19.             return true;
  20.         }
  21.        
  22.         public boolean isChecked(int groupPosition, int childPosition) {
  23.             return checkData.get(groupPosition).get(childPosition);
  24.         }
  25.        
  26.         private void bindView(View view, Map<String, ?> data, String[] from, int[] to) {
  27.             int len = to.length;
  28.            
  29.             for (int i = 0; i < len; i++) {
  30.                 TextView v = (TextView)view.findViewById(to[i]);
  31.                 if (v != null) {
  32.                     v.setText((String)data.get(from[i]));
  33.                 }
  34.             }
  35.         }
  36.        
  37.         public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
  38.             View rowView;
  39.             rowView = new RelativeLayout(mCtx);
  40.             if(vi != null) {
  41.                 vi.inflate(R.layout.call_list_item, (RelativeLayout)rowView, true);
  42.             }
  43.            
  44.             if(this.checkData.get(groupPosition).get(childPosition)) {
  45.                 ((CheckedTextView)rowView.findViewById(R.id.checkmark)).setChecked(true);
  46.             } else {
  47.                 ((CheckedTextView)rowView.findViewById(R.id.checkmark)).setChecked(false);
  48.             }
  49.            
  50.             switch(mMode) {
  51.                 case MODE_PENDING:
  52.                     if(((TextView)rowView.findViewById(R.id.item_text_job))!=null){
  53.                         ((TextView)rowView.findViewById(R.id.item_text_job)).setVisibility(View.VISIBLE);
  54.                     }
  55.                     break;
  56.                 case MODE_BILLING:
  57.                     //rowView.forceLayout();
  58.                     break;
  59.                 default:
  60.                     break;
  61.             }
  62.            
  63.             //if the child is in the "Not Registered" group, display different fields
  64.             String display_name = null;
  65.            
  66.             if(groupData.get(groupPosition).containsValue("Not Registered")) {
  67.                 display_name = childData.get(groupPosition).get(childPosition).get("display_name");
  68.                
  69.                 if(display_name != null && !display_name.equals("")) {
  70.                     TextView displayNameView = ((TextView)rowView.findViewById(R.id.text_minutes_billed));
  71.                     RelativeLayout.LayoutParams displayNameParams = ((RelativeLayout.LayoutParams)(displayNameView.getLayoutParams()));
  72.                     displayNameParams.addRule(RelativeLayout.BELOW, R.id.item_hidden_number);
  73.                     displayNameView.setLayoutParams(displayNameParams);
  74.                     displayNameView.setText(display_name);
  75.                 }
  76.             }
  77.            
  78.             bindView(rowView, childData.get(groupPosition).get(childPosition), mChildFrom, mChildTo);
  79.             if(groupData.get(groupPosition).containsValue("Not Registered")) {
  80.                 if(display_name!=null && !display_name.equals("")) {
  81.                     ((TextView)rowView.findViewById(R.id.text_minutes_billed)).setText(display_name);
  82.                     ((TextView)rowView.findViewById(R.id.text_minutes_billed)).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
  83.                 } else {
  84.                     ((TextView)rowView.findViewById(R.id.text_minutes_billed)).setVisibility(View.GONE);
  85.                 }
  86.                 ((TextView)rowView.findViewById(R.id.item_text_duration_billed)).setVisibility(View.GONE);
  87.             }
  88.             //return super.getChildView(groupPosition, childPosition, isLastChild, rowView, parent);
  89.             return rowView;
  90.         }
  91.        
  92.         public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
  93.             RelativeLayout rowView;
  94.             if(convertView == null) {
  95.                 rowView = new RelativeLayout(mCtx);
  96.                 if(vi!=null){
  97.                     vi.inflate(R.layout.call_group_item, rowView, true);
  98.                 }
  99.             } else {
  100.                 rowView = (RelativeLayout)convertView;
  101.             }
  102.            
  103.             if(!(((TextView)rowView.findViewById(R.id.item_text_job)) == null) )
  104.             {
  105.                 ((TextView)rowView.findViewById(R.id.item_text_job)).setVisibility(View.GONE);
  106.             }
  107.            
  108.             switch(mMode) {
  109.                 case MODE_PENDING:
  110.                     break;
  111.                 case MODE_BILLING:
  112.                     if(((TextView)rowView.findViewById(R.id.item_text_job))!=null) {
  113.                         ((TextView)rowView.findViewById(R.id.item_text_job)).setVisibility(View.VISIBLE);
  114.                     }
  115.                     //rowView.forceLayout();
  116.                     break;
  117.                 default:
  118.                     break;
  119.             }
  120.            
  121.             //TODO: add code to resize the item when showing the job, as it is not done automagically.
  122.             //parent.forceLayout();
  123.            
  124.             return super.getGroupView(groupPosition, isExpanded, rowView, parent);
  125.         }
  126.     }
Add Comment
Please, Sign In to add comment