android - How to set circle progress bar on image using custom adapter -
hello creating social app whats app... want show circle progress bar on every image or video while uploading , downloading same whats app. please me how can using custom adapter. here code
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <relativelayout android:id="@+id/main_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" > <relativelayout android:id="@+id/imageview_layout" android:layout_width="150dp" android:layout_height="150dp"> <imageview android:id="@+id/displayimg" android:layout_width="150dp" android:layout_height="150dp" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:scaletype="fitxy" android:src="@drawable/ic_launcher" /> </relativelayout> <relativelayout android:id="@+id/progressbar_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_alignright="@+id/imageview_layout" android:layout_marginright="49dp" android:layout_margintop="50dp" android:visibility="gone"> <progressbar android:id="@+id/progressbar1" style="?android:attr/progressbarstylehorizontal" android:layout_width="60dp" android:layout_height="60dp" android:progressdrawable="@drawable/circular_progress_bar" /> <imageview android:id="@+id/cancel_downloadimg" android:layout_width="40dp" android:layout_height="40dp" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:src="@drawable/dialog_ic_close_normal_holo_light" />
</relativelayout>
above custom layout of adapter class
/** * uploading file server * */ private class uploadfiletoserver extends asynctask<void, integer, string> { @override protected void onpreexecute() { // setting progress bar 0 chat_adapter.viewholder.progressbar.setprogress(0); mnotifymanager = (notificationmanager)mcontext. getsystemservice(context.notification_service); mbuilder = new notificationcompat.builder(mcontext); super.onpreexecute(); } @override protected void onprogressupdate(integer... progress) { // making progress bar visible progressbar.setvisibility(view.visible); .progressbar.setprogress(progress[0]); // updating percentage value //txtpercentage.settext(string.valueof(progress[0]) + "%"); } @override protected string doinbackground(void... params) { return uploadfile(); } @suppresswarnings("deprecation") private string uploadfile() { string responsestring = null; httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(serviceurl+"conversations.php"); try { multipartentitybuilder entity = multipartentitybuilder.create(); mbuilder.setcontenttitle("zaplink") .setcontenttext("uploading in progress") .setsmallicon(r.drawable.ic_launcher); /* example setting httpmultipartmode */ entity.setmode(httpmultipartmode.browser_compatible); file sourcefile = new file(imgdecodablestring); // progress listener - updates task's progress myhttpentity.progresslistener progresslistener = new myhttpentity.progresslistener() { @override public void transferred(float progress) { publishprogress((int) progress); mbuilder.setprogress(100, (int) progress, false); mnotifymanager.notify(1, mbuilder.build()); } }; // adding file data http body entity.addpart("file", new filebody(sourcefile)); // parameters if want pass server entity.addtextbody("from_user",(prefid.getstring("userid", null)),contenttype.text_plain); entity.addtextbody("to_user",touser_id,contenttype.text_plain); entity.addtextbody("message_type", type,contenttype.text_plain); httppost.setentity(new myhttpentity(entity.build(), progresslistener)); // making server call httpresponse response = httpclient.execute(httppost); httpentity r_entity = response.getentity(); int statuscode = response.getstatusline().getstatuscode(); if (statuscode == 200) { // server response responsestring = entityutils.tostring(r_entity); } else { responsestring = "error occurred! http status code: " + statuscode; } } catch (clientprotocolexception e) { responsestring = e.tostring(); } catch (ioexception e) { responsestring = e.tostring(); } return responsestring; } @override protected void onpostexecute(string result) { super.onpostexecute(result); progressbar.setvisibility(view.gone); mbuilder.setcontenttext("upload successful"); // removes progress bar mbuilder.setprogress(0, 0, false); mnotifymanager.notify(1, mbuilder.build()); } }
above code uploading image , video in advance
Comments
Post a Comment