java - Display ProgressBar while saving an image from Activity -
in app letting user save drawing. while drawing saved, want display progress bar on top of drawing let user know saving.
my xml layout:
<framelayout android:id="@+id/viewd" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3" android:orientation="vertical" android:layout_gravity="center" > <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="0dp" android:background="@drawable/bd" android:id="@+id/llfreedraw" > </linearlayout> <progressbar android:layout_height="fill_parent" android:layout_width="fill_parent" style="@android:style/widget.progressbar.large" android:id="@+id/pbsave" android:visibility="invisible" /> </framelayout>
portion of java code is:
view.onclicklistener savehandle = new view.onclicklistener() { public void onclick(view v) { savepb = (progressbar) findviewbyid(r.id.pbsave); savepb.setvisibility(view.visible); view content = layout; content.setdrawingcacheenabled(true); content.setdrawingcachequality(view.drawing_cache_quality_high); bitmap bitmap = content.getdrawingcache(); file folder = new file(environment.getexternalstoragedirectory() + "/pb"); if (!folder.exists()) { folder.mkdir(); } file = new file(folder + "/pb_image_" + math.random() + ".png"); fileoutputstream ostream; try { file.createnewfile(); ostream = new fileoutputstream(file); bitmap.compress(compressformat.png, 100, ostream); ostream.flush(); ostream.close(); displaytoast("image saved."); savepb.setvisibility(view.gone); btnsave.setvisibility(view.gone); btnshare.setvisibility(view.visible); } catch (exception e) { e.printstacktrace(); displaytoast("unable save image. try again later."); } } };
i want display progress bar on top of framelayou, 25% transparent background. image saving not see progress bar. idea how modify works way wanting to?
asynctask can handle this.
public class saveimagetask extends asynctask<void, void, void> { @override protected void doinbackground(void... params) { // save image here. return null; } @override protected void onpreexecute(){ // show progress bar here. } @override protected void onpostexecute() { // hide progress bar here. } }
call like:
new saveimagetask().execute(null, null, null);
Comments
Post a Comment