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.
This blog post is connected to two posts above
Android Get album list implementation (i)
Android Get album list implementation (II)
Continue to tell the picture list in the album Interface implementation, first give the album list interface Acitivity class code:
Public class albumitemactivity extends Activity { PrivateGridView GridView;PrivatePhotoupimagebucket Photoupimagebucket;//Album object, photo album inside the album is saved inside the picture list @Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (R.layout.album_item); Init ();//InitializeSetlistener ();//Set listener}Private void Init() {gridview = (GridView) Findviewbyid (R.ID.ALBUM_ITEM_GRIDV); Intent Intent = Getintent (); Photoupimagebucket = (photoupimagebucket) Intent.getserializableextra ("ImageList"); Albumitemadapter adapter =NewAlbumitemadapter (Photoupimagebucket.getimagelist (), albumitemactivity. This); Gridview.setadapter (adapter); }Private void Setlistener() {Gridview.setonitemclicklistener (NewOnitemclicklistener () {@Override Public void Onitemclick(adapterview<?> parent, view view,intPositionLongID) {Toast.maketext (albumitemactivity. This,"checked."+position, Toast.length_short). Show (); } }); }@Override protected void OnDestroy() {Super. OnDestroy (); }}
The adapter code is given below:
Public class albumitemadapter extends baseadapter { PrivateList<photoupimageitem> list;PrivateLayoutinflater Layoutinflater;PrivateImageloader Imageloader;//Picture loader PrivateDisplayimageoptions options; Public Albumitemadapter(list<photoupimageitem> list,context Context) { This. list = list; Layoutinflater = Layoutinflater.from (context); Imageloader = Imageloader.getinstance ();//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.argb_8888). Imagescaletype (Imagescaletype.in_sample_int). build ();//Create a configured Displayimageoption object}@Override Public int GetCount() {returnList.size (); }@Override PublicObjectGetItem(intPosition) {returnList.get (position); }@Override Public Long Getitemid(intPosition) {returnPosition }@Override PublicViewGetView(intPosition, View Convertview, ViewGroup parent) {Holder Holder;if(Convertview = =NULL) {Convertview = Layoutinflater.inflate (R.layout.album_item_image_view, parent,false); Holder =NewHolder (); Holder.imageview = (ImageView) Convertview.findviewbyid (R.id.image_item); Convertview.settag (holder); }Else{holder = (holder) Convertview.gettag (); }//Image loader using code, this sentence code can be implemented to load the picture. Please note//Here's the URI address, as we now implement is to get the local picture, so make//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://"+list.get (position). Getimagepath (), Holder.imageview, options);returnConvertview; } class holder{ImageView ImageView; }}
The adapter of the Picture list interface is simple and can be loaded after getting the data. In this case, the album object class Photoupimagebucket is used, and the code is as follows:
/** * Album object in a directory * / Public class photoupimagebucket implements Serializable{ Public intCount =0; PublicString Bucketname; PublicList<photoupimageitem> imageList; Public int GetCount() {returnCount } Public void SetCount(intCount) { This. Count = Count; } PublicStringGetbucketname() {returnBucketname; } Public void Setbucketname(String bucketname) { This. bucketname = Bucketname; } PublicList<photoupimageitem>getimagelist() {returnImageList; } Public void SetImageList(list<photoupimageitem> imageList) { This. imageList = imageList; }}
At the same time the code is also used in the Picture object class Photoupimageitem, the class code is as follows:
Public class Photoupimageitem implements Serializable { //Image ID PrivateString imageId;//original path PrivateString ImagePath;//is selected Private BooleanisSelected =false; PublicStringGetimageid() {returnImageId; } Public void Setimageid(String imageId) { This. imageId = ImageId; } PublicStringGetimagepath() {returnImagePath; } Public void setImagePath(String ImagePath) { This. ImagePath = ImagePath; } Public Boolean isSelected() {returnisSelected; } Public void setselected(BooleanisSelected) { This. isSelected = isSelected; }}
The creation of each album and each picture as an object is easy to maintain and easier to develop, if the late addition of what features, on the basis of the development of the object will be a great degree of convenience.
Two additional blog links:
Android Get album list implementation (i)
Android Get album list implementation (II)
Android Get album list implementation (III)