Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. public void exeCuteApi() {
  2. printLog(TAG, "46 : exeCuteApi: " + API);
  3. VolleyMultipartRequest volleyMultipartRequest = new VolleyMultipartRequest(Request.Method.POST, API,
  4. new Response.Listener<NetworkResponse>() {
  5. @Override
  6. public void onResponse(NetworkResponse response) {
  7. String resultResponse = new String(response.data);
  8. printLog(TAG, "218 : onResponse: " + resultResponse);
  9.  
  10. }
  11. }, new Response.ErrorListener() {
  12. @Override
  13. public void onErrorResponse(VolleyError error) {
  14. printLog(TAG, "253 : onErrorResponse: " + error.getMessage());
  15. }
  16. }) {
  17. @Override
  18. protected Map<String, String> getParams() {
  19. Map<String, String> params = new HashMap<>();
  20. params.put("user_id", "52");
  21. params.put("type", "5");
  22. params.put("requested_id", "154");
  23. printLog(TAG, "459 : getParams: " + params);
  24. return params;
  25. }
  26. @Override
  27. protected Map<String, DataPart> getByteData() {
  28. Map<String, DataPart> params = new HashMap<>();
  29. long name = System.currentTimeMillis();
  30. Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.placeholderr);
  31. Bitmap bitmap = scaleDown((imageBitmap), 500, true);
  32. params.put("image_front_building1[0]", new DataPart(name + ".png", getBitmapAsByteArray(bitmap)));
  33. params.put("image_front_building1[1]", new DataPart(name + ".png", getBitmapAsByteArray(bitmap)));
  34. printLog(TAG, "72 : getByteData: " + params);
  35. return params;
  36. }
  37. /*@Override
  38. public Map<String, String> getHeaders() throws AuthFailureError {
  39. HashMap<String, String> headers = new HashMap<String, String>();
  40. headers.put(GrupKeys.AUTH_KEY, GrupKeys.AUTH_VALUE);
  41. headers.put(GrupKeys.CONTENT_TYPE_KEY, GrupKeys.CONTENT_TYPE_VALUE);
  42. return headers;
  43. }*/
  44. };
  45. volleyMultipartRequest.setShouldCache(false);
  46. volleyMultipartRequest.setTag(TAG);
  47. // volleyMultipartRequest.setRetryPolicy(new DefaultRetryPolicy(1990000000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  48. volleyMultipartRequest.setRetryPolicy(new DefaultRetryPolicy(1990000000, 10, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  49. AppController.getInstance().addToRequestQueue(volleyMultipartRequest);
  50. }
  51.  
  52. public byte[] getBitmapAsByteArray(Bitmap bitmap) {
  53. if (bitmap != null) {
  54. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  55. bitmap.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
  56. return outputStream.toByteArray();
  57. } else {
  58. byte[] emptyArray = new byte[0];
  59. return emptyArray;
  60. }
  61. }
  62.  
  63. public static Bitmap scaleDown(Bitmap realImage, float maxImageSize, boolean filter) {
  64. float ratio = Math.min(
  65. maxImageSize / realImage.getWidth(),
  66. maxImageSize / realImage.getHeight());
  67. int width = Math.round(ratio * realImage.getWidth());
  68. int height = Math.round(ratio * realImage.getHeight());
  69.  
  70. Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width, height, filter);
  71. return newBitmap;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement