Search in sources :

Example 1 with LiveOperationException

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

the class ContactsActivity method loadContacts.

private void loadContacts() {
    final ProgressDialog progDialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
    mClient.getAsync("me/contacts", new LiveOperationListener() {

        @Override
        public void onError(LiveOperationException exception, LiveOperation operation) {
            progDialog.dismiss();
            showToast(exception.getMessage());
        }

        @Override
        public void onComplete(LiveOperation operation) {
            progDialog.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<Contact> contacts = mAdapter.getContacts();
            contacts.clear();
            JSONArray data = result.optJSONArray(JsonKeys.DATA);
            for (int i = 0; i < data.length(); i++) {
                Contact contact = new Contact(data.optJSONObject(i));
                contacts.add(contact);
            }
            mAdapter.notifyDataSetChanged();
        }
    });
}
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 2 with LiveOperationException

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

the class FileOperationApiTest method testAsyncResponseBodyInvalid.

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

Example 3 with LiveOperationException

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

the class UploadTest method testAsyncResponseBodyInvalid.

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

Example 4 with LiveOperationException

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

the class PutTest method testAsyncResponseBodyInvalid.

@Override
public void testAsyncResponseBodyInvalid() throws Throwable {
    this.loadInvalidResponseBody();
    String requestPath = Paths.INVALID;
    this.runTestOnUiThread(createAsyncRunnable(requestPath, CALENDAR));
    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)

Example 5 with LiveOperationException

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

the class ViewProfileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_profile);
    mNameTextView = (TextView) findViewById(R.id.nameTextView);
    final LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication();
    findViewById(R.id.signOutButton).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            LiveAuthClient authClient = app.getAuthClient();
            authClient.logout(new LiveAuthListener() {

                @Override
                public void onAuthError(LiveAuthException exception, Object userState) {
                    showToast(exception.getMessage());
                }

                @Override
                public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                    app.setSession(null);
                    app.setConnectClient(null);
                    getParent().finish();
                }
            });
        }
    });
    final LiveConnectClient connectClient = app.getConnectClient();
    connectClient.getAsync("me", new LiveOperationListener() {

        @Override
        public void onError(LiveOperationException exception, LiveOperation operation) {
            showToast(exception.getMessage());
        }

        @Override
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            if (result.has(JsonKeys.ERROR)) {
                JSONObject error = result.optJSONObject(JsonKeys.ERROR);
                String code = error.optString(JsonKeys.CODE);
                String message = error.optString(JsonKeys.MESSAGE);
                showToast(code + ": " + message);
            } else {
                User user = new User(result);
                mNameTextView.setText("Hello, " + user.getName() + "!");
            }
        }
    });
    connectClient.getAsync("me/picture", new LiveOperationListener() {

        @Override
        public void onError(LiveOperationException exception, LiveOperation operation) {
            showToast(exception.getMessage());
        }

        @Override
        public void onComplete(LiveOperation operation) {
            JSONObject result = operation.getResult();
            if (result.has(JsonKeys.ERROR)) {
                JSONObject error = result.optJSONObject(JsonKeys.ERROR);
                String code = error.optString(JsonKeys.CODE);
                String message = error.optString(JsonKeys.MESSAGE);
                showToast(code + ": " + message);
                return;
            }
            String location = result.optString(JsonKeys.LOCATION);
            connectClient.downloadAsync(location, new LiveDownloadOperationListener() {

                @Override
                public void onDownloadProgress(int totalBytes, int bytesRemaining, LiveDownloadOperation operation) {
                }

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

                @Override
                public void onDownloadCompleted(LiveDownloadOperation operation) {
                    DownloadProfilePictureAsyncTask task = new DownloadProfilePictureAsyncTask();
                    task.execute(operation);
                }
            });
        }
    });
}
Also used : LiveConnectClient(com.microsoft.live.LiveConnectClient) LiveConnectSession(com.microsoft.live.LiveConnectSession) LiveAuthException(com.microsoft.live.LiveAuthException) LiveOperation(com.microsoft.live.LiveOperation) LiveDownloadOperationListener(com.microsoft.live.LiveDownloadOperationListener) LiveOperationException(com.microsoft.live.LiveOperationException) TextView(android.widget.TextView) View(android.view.View) LiveAuthListener(com.microsoft.live.LiveAuthListener) LiveStatus(com.microsoft.live.LiveStatus) LiveDownloadOperation(com.microsoft.live.LiveDownloadOperation) JSONObject(org.json.JSONObject) LiveOperationListener(com.microsoft.live.LiveOperationListener) LiveAuthClient(com.microsoft.live.LiveAuthClient) OnClickListener(android.view.View.OnClickListener) LiveSdkSampleApplication(com.microsoft.live.sample.LiveSdkSampleApplication) JSONObject(org.json.JSONObject)

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