Android Open Source - Fabby-Chat U R L Drawable Producer






From Project

Back to project page Fabby-Chat.

License

The source code is released under:

MIT License

If you think the Android project Fabby-Chat 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.fabbychat.utils;
/*from  w ww  . j a  va  2s  .c o m*/
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;

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

import android.graphics.drawable.Drawable;
import android.util.Log;

public class URLDrawableProducer implements DrawableProducer {
  
  private final static String TAG = URLDrawableProducer.class.getName();
  
  private String mUrl;
  
  public URLDrawableProducer(String url) {
    mUrl = url;
  }

  @Override
  public Drawable getDrawable() {
      try {
        InputStream is = fetchURL(mUrl);
        Drawable drawable = Drawable.createFromStream(is, "src");
        Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " 
            + drawable.getBounds() + ", "
            + drawable.getIntrinsicHeight() + "," 
            + drawable.getIntrinsicWidth() + ", "
            + drawable.getMinimumHeight() + "," 
            + drawable.getMinimumWidth());
        return drawable;
      } catch (MalformedURLException e) {
        Log.e(TAG, "fetchDrawable failed", e);
        return null;
      } catch (IOException e) {
        Log.e(TAG, "fetchDrawable failed", e);
        return null;
      }
  }
  
    private InputStream 
    fetchURL(String urlString) throws MalformedURLException, IOException {
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpGet request = new HttpGet(urlString);
      HttpResponse response = httpClient.execute(request);
      return response.getEntity().getContent();
    }

  @Override
  public String getKey() {
    return this.getClass().getName() + ":" + mUrl;
  }

}




Java Source Code List

com.fabbychat.Application.java
com.fabbychat.ChatDialog.java
com.fabbychat.ChatDialogs.java
com.fabbychat.Contacts.java
com.fabbychat.FbAvatarProducer.java
com.fabbychat.FbChatConnection.java
com.fabbychat.FbChatService.java
com.fabbychat.Login.java
com.fabbychat.adapters.ChatContentAdapter.java
com.fabbychat.adapters.FbContactAdapter.java
com.fabbychat.models.FbContact.java
com.fabbychat.sasl.SASLFacebookMechanism.java
com.fabbychat.utils.DrawableManager.java
com.fabbychat.utils.DrawableProducer.java
com.fabbychat.utils.URLDrawableProducer.java