Advertisement
Guest User

FromRecord

a guest
Jun 25th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.30 KB | None | 0 0
  1. package rpl2016_17.example.com.salesmanmake2;
  2.  
  3. import android.Manifest;
  4. import android.app.Dialog;
  5. import android.app.ProgressDialog;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.content.SharedPreferences;
  10. import android.content.pm.PackageManager;
  11. import android.graphics.Bitmap;
  12. import android.graphics.Canvas;
  13. import android.graphics.Color;
  14. import android.graphics.drawable.ColorDrawable;
  15. import android.location.Location;
  16. import android.location.LocationManager;
  17. import android.net.Uri;
  18. import android.os.Build;
  19. import android.os.Bundle;
  20. import android.os.Environment;
  21. import android.provider.MediaStore;
  22. import android.provider.Settings;
  23. import android.support.v4.app.ActivityCompat;
  24. import android.support.v4.content.ContextCompat;
  25. import android.support.v4.content.FileProvider;
  26. import android.support.v7.app.AlertDialog;
  27. import android.support.v7.app.AppCompatActivity;
  28. import android.support.v7.widget.Toolbar;
  29. import android.util.Log;
  30. import android.view.View;
  31. import android.widget.Button;
  32. import android.widget.EditText;
  33. import android.widget.ImageView;
  34. import android.widget.TextView;
  35. import android.widget.Toast;
  36.  
  37. import com.androidnetworking.AndroidNetworking;
  38. import com.androidnetworking.common.Priority;
  39. import com.androidnetworking.error.ANError;
  40. import com.androidnetworking.interfaces.JSONObjectRequestListener;
  41. import com.androidnetworking.interfaces.UploadProgressListener;
  42. import com.github.gcacace.signaturepad.views.SignaturePad;
  43.  
  44. import org.json.JSONArray;
  45. import org.json.JSONException;
  46. import org.json.JSONObject;
  47.  
  48. import java.io.BufferedReader;
  49. import java.io.BufferedWriter;
  50. import java.io.ByteArrayOutputStream;
  51. import java.io.File;
  52. import java.io.FileOutputStream;
  53. import java.io.IOException;
  54. import java.io.InputStreamReader;
  55. import java.io.OutputStream;
  56. import java.io.OutputStreamWriter;
  57. import java.io.UnsupportedEncodingException;
  58. import java.net.HttpURLConnection;
  59. import java.net.URL;
  60. import java.net.URLEncoder;
  61. import java.text.DateFormat;
  62. import java.text.SimpleDateFormat;
  63. import java.util.Calendar;
  64. import java.util.Date;
  65. import java.util.HashMap;
  66. import java.util.Map;
  67. import java.text.SimpleDateFormat;
  68. import java.util.Date;
  69.  
  70. import javax.net.ssl.HttpsURLConnection;
  71.  
  72. import rpl2016_17.example.com.salesmanmake2.data.Job;
  73. import rpl2016_17.example.com.salesmanmake2.ui.JobsActivity;
  74.  
  75. public class FormRecord extends AppCompatActivity {
  76. private String cameraFilePath;
  77.  
  78. Button GetImageFromGalleryButton, UploadImageOnServerButton, UploadSignature;
  79.  
  80. ImageView ShowSelectedImage;
  81.  
  82. EditText imageName;
  83.  
  84. Bitmap FixBitmap;
  85.  
  86. String ImageTag = "image_tag";
  87.  
  88. String ImageName = "image_data";
  89.  
  90. ProgressDialog progressDialog;
  91.  
  92. ByteArrayOutputStream byteArrayOutputStream;
  93.  
  94. byte[] byteArray;
  95.  
  96. String ConvertImage;
  97.  
  98. String GetImageNameFromEditText;
  99.  
  100. HttpURLConnection httpURLConnection;
  101.  
  102. URL url;
  103.  
  104. OutputStream outputStream;
  105.  
  106. BufferedWriter bufferedWriter;
  107.  
  108. int RC;
  109.  
  110. BufferedReader bufferedReader;
  111.  
  112. StringBuilder stringBuilder;
  113.  
  114. boolean check = true;
  115.  
  116. private int GALLERY = 1, CAMERA = 2;
  117.  
  118. Toolbar toolbar;
  119.  
  120. private static final int REQUEST_LOCATION = 1;
  121. Button button;
  122. TextView textViewLoc , textViewTime;
  123. LocationManager locationManager;
  124. String lattitude,longitude;
  125.  
  126. private File selectedImageFile = null;
  127. private ProgressDialog mProgress;
  128.  
  129.  
  130.  
  131. @Override
  132. protected void onCreate(Bundle savedInstanceState) {
  133. super.onCreate(savedInstanceState);
  134. setContentView(R.layout.activity_form_record);
  135.  
  136. toolbar = findViewById(R.id.toolbar);
  137. setSupportActionBar(toolbar);
  138. getSupportActionBar().setTitle("Input Data");
  139. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  140.  
  141. mProgress = new ProgressDialog(this);
  142. mProgress.setTitle("Processing...");
  143. mProgress.setMessage("Please wait...");
  144. mProgress.setCancelable(false);
  145. mProgress.setIndeterminate(true);
  146.  
  147.  
  148. GetImageFromGalleryButton = (Button) findViewById(R.id.buttonSelect);
  149.  
  150. UploadImageOnServerButton = (Button) findViewById(R.id.buttonUpload);
  151.  
  152. UploadSignature = (Button) findViewById(R.id.btn_Signature);
  153.  
  154. ShowSelectedImage = (ImageView) findViewById(R.id.imageView);
  155.  
  156.  
  157. byteArrayOutputStream = new ByteArrayOutputStream();
  158.  
  159. GetImageFromGalleryButton.setOnClickListener(new View.OnClickListener() {
  160. @Override
  161. public void onClick(View view) {
  162. showPictureDialog();
  163. }
  164. });
  165.  
  166. UploadSignature.setOnClickListener(new View.OnClickListener() {
  167. @Override
  168. public void onClick(View view) {
  169. showSignatureDialog();
  170. }
  171. });
  172.  
  173.  
  174. UploadImageOnServerButton.setOnClickListener(new View.OnClickListener() {
  175. @Override
  176. public void onClick(View view) {
  177.  
  178. GetImageNameFromEditText = "makan";
  179.  
  180. new AlertDialog.Builder(FormRecord.this)
  181. .setTitle("Save data")
  182. .setMessage("Apakah anda yakin ingin save data ?")
  183. .setNegativeButton("Tidak", null)
  184. .setPositiveButton("Ya", new DialogInterface.OnClickListener() {
  185. public void onClick(DialogInterface arg0, int arg1) {
  186. // kirim datanya
  187. mProgress.show();
  188. senData();
  189. mProgress.dismiss();
  190. }
  191. }).create().show();
  192.  
  193.  
  194. }
  195. });
  196.  
  197.  
  198. if (ContextCompat.checkSelfPermission(FormRecord.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(FormRecord.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
  199. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  200. requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE},
  201. 5);
  202. }
  203. }
  204.  
  205.  
  206. ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
  207. textViewLoc = (TextView)findViewById(R.id.tv_lokasi);
  208. button = (Button)findViewById(R.id.buttonSelect);
  209. textViewTime = (TextView)findViewById(R.id.tv_waktu);
  210.  
  211. SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy. 'at' HH:mm:ss z");
  212. String currentDateandTime = sdf.format(new Date());
  213. textViewTime.setText("Your current time : " + "\n" + currentDateandTime);
  214.  
  215.  
  216. }
  217.  
  218. public void onBackPressed() {
  219. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  220. builder.setCancelable(false);
  221. builder.setTitle("Konfirmasi Pembatalan");
  222. builder.setMessage("Apakah anda yakin membatalkan input data?");
  223. builder.setPositiveButton("YA", new DialogInterface.OnClickListener() {
  224. @Override
  225. public void onClick(DialogInterface dialog, int which) {
  226. //if user pressed "yes", then he is allowed to exit from application
  227. finish();
  228. }
  229. });
  230. builder.setNegativeButton("TIDAK", new DialogInterface.OnClickListener() {
  231. @Override
  232. public void onClick(DialogInterface dialog, int which) {
  233. //if user select "No", just cancel this dialog and continue with app
  234. dialog.cancel();
  235. }
  236. });
  237. AlertDialog alert = builder.create();
  238. alert.show();
  239. }
  240.  
  241. private void showPictureDialog() {
  242. // locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  243. // if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  244. // buildAlertMessageNoGps();
  245. //
  246. // } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  247. // getLocation();
  248. // }
  249.  
  250. AlertDialog.Builder pictureDialog = new AlertDialog.Builder(this);
  251. pictureDialog.setTitle("Select Action");
  252. String[] pictureDialogItems = {
  253. "Photo Gallery",
  254. "Camera"};
  255. pictureDialog.setItems(pictureDialogItems,
  256. new DialogInterface.OnClickListener() {
  257. @Override
  258. public void onClick(DialogInterface dialog, int which) {
  259. switch (which) {
  260. case 0:
  261. choosePhotoFromGallary();
  262. break;
  263. case 1:
  264. takePhotoFromCamera();
  265. break;
  266. }
  267. }
  268. });
  269. pictureDialog.show();
  270. }
  271.  
  272. public void choosePhotoFromGallary() {
  273. Intent galleryIntent = new Intent(Intent.ACTION_PICK,
  274. MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  275.  
  276. startActivityForResult(galleryIntent, GALLERY);
  277. }
  278.  
  279. private void takePhotoFromCamera() {
  280. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  281. try {
  282. intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", createImageFile()));
  283. Log.e("", "putExtra: " );
  284. } catch (IOException e) {
  285. e.printStackTrace();
  286. Log.e("", "ioexception: " + e.getLocalizedMessage() );
  287. }
  288. Log.e("", "takePhotoFromCamera: " );
  289. startActivityForResult(intent, CAMERA);
  290. }
  291.  
  292. @Override
  293. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  294.  
  295. super.onActivityResult(requestCode, resultCode, data);
  296. if (resultCode == this.RESULT_CANCELED) {
  297. return;
  298. }
  299. if (requestCode == GALLERY) {
  300. if (data != null) {
  301. Uri contentURI = data.getData();
  302. try {
  303. FixBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), contentURI);
  304. // String path = saveImage(bitmap);
  305. //Toast.makeText(MainActivity.this, "Image Saved!", Toast.LENGTH_SHORT).show();
  306. ShowSelectedImage.setImageBitmap(FixBitmap);
  307. ShowSelectedImage.setVisibility(View.VISIBLE);
  308. UploadImageOnServerButton.setVisibility(View.VISIBLE);
  309.  
  310.  
  311. locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  312. if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  313. buildAlertMessageNoGps();
  314.  
  315. } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  316. getLocation();
  317. }
  318. } catch (IOException e) {
  319. e.printStackTrace();
  320. Toast.makeText(FormRecord.this, "Failed!", Toast.LENGTH_SHORT).show();
  321. }
  322. }
  323.  
  324. } else if (requestCode == CAMERA) {
  325. // FixBitmap = (Bitmap) data.getExtras().get("data");
  326. Log.e("", "onActivityResult: " + cameraFilePath );
  327. selectedImageFile = new File(cameraFilePath);
  328. ShowSelectedImage.setImageURI(Uri.parse(cameraFilePath));
  329. try {
  330. FixBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), Uri.parse(cameraFilePath));
  331. } catch (IOException e) {
  332. e.printStackTrace();
  333. }
  334. UploadImageOnServerButton.setVisibility(View.VISIBLE);
  335. ShowSelectedImage.setVisibility(View.VISIBLE);
  336. locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  337. if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  338. buildAlertMessageNoGps();
  339.  
  340. } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  341. getLocation();
  342. }
  343. // saveImage(thumbnail);
  344. //Toast.makeText(ShadiRegistrationPart5.this, "Image Saved!", Toast.LENGTH_SHORT).show();
  345. }
  346. }
  347.  
  348.  
  349.  
  350. @Override
  351. public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  352. super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  353. if (requestCode == 5) {
  354. if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  355. // Now user should be able to use camera
  356.  
  357. } else {
  358.  
  359. Toast.makeText(FormRecord.this, "Unable to use Camera..Please Allow us to use Camera", Toast.LENGTH_LONG).show();
  360.  
  361. }
  362. }
  363. }
  364.  
  365. public class ImageProcessClass {
  366.  
  367. public String ImageHttpRequest(String requestURL, HashMap<String, String> PData) {
  368.  
  369. StringBuilder stringBuilder = new StringBuilder();
  370.  
  371. try {
  372. url = new URL(requestURL);
  373.  
  374. httpURLConnection = (HttpURLConnection) url.openConnection();
  375.  
  376. httpURLConnection.setReadTimeout(20000);
  377.  
  378. httpURLConnection.setConnectTimeout(20000);
  379.  
  380. httpURLConnection.setRequestMethod("POST");
  381.  
  382. httpURLConnection.setDoInput(true);
  383.  
  384. httpURLConnection.setDoOutput(true);
  385.  
  386. outputStream = httpURLConnection.getOutputStream();
  387.  
  388. bufferedWriter = new BufferedWriter(
  389.  
  390. new OutputStreamWriter(outputStream, "UTF-8"));
  391.  
  392. bufferedWriter.write(bufferedWriterDataFN(PData));
  393.  
  394. bufferedWriter.flush();
  395.  
  396. bufferedWriter.close();
  397.  
  398. outputStream.close();
  399.  
  400. RC = httpURLConnection.getResponseCode();
  401.  
  402. if (RC == HttpsURLConnection.HTTP_OK) {
  403.  
  404. bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
  405.  
  406. stringBuilder = new StringBuilder();
  407.  
  408. String RC2;
  409.  
  410. while ((RC2 = bufferedReader.readLine()) != null) {
  411.  
  412. stringBuilder.append(RC2);
  413. }
  414. }
  415.  
  416. } catch (Exception e) {
  417. e.printStackTrace();
  418. }
  419. return stringBuilder.toString();
  420. }
  421.  
  422. private String bufferedWriterDataFN(HashMap<String, String> HashMapParams) throws UnsupportedEncodingException {
  423.  
  424. stringBuilder = new StringBuilder();
  425.  
  426. for (Map.Entry<String, String> KEY : HashMapParams.entrySet()) {
  427. if (check)
  428. check = false;
  429. else
  430. stringBuilder.append("&");
  431.  
  432. stringBuilder.append(URLEncoder.encode(KEY.getKey(), "UTF-8"));
  433.  
  434. stringBuilder.append("=");
  435.  
  436. stringBuilder.append(URLEncoder.encode(KEY.getValue(), "UTF-8"));
  437. }
  438.  
  439. return stringBuilder.toString();
  440. }
  441.  
  442. }
  443.  
  444. private File createImageFile() throws IOException {
  445. // Create an image file name
  446. String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
  447. String imageFileName = "JPEG_" + timeStamp + "_";
  448. //This is the directory in which the file will be created. This is the default location of Camera photos
  449. File storageDir = new File(Environment.getExternalStoragePublicDirectory(
  450. Environment.DIRECTORY_DCIM), "Camera");
  451. File image = File.createTempFile(
  452. imageFileName, /* prefix */
  453. ".jpg", /* suffix */
  454. storageDir /* directory */
  455. );
  456. // Save a file: path for using again
  457. cameraFilePath = "file://" + image.getAbsolutePath();
  458. Log.e("", "createImageFile: " + cameraFilePath);
  459. return image;
  460. }
  461.  
  462.  
  463. private void getLocation() {
  464. if (ActivityCompat.checkSelfPermission(FormRecord.this, Manifest.permission.ACCESS_FINE_LOCATION)
  465. != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission
  466. (FormRecord.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  467.  
  468. ActivityCompat.requestPermissions(FormRecord.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
  469.  
  470. } else {
  471. Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  472.  
  473. Location location1 = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  474.  
  475. Location location2 = locationManager.getLastKnownLocation(LocationManager. PASSIVE_PROVIDER);
  476.  
  477. if (location != null) {
  478. double latti = location.getLatitude();
  479. double longi = location.getLongitude();
  480. lattitude = String.valueOf(latti);
  481. longitude = String.valueOf(longi);
  482.  
  483. textViewLoc.setVisibility(View.VISIBLE);
  484. textViewTime.setVisibility(View.VISIBLE);
  485.  
  486. textViewLoc.setText("Your current location is :"+ "\n" + "Lattitude = " + lattitude
  487. + "\n" + "Longitude = " + longitude);
  488.  
  489. textViewLoc.setOnClickListener(new View.OnClickListener() {
  490. @Override
  491. public void onClick(View view) {
  492. maps();
  493. }
  494. });
  495.  
  496. } else if (location1 != null) {
  497. double latti = location1.getLatitude();
  498. double longi = location1.getLongitude();
  499. lattitude = String.valueOf(latti);
  500. longitude = String.valueOf(longi);
  501. textViewLoc.setVisibility(View.VISIBLE);
  502. textViewTime.setVisibility(View.VISIBLE);
  503.  
  504. textViewLoc.setText("Your current location is :"+ "\n" + "Lattitude = " + lattitude
  505. + "\n" + "Longitude = " + longitude);
  506.  
  507. textViewLoc.setOnClickListener(new View.OnClickListener() {
  508. @Override
  509. public void onClick(View view) {
  510. maps();
  511. }
  512. });
  513.  
  514.  
  515. } else if (location2 != null) {
  516. double latti = location2.getLatitude();
  517. double longi = location2.getLongitude();
  518. lattitude = String.valueOf(latti);
  519. longitude = String.valueOf(longi);
  520. textViewLoc.setVisibility(View.VISIBLE);
  521. textViewTime.setVisibility(View.VISIBLE);
  522. // "geo:"+lattitude+","+longitude;
  523. textViewLoc.setText("Your current location is :"+ "\n" + "Lattitude = " + lattitude
  524. + "\n" + "Longitude = " + longitude);
  525.  
  526. textViewLoc.setOnClickListener(new View.OnClickListener() {
  527. @Override
  528. public void onClick(View view) {
  529. maps();
  530. }
  531. });
  532.  
  533. }else{
  534.  
  535. Toast.makeText(this,"Unble to Trace your location",Toast.LENGTH_SHORT).show();
  536.  
  537. }
  538. }
  539. }
  540.  
  541. private void maps() {
  542.  
  543. // Intent intent = new Intent(Intent.ACTION_VIEW);
  544. // intent.setData(Uri.parse("geo:"+lattitude+","+longitude));
  545. // startActivity(intent);
  546. Intent intent = new Intent(Intent.ACTION_VIEW);
  547. intent.setData(Uri.parse("geo:?q="+lattitude+","+longitude));
  548. startActivity(intent);
  549. }
  550.  
  551. protected void buildAlertMessageNoGps() {
  552.  
  553. final AlertDialog.Builder builder = new AlertDialog.Builder(this);
  554. builder.setMessage("Please Turn ON your GPS Connection")
  555. .setCancelable(false)
  556. .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  557. public void onClick(final DialogInterface dialog, final int id) {
  558. startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
  559. }
  560. })
  561. .setNegativeButton("No", new DialogInterface.OnClickListener() {
  562. public void onClick(final DialogInterface dialog, final int id) {
  563. dialog.cancel();
  564. }
  565. });
  566. final AlertDialog alert = builder.create();
  567. alert.show();
  568. }
  569.  
  570. // public void getCurrentTime(View view) {
  571. // Calendar calendar = Calendar.getInstance();
  572. // SimpleDateFormat mdformat = new SimpleDateFormat("HH:mm:ss");
  573. // String strDate = "Current Time : " + mdformat.format(calendar.getTime());
  574. // display(strDate);
  575. // }
  576. //
  577. // private void display(String num) {
  578. // textViewTime.setText(num);
  579. // }
  580.  
  581. private void showSignatureDialog() {
  582. final Dialog dialog = new Dialog(this);
  583. dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  584. dialog.setContentView(R.layout.dialog_signature);
  585. final SignaturePad signaturePad = dialog.findViewById(R.id.signature_pad);
  586. Button btnApply = dialog.findViewById(R.id.btn_apply);
  587. btnApply.setOnClickListener(new View.OnClickListener() {
  588. @Override
  589. public void onClick(View view) {
  590. Bitmap signatureBitmap = signaturePad.getTransparentSignatureBitmap(true);
  591. drawSignatureOnImage(signatureBitmap);
  592. dialog.dismiss();
  593. }
  594. });
  595. dialog.show();
  596. }
  597.  
  598. private void drawSignatureOnImage(Bitmap signature) {
  599. int w = FixBitmap.getWidth();
  600. int h = FixBitmap.getHeight();
  601. Bitmap result = Bitmap.createBitmap(w, h, FixBitmap.getConfig());
  602. Canvas canvas = new Canvas(result);
  603. canvas.drawBitmap(FixBitmap, 0f, 0f, null);
  604. canvas.drawBitmap(signature, 100f, 100f, null);
  605.  
  606. ShowSelectedImage.setImageBitmap(result);
  607. }
  608.  
  609. @Override
  610. public boolean onSupportNavigateUp() {
  611. finish();
  612. return true;
  613. }
  614.  
  615. private void senData (){
  616. SharedPreferences preferences = getSharedPreferences("login", Context.MODE_PRIVATE);
  617. AndroidNetworking.upload(Constants.BASE_URL + "/api/report/send")
  618. .addMultipartFile("proof_image", selectedImageFile)
  619. .addMultipartParameter("job_id",String.valueOf(preferences.getLong("id", 0)))
  620. .addMultipartParameter("location", longitude + ";" + lattitude)
  621. .setPriority(Priority.HIGH)
  622. .build()
  623. .setUploadProgressListener(new UploadProgressListener() {
  624. @Override
  625. public void onProgress(long bytesUploaded, long totalBytes) {
  626. // do anything with progress
  627. }
  628. })
  629. .getAsJSONObject(new JSONObjectRequestListener() {
  630. @Override
  631. public void onResponse(JSONObject response) {
  632. // do anything with response
  633. try {
  634. if (response.getBoolean("success")) {
  635. //tost
  636. Toast.makeText(getApplicationContext(), "Laporan berhasil dikirim", Toast.LENGTH_SHORT).show();
  637.  
  638. }else{//toast gagal
  639. Toast.makeText(getApplicationContext(), "Laporan gagal dikirim", Toast.LENGTH_SHORT).show();
  640. }
  641. } catch (JSONException e) {
  642. e.printStackTrace();
  643. Toast.makeText(FormRecord.this, Constants.EROR, Toast.LENGTH_SHORT).show();
  644. }
  645. }
  646. @Override
  647. public void onError(ANError error) {
  648. // handle error
  649. }
  650. });
  651. }
  652. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement