Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void exeCuteApi() {
- printLog(TAG, "46 : exeCuteApi: " + API);
- VolleyMultipartRequest volleyMultipartRequest = new VolleyMultipartRequest(Request.Method.POST, API,
- new Response.Listener<NetworkResponse>() {
- @Override
- public void onResponse(NetworkResponse response) {
- String resultResponse = new String(response.data);
- printLog(TAG, "218 : onResponse: " + resultResponse);
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- printLog(TAG, "253 : onErrorResponse: " + error.getMessage());
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- Map<String, String> params = new HashMap<>();
- params.put("user_id", "52");
- params.put("type", "5");
- params.put("requested_id", "154");
- printLog(TAG, "459 : getParams: " + params);
- return params;
- }
- @Override
- protected Map<String, DataPart> getByteData() {
- Map<String, DataPart> params = new HashMap<>();
- long name = System.currentTimeMillis();
- Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.placeholderr);
- Bitmap bitmap = scaleDown((imageBitmap), 500, true);
- params.put("image_front_building1[0]", new DataPart(name + ".png", getBitmapAsByteArray(bitmap)));
- params.put("image_front_building1[1]", new DataPart(name + ".png", getBitmapAsByteArray(bitmap)));
- printLog(TAG, "72 : getByteData: " + params);
- return params;
- }
- /*@Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- HashMap<String, String> headers = new HashMap<String, String>();
- headers.put(GrupKeys.AUTH_KEY, GrupKeys.AUTH_VALUE);
- headers.put(GrupKeys.CONTENT_TYPE_KEY, GrupKeys.CONTENT_TYPE_VALUE);
- return headers;
- }*/
- };
- volleyMultipartRequest.setShouldCache(false);
- volleyMultipartRequest.setTag(TAG);
- // volleyMultipartRequest.setRetryPolicy(new DefaultRetryPolicy(1990000000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
- volleyMultipartRequest.setRetryPolicy(new DefaultRetryPolicy(1990000000, 10, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
- AppController.getInstance().addToRequestQueue(volleyMultipartRequest);
- }
- public byte[] getBitmapAsByteArray(Bitmap bitmap) {
- if (bitmap != null) {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
- return outputStream.toByteArray();
- } else {
- byte[] emptyArray = new byte[0];
- return emptyArray;
- }
- }
- public static Bitmap scaleDown(Bitmap realImage, float maxImageSize, boolean filter) {
- float ratio = Math.min(
- maxImageSize / realImage.getWidth(),
- maxImageSize / realImage.getHeight());
- int width = Math.round(ratio * realImage.getWidth());
- int height = Math.round(ratio * realImage.getHeight());
- Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width, height, filter);
- return newBitmap;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement