The project implements the following functions :
Get Mobile album, click on each album to enter the picture list of the album interface, in the Picture list interface can achieve multiple selection of pictures, and then into the selected image interface, in this interface can achieve the selected image upload and other functions.
the biggest feature of the project:
1, to obtain a list of albums, the current network above the introduction of the album to obtain a few items, this article specifically about the acquisition of albums.
2, using the Android-universal-image-loader Integration Framework-third-party jar load local images, familiar with the jar developer is not unfamiliar, the jar is very powerful, in addition to access to network images, Local images are also possible . At the same time, an Oom exception can be effectively resolved by referencing a third-party jar.
Link Android Get album list implementation (i)
Continue on a blog post, the previous blog through an asynchronous loading class to obtain local photos and local images of the data, this post mainly on the album List interface implementation, first give the album list activity class code as follows:
Public class albumsactivity extends Activity { PrivateGridView GridView;PrivateAlbumsadapter adapter;//Adapter PrivatePhotoupalbumhelper Photoupalbumhelper;//Load an asynchronous thread class for albums and pictures PrivateList<photoupimagebucket> list;//Store album list data @Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (R.layout.albums_gridview); Init ();//InitializeLoadData ();//Load DataOnitemclick ();//Set album Click Events}Private void Init() {gridview = (GridView) Findviewbyid (R.ID.ALBUM_GRIDV); adapter =NewAlbumsadapter (albumsactivity. This); Gridview.setadapter (adapter); }Private void LoadData() {photoupalbumhelper = Photoupalbumhelper.gethelper ();//Create an asynchronous thread instancePhotoupalbumhelper.init (albumsactivity. This);//Initialize instance ///callback interface, create an anonymous internal object, implement the method in the interface, get the data passed to Photoupalbumhelper interface GetalbumlistPhotoupalbumhelper.setgetalbumlist (NewGetalbumlist () {@Override Public void getalbumlist(list<photoupimagebucket> List) {adapter.setarraylist (list); Adapter.notifydatasetchanged ();//Update ViewAlbumsactivity. This. list = list; } }); Photoupalbumhelper.execute (false);//Asynchronous Thread execution}//Click on each album to see the pictures inside the album Private void Onitemclick() {Gridview.setonitemclicklistener (NewOnitemclicklistener () {@Override Public void Onitemclick(adapterview<?> parent, view view,intPositionLongID) {Intent Intent =NewIntent (albumsactivity. This, Albumitemactivity.class); Intent.putextra ("ImageList", List.get (position)); StartActivity (Intent); } }); }@Override protected void OnDestroy() {Super. OnDestroy (); }}
Album list interface is relatively simple, do not understand, the following gives the interface of the adapter code, the adapter code is overridden by the very common Baseadapter class implementation, is also very simple, The main feature is the use of third-party jar package Android-universal-image-loader to enable the loading of album covers:
Public class albumsadapter extends baseadapter { PrivateList<photoupimagebucket> arrayList;PrivateLayoutinflater Layoutinflater;PrivateImageloader Imageloader = Imageloader.getinstance ();//Initialize get instance PrivateDisplayimageoptions options;PrivateString TAG = AlbumsAdapter.class.getSimpleName ();//dev test mark bit Public Albumsadapter(Context context) {Layoutinflater = Layoutinflater.from (context); ArrayList =NewArraylist<photoupimagebucket> ();//Initialize collectionimageloaderconfiguration config =NewImageloaderconfiguration.builder (context). threadpriority (Thread.norm_priority-2). Denycacheimagemultiplesizesinmemory (). Disccachefilenamegenerator (NewMd5filenamegenerator ()). Tasksprocessingorder (Queueprocessingtype.lifo). Memorycacheextraoptions ( the, -). build ();//Initialize the configuration of the picture loader //Initialize imageloader with configuration.Imageloader.init (config);//Use Displayimageoption.builder () to create DisplayimageoptionsOptions =NewDisplayimageoptions.builder (). Showstubimage (R.drawable.default_loading_pic)//Set up pictures to display during picture download. Showimageforemptyuri (R.drawable.default_loading_pic)//Set picture to display when the image URI is empty or wrong. Showimageonfail (R.drawable.default_loading_pic)//Set Picture of error display during picture loading or decoding. Cacheinmemory (true)//Set whether the downloaded picture is slow in memory. Cacheondisc (true)//Set whether the downloaded picture is slow to exist on the SD card //. Displayer (New Roundedbitmapdisplayer (20))//set rounded picture. Bitmapconfig (config.rgb_565). Imagescaletype (Imagescaletype.in_sample_int). build ();//Create a configured Displayimageoption object //The default picture above or the picture that cannot be loaded can be set by the developer themselves, of course, you can set a different display picture. I'm here for convenience, using the same picture as the default image};@Override Public int GetCount() {returnArraylist.size (); }@Override PublicObjectGetItem(intPosition) {returnArraylist.get (position); }@Override Public Long Getitemid(intPosition) {returnPosition }@Override PublicViewGetView(intPosition, View Convertview, ViewGroup parent) {Holder Holder;if(Convertview = =NULL) {holder =NewHolder (); Convertview = Layoutinflater.inflate (R.layout.ablum_item, parent,false); Holder.image = (ImageView) Convertview.findviewbyid (r.id.image); Holder.name = (TextView) Convertview.findviewbyid (r.id.name); Holder.count = (TextView) Convertview.findviewbyid (R.id.count); Convertview.settag (holder); }Else{holder = (holder) Convertview.gettag (); } holder.count.setText (""+arraylist.get (position). GetCount ()); Holder.name.setText (Arraylist.get (position). Getbucketname ());//Image loader using code, this sentence code can be implemented to load the picture. Please note the URI address here, because we are now implementing a local image, so use "file://" + the storage address of the picture. If you want to get a network picture, the URI here is the network address of the picture. Imageloader.displayimage ("file://"+arraylist.get (position). GetImageList (). Get (0). Getimagepath (), holder.image, options);returnConvertview; } class holder{ImageView image; TextView name; TextView count; }//Set up album list data, mainly used to transfer album data to adapter Public void setarraylist(list<photoupimagebucket> arrayList) { This. arrayList = arrayList; }}
The interface code for the entire album list is still relatively simple. Next blog post about Android Get album list implementation (III)
Android Get album list implementation (II)