Beispiel #1
0
 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
   final TreeNode item = getItem(position);
   int itemViewType = getItemViewType(position);
   View convertView = holder.itemView;
   convertView.setTag(position);
   if (type == RosterHelper.ACTIVE_CONTACTS) {
     RosterItemView rosterItemView = (RosterItemView) holder.itemView;
     rosterItemView.setNull();
     if (item != null) {
       if (itemViewType == ITEM_LAYER) {
         rosterItemView.addLayer(item.getText());
       }
       if (itemViewType == ITEM_CONTACT) {
         Contact contact = (Contact) item;
         populateFromContact(
             rosterItemView, RosterHelper.getInstance(), contact.getProtocol(), contact);
       }
       setShowDivider(rosterItemView, getItemViewType(position + 1) == ITEM_CONTACT);
     }
     rosterItemView.repaint();
   } else {
     if (itemViewType == ITEM_PROTOCOL) {
       RosterItemView rosterItemView = (RosterItemView) ((ViewGroup) convertView).getChildAt(0);
       ProgressBar progressBar = (ProgressBar) ((ViewGroup) convertView).getChildAt(1);
       MyImageButton imageButton = (MyImageButton) ((ViewGroup) convertView).getChildAt(2);
       rosterItemView.setNull();
       if (item != null) {
         progressBar.setVisibility(
             ((ProtocolBranch) item).getProtocol().getConnectingProgress() != 100
                 ? View.VISIBLE
                 : View.GONE);
         imageButton.setTag(item);
         imageButton.setOnClickListener(this);
         populateFromProtocol(rosterItemView, (ProtocolBranch) item);
         setShowDivider(rosterItemView, true);
       }
       rosterItemView.repaint();
     } else if (itemViewType == ITEM_GROUP) {
       RosterItemView rosterItemView = (RosterItemView) convertView;
       rosterItemView.setNull();
       if (item != null) {
         populateFromGroup(rosterItemView, (Group) item);
         setShowDivider(rosterItemView, true);
       }
       rosterItemView.repaint();
     } else if (itemViewType == ITEM_CONTACT) {
       RosterItemView rosterItemView = (RosterItemView) convertView;
       rosterItemView.setNull();
       if (item != null) {
         Contact contact = (Contact) item;
         populateFromContact(
             rosterItemView, RosterHelper.getInstance(), contact.getProtocol(), contact);
         setShowDivider(rosterItemView, true);
       }
       rosterItemView.repaint();
     }
   }
 }
Beispiel #2
0
 @Override
 public ViewHolder onCreateViewHolder(ViewGroup parent, int itemViewType) {
   View convertView = null;
   Context context = parent.getContext();
   if (type == RosterHelper.ACTIVE_CONTACTS) {
     convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext());
   }
   if (itemViewType == ITEM_PROTOCOL) {
     convertView = new LinearLayout(context);
     RosterItemView rosterItemView = new RosterItemView(context);
     MyImageButton imageButton = new MyImageButton(context);
     ProgressBar progressBar =
         new ProgressBar(context, null, android.R.attr.progressBarStyleInverse);
     LinearLayout.LayoutParams progressLinearLayout =
         new LinearLayout.LayoutParams(
             ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
     progressLinearLayout.gravity = Gravity.RIGHT;
     progressBar.setLayoutParams(progressLinearLayout);
     progressBar.setMax(100);
     LinearLayout.LayoutParams buttonLinearLayout =
         new LinearLayout.LayoutParams(
             ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
     buttonLinearLayout.gravity = Gravity.RIGHT;
     imageButton.setLayoutParams(buttonLinearLayout);
     LinearLayout.LayoutParams rosterLinearLayout =
         new LinearLayout.LayoutParams(
             LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
     rosterLinearLayout.gravity = Gravity.LEFT;
     rosterLinearLayout.weight = 1;
     convertView.setBackgroundColor(Scheme.getColor(R.attr.item_selected));
     rosterItemView.setLayoutParams(rosterLinearLayout);
     imageButton.setImageDrawable(SawimResources.MENU_ICON);
     ((ViewGroup) convertView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
     ((ViewGroup) convertView).addView(rosterItemView);
     ((ViewGroup) convertView).addView(progressBar);
     ((ViewGroup) convertView).addView(imageButton);
   }
   if (itemViewType == ITEM_GROUP) {
     convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext());
   }
   if (itemViewType == ITEM_CONTACT) {
     convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext());
   }
   return new ViewHolder(convertView);
 }