-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageLoader.java
47 lines (39 loc) · 1.21 KB
/
ImageLoader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.example.majisha.ebayshopping;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by Majisha on 4/20/2015.
*/
public class ImageLoader extends AsyncTask<Void, Void, Bitmap> {
private String imgURL;
private ImageView imgView;
public ImageLoader(String url, ImageView imgView){
this.imgURL = url;
this.imgView = imgView;
}
@Override
protected Bitmap doInBackground(Void... params) {
try {
URL urlConnection = new URL(imgURL);
HttpURLConnection connection = (HttpURLConnection) urlConnection.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream is = connection.getInputStream();
Bitmap imgBMP = BitmapFactory.decodeStream(is);
return imgBMP;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap bmp) {
super.onPostExecute(bmp);
imgView.setImageBitmap(bmp);
}
}