本文整理汇总了Java中com.androidnetworking.error.ANError类的典型用法代码示例。如果您正苦于以下问题:Java ANError类的具体用法?Java ANError怎么用?Java ANError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ANError类属于com.androidnetworking.error包,在下文中一共展示了ANError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logError
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public static void logError(String TAG, 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());
}
}
示例2: getImageListener
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public static ImageListener getImageListener(final ImageView view,
final int defaultImageResId,
final int errorImageResId) {
return new ImageListener() {
@Override
public void onResponse(ImageContainer response, boolean isImmediate) {
if (response.getBitmap() != null) {
view.setImageBitmap(response.getBitmap());
} else if (defaultImageResId != 0) {
view.setImageResource(defaultImageResId);
}
}
@Override
public void onError(ANError anError) {
if (errorImageResId != 0) {
view.setImageResource(errorImageResId);
}
}
};
}
示例3: testStringGetRequest
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testStringGetRequest() throws InterruptedException {
server.enqueue(new MockResponse().setBody("data"));
final AtomicReference<String> responseRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.get(server.url("/").toString())
.build()
.getAsString(new StringRequestListener() {
@Override
public void onResponse(String response) {
responseRef.set(response);
latch.countDown();
}
@Override
public void onError(ANError anError) {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals("data", responseRef.get());
}
示例4: testResponseBodyAndObjectPost404
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testResponseBodyAndObjectPost404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.setExecutor(Executors.newSingleThreadExecutor())
.build()
.getAsOkHttpResponseAndObject(User.class,
new OkHttpResponseAndParsedRequestListener<User>() {
@Override
public void onResponse(Response okHttpResponse, User user) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
示例5: testResponseBodyAndJSONObjectMultipart
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testResponseBodyAndJSONObjectMultipart() throws InterruptedException {
server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final AtomicReference<Boolean> responseBodySuccess = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.upload(server.url("/").toString())
.addMultipartParameter("key", "value")
.setExecutor(Executors.newSingleThreadExecutor())
.build()
.getAsOkHttpResponseAndJSONObject(new OkHttpResponseAndJSONObjectRequestListener() {
@Override
public void onResponse(Response okHttpResponse, JSONObject response) {
try {
firstNameRef.set(response.getString("firstName"));
lastNameRef.set(response.getString("lastName"));
responseBodySuccess.set(okHttpResponse.isSuccessful());
latch.countDown();
} catch (JSONException e) {
assertTrue(false);
}
}
@Override
public void onError(ANError anError) {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(responseBodySuccess.get());
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
示例6: onDrawerOptionLogoutClick
import com.androidnetworking.error.ANError; //导入依赖的package包/类
@Override
public void onDrawerOptionLogoutClick() {
getMvpView().showLoading();
getCompositeDisposable().add(getDataManager().doLogoutApiCall()
.subscribeOn(getSchedulerProvider().io())
.observeOn(getSchedulerProvider().ui())
.subscribe(new Consumer<LogoutResponse>() {
@Override
public void accept(LogoutResponse response) throws Exception {
if (!isViewAttached()) {
return;
}
getDataManager().setUserAsLoggedOut();
getMvpView().hideLoading();
getMvpView().openLoginActivity();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!isViewAttached()) {
return;
}
getMvpView().hideLoading();
// handle the login error here
if (throwable instanceof ANError) {
ANError anError = (ANError) throwable;
handleApiError(anError);
}
}
}));
}
示例7: testObjectGetRequest
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testObjectGetRequest() throws InterruptedException {
server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.get(server.url("/").toString())
.build()
.getAsObject(User.class, new ParsedRequestListener<User>() {
@Override
public void onResponse(User user) {
firstNameRef.set(user.firstName);
lastNameRef.set(user.lastName);
latch.countDown();
}
@Override
public void onError(ANError anError) {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
示例8: testObjectListGetRequest404
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testObjectListGetRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.get(server.url("/").toString())
.build()
.getAsObjectList(User.class, new ParsedRequestListener<List<User>>() {
@Override
public void onResponse(List<User> userList) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
示例9: testJSONArrayGetRequest404
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testJSONArrayGetRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.get(server.url("/").toString())
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
示例10: getAllUsers
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void getAllUsers(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setTag(this)
.setPriority(Priority.LOW)
.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);
}
})
.getAsObjectList(User.class, new ParsedRequestListener<List<User>>() {
@Override
public void onResponse(List<User> users) {
Log.d(TAG, "userList size : " + users.size());
for (User user : users) {
Log.d(TAG, "id : " + user.id);
Log.d(TAG, "firstname : " + user.firstname);
Log.d(TAG, "lastname : " + user.lastname);
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
示例11: makeJSONArrayRequest
import com.androidnetworking.error.ANError; //导入依赖的package包/类
private void makeJSONArrayRequest() {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.setTag(this)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setPriority(Priority.LOW)
.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);
}
})
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, "onResponse array : " + response.toString());
}
@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());
}
}
});
}
示例12: testResponseBodyAndObjectGet404
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testResponseBodyAndObjectGet404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.get(server.url("/").toString())
.setExecutor(Executors.newSingleThreadExecutor())
.build()
.getAsOkHttpResponseAndObject(User.class,
new OkHttpResponseAndParsedRequestListener<User>() {
@Override
public void onResponse(Response okHttpResponse, User user) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
示例13: testStringPostRequest404
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testStringPostRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.build()
.getAsString(new StringRequestListener() {
@Override
public void onResponse(String response) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
示例14: getErrorForNetworkOnMainThreadOrConnection
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public static ANError getErrorForNetworkOnMainThreadOrConnection(Exception e) {
ANError error = new ANError(e);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
&& e instanceof NetworkOnMainThreadException) {
error.setErrorDetail(ANConstants.NETWORK_ON_MAIN_THREAD_ERROR);
} else {
error.setErrorDetail(ANConstants.CONNECTION_ERROR);
}
error.setErrorCode(0);
return error;
}
示例15: testObjectPostRequest404
import com.androidnetworking.error.ANError; //导入依赖的package包/类
public void testObjectPostRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.build()
.getAsObject(User.class, new ParsedRequestListener<User>() {
@Override
public void onResponse(User user) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}