Search in sources :

Example 46 with AnalyticsListener

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

the class Rx2ApiTestActivity method downloadFile.

public void downloadFile(final View view) {
    String url = "http://www.colorado.edu/conflict/peace/download/peace_problem.ZIP";
    Rx2AndroidNetworking.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()));
        }
    }).getDownloadCompletable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new CompletableObserver() {

        @Override
        public void onSubscribe(@NonNull Disposable disposable) {
        }

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

        @Override
        public void onError(@NonNull Throwable throwable) {
            Utils.logError(TAG, throwable);
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) DownloadProgressListener(com.androidnetworking.interfaces.DownloadProgressListener) CompletableObserver(io.reactivex.CompletableObserver)

Example 47 with AnalyticsListener

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

the class Rx2ApiTestActivity method loadImage.

public void loadImage(View view) {
    final String URL_IMAGE = "http://i.imgur.com/2M7Hasn.png";
    Rx2AndroidNetworking.get(URL_IMAGE).setImageScaleType(null).setBitmapMaxHeight(0).setBitmapMaxWidth(0).setBitmapConfig(Bitmap.Config.ARGB_8888).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);
        }
    }).getBitmapSingle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<Bitmap>() {

        @Override
        public void onSubscribe(@NonNull Disposable disposable) {
        }

        @Override
        public void onSuccess(@NonNull Bitmap bitmap) {
            Log.d(TAG, "onResponse Bitmap");
            ImageView imageView = findViewById(R.id.imageView);
            imageView.setImageBitmap(bitmap);
        }

        @Override
        public void onError(@NonNull Throwable throwable) {
            Utils.logError(TAG, throwable);
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) Bitmap(android.graphics.Bitmap) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) ImageView(android.widget.ImageView)

Example 48 with AnalyticsListener

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

the class Rx2ApiTestActivity method downloadImage.

public void downloadImage(final View view) {
    String url = "http://i.imgur.com/AtbX9iX.png";
    Rx2AndroidNetworking.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);
        }
    }).getDownloadCompletable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new CompletableObserver() {

        @Override
        public void onSubscribe(@NonNull Disposable disposable) {
        }

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

        @Override
        public void onError(@NonNull Throwable throwable) {
            Utils.logError(TAG, throwable);
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) CompletableObserver(io.reactivex.CompletableObserver)

Example 49 with AnalyticsListener

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

the class RxApiTestActivity method checkForHeaderPost.

public void checkForHeaderPost(View view) {
    RxANRequest.PostRequestBuilder postRequestBuilder = RxAndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.CHECK_FOR_HEADER);
    postRequestBuilder.addHeaders("token", "1234");
    RxANRequest rxAnRequest = postRequestBuilder.setTag(this).build();
    rxAnRequest.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);
        }
    });
    rxAnRequest.getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<JSONObject>() {

        @Override
        public void onCompleted() {
            Log.d(TAG, "onComplete Detail : checkForHeaderPost 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 50 with AnalyticsListener

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

the class RxApiTestActivity method loadImage.

public void loadImage(View view) {
    final String URL_IMAGE = "http://i.imgur.com/2M7Hasn.png";
    RxAndroidNetworking.get(URL_IMAGE).setImageScaleType(null).setBitmapMaxHeight(0).setBitmapMaxWidth(0).setBitmapConfig(Bitmap.Config.ARGB_8888).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);
        }
    }).getBitmapObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() {

        @Override
        public void onCompleted() {
            Log.d(TAG, "onComplete Bitmap");
        }

        @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(Bitmap bitmap) {
            Log.d(TAG, "onResponse Bitmap");
            ImageView imageView = (ImageView) findViewById(R.id.imageView);
            imageView.setImageBitmap(bitmap);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) ANError(com.androidnetworking.error.ANError) ImageView(android.widget.ImageView)

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