Android Open Source - VoxPopuli-Android Player Adapter






From Project

Back to project page VoxPopuli-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project VoxPopuli-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.kyriog.android.voxpopuli.adapter;
/*  w  ww  .  j a  v  a2  s.co m*/
import java.util.List;

import fr.kyriog.android.voxpopuli.R;
import fr.kyriog.android.voxpopuli.entity.Player;
import fr.kyriog.android.voxpopuli.handler.AvatarHandler;
import fr.kyriog.android.voxpopuli.thread.AvatarDownloader;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PlayerAdapter extends BaseAdapter {
  protected final Activity activity;
  private final List<Player> players;

  public PlayerAdapter(Activity activity, List<Player> players) {
    this.activity = activity;
    this.players = players;
  }

  @Override
  public int getCount() {
    return players.size();
  }

  @Override
  public Player getItem(int position) {
    return players.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null)
      convertView = activity.getLayoutInflater().inflate(R.layout.game_waiting_player, null);

    Player player = getItem(position);

    TextView username = (TextView) convertView.findViewById(R.id.game_waiting_player_username);
    username.setText(player.getUsername());

    ImageView avatar = (ImageView) convertView.findViewById(R.id.game_waiting_player_image);
    if(player.getAvatarBitmap() == null) {
      avatar.setImageResource(R.drawable.default_avatar);
      AvatarDownloader downloader = new AvatarDownloader(new AvatarHandler(this), player);
      downloader.start();
    } else
      avatar.setImageBitmap(player.getAvatarBitmap());

    return convertView;
  }
}




Java Source Code List

fr.kyriog.android.voxpopuli.GameActivity.java
fr.kyriog.android.voxpopuli.HomeActivity.java
fr.kyriog.android.voxpopuli.LoginActivity.java
fr.kyriog.android.voxpopuli.adapter.HomeAdapter.java
fr.kyriog.android.voxpopuli.adapter.PlayerAdapter.java
fr.kyriog.android.voxpopuli.adapter.ResultPlayerAdapter.java
fr.kyriog.android.voxpopuli.adapter.VotedPlayerAdapter.java
fr.kyriog.android.voxpopuli.entity.Game.java
fr.kyriog.android.voxpopuli.entity.Player.java
fr.kyriog.android.voxpopuli.entity.Question.java
fr.kyriog.android.voxpopuli.handler.AvatarHandler.java
fr.kyriog.android.voxpopuli.handler.GameHandler.java
fr.kyriog.android.voxpopuli.handler.HomeHandler.java
fr.kyriog.android.voxpopuli.socketio.BaseCallback.java
fr.kyriog.android.voxpopuli.socketio.GameCallback.java
fr.kyriog.android.voxpopuli.socketio.HomeCallback.java
fr.kyriog.android.voxpopuli.thread.AvatarDownloader.java