use of com.microsoft.live.LiveConnectSession 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;
}
use of com.microsoft.live.LiveConnectSession 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();
}
}
});
}
use of com.microsoft.live.LiveConnectSession 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);
}
});
}
});
}
use of com.microsoft.live.LiveConnectSession 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());
}
});
}
});
}
Aggregations