Search in sources :

Example 1 with LiveUploadOperationListener

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();
                }
            });
        }
    }
}
Also used : JSONObject(org.json.JSONObject) DialogInterface(android.content.DialogInterface) LiveOperation(com.microsoft.live.LiveOperation) LiveUploadOperationListener(com.microsoft.live.LiveUploadOperationListener) ProgressDialog(android.app.ProgressDialog) LiveOperationException(com.microsoft.live.LiveOperationException) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 LiveOperation (com.microsoft.live.LiveOperation)1 LiveOperationException (com.microsoft.live.LiveOperationException)1 LiveUploadOperationListener (com.microsoft.live.LiveUploadOperationListener)1 File (java.io.File)1 JSONObject (org.json.JSONObject)1