[android-developers] Re: load image from the web?
To make loading images from the web less of a pain, I created a little helper class To load an image you simply call ImageLoader.getInstance().load(myImageView, myimage.jpg, true); http://wu-media.com/2009/06/android-imageloader-load-images-sequencially-in-the-background/ 1. It loads images sequentially 2. It has the ability to cache the loaded images 3. you can stop the downloads by calling clearQueue() (it doesn't stop the current downloads, just the ones to follow) 4. you can clear the cache by calling clearCache() I hope somebody finds this useful, or if you have any suggestion on how i can make it better, leave me a comment :) On May 25, 1:04 am, schwiz sch...@gmail.com wrote: Can anyone show me documentation or give me a quick web sample of how to display animagefrom the web. I read up on the drawables section in the android reference, but I either missed it, or its covered in another section. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
Ok so I am using a placeholder Imageview that I have set up in a layout, but how do I access it. The function Nithin showedi1 = (ImageView) findViewById(R.id.i1); doesn't seem to be in the latest api. On May 25, 5:11 am, Mark Murphy mmur...@commonsware.com wrote: Bear in mind that the code shown below runs on the UI thread. This means the UI thread is blocked until the HTTP request returns. If the HTTP request has a problem (e.g., the server is not responding), it could very easily take beyond the ~5 seconds allowed before an application-not-responding (ANR) error occurs and your activity is forcibly closed. I heartily encourage you to use a placeholder image when launching your UI and have the real image downloaded off the Web in the background. AsyncTask should work very well for this case -- you can download and decode the image in doInBackground() and apply it to the ImageView in onPostExecute(). Nithin Varamballi wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); } } public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Training:http://commonsware.com/training.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
Im making a widget if that makes a difference... On May 26, 4:55 pm, schwiz sch...@gmail.com wrote: Ok so I am using a placeholder Imageview that I have set up in a layout, but how do I access it. The function Nithin showed i1 = (ImageView) findViewById(R.id.i1); doesn't seem to be in the latest api. On May 25, 5:11 am, Mark Murphy mmur...@commonsware.com wrote: Bear in mind that the code shown below runs on the UI thread. This means the UI thread is blocked until the HTTP request returns. If the HTTP request has a problem (e.g., the server is not responding), it could very easily take beyond the ~5 seconds allowed before an application-not-responding (ANR) error occurs and your activity is forcibly closed. I heartily encourage you to use a placeholder image when launching your UI and have the real image downloaded off the Web in the background. AsyncTask should work very well for this case -- you can download and decode the image in doInBackground() and apply it to the ImageView in onPostExecute(). Nithin Varamballi wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); } } public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Training:http://commonsware.com/training.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
I am using a placeholder image, but I can't access it the way Nithin showed. I am including android.app.* but findImageById doesn't seem to be in the api anymore. Can it only be used in a particular function? How can I access an imageview otherwise? On May 25, 5:11 am, Mark Murphy mmur...@commonsware.com wrote: Bear in mind that the code shown below runs on the UI thread. This means the UI thread is blocked until the HTTP request returns. If the HTTP request has a problem (e.g., the server is not responding), it could very easily take beyond the ~5 seconds allowed before an application-not-responding (ANR) error occurs and your activity is forcibly closed. I heartily encourage you to use a placeholder image when launching your UI and have the real image downloaded off the Web in the background. AsyncTask should work very well for this case -- you can download and decode the image in doInBackground() and apply it to the ImageView in onPostExecute(). Nithin Varamballi wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); } } public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Training:http://commonsware.com/training.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
Ok I found it by saying Dialog.this.findViewById but I am getting an error message saying 'No enclosing instance of the type Dialog is accessible in scope' how do I access my ImageViews from a widget? On May 26, 5:26 pm, schwiz sch...@gmail.com wrote: I am using a placeholder image, but I can't access it the way Nithin showed. I am including android.app.* but findImageById doesn't seem to be in the api anymore. Can it only be used in a particular function? How can I access an imageview otherwise? On May 25, 5:11 am, Mark Murphy mmur...@commonsware.com wrote: Bear in mind that the code shown below runs on the UI thread. This means the UI thread is blocked until the HTTP request returns. If the HTTP request has a problem (e.g., the server is not responding), it could very easily take beyond the ~5 seconds allowed before an application-not-responding (ANR) error occurs and your activity is forcibly closed. I heartily encourage you to use a placeholder image when launching your UI and have the real image downloaded off the Web in the background. AsyncTask should work very well for this case -- you can download and decode the image in doInBackground() and apply it to the ImageView in onPostExecute(). Nithin Varamballi wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); } } public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Training:http://commonsware.com/training.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1= (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); } } public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
Hi nithin Thanks... Its works for me Thank You Rock --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
cool looks pretty straight forward, thanks for the quick reply this will be a big help! On May 25, 1:32 am, Nithin Varamballi nithi...@gmail.com wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); }} public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
Bear in mind that the code shown below runs on the UI thread. This means the UI thread is blocked until the HTTP request returns. If the HTTP request has a problem (e.g., the server is not responding), it could very easily take beyond the ~5 seconds allowed before an application-not-responding (ANR) error occurs and your activity is forcibly closed. I heartily encourage you to use a placeholder image when launching your UI and have the real image downloaded off the Web in the background. AsyncTask should work very well for this case -- you can download and decode the image in doInBackground() and apply it to the ImageView in onPostExecute(). Nithin Varamballi wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1= (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); } } public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android App Developer Training: http://commonsware.com/training.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
In addition to Mark's suggestion, I would encourage you to use httpclient apis, instead of direct urlconnection. On May 25, 3:11 am, Mark Murphy mmur...@commonsware.com wrote: Bear in mind that the code shown below runs on the UI thread. This means the UI thread is blocked until the HTTP request returns. If the HTTP request has a problem (e.g., the server is not responding), it could very easily take beyond the ~5 seconds allowed before an application-not-responding (ANR) error occurs and your activity is forcibly closed. I heartily encourage you to use a placeholder image when launching your UI and have the real image downloaded off the Web in the background. AsyncTask should work very well for this case -- you can download and decode the image in doInBackground() and apply it to the ImageView in onPostExecute(). Nithin Varamballi wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); } } public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Training:http://commonsware.com/training.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: load image from the web?
cool thanks a lot 2009/5/25 schwiz sch...@gmail.com cool looks pretty straight forward, thanks for the quick reply this will be a big help! On May 25, 1:32 am, Nithin Varamballi nithi...@gmail.com wrote: hi... I did like this.. This may help you public class demo extends Activity { /** Called when the activity is first created. */ ImageView i1; public int position=0; private String[] myRemoteImages = { http://www.cssnz.org/flower.jpg}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1= (Button) findViewById(R.id.clear); i1 =(ImageView) findViewById(R.id.i1); load(); }} public void load() { try { URL aURL = new URL(myRemoteImages[i]); URLConnection con = aURL.openConnection(); con.connect(); InputStream is = con.getInputStream(); /* Buffered is always good for a performance plus. */ BufferedInputStream bis = new BufferedInputStream(is); /* Decode url-data to a bitmap. */ Bitmap bm = BitmapFactory.decodeStream(bis); i1.setImageBitmap(bm)); bis.close(); is.close(); /* Apply the Bitmap to the ImageView that will be returned. */ } catch (IOException e) { Log.e(DEBUGTAG, Remtoe Image Exception, e); } } Thank You Nithin N V --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---