java - Android take multiple photos and return them in a list with delete button -
i working on app have choose 2 values spinner, give them description , take photo (which multiple photos). have simple app needs changes.
when press take photo button go camera activity, , after accepting taken photo automatically send photo sever instead return previous activity , see taken photo in list view (under description in main activity) , have possibility remove photo list view. want send data (and photos) after pressing send button. can suggest me guys how possible or links similar examples? have searched not find this. thank you!
here java code:
oncreateview()
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { db = new sqlitehandler(getactivity().getapplicationcontext()); db.deletezones(); db.deletepoints(); //adding zones database try { new addzonestodatabase().execute().get(); } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } //adding points database try { new addpointstothedatabase().execute().get(); } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } //inflate layout framelayout rootview = (framelayout) inflater.inflate(r.layout.fragment_send, container, false); //zone name , id separated final list<string> zoneidforname = db.getzoneids(); final list<string> zonelist = db.getzonenames(); spinner1 = (spinner) rootview.findviewbyid(r.id.spinnerchooselocation1); arrayadapter<string> spinner1adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_spinner_item, zonelist); spinner1adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinner1.setadapter(spinner1adapter); spinner1.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parentview, view selecteditemview, int position, long id) { chosenspinner1 = zonelist.get(position); positionforfirstspinner = position; } @override public void onnothingselected(adapterview<?> parentview) { } }); final list<string> pointname = db.getpointname(integer.valueof(zoneidforname.get(positionforfirstspinner))); arrayadapter<string> spinner2adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_spinner_item, pointname); spinner2 = (spinner) rootview.findviewbyid(r.id.spinnerchooselocation2); spinner2adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinner2.setadapter(spinner2adapter); spinner2.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parentview, view selecteditemview, int position, long id) { string spinner2text[] = {"location 2-1", "location 2-2", "location 2-3", "location 2-4", "location 2-5", "location 2-6"}; chosenspinner2 = spinner2text[position]; } @override public void onnothingselected(adapterview<?> parentview) { } }); //spinner rate1 chosen spinnerrate1 = (spinner) rootview.findviewbyid(r.id.spinnerrate1); adapterrate1 = new arrayadapter<string>(getactivity(), android.r.layout.simple_spinner_item, rate1); adapterrate1.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinnerrate1.setadapter(adapterrate1); spinnerrate1.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parentview, view selecteditemview, int position, long id) { string rate1[] = {"10", "9", "8", "7", "6", "5", "4", "3", "2", "1"}; chosenrate1 = integer.parseint(rate1[position]); } @override public void onnothingselected(adapterview<?> parentview) { } }); //spinner rate2 spinnerrate2 = (spinner) rootview.findviewbyid(r.id.spinnerrate2); adapterrate2 = new arrayadapter<string>(getactivity(), android.r.layout.simple_spinner_item, rate2); adapterrate2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinnerrate2.setadapter(adapterrate2); spinnerrate2.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parentview, view selecteditemview, int position, long id) { string rate2[] = {"10", "9", "8", "7", "6", "5", "4", "3", "2", "1"}; chosenrate2 = integer.parseint(rate2[position]); } @override public void onnothingselected(adapterview<?> parentview) { } }); button takephotobutton = (button) rootview.findviewbyid(r.id.take_photo); button sendwithoutphotobutton = (button) rootview.findviewbyid(r.id.send_without_photo); detail1 = (edittext) rootview.findviewbyid(r.id.etdetail1); detail1.gettext().clear(); //take photo button takephotobutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (validate()) { intent = new intent(mediastore.action_image_capture); getfileuri(); i.putextra(mediastore.extra_output, file_uri); startactivityforresult(i, 10); } } }); sendwithoutphotobutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (validatesendwithoutphoto()) { sendjson(detail1.gettext().tostring()); detail1.gettext().clear(); if (dialog.isshowing()) { dialog.dismiss(); } } } }); return rootview; }
going camera activity
@override public void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == 10 && resultcode == getactivity().result_ok) { new encode_image().execute(); } } private void getfileuri() { string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date()); image_name = "jpeg_" + timestamp + "_.jpg"; ; if (getexternalstoragestate() == storagestate.writeable) { file = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures) + file.separator + image_name); file_uri = uri.fromfile(file); } }
encodeimage function
private class encode_image extends asynctask<void, void, void> { @override protected void doinbackground(void... params) { bitmap = bitmapfactory.decodefile(file_uri.getpath()); bytearrayoutputstream stream = new bytearrayoutputstream(); bitmap.compress(bitmap.compressformat.jpeg, 100, stream); //convert stream byte array byte[] array = stream.tobytearray(); encoded_string = base64.encodetostring(array, 0); return null; } @override protected void onpostexecute(void avoid) { sendjson(detail1.gettext().tostring()); if (responseglob == "data successefully added") { toast.maketext(getactivity().getapplicationcontext(), "data added successfully", toast.length_long).show(); } if (dialog.isshowing()) { dialog.dismiss(); } } }
Comments
Post a Comment