Search in sources :

Example 51 with AnalyticsListener

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

the class RxApiTestActivity method downloadImage.

public void downloadImage(final View view) {
    String url = "http://i.imgur.com/AtbX9iX.png";
    RxAndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "image1.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);
        }
    }).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) ANError(com.androidnetworking.error.ANError)

Aggregations

AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)51 ANError (com.androidnetworking.error.ANError)42 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