Search in sources :

Example 6 with LiveDownloadOperation

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

the class DownloadTest method testAsyncResponseBodyInvalid.

@Override
public void testAsyncResponseBodyInvalid() throws Throwable {
    this.loadInvalidResponseBody();
    String requestPath = VALID_PATH;
    this.runTestOnUiThread(this.createAsyncRunnable(requestPath));
    LiveDownloadOperation fromMethod = this.responseQueue.take();
    LiveDownloadOperation fromCallback = this.pollResponseQueue();
    this.checkReturnedOperations(fromMethod, fromCallback);
    this.checkOperationMembers(fromMethod, this.getMethod(), requestPath);
    this.checkResponseBodyInvalid(fromMethod);
}
Also used : LiveDownloadOperation(com.microsoft.live.LiveDownloadOperation)

Example 7 with LiveDownloadOperation

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

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

LiveDownloadOperation (com.microsoft.live.LiveDownloadOperation)8 OnClickListener (android.view.View.OnClickListener)2 LiveDownloadOperationListener (com.microsoft.live.LiveDownloadOperationListener)2 LiveOperationException (com.microsoft.live.LiveOperationException)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)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 LiveAuthListener (com.microsoft.live.LiveAuthListener)1 LiveConnectClient (com.microsoft.live.LiveConnectClient)1 LiveConnectSession (com.microsoft.live.LiveConnectSession)1 LiveOperation (com.microsoft.live.LiveOperation)1 LiveOperationListener (com.microsoft.live.LiveOperationListener)1 LiveStatus (com.microsoft.live.LiveStatus)1