use of com.microsoft.live.LiveOperationListener 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();
}
});
}
use of com.microsoft.live.LiveOperationListener in project LiveSDK-for-Android by liveservices.
the class SkyDriveActivity method loadFolder.
private void loadFolder(String folderId) {
assert folderId != null;
mCurrentFolderId = folderId;
final ProgressDialog progressDialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
mClient.getAsync(folderId + "/files", new LiveOperationListener() {
@Override
public void onComplete(LiveOperation operation) {
progressDialog.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<SkyDriveObject> skyDriveObjs = mPhotoAdapter.getSkyDriveObjs();
skyDriveObjs.clear();
JSONArray data = result.optJSONArray(JsonKeys.DATA);
for (int i = 0; i < data.length(); i++) {
SkyDriveObject skyDriveObj = SkyDriveObject.create(data.optJSONObject(i));
if (skyDriveObj != null) {
skyDriveObjs.add(skyDriveObj);
}
}
mPhotoAdapter.notifyDataSetChanged();
}
@Override
public void onError(LiveOperationException exception, LiveOperation operation) {
progressDialog.dismiss();
showToast(exception.getMessage());
}
});
}
use of com.microsoft.live.LiveOperationListener 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);
}
});
}
});
}
Aggregations