use of com.loopj.android.http.AsyncHttpClient in project KLog by ZhaoKaiQiang.
the class MainActivity method initData.
private void initData() {
httpClient = new AsyncHttpClient();
JSON_LONG = getResources().getString(R.string.json_long);
JSON = getResources().getString(R.string.json);
STRING_LONG = getString(R.string.string_long);
}
use of com.loopj.android.http.AsyncHttpClient in project xabber-android by redsolution.
the class HttpFileUploadManager method uploadFile.
public void uploadFile(final String account, final String user, final String filePath) {
final String uploadServerUrl = uploadServers.get(account);
if (uploadServerUrl == null) {
return;
}
final File file = new File(filePath);
final Request httpFileUpload = new Request();
httpFileUpload.setFilename(file.getName());
httpFileUpload.setSize(String.valueOf(file.length()));
httpFileUpload.setTo(uploadServerUrl);
try {
ConnectionManager.getInstance().sendRequest(account, httpFileUpload, new OnResponseListener() {
@Override
public void onReceived(final String account, String packetId, IQ iq) {
if (!httpFileUpload.getStanzaId().equals(packetId) || !(iq instanceof Slot)) {
return;
}
uploadFileToSlot(account, (Slot) iq);
}
private void uploadFileToSlot(final String account, final Slot slot) {
AsyncHttpClient client = new AsyncHttpClient();
client.setLoggingEnabled(SettingsManager.debugLog());
client.setResponseTimeout(60 * 1000);
FileEntity fileEntity = new FileEntity(file, ContentType.DEFAULT_BINARY);
LogManager.i(this, "fileEntity.getContentLength() " + fileEntity.getContentLength());
client.put(Application.getInstance(), slot.getPutUrl(), fileEntity, CONTENT_TYPE, new AsyncHttpResponseHandler() {
MessageItem fileMessage;
@Override
public void onStart() {
super.onStart();
LogManager.i(this, "uploadFileToSlot onStart");
fileMessage = MessageManager.getInstance().createFileMessage(account, user, file);
}
@Override
public void onSuccess(int i, Header[] headers, byte[] bytes) {
LogManager.i(this, "uploadFileToSlot onSuccess " + i);
MessageManager.getInstance().replaceMessage(account, user, fileMessage, slot.getGetUrl());
if (FileManager.fileIsImage(file)) {
saveImageToCache(slot.getGetUrl(), file);
}
}
@Override
public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
LogManager.i(this, "uploadFileToSlot onFailure " + i);
MessageManager.getInstance().updateMessageWithError(account, user, fileMessage, file.getName());
}
@Override
public void onRetry(int retryNo) {
super.onRetry(retryNo);
LogManager.i(this, "uploadFileToSlot onRetry " + retryNo);
}
@Override
public void onCancel() {
super.onCancel();
LogManager.i(this, "uploadFileToSlot onCancel");
}
@Override
public void onFinish() {
super.onFinish();
LogManager.i(this, "uploadFileToSlot onFinish");
}
});
}
@Override
public void onError(String account, String packetId, IQ iq) {
LogManager.i(this, "On HTTP file upload slot error");
Application.getInstance().onError(R.string.http_file_upload_slot_error);
}
@Override
public void onTimeout(String account, String packetId) {
}
@Override
public void onDisconnect(String account, String packetId) {
}
});
} catch (NetworkException e) {
e.printStackTrace();
}
}
use of com.loopj.android.http.AsyncHttpClient in project xabber-android by redsolution.
the class FileManager method downloadFile.
public void downloadFile(final MessageItem messageItem, final ProgressListener progressListener) {
final String downloadUrl = messageItem.getText();
if (startedDownloads.contains(downloadUrl)) {
LogManager.i(FileManager.class, "Downloading of file " + downloadUrl + " already started");
return;
}
LogManager.i(FileManager.class, "Downloading file " + downloadUrl);
startedDownloads.add(downloadUrl);
final AsyncHttpClient client = new AsyncHttpClient();
client.setLoggingEnabled(SettingsManager.debugLog());
client.setResponseTimeout(60 * 1000);
client.get(downloadUrl, new AsyncHttpResponseHandler() {
@Override
public void onStart() {
super.onStart();
LogManager.i(FileManager.class, "on download start");
}
@Override
public void onSuccess(int statusCode, Header[] headers, final byte[] responseBody) {
LogManager.i(FileManager.class, "on download onSuccess: " + statusCode);
saveFile(responseBody, messageItem.getFile(), progressListener);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
LogManager.i(FileManager.class, "on download onFailure: " + statusCode);
}
@Override
public void onProgress(long bytesWritten, long totalSize) {
if (progressListener != null) {
progressListener.onProgress(bytesWritten, totalSize);
}
}
@Override
public void onFinish() {
super.onFinish();
startedDownloads.remove(downloadUrl);
}
});
}
use of com.loopj.android.http.AsyncHttpClient in project android-async-http by loopj.
the class Redirect302Sample method getAsyncHttpClient.
@Override
public AsyncHttpClient getAsyncHttpClient() {
AsyncHttpClient ahc = super.getAsyncHttpClient();
HttpClient client = ahc.getHttpClient();
if (client instanceof DefaultHttpClient) {
Toast.makeText(this, String.format("redirects: %b\nrelative redirects: %b\ncircular redirects: %b", enableRedirects, enableRelativeRedirects, enableCircularRedirects), Toast.LENGTH_SHORT).show();
ahc.setEnableRedirects(enableRedirects, enableRelativeRedirects, enableCircularRedirects);
}
return ahc;
}
use of com.loopj.android.http.AsyncHttpClient in project android-sex-http by dtboy1995.
the class HTTPUtil method setPorts.
public static void setPorts(int httpPort, int httpsPort) {
HTTP_PORT = httpPort;
HTTPS_PORT = httpsPort;
client = new AsyncHttpClient(true, HTTP_PORT, HTTPS_PORT);
client.setURLEncodingEnabled(false);
}
Aggregations