Search in sources :

Example 1 with LiveAuthClient

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

Example 2 with LiveAuthClient

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

View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 TextView (android.widget.TextView)2 LiveAuthClient (com.microsoft.live.LiveAuthClient)2 LiveAuthException (com.microsoft.live.LiveAuthException)2 LiveAuthListener (com.microsoft.live.LiveAuthListener)2 LiveConnectSession (com.microsoft.live.LiveConnectSession)2 LiveStatus (com.microsoft.live.LiveStatus)2 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 LiveSdkSampleApplication (com.microsoft.live.sample.LiveSdkSampleApplication)1 JSONObject (org.json.JSONObject)1