Simpandroidfarme is a fast-growing brain-burning framework for Android's rapid development that aims to be modular
Commonly used controls, easy for beginners to learn and use. We also welcome the veteran to enrich the project: Project address
The boot page is a very common feature of our app development, but it's usually the first one to run, and every project you write
It's so annoying to write so many repetitive codes for this one-time thing.
There's no need to worry about this anymore!
General boot There are two kinds of picture source, local picture/network picture
How to use the target:
Use the image ID provided locally
Parameter one: Viewpager
Parameter two: Picture URL collection (use local to pass null)
Parameter three: Collection of picture IDs (null if using URLs)
Parameter four: the page to jump to when the boot is complete
New Leaderpager (second.this). Leaderpageradapter (Viewpager, NULL, Imgid, mainactivity.class);
Does it look easy to use? ~!!
On the code:
Leaderpager:
Packagecom.wbnq.simpleandroidframe.plugs;Importandroid.app.Activity;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.graphics.Bitmap;ImportAndroid.support.v4.view.PagerAdapter;ImportAndroid.support.v4.view.ViewPager;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.ImageView;Importjava.util.ArrayList;Importjava.util.List;/*** Created by Guwei on 16-11-4.*/ Public classLeaderpager {Context mcontext; List<ImageView> mimageviews =NewArraylist<>(); Private Static FinalString TAG = "Leaderpager"; PublicLeaderpager (Context context) { This. Mcontext =context; } /*** Parameter two or three optional fill in * <p> * parameter two not empty when using bitmap picture otherwise use the picture inside Mipmap **/ Public voidLeaderpageradapter (Viewpager Viewpager,FinalList<string> Imgs_url,FinalList<integer> imgs_id,FinalClass nextpage) {Viewpager.setadapter (NewPageradapter () {@Override PublicObject Instantiateitem (ViewGroup container,intposition) {ImageView ImageView=NewImageView (Mcontext); if(Imgs_url! =NULL) {Imageview.settag (Imgs_url.get (position)); NewImageloader (). Showimagebythread (ImageView, imgs_url.get (position)); //Imageview.setimagebitmap ();}Else if(imgs_id! =NULL) {Imageview.setimageresource (Imgs_id.get (position)); } Else{log.e (TAG,"Banner method: Do not pass the picture parameters, please check the parameters are filled in correctly!" "); } imageview.setscaletype (ImageView.ScaleType.CENTER_CROP); Container.addview (ImageView); Mimageviews.add (ImageView); returnImageView; } //Remove ImageView@Override Public voidDestroyitem (ViewGroup container,intposition, Object object) {LOG.E (TAG,"Destroyitem:position =" +position); Container.removeview (Mimageviews.get (position)); if(Position = = 0) {Intent Intent=NewIntent (Mcontext, nextpage); Mcontext.startactivity (Intent); }} @Override Public intGetCount () {intcount; if(Imgs_url! =NULL) {Count=imgs_url.size (); }Else{Count=imgs_id.size (); } returncount; } @Override Public Booleanisviewfromobject (View view, Object object) {returnView = =object; } }); }}
Is the use of general viewpager not much to say
If you want to use the network picture function first need to cooperate with Imageloader Oh!
Imageloader:
Packagecom.wbnq.simpleandroidframe.plugs;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.os.Handler;ImportAndroid.os.Message;ImportAndroid.util.Log;ImportAndroid.util.LruCache;ImportAndroid.widget.ImageView;ImportJava.io.BufferedInputStream;Importjava.io.IOException;ImportJava.io.InputStream;Importjava.net.HttpURLConnection;Importjava.net.MalformedURLException;ImportJava.net.URL;/*** Created by Guwei on 16-4-13.*/ Public classImageloader {PrivateImageView Mimageview; PrivateString Murl; //Create Cache PrivateLrucache<string, bitmap>mcaches; Private Static FinalString TAG = "Imageloader"; PublicImageloader () {//get maximum available memory intMaxMemory = (int) Runtime.getruntime (). MaxMemory (); intCacheSize = MAXMEMORY/3; Mcaches=NewLrucache<string, bitmap>(cacheSize) {@Overrideprotected intsizeOf (String key, Bitmap value) {//called every time the cache is cached, the size of the bitmap is returned . returnValue.getbytecount (); } }; } //add images to the cache (caches like map) Public voidaddbitmaptocache (String URL, Bitmap Bitmap) {//if the cache does not have this picture, save the picture in the cache if(Getbitmapformcache (URL) = =NULL) {mcaches.put (URL, bitmap); } } //remove a picture from the cache PublicBitmap getbitmapformcache (String url) {returnmcaches.get (URL); } PrivateHandler Handler =NewHandler () {@Override Public voidhandlemessage (Message msg) {Super. Handlemessage (msg); if(Mimageview.gettag (). Equals (Murl)) {Mimageview.setimagebitmap ((Bitmap) msg.obj); } } }; //loading pictures via URLs in thread Public voidShowimagebythread (FinalImageView image,FinalString URL) {Mimageview=image; Murl=URL; Bitmap Bitmap=getbitmapformcache (URL); if(Bitmap = =NULL) { NewThread () {@Override Public voidrun () {Super. Run (); Bitmap Bitmap=getbitmapformurl (URL); Message msg=Message.obtain (); Msg.obj=bitmap; Handler.sendmessage (msg); //log.i ("xyz", "1");}}.start (); } Else{image.setimagebitmap (bitmap); } } PublicBitmap Getbitmapformurl (String urlstring) {Bitmap Bitmap=NULL; InputStream is=NULL; Try{URL URL=NewURL (urlstring); Try{httpurlconnection Connection=(HttpURLConnection) url.openconnection (); is=NewBufferedinputstream (Connection.getinputstream ()); Bitmap=Bitmapfactory.decodestream (IS); Connection.disconnect (); Addbitmaptocache (urlstring, bitmap); LOG.E (TAG,"Getbitmapformurl: Get the picture inside the network method and put the picture in the cache" +bitmap); } Catch(IOException e) {e.printstacktrace (); } } Catch(malformedurlexception e) {e.printstacktrace (); } finally { Try{is.close (); } Catch(IOException e) {e.printstacktrace (); } } returnbitmap; }}
Comments are also relatively in place, there are caching features Oh! Picture loading method from Mu-Xu Dashen
That's it.
All come to see the female emperor and the Dew Qi Asian Bar ~ also has one is the young field Oh!
Android Boot page Public method Leaderpager