use of com.microsoft.live.LiveUploadOperationListener in project LiveSDK-for-Android by liveservices.
the class SkyDriveActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FilePicker.PICK_FILE_REQUEST) {
if (resultCode == RESULT_OK) {
String filePath = data.getStringExtra(FilePicker.EXTRA_FILE_PATH);
if (TextUtils.isEmpty(filePath)) {
showToast("No file was choosen.");
return;
}
File file = new File(filePath);
final ProgressDialog uploadProgressDialog = new ProgressDialog(SkyDriveActivity.this);
uploadProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
uploadProgressDialog.setMessage("Uploading...");
uploadProgressDialog.setCancelable(true);
uploadProgressDialog.show();
final LiveOperation operation = mClient.uploadAsync(mCurrentFolderId, file.getName(), file, new LiveUploadOperationListener() {
@Override
public void onUploadProgress(int totalBytes, int bytesRemaining, LiveOperation operation) {
int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining);
uploadProgressDialog.setProgress(percentCompleted);
}
@Override
public void onUploadFailed(LiveOperationException exception, LiveOperation operation) {
uploadProgressDialog.dismiss();
showToast(exception.getMessage());
}
@Override
public void onUploadCompleted(LiveOperation operation) {
uploadProgressDialog.dismiss();
JSONObject result = operation.getResult();
if (result.has(JsonKeys.ERROR)) {
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
String message = error.optString(JsonKeys.MESSAGE);
String code = error.optString(JsonKeys.CODE);
showToast(code + ": " + message);
return;
}
loadFolder(mCurrentFolderId);
}
});
uploadProgressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
operation.cancel();
}
});
}
}
}
Aggregations