Search in sources :

Example 6 with LiveOperationException

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

Example 7 with LiveOperationException

use of com.microsoft.live.LiveOperationException 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 8 with LiveOperationException

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

the class SkyDriveActivity method onCreateDialog.

@Override
protected Dialog onCreateDialog(final int id, final Bundle bundle) {
    Dialog dialog = null;
    switch(id) {
        case DIALOG_DOWNLOAD_ID:
            {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.").setPositiveButton("OK", new Dialog.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this);
                        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        progressDialog.setMessage("Downloading...");
                        progressDialog.setCancelable(true);
                        progressDialog.show();
                        String fileId = bundle.getString(JsonKeys.ID);
                        String name = bundle.getString(JsonKeys.NAME);
                        File file = new File(Environment.getExternalStorageDirectory(), name);
                        final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file, new LiveDownloadOperationListener() {

                            @Override
                            public void onDownloadProgress(int totalBytes, int bytesRemaining, LiveDownloadOperation operation) {
                                int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining);
                                progressDialog.setProgress(percentCompleted);
                            }

                            @Override
                            public void onDownloadFailed(LiveOperationException exception, LiveDownloadOperation operation) {
                                progressDialog.dismiss();
                                showToast(exception.getMessage());
                            }

                            @Override
                            public void onDownloadCompleted(LiveDownloadOperation operation) {
                                progressDialog.dismiss();
                                showToast("File downloaded.");
                            }
                        });
                        progressDialog.setOnCancelListener(new OnCancelListener() {

                            @Override
                            public void onCancel(DialogInterface dialog) {
                                operation.cancel();
                            }
                        });
                    }
                }).setNegativeButton("Cancel", new Dialog.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                dialog = builder.create();
                break;
            }
    }
    if (dialog != null) {
        dialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                removeDialog(id);
            }
        });
    }
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) LiveDownloadOperationListener(com.microsoft.live.LiveDownloadOperationListener) ProgressDialog(android.app.ProgressDialog) LiveOperationException(com.microsoft.live.LiveOperationException) LiveDownloadOperation(com.microsoft.live.LiveDownloadOperation) AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) ProgressDialog(android.app.ProgressDialog) OnClickListener(android.view.View.OnClickListener) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 9 with LiveOperationException

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

the class ApiTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // Set up the MockClient
    this.mockEntity = new MockHttpEntity();
    StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    this.mockResponse = new MockHttpResponse(this.mockEntity, statusLine);
    this.mockClient = new MockHttpClient(this.mockResponse);
    this.loadLiveLibraryHeaderChecker();
    this.exceptionQueue = new LinkedBlockingQueue<LiveOperationException>();
    this.liveConnectClient = TestUtils.newLiveConnectClient(this.mockClient);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) MockHttpEntity(com.microsoft.live.mock.MockHttpEntity) LiveOperationException(com.microsoft.live.LiveOperationException) MockHttpClient(com.microsoft.live.mock.MockHttpClient) BasicStatusLine(org.apache.http.message.BasicStatusLine) MockHttpResponse(com.microsoft.live.mock.MockHttpResponse)

Example 10 with LiveOperationException

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

the class GetTest method testAsyncResponseBodyInvalid.

@Override
public void testAsyncResponseBodyInvalid() throws Throwable {
    this.loadInvalidResponseBody();
    String requestPath = Paths.ME;
    this.runTestOnUiThread(createAsyncRunnable(requestPath));
    LiveOperation fromMethod = this.responseQueue.take();
    LiveOperation fromCallback = this.pollResponseQueue();
    LiveOperationException exception = this.pollExceptionQueue();
    this.checkReturnedException(fromMethod, fromCallback, exception);
    this.checkOperationMembers(fromMethod, METHOD, requestPath);
    this.checkResponseBodyInvalid(fromMethod);
}
Also used : LiveOperation(com.microsoft.live.LiveOperation) LiveOperationException(com.microsoft.live.LiveOperationException)

Aggregations

LiveOperationException (com.microsoft.live.LiveOperationException)12 LiveOperation (com.microsoft.live.LiveOperation)10 ProgressDialog (android.app.ProgressDialog)4 JSONObject (org.json.JSONObject)4 LiveOperationListener (com.microsoft.live.LiveOperationListener)3 DialogInterface (android.content.DialogInterface)2 OnCancelListener (android.content.DialogInterface.OnCancelListener)2 OnClickListener (android.view.View.OnClickListener)2 LiveDownloadOperation (com.microsoft.live.LiveDownloadOperation)2 LiveDownloadOperationListener (com.microsoft.live.LiveDownloadOperationListener)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 View (android.view.View)1 TextView (android.widget.TextView)1 LiveAuthClient (com.microsoft.live.LiveAuthClient)1 LiveAuthException (com.microsoft.live.LiveAuthException)1