Android Open Source - cnBeta Avatar List Service






From Project

Back to project page cnBeta.

License

The source code is released under:

Apache License

If you think the Android project cnBeta 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 com.guest.cnbeta.service;
//from   w  ww .j a va  2  s .co m
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.content.Context;

import com.guest.cnbeta.module.Article;
import com.guest.cnbeta.util.T;

public class AvatarListService {

  public AvatarListService(Context context) {
  }

  public String getAvatarImg(Article article) {

    String imgString = "cb.gif";
    imgString = article.getAvatar();
    imgString = imgString.replace("\"", "");
    imgString = imgString.replace(" ", "%20");

    downloadAvatar(imgString);
    
    T.d(imgString);

    return imgString;

  }

  public static void downloadAvatar(String avatarImgString) {
    try {

      File file = new File("/sdcard/.cnBeta/" + avatarImgString + ".gif");
      if (!file.exists()) {
        URL url = new URL("http://img.cnbeta.com/topics/"
            + avatarImgString);
        HttpURLConnection conn = (HttpURLConnection) url
            .openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();
        FileOutputStream fos = new FileOutputStream(file);
        byte buf[] = new byte[128];
        do {
          int numread = is.read(buf);
          if (numread <= 0) {
            break;
          }
          fos.write(buf, 0, numread);
        } while (true);
        is.close();
      }
    } catch (NullPointerException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}




Java Source Code List

.ArticleActivity.java
.ArticleListService.java
.ArticleService.java
.Article.java
.CommentActivity.java
.CommentService.java
.Comment.java
.LoadSourceInterface.java
.LoadSource.java
.MainActivity.java
.PostCommentActivity.java
.Util.java
com.guest.cnbeta.FirstActivity.java
com.guest.cnbeta.SettingsActivity.java
com.guest.cnbeta.database.ArticleDB.java
com.guest.cnbeta.database.BaseDBHelper.java
com.guest.cnbeta.database.BaseDB.java
com.guest.cnbeta.loadsource.BaseLoadSource.java
com.guest.cnbeta.module.Avatar.java
com.guest.cnbeta.service.AvatarListService.java
com.guest.cnbeta.service.BaseService.java
com.guest.cnbeta.util.BaseApplication.java
com.guest.cnbeta.util.DataEngine.java
com.guest.cnbeta.util.FlingGallery.java
com.guest.cnbeta.util.NetworkStatusReceiver.java
com.guest.cnbeta.util.PullToRefreshListView.java
com.guest.cnbeta.util.ScaleAnimationHelper.java
com.guest.cnbeta.util.T.java