本文整理汇总了Java中com.loopj.android.http.ResponseHandlerInterface类的典型用法代码示例。如果您正苦于以下问题:Java ResponseHandlerInterface类的具体用法?Java ResponseHandlerInterface怎么用?Java ResponseHandlerInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResponseHandlerInterface类属于com.loopj.android.http包,在下文中一共展示了ResponseHandlerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeSample
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) {
if (client instanceof SyncHttpClient) {
new Thread(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "Before Request");
client.get(SynchronousClientSample.this, URL, headers, null, responseHandler);
Log.d(LOG_TAG, "After Request");
}
}).start();
} else {
Log.e(LOG_TAG, "Error, not using SyncHttpClient");
}
/**
* SyncHttpClient does not return RequestHandle,
* it executes each request directly,
* therefore those requests are not in cancelable threads
* */
return null;
}
示例2: executeSample
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
RequestParams params = new RequestParams();
params.setUseJsonStreamer(true);
JSONObject body;
if (isRequestBodyAllowed() && (body = getBodyTextAsJSON()) != null) {
try {
Iterator keys = body.keys();
Log.d(LOG_TAG, "JSON data:");
while (keys.hasNext()) {
String key = (String) keys.next();
Log.d(LOG_TAG, " " + key + ": " + body.get(key));
params.put(key, body.get(key).toString());
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Unable to retrieve a JSON value", e);
}
}
return client.post(this, URL, headers, params,
RequestParams.APPLICATION_JSON, responseHandler);
}
示例3: executeSample
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) {
final Activity ctx = this;
FutureTask<RequestHandle> future = new FutureTask<>(new Callable<RequestHandle>() {
public RequestHandle call() {
Log.d(LOG_TAG, "Executing GET request on background thread");
return client.get(ctx, URL, headers, null, responseHandler);
}
});
executor.execute(future);
RequestHandle handle = null;
try {
handle = future.get(5, TimeUnit.SECONDS);
Log.d(LOG_TAG, "Background thread for GET request has finished");
} catch (Exception e) {
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return handle;
}
示例4: executeSample
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
RequestParams rParams = new RequestParams();
rParams.put("sample_key", "Sample String");
try {
File sample_file = File.createTempFile("temp_", "_handled", getCacheDir());
rParams.put("sample_file", sample_file);
} catch (IOException e) {
Log.e(LOG_TAG, "Cannot add sample file", e);
}
return client.post(this, URL, headers, rParams, "multipart/form-data", responseHandler);
}
示例5: executeSample
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
try {
RequestParams params = new RequestParams();
final String contentType = RequestParams.APPLICATION_OCTET_STREAM;
params.put("fileOne", createTempFile("fileOne", 1020), contentType, "fileOne");
params.put("fileTwo", createTempFile("fileTwo", 1030), contentType);
params.put("fileThree", createTempFile("fileThree", 1040), contentType, "customFileThree");
params.put("fileFour", createTempFile("fileFour", 1050), contentType);
params.put("fileFive", createTempFile("fileFive", 1060), contentType, "testingFileFive");
params.setHttpEntityIsRepeatable(true);
params.setUseJsonStreamer(false);
return client.post(this, URL, params, responseHandler);
} catch (FileNotFoundException fnfException) {
Log.e(LOG_TAG, "executeSample failed with FileNotFoundException", fnfException);
}
return null;
}
示例6: sendSubscription
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
public void sendSubscription(Subscription subscription) {
String interest = subscription.getInterest();
InterestSubscriptionChange change = subscription.getChange();
JSONObject json = new JSONObject();
try {
json.put("app_key", appKey);
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
}
StringEntity entity = new StringEntity(json.toString(), "UTF-8");
String url = options.buildNotificationURL("/clients/" + clientId + "/interests/" + interest);
ResponseHandlerInterface handler = factory.newSubscriptionChangeHandler(subscription);
AsyncHttpClient client = factory.newHttpClient();
switch (change) {
case SUBSCRIBE:
client.post(context, url, entity, "application/json", handler);
break;
case UNSUBSCRIBE:
client.delete(context, url, entity, "application/json", handler);
break;
}
}
示例7: postKonke
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
public static void postKonke(Context context, String url, String json, ResponseHandlerInterface callback) {
Header[] headers = new Header[3];
// Log.i("", "accesstoken:" + accessToken);
headers[0] = new BasicHeader("Authorization", "Bearer " + getAccessToken(context));
headers[1] = new BasicHeader("Content-Type", "application/json");
headers[2] = new BasicHeader("User-Agent", "imgfornote");
try {
StringEntity s = new StringEntity(json);
s.setContentEncoding("UTF-8");
s.setContentType("application/json");
Unit.httpClient.post(context, url, headers, s, "application/json", callback);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
示例8: HttpManager
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
private HttpManager(HttpConfig config) {
super();
CLIENT_HEADER_FIELD = ReflectUtil.getField(getClass(),
"clientHeaderMap");
CLIENT_HEADER_FIELD.setAccessible(true);
PARAMS_TO_ENTITY = ReflectUtil.getMethod(getClass(), "paramsToEntity",
RequestParams.class, ResponseHandlerInterface.class);
PARAMS_TO_ENTITY.setAccessible(true);
ADD_ENTITY_TO_REQUEST_ENTITY = ReflectUtil.getMethod(getClass(),
"addEntityToRequestBase", HttpEntityEnclosingRequestBase.class,
HttpEntity.class);
ADD_ENTITY_TO_REQUEST_ENTITY.setAccessible(true);
this.mHttpConfig = config;
final Map<String, String> headMap = config.getHeadMap();
if (headMap != null) {
getHeaders().putAll(headMap);
}
}
示例9: postScc
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
public void postScc(String url, ResponseHandlerInterface responseHandler,
Map<String, Object> pararms) {
RequestParams params = new RequestParams();
if (pararms != null) {
Iterator<Map.Entry<String, Object>> iter = pararms.entrySet()
.iterator();
while (iter.hasNext()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) iter
.next();
final String key = entry.getKey();
final Object val = entry.getValue();
if (val instanceof String || val instanceof Integer
|| val instanceof Long || val instanceof Short) {
params.put(key, String.valueOf(val));
} else {
params.put(key, GsonProvider.getInstance().toJson(val));
}
}
}
post(url, params, responseHandler);
}
示例10: call
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Nullable
private static RequestHandle call(int method, Context context, String url, RequestParams params, ResponseHandlerInterface responseHandler) {
if (NetWorkUtil.isNetWorkConnected(context)) {
switch (method) {
case METHOD_GET:
if (params == null) {
return getInstance().get(context, url, responseHandler);
} else {
return getInstance().get(context, url, params, responseHandler);
}
case METHOD_POST:
return getInstance().post(context, url, params, responseHandler);
default:
return null;
}
} else {
responseHandler.sendFailureMessage(FAILED_NO_NETWORK, null, null, new NetworkErrorException(MESSAGE_NO_NETWORK));
return null;
}
}
示例11: get
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
public void get(ResponseHandlerInterface callback) {
if (callback == null) {
DebugLog.e(TAG, "CALLBACK IS NULL");
return;
}
if (StringUtil.isEmpty(url)) {
DebugLog.e(TAG, "URL IS NULL");
return;
}
/*if (params != null) {
getClient().get(context, url, headers, params, callback);
} else */
if (contentType != null) {
getClient().get(context, url, entity, contentType, callback);
} else {
getClient().get(context, url, callback);
}
}
示例12: post
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
public void post(ResponseHandlerInterface callback) {
if (callback == null) {
DebugLog.e(TAG, "CALLBACK IS NULL");
return;
}
if (StringUtil.isEmpty(url)) {
DebugLog.e(TAG, "URL IS NULL");
return;
}
if (params != null) {
getClient().post(context, url, headers, params, contentType, callback);
} else if (entity != null) {
getClient().post(context, url, entity, contentType, callback);
} else {
getClient().post(url, callback);
}
DebugLog.e(TAG, url + "?" + params.toString());
}
示例13: sendRequest
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
protected RequestHandle sendRequest(
cz.msebera.android.httpclient.impl.client.DefaultHttpClient client,
cz.msebera.android.httpclient.protocol.HttpContext httpContext,
cz.msebera.android.httpclient.client.methods.HttpUriRequest uriRequest,
String contentType, ResponseHandlerInterface responseHandler,
Context context) {
if (this.service != null && accessToken != null) {
try {
ScribeRequestAdapter adapter = new ScribeRequestAdapter(uriRequest);
this.service.signRequest(accessToken, adapter);
return super.sendRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
} catch (Exception e) {
e.printStackTrace();
}
} else if (accessToken == null) {
throw new OAuthException("Cannot send unauthenticated requests for " + apiInstance.getClass().getSimpleName() + " client. Please attach an access token!");
} else { // service is null
throw new OAuthException("Cannot send unauthenticated requests for undefined service. Please specify a valid api service!");
}
return null; // Hopefully never reaches here
}
示例14: executeSample
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
Intent serviceCall = new Intent(this, ExampleIntentService.class);
serviceCall.putExtra(ExampleIntentService.INTENT_URL, URL);
startService(serviceCall);
return null;
}
示例15: newAsyncHttpRequest
import com.loopj.android.http.ResponseHandlerInterface; //导入依赖的package包/类
@Override
protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
AsyncHttpRequest httpRequest = getHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
return httpRequest == null
? super.newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context)
: httpRequest;
}