|
|
@ -4,8 +4,29 @@ import android.graphics.Bitmap; |
|
|
|
import android.graphics.BitmapFactory; |
|
|
|
import android.os.AsyncTask; |
|
|
|
import android.util.Log; |
|
|
|
import cz.msebera.android.httpclient.HttpEntity; |
|
|
|
import cz.msebera.android.httpclient.HttpResponse; |
|
|
|
import cz.msebera.android.httpclient.HttpVersion; |
|
|
|
import cz.msebera.android.httpclient.StatusLine; |
|
|
|
import cz.msebera.android.httpclient.client.HttpClient; |
|
|
|
import cz.msebera.android.httpclient.client.methods.HttpGet; |
|
|
|
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; |
|
|
|
import cz.msebera.android.httpclient.conn.ClientConnectionManager; |
|
|
|
import cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory; |
|
|
|
import cz.msebera.android.httpclient.conn.scheme.Scheme; |
|
|
|
import cz.msebera.android.httpclient.conn.scheme.SchemeRegistry; |
|
|
|
import cz.msebera.android.httpclient.conn.ssl.SSLSocketFactory; |
|
|
|
import cz.msebera.android.httpclient.impl.client.DefaultHttpClient; |
|
|
|
import cz.msebera.android.httpclient.impl.conn.tsccm.ThreadSafeClientConnManager; |
|
|
|
import cz.msebera.android.httpclient.params.BasicHttpParams; |
|
|
|
import cz.msebera.android.httpclient.params.HttpParams; |
|
|
|
import cz.msebera.android.httpclient.params.HttpProtocolParams; |
|
|
|
import cz.msebera.android.httpclient.protocol.HTTP; |
|
|
|
import cz.msebera.android.httpclient.util.EntityUtils; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.security.KeyStore; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
@ -17,20 +38,29 @@ public class ImageDownload extends AsyncTask<String, Void, Bitmap> { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected Bitmap doInBackground(String... URL) { |
|
|
|
try { |
|
|
|
String imageURL = URL[0]; |
|
|
|
HttpUriRequest request = new HttpGet(imageURL.toString()); |
|
|
|
HttpClient httpClient = MySSLSocketFactory.getNewHttpClient(); |
|
|
|
HttpResponse response = httpClient.execute(request); |
|
|
|
|
|
|
|
String imageURL = URL[0]; |
|
|
|
Log.d("[BOOKMARK]",imageURL); |
|
|
|
StatusLine statusLine = response.getStatusLine(); |
|
|
|
int statusCode = statusLine.getStatusCode(); |
|
|
|
if (statusCode == 200) { |
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
byte[] bytes = EntityUtils.toByteArray(entity); |
|
|
|
|
|
|
|
Bitmap bitmap = null; |
|
|
|
try { |
|
|
|
// Download Image from URL |
|
|
|
InputStream input = new java.net.URL(imageURL).openStream(); |
|
|
|
// Decode Bitmap |
|
|
|
bitmap = BitmapFactory.decodeStream(input); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, |
|
|
|
bytes.length); |
|
|
|
return bitmap; |
|
|
|
}else{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
Log.e("[ERROR]","Download failed because " + e.getMessage()); |
|
|
|
return null; |
|
|
|
} |
|
|
|
return bitmap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -42,4 +72,5 @@ public class ImageDownload extends AsyncTask<String, Void, Bitmap> { |
|
|
|
public void addListener(imageListener toAdd) { |
|
|
|
listeners.add(toAdd); |
|
|
|
} |
|
|
|
|
|
|
|
} |