Search in sources :

Example 31 with LiveOperation

use of com.microsoft.live.LiveOperation in project LiveSDK-for-Android by liveservices.

the class UploadTest method testSyncResponseBodyValid.

@Override
public void testSyncResponseBodyValid() throws Exception {
    this.loadUploadLocationResponseBody();
    this.loadValidResponseBody();
    String requestPath = Paths.ME_SKYDRIVE;
    LiveOperation operation = this.liveConnectClient.upload(requestPath, FILENAME, FILE);
    this.checkOperationMembers(operation, getMethod(), requestPath);
    this.checkValidResponseBody(operation);
}
Also used : LiveOperation(com.microsoft.live.LiveOperation)

Example 32 with LiveOperation

use of com.microsoft.live.LiveOperation in project LiveSDK-for-Android by liveservices.

the class PutTest method testSyncResponseBodyValid.

@Override
public void testSyncResponseBodyValid() throws Exception {
    this.loadValidResponseBody();
    String requestPath = this.calendarId;
    LiveOperation operation = this.liveConnectClient.put(requestPath, CALENDAR);
    this.checkOperationMembers(operation, METHOD, requestPath);
    this.checkValidResponseBody(operation);
}
Also used : LiveOperation(com.microsoft.live.LiveOperation)

Example 33 with LiveOperation

use of com.microsoft.live.LiveOperation in project LiveSDK-for-Android by liveservices.

the class PutTest method testAsyncResponseBodyValid.

@Override
public void testAsyncResponseBodyValid() throws Throwable {
    this.loadValidResponseBody();
    String requestPath = this.calendarId;
    this.runTestOnUiThread(createAsyncRunnable(requestPath, CALENDAR));
    LiveOperation fromMethod = this.responseQueue.take();
    LiveOperation fromCallback = this.pollResponseQueue();
    this.checkReturnedOperations(fromMethod, fromCallback);
    this.checkOperationMembers(fromMethod, METHOD, requestPath);
    this.checkValidResponseBody(fromMethod);
}
Also used : LiveOperation(com.microsoft.live.LiveOperation)

Example 34 with LiveOperation

use of com.microsoft.live.LiveOperation in project LiveSDK-for-Android by liveservices.

the class SkyDriveActivity method loadFolder.

private void loadFolder(String folderId) {
    assert folderId != null;
    mCurrentFolderId = folderId;
    final ProgressDialog progressDialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
    mClient.getAsync(folderId + "/files", new LiveOperationListener() {

        @Override
        public void onComplete(LiveOperation operation) {
            progressDialog.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;
            }
            ArrayList<SkyDriveObject> skyDriveObjs = mPhotoAdapter.getSkyDriveObjs();
            skyDriveObjs.clear();
            JSONArray data = result.optJSONArray(JsonKeys.DATA);
            for (int i = 0; i < data.length(); i++) {
                SkyDriveObject skyDriveObj = SkyDriveObject.create(data.optJSONObject(i));
                if (skyDriveObj != null) {
                    skyDriveObjs.add(skyDriveObj);
                }
            }
            mPhotoAdapter.notifyDataSetChanged();
        }

        @Override
        public void onError(LiveOperationException exception, LiveOperation operation) {
            progressDialog.dismiss();
            showToast(exception.getMessage());
        }
    });
}
Also used : JSONObject(org.json.JSONObject) LiveOperationListener(com.microsoft.live.LiveOperationListener) LiveOperation(com.microsoft.live.LiveOperation) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ProgressDialog(android.app.ProgressDialog) LiveOperationException(com.microsoft.live.LiveOperationException)

Example 35 with LiveOperation

use of com.microsoft.live.LiveOperation 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

LiveOperation (com.microsoft.live.LiveOperation)36 LiveOperationException (com.microsoft.live.LiveOperationException)10 JSONObject (org.json.JSONObject)10 OperationQueueingListener (com.microsoft.live.test.util.OperationQueueingListener)4 ProgressDialog (android.app.ProgressDialog)3 LiveOperationListener (com.microsoft.live.LiveOperationListener)3 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 DialogInterface (android.content.DialogInterface)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 TextView (android.widget.TextView)1 LiveAuthClient (com.microsoft.live.LiveAuthClient)1 LiveAuthException (com.microsoft.live.LiveAuthException)1 LiveAuthListener (com.microsoft.live.LiveAuthListener)1 LiveConnectClient (com.microsoft.live.LiveConnectClient)1 LiveConnectSession (com.microsoft.live.LiveConnectSession)1 LiveDownloadOperation (com.microsoft.live.LiveDownloadOperation)1 LiveDownloadOperationListener (com.microsoft.live.LiveDownloadOperationListener)1