Search in sources :

Example 6 with AnalyticsListener

use of com.androidnetworking.interfaces.AnalyticsListener in project Fast-Android-Networking by amitshekhariitbhu.

the class OkHttpResponseTestActivity method downloadImage.

public void downloadImage(final View view) {
    String url = "http://i.imgur.com/AtbX9iX.png";
    AndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "image1.png").setPriority(Priority.MEDIUM).setTag(this).build().setAnalyticsListener(new AnalyticsListener() {

        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
            Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
            Log.d(TAG, " bytesSent : " + bytesSent);
            Log.d(TAG, " bytesReceived : " + bytesReceived);
            Log.d(TAG, " isFromCache : " + isFromCache);
        }
    }).startDownload(new DownloadListener() {

        @Override
        public void onDownloadComplete() {
            Log.d(TAG, "Image download Completed");
            Log.d(TAG, "onDownloadComplete isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }

        @Override
        public void onError(ANError error) {
            if (error.getErrorCode() != 0) {
                // received ANError from server
                // error.getErrorCode() - the ANError code from server
                // error.getErrorBody() - the ANError body from server
                // error.getErrorDetail() - just a ANError detail
                Log.d(TAG, "onError errorCode : " + error.getErrorCode());
                Log.d(TAG, "onError errorBody : " + error.getErrorBody());
                Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
            } else {
                // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
            }
        }
    });
}
Also used : AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) DownloadListener(com.androidnetworking.interfaces.DownloadListener) ANError(com.androidnetworking.error.ANError)

Example 7 with AnalyticsListener

use of com.androidnetworking.interfaces.AnalyticsListener in project Fast-Android-Networking by amitshekhariitbhu.

the class RxApiTestActivity method downloadFile.

public void downloadFile(final View view) {
    String url = "http://www.colorado.edu/conflict/peace/download/peace_problem.ZIP";
    RxAndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "file1.zip").build().setAnalyticsListener(new AnalyticsListener() {

        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
            Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
            Log.d(TAG, " bytesSent : " + bytesSent);
            Log.d(TAG, " bytesReceived : " + bytesReceived);
            Log.d(TAG, " isFromCache : " + isFromCache);
        }
    }).setDownloadProgressListener(new DownloadProgressListener() {

        @Override
        public void onProgress(long bytesDownloaded, long totalBytes) {
            Log.d(TAG, "bytesDownloaded : " + bytesDownloaded + " totalBytes : " + totalBytes);
            Log.d(TAG, "setDownloadProgressListener isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }
    }).getDownloadObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {

        @Override
        public void onCompleted() {
            Log.d(TAG, "File download Completed");
            Log.d(TAG, "onDownloadComplete isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }

        @Override
        public void onError(Throwable e) {
            if (e instanceof ANError) {
                ANError anError = (ANError) e;
                if (anError.getErrorCode() != 0) {
                    // received ANError from server
                    // error.getErrorCode() - the ANError code from server
                    // error.getErrorBody() - the ANError body from server
                    // error.getErrorDetail() - just a ANError detail
                    Log.d(TAG, "onError errorCode : " + anError.getErrorCode());
                    Log.d(TAG, "onError errorBody : " + anError.getErrorBody());
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                } else {
                    // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                }
            } else {
                Log.d(TAG, "onError errorMessage : " + e.getMessage());
            }
        }

        @Override
        public void onNext(String s) {
            Log.d(TAG, "onNext : " + s);
        }
    });
}
Also used : AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) DownloadProgressListener(com.androidnetworking.interfaces.DownloadProgressListener) ANError(com.androidnetworking.error.ANError)

Example 8 with AnalyticsListener

use of com.androidnetworking.interfaces.AnalyticsListener in project Fast-Android-Networking by amitshekhariitbhu.

the class RxApiTestActivity method uploadImage.

public void uploadImage(final View view) {
    RxAndroidNetworking.upload(ApiEndPoint.BASE_URL + ApiEndPoint.UPLOAD_IMAGE).addMultipartFile("image", new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "test.png")).build().setAnalyticsListener(new AnalyticsListener() {

        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
            Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
            Log.d(TAG, " bytesSent : " + bytesSent);
            Log.d(TAG, " bytesReceived : " + bytesReceived);
            Log.d(TAG, " isFromCache : " + isFromCache);
        }
    }).setUploadProgressListener(new UploadProgressListener() {

        @Override
        public void onProgress(long bytesUploaded, long totalBytes) {
            Log.d(TAG, "bytesUploaded : " + bytesUploaded + " totalBytes : " + totalBytes);
            Log.d(TAG, "setUploadProgressListener isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }
    }).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<JSONObject>() {

        @Override
        public void onCompleted() {
            Log.d(TAG, "onComplete Detail : uploadImage completed");
        }

        @Override
        public void onError(Throwable e) {
            if (e instanceof ANError) {
                ANError anError = (ANError) e;
                if (anError.getErrorCode() != 0) {
                    // received ANError from server
                    // error.getErrorCode() - the ANError code from server
                    // error.getErrorBody() - the ANError body from server
                    // error.getErrorDetail() - just a ANError detail
                    Log.d(TAG, "onError errorCode : " + anError.getErrorCode());
                    Log.d(TAG, "onError errorBody : " + anError.getErrorBody());
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                } else {
                    // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                }
            } else {
                Log.d(TAG, "onError errorMessage : " + e.getMessage());
            }
        }

        @Override
        public void onNext(JSONObject response) {
            Log.d(TAG, "Image upload Completed");
            Log.d(TAG, "onResponse object : " + response.toString());
        }
    });
}
Also used : UploadProgressListener(com.androidnetworking.interfaces.UploadProgressListener) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) JSONObject(org.json.JSONObject) ANError(com.androidnetworking.error.ANError) File(java.io.File)

Example 9 with AnalyticsListener

use of com.androidnetworking.interfaces.AnalyticsListener in project Fast-Android-Networking by amitshekhariitbhu.

the class RxApiTestActivity method checkForHeaderGet.

public void checkForHeaderGet(View view) {
    RxANRequest.GetRequestBuilder getRequestBuilder = new RxANRequest.GetRequestBuilder(ApiEndPoint.BASE_URL + ApiEndPoint.CHECK_FOR_HEADER);
    getRequestBuilder.addHeaders("token", "1234").build().setAnalyticsListener(new AnalyticsListener() {

        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
            Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
            Log.d(TAG, " bytesSent : " + bytesSent);
            Log.d(TAG, " bytesReceived : " + bytesReceived);
            Log.d(TAG, " isFromCache : " + isFromCache);
        }
    }).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<JSONObject>() {

        @Override
        public void onCompleted() {
            Log.d(TAG, "onComplete Detail : checkForHeaderGet completed");
        }

        @Override
        public void onError(Throwable e) {
            if (e instanceof ANError) {
                ANError anError = (ANError) e;
                if (anError.getErrorCode() != 0) {
                    // received ANError from server
                    // error.getErrorCode() - the ANError code from server
                    // error.getErrorBody() - the ANError body from server
                    // error.getErrorDetail() - just a ANError detail
                    Log.d(TAG, "onError errorCode : " + anError.getErrorCode());
                    Log.d(TAG, "onError errorBody : " + anError.getErrorBody());
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                } else {
                    // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                }
            } else {
                Log.d(TAG, "onError errorMessage : " + e.getMessage());
            }
        }

        @Override
        public void onNext(JSONObject response) {
            Log.d(TAG, "onResponse object : " + response.toString());
            Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }
    });
}
Also used : AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) JSONObject(org.json.JSONObject) ANError(com.androidnetworking.error.ANError) RxANRequest(com.rxandroidnetworking.RxANRequest)

Example 10 with AnalyticsListener

use of com.androidnetworking.interfaces.AnalyticsListener in project Fast-Android-Networking by amitshekhariitbhu.

the class RxApiTestActivity method createAnUserJSONObject.

public void createAnUserJSONObject(View view) {
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("firstname", "Rohit");
        jsonObject.put("lastname", "Kumar");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    RxAndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addJSONObjectBody(jsonObject).build().setAnalyticsListener(new AnalyticsListener() {

        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
            Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
            Log.d(TAG, " bytesSent : " + bytesSent);
            Log.d(TAG, " bytesReceived : " + bytesReceived);
            Log.d(TAG, " isFromCache : " + isFromCache);
        }
    }).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<JSONObject>() {

        @Override
        public void onCompleted() {
            Log.d(TAG, "onComplete Detail : createAnUserJSONObject completed");
        }

        @Override
        public void onError(Throwable e) {
            if (e instanceof ANError) {
                ANError anError = (ANError) e;
                if (anError.getErrorCode() != 0) {
                    // received ANError from server
                    // error.getErrorCode() - the ANError code from server
                    // error.getErrorBody() - the ANError body from server
                    // error.getErrorDetail() - just a ANError detail
                    Log.d(TAG, "onError errorCode : " + anError.getErrorCode());
                    Log.d(TAG, "onError errorBody : " + anError.getErrorBody());
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                } else {
                    // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                    Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
                }
            } else {
                Log.d(TAG, "onError errorMessage : " + e.getMessage());
            }
        }

        @Override
        public void onNext(JSONObject response) {
            Log.d(TAG, "onResponse object : " + response.toString());
            Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }
    });
}
Also used : AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ANError(com.androidnetworking.error.ANError)

Aggregations

AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)51 ANError (com.androidnetworking.error.ANError)49 JSONObject (org.json.JSONObject)23 ANResponse (com.androidnetworking.common.ANResponse)15 Response (okhttp3.Response)15 JSONArray (org.json.JSONArray)11 DownloadProgressListener (com.androidnetworking.interfaces.DownloadProgressListener)10 DownloadListener (com.androidnetworking.interfaces.DownloadListener)8 JSONObjectRequestListener (com.androidnetworking.interfaces.JSONObjectRequestListener)7 Disposable (io.reactivex.disposables.Disposable)7 ANRequest (com.androidnetworking.common.ANRequest)6 JSONArrayRequestListener (com.androidnetworking.interfaces.JSONArrayRequestListener)6 OkHttpResponseAndJSONObjectRequestListener (com.androidnetworking.interfaces.OkHttpResponseAndJSONObjectRequestListener)6 UploadProgressListener (com.androidnetworking.interfaces.UploadProgressListener)6 File (java.io.File)6 JSONException (org.json.JSONException)6 OkHttpResponseAndJSONArrayRequestListener (com.androidnetworking.interfaces.OkHttpResponseAndJSONArrayRequestListener)5 IOException (java.io.IOException)4 OkHttpClient (okhttp3.OkHttpClient)4 Bitmap (android.graphics.Bitmap)3