Exemplo n.º 1
0
 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
   switch (getItemViewType(position)) {
     case ItemViewType_Contact:
       ((ContactHolder) holder).setBeans(beans.get(position), position);
       break;
     case ItemViewType_Division:
       ((DivisionHolder) holder).setBeans(beans.get(position));
       break;
   }
 }
Exemplo n.º 2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    ContactHolder holder = null;

    if (row == null) {
      LayoutInflater inflater = ((Activity) context).getLayoutInflater();
      row = inflater.inflate(layoutResourceId, parent, false);

      holder = new ContactHolder();
      holder.imgIcon = (ImageView) row.findViewById(R.id.ownImage);
      holder.txtName = (TextView) row.findViewById(R.id.ownNameTV);
      holder.txtDistance = (TextView) row.findViewById(R.id.currentPositionTV);
      holder.txtTimeStamp = (TextView) row.findViewById(R.id.lastUpdateTV);
      holder.orientation = (ImageView) row.findViewById(R.id.orientation);

      row.setTag(holder);
    } else {
      holder = (ContactHolder) row.getTag();
    }

    User user = data[position];

    // Location location = contact.getCurrentLocation();
    float compassHeading =
        getBearing(
            user.getCurrentPositionLatitude(),
            user.getCurrentPositionLongitude(),
            _myLocation.getLatitude(),
            _myLocation.getLongitude()); // Calculate bearing
    float distance =
        getDistance(
            user.getCurrentPositionLatitude(),
            user.getCurrentPositionLongitude(),
            _myLocation.getLatitude(),
            _myLocation.getLongitude()); // Calculate distance

    holder.txtName.setText(user.getName());
    holder.imgIcon.setImageResource(user.getIcon());

    holder.txtTimeStamp.setText(formatLastUpdate(user.getTimeStamp()));
    holder.txtDistance.setText(formatDistance(distance));
    holder.orientation.setImageDrawable(rotateDrawable(compassHeading));

    return row;
  }