Search in sources :

Example 1 with LiveStatus

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

the class MainActivity method onCreateDialog.

@Override
protected Dialog onCreateDialog(final int id) {
    Dialog dialog = null;
    switch(id) {
        case DIALOG_LOGOUT_ID:
            {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Logout").setMessage("The Live Connect Session will be cleared.").setPositiveButton("OK", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mAuthClient.logout(new LiveAuthListener() {

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

                            @Override
                            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                                LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication();
                                app.setSession(null);
                                app.setConnectClient(null);
                                finish();
                            }
                        });
                    }
                }).setNegativeButton("Cancel", new 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) LiveConnectSession(com.microsoft.live.LiveConnectSession) OnDismissListener(android.content.DialogInterface.OnDismissListener) LiveAuthException(com.microsoft.live.LiveAuthException) LiveAuthListener(com.microsoft.live.LiveAuthListener) LiveStatus(com.microsoft.live.LiveStatus) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 2 with LiveStatus

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

the class SignInActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    mAuthClient.initialize(Arrays.asList(Config.SCOPES), new LiveAuthListener() {

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

        @Override
        public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
            mInitializeDialog.dismiss();
            if (status == LiveStatus.CONNECTED) {
                launchMainActivity(session);
            } else {
                showSignIn();
            }
        }
    });
}
Also used : LiveConnectSession(com.microsoft.live.LiveConnectSession) LiveAuthException(com.microsoft.live.LiveAuthException) LiveAuthListener(com.microsoft.live.LiveAuthListener) LiveStatus(com.microsoft.live.LiveStatus)

Example 3 with LiveStatus

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

Example 4 with LiveStatus

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

the class SignInActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.signin);
    mApp = (LiveSdkSampleApplication) getApplication();
    mAuthClient = new LiveAuthClient(mApp, Config.CLIENT_ID);
    mApp.setAuthClient(mAuthClient);
    mInitializeDialog = ProgressDialog.show(this, "", "Initializing. Please wait...", true);
    mBeginTextView = (TextView) findViewById(R.id.beginTextView);
    mSignInButton = (Button) findViewById(R.id.signInButton);
    mBeginTextViewNeedId = (TextView) findViewById(R.id.beginTextViewNeedId);
    mNeedIdButton = (Button) findViewById(R.id.needIdButton);
    // Check to see if the CLIENT_ID has been changed. 
    if (Config.CLIENT_ID.equals("0000000048122D4E")) {
        mNeedIdButton.setVisibility(View.VISIBLE);
        mBeginTextViewNeedId.setVisibility(View.VISIBLE);
        mNeedIdButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                final Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(getBaseContext().getString(R.string.AndroidSignInHelpLink)));
                startActivity(intent);
            }
        });
    }
    mSignInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mAuthClient.login(SignInActivity.this, Arrays.asList(Config.SCOPES), new LiveAuthListener() {

                @Override
                public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                    if (status == LiveStatus.CONNECTED) {
                        launchMainActivity(session);
                    } else {
                        showToast("Login did not connect. Status is " + status + ".");
                    }
                }

                @Override
                public void onAuthError(LiveAuthException exception, Object userState) {
                    showToast(exception.getMessage());
                }
            });
        }
    });
}
Also used : LiveConnectSession(com.microsoft.live.LiveConnectSession) LiveAuthClient(com.microsoft.live.LiveAuthClient) LiveAuthException(com.microsoft.live.LiveAuthException) OnClickListener(android.view.View.OnClickListener) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) LiveAuthListener(com.microsoft.live.LiveAuthListener) LiveStatus(com.microsoft.live.LiveStatus)

Aggregations

LiveAuthException (com.microsoft.live.LiveAuthException)4 LiveAuthListener (com.microsoft.live.LiveAuthListener)4 LiveConnectSession (com.microsoft.live.LiveConnectSession)4 LiveStatus (com.microsoft.live.LiveStatus)4 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 TextView (android.widget.TextView)2 LiveAuthClient (com.microsoft.live.LiveAuthClient)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 Intent (android.content.Intent)1 LiveConnectClient (com.microsoft.live.LiveConnectClient)1 LiveDownloadOperation (com.microsoft.live.LiveDownloadOperation)1 LiveDownloadOperationListener (com.microsoft.live.LiveDownloadOperationListener)1 LiveOperation (com.microsoft.live.LiveOperation)1 LiveOperationException (com.microsoft.live.LiveOperationException)1 LiveOperationListener (com.microsoft.live.LiveOperationListener)1