hello friends want display slideshow in view pager universal image loader set below code that
public class viewpageradapter extends pageradapter { layoutinflater inflater; arraylist<imagedata> mlist; activity mactivity; public viewpageradapter(activitygallery fragmentviewgallery, arraylist<imagedata> marraylistimagedatas) { // todo auto-generated constructor stub mactivity = fragmentviewgallery; mlist=marraylistimagedatas; } @override public int getcount() { return mlist.size(); } @override public boolean isviewfromobject(view view, object object) { return view == ((imageview) object); } @override public void destroyitem(viewgroup container, int position, object object) { ((viewpager) container).removeview((imageview) object); } @override public object instantiateitem(viewgroup container, final int position) { int loader = r.drawable.no_homes; imageview imageview = new imageview(mactivity); imageloader imgloader = new imageloader(mactivity); imgloader.displayimage( tag.webapiimagelink + mlist.get(position).getimage(), loader, imageview); ((viewpager) container).addview(imageview, 0); return imageview; } } imageloader.java
public class imageloader { memorycache memorycache=new memorycache(); filecache filecache; context mcontext; private map<imageview, string> imageviews=collections.synchronizedmap(new weakhashmap<imageview, string>()); executorservice executorservice; public imageloader(context context){ filecache=new filecache(context); mcontext=context; executorservice=executors.newfixedthreadpool(5); } int stub_id = r.drawable.ic_launcher; public void displayimage(string url, int loader, imageview imageview) { stub_id = loader; imageviews.put(imageview, url); bitmap bitmap=memorycache.get(url); if(bitmap!=null) imageview.setimagebitmap(bitmap); else { queuephoto(url, imageview); imageview.setimageresource(loader); } } private void queuephoto(string url, imageview imageview) { phototoload p=new phototoload(url, imageview); executorservice.submit(new photosloader(p)); } private bitmap getbitmap(string url) { file f=filecache.getfile(url); //from sd cache bitmap b = decodefile(f); if(b!=null) return b; //from web try { bitmap bitmap=null; url imageurl = new url(url); httpurlconnection conn = (httpurlconnection)imageurl.openconnection(); conn.setconnecttimeout(30000); conn.setreadtimeout(30000); conn.setinstancefollowredirects(true); inputstream is=conn.getinputstream(); outputstream os = new fileoutputstream(f); utils.copystream(is, os); os.close(); bitmap = decodefile(f); return bitmap; } catch (exception ex){ ex.printstacktrace(); return null; } } //decodes image , scales reduce memory consumption private bitmap decodefile(file f){ try { //decode image size bitmapfactory.options o = new bitmapfactory.options(); o.injustdecodebounds = true; bitmapfactory.decodestream(new fileinputstream(f),null,o); int required_size=1000; int width_tmp=o.outwidth, height_tmp=o.outheight; int scale=1; while(true){ if(width_tmp/2<required_size || height_tmp/2<required_size) break; width_tmp/=2; height_tmp/=2; scale*=2; } bitmapfactory.options o2 = new bitmapfactory.options(); o2.insamplesize=scale; return bitmapfactory.decodestream(new fileinputstream(f), null, o2); } catch (filenotfoundexception e) {} return null; } //task queue private class phototoload { public string url; public imageview imageview; public phototoload(string u, imageview i){ url=u; imageview=i; } } class photosloader implements runnable { phototoload phototoload; photosloader(phototoload phototoload){ this.phototoload=phototoload; } @override public void run() { if(imageviewreused(phototoload)) return; bitmap bmp=getbitmap(phototoload.url); memorycache.put(phototoload.url, bmp); if(imageviewreused(phototoload)) return; bitmapdisplayer bd=new bitmapdisplayer(bmp, phototoload); activity a=(activity)phototoload.imageview.getcontext(); a.runonuithread(bd); } } public bitmap roundcornerimage(bitmap src, float round) { // source image size int width = src.getwidth(); int height = src.getheight(); // create result bitmap output bitmap result = bitmap.createbitmap(width, height, config.argb_8888); // set canvas painting canvas canvas = new canvas(result); canvas.drawargb(0, 0, 0, 0); // configure paint final paint paint = new paint(); paint.setantialias(true); paint.setcolor(color.black); // configure rectangle embedding final rect rect = new rect(0, 0, width, height); final rectf rectf = new rectf(rect); // draw round rectangle canvas canvas.drawroundrect(rectf, round, round, paint); // create xfer mode paint.setxfermode(new porterduffxfermode(mode.src_in)); // draw source image canvas canvas.drawbitmap(src, rect, rect, paint); // return final image return result; } boolean imageviewreused(phototoload phototoload){ string tag=imageviews.get(phototoload.imageview); if(tag==null || !tag.equals(phototoload.url)) return true; return false; } //used display bitmap in ui thread class bitmapdisplayer implements runnable { bitmap bitmap; phototoload phototoload; public bitmapdisplayer(bitmap b, phototoload p){bitmap=b;phototoload=p;} public void run() { if(imageviewreused(phototoload)) return; if(bitmap!=null) phototoload.imageview.setimagebitmap(bitmap); else phototoload.imageview.setimageresource(stub_id); } } public void clearcache() { memorycache.clear(); filecache.clear(); } } pagerlayout.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /> </relativelayout> when run above code high defination image url display below 
this image size 1600x1000 when run in device getting small want full screen in mobile idea how can solve problem ? suggestion appreciable.
Comments
Post a Comment