Skip to content

Instantly share code, notes, and snippets.

@AraujoJordan
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AraujoJordan/8602699d887936b42ffe to your computer and use it in GitHub Desktop.
Save AraujoJordan/8602699d887936b42ffe to your computer and use it in GitHub Desktop.
LoadProfileImage.java
/**
* Get the user profile picture from Google Plus account
*
* USAGE: new LoadProfileImage(imageView).execute(urlToTheImage);
*/
private class LoadProfileImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
//CONSTRUCTOR
public LoadProfileImage(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
urldisplay = urldisplay.split("sz=50")[0] + "sz=500"; //get 500x500 user picture (50x50 is too small)
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment