Android Open Source - VoxPopuli-Android Avatar Downloader






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.thread;
//from w  ww . j  a v a  2 s  .c  om
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import fr.kyriog.android.voxpopuli.entity.Player;
import fr.kyriog.android.voxpopuli.handler.AvatarHandler;

public class AvatarDownloader extends Thread {
  private final AvatarHandler handler;
  private final Player player;

  public AvatarDownloader(AvatarHandler handler, Player player) {
    this.handler = handler;
    this.player = player;
  }

  @Override
  public void run() {
    if(player.getAvatarBitmap() == null) {
      HttpClient httpClient = new DefaultHttpClient();
      HttpGet httpGet = new HttpGet();
      try {
        URI uri = new URI(player.getAvatarUrl());
        httpGet.setURI(uri);
        httpGet.addHeader("Accept-Encoding", "gzip");
        HttpResponse response = httpClient.execute(httpGet);
        InputStream is = response.getEntity().getContent();
        Bitmap bitmap = BitmapFactory.decodeStream(is);
        if(bitmap != null) {
          player.setAvatarBitmap(bitmap);
          handler.sendEmptyMessage(0);
        }
      } catch (URISyntaxException e) {
        e.printStackTrace();
      } catch (ClientProtocolException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

}




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