Back to project page Alkomer.
The source code is released under:
MIT License
If you think the Android project Alkomer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package cz.jmx.tomik.alkomer.android.threads; //from w ww . j a v a 2 s.c om import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.util.Log; import android.widget.ImageView; import android.widget.Toast; /** * Alkomer - Server App * -------------------- * Downloads Image and Displays it (ASyncTask) * * @copyright Copyright (c) 2011 Tomas Vitek * @author Tomas Vitek ~ http://tomik.jmx.cz * @package Alkomer * @version 1.0 */ public class ImageDownloadAsyncTask extends AsyncTask<String, Void, Bitmap> { protected Activity screen; protected ImageView placer; public ImageDownloadAsyncTask(Activity screen, ImageView placer) { this.placer = placer; this.screen = screen; } protected void onPostExecute(Bitmap image) { placer.clearAnimation(); placer.setImageBitmap(image); if (image == null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(screen); if (!prefs.getBoolean("chartErrorShown", false)) { Toast.makeText(screen, "P?i na??t?n? graf? nastala chyba! Zkontrolujte, zda m?te funk?n? p?ipojen? k internetu. \n\nPokud chyba p?etrv?v?, zkuste to pros?m pozd?ji.", Toast.LENGTH_SHORT).show(); Editor editor = prefs.edit(); editor.putBoolean("chartErrorShown", true); editor.commit(); } } } @Override protected Bitmap doInBackground(String... arg0) { String url = arg0[0]; Log.d("Downloading IMAGE", url); URL myFileUrl = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { Log.e("ImageDownload Error", e.getMessage()); } try { HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); return BitmapFactory.decodeStream(is); } catch (IOException e) { Log.e("ImageDownload Error", e.getMessage()); } return null; } }