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);
}
});
}
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);
}
});
}
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);
}
});
}
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);
}
});
}
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());
}
}
});
}
Aggregations