Search in sources :

Example 1 with AnalyticsListener

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

the class Rx2ApiTestActivity method checkForHeaderPost.

public void checkForHeaderPost(View view) {
    Rx2ANRequest.PostRequestBuilder postRequestBuilder = Rx2AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.CHECK_FOR_HEADER);
    postRequestBuilder.addHeaders("token", "1234");
    Rx2ANRequest 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.getJSONObjectSingle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<JSONObject>() {

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

        @Override
        public void onSuccess(@NonNull JSONObject jsonObject) {
            Log.d(TAG, "onResponse object : " + jsonObject.toString());
            Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }

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

Example 2 with AnalyticsListener

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

the class Rx2ApiTestActivity 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();
    }
    Rx2AndroidNetworking.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);
        }
    }).getJSONObjectSingle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<JSONObject>() {

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

        @Override
        public void onSuccess(@NonNull JSONObject jsonObject) {
            Log.d(TAG, "onResponse object : " + jsonObject.toString());
            Log.d(TAG, "onResponse 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) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 3 with AnalyticsListener

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

the class Rx2ApiTestActivity method checkForHeaderGet.

public void checkForHeaderGet(View view) {
    Rx2ANRequest.GetRequestBuilder getRequestBuilder = new Rx2ANRequest.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);
        }
    }).getJSONObjectSingle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<JSONObject>() {

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

        @Override
        public void onSuccess(@NonNull JSONObject jsonObject) {
            Log.d(TAG, "onResponse object : " + jsonObject.toString());
            Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
        }

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

Example 4 with AnalyticsListener

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

the class Rx2ApiTestActivity method uploadImage.

public void uploadImage(final View view) {
    Single<JSONObject> single = Rx2AndroidNetworking.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()));
        }
    }).getJSONObjectSingle();
    single.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<JSONObject>() {

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

        @Override
        public void onSuccess(@NonNull JSONObject jsonObject) {
            Log.d(TAG + "_1", "Image upload Completed");
            Log.d(TAG + "_1", "onResponse object : " + jsonObject.toString());
        }

        @Override
        public void onError(@NonNull Throwable throwable) {
            Utils.logError(TAG, throwable);
        }
    });
    single.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<JSONObject>() {

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

        @Override
        public void onSuccess(@NonNull JSONObject jsonObject) {
            Log.d(TAG + "_2", "Image upload Completed");
            Log.d(TAG + "_2", "onResponse object : " + jsonObject.toString());
        }

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

Example 5 with AnalyticsListener

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

the class ApiTestActivity method checkCacheForCustomClient.

public void checkCacheForCustomClient(View view) {
    String url = "http://www.colorado.edu/conflict/peace/download/peace_problem.ZIP";
    AndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "file1.zip").setPriority(Priority.HIGH).setTag(this).setOkHttpClient(new OkHttpClient()).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()));
        }
    }).startDownload(new DownloadListener() {

        @Override
        public void onDownloadComplete() {
            Log.d(TAG, "File 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 an 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 : OkHttpClient(okhttp3.OkHttpClient) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) DownloadProgressListener(com.androidnetworking.interfaces.DownloadProgressListener) DownloadListener(com.androidnetworking.interfaces.DownloadListener) 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