com.google.android.gms.plus.People Java Examples
The following examples show how to use
com.google.android.gms.plus.People.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleApiClientBridge.java From friendspell with Apache License 2.0 | 5 votes |
public void getProfileImages( String token, final List<String> userIds, final GetProfileImagesCallback callback) { ArrayList<String> toFetch = new ArrayList<>(); for (int i = 0; i < userIds.size(); ++i) { String userId = userIds.get(i); if (!profileImages.containsKey(userId)) { toFetch.add(userId); } } GoogleApiClient googleApiClient = clients.get(token); if (googleApiClient == null) { return; } Plus.PeopleApi.load(googleApiClient, userIds).setResultCallback( new ResultCallback<People.LoadPeopleResult>() { @Override public void onResult(People.LoadPeopleResult peopleData) { if (peopleData.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) { PersonBuffer personBuffer = peopleData.getPersonBuffer(); try { int count = personBuffer.getCount(); for (int i = 0; i < count; ++i) { Person person = personBuffer.get(i); profileImages.put(person.getId(), getProfileImageUrl(person)); } callback.onSuccess(); } finally { personBuffer.close(); } } else { Timber.e("Error requesting people data: %s", peopleData.getStatus()); } } }); }
Example #2
Source File: SoomlaGooglePlus.java From android-profile with Apache License 2.0 | 5 votes |
@Override public void getContacts(boolean fromStart, final SocialCallbacks.ContactsListener contactsListener) { RefProvider = getProvider(); if (googleApiClient != null && googleApiClient.isConnected()){ String lastContactCursor = this.lastContactCursor; this.lastContactCursor = null; Plus.PeopleApi.loadVisible(googleApiClient, fromStart ? null : lastContactCursor) .setResultCallback(new ResultCallback<People.LoadPeopleResult>() { @Override public void onResult(People.LoadPeopleResult peopleData) { if (peopleData.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) { List<UserProfile> userProfiles = new ArrayList<UserProfile>(); PersonBuffer personBuffer = peopleData.getPersonBuffer(); try { int count = personBuffer.getCount(); for (int i = 0; i < count; i++) { Person googleContact = personBuffer.get(i); userProfiles.add(parseGoogleContact(googleContact)); } SoomlaGooglePlus.this.lastContactCursor = peopleData.getNextPageToken(); contactsListener.success(userProfiles, SoomlaGooglePlus.this.lastContactCursor != null); } catch (Exception e){ contactsListener.fail("Failed getting contacts with exception: " + e.getMessage()); }finally { personBuffer.close(); } } else { contactsListener.fail("Contact information is not available."); } } }); }else{ contactsListener.fail("Failed getting contacts because because not connected to Google Plus."); } }
Example #3
Source File: SyncAdapter.java From attendee-checkin with Apache License 2.0 | 4 votes |
private ContentValues[] parseAttendees(String eventId, JSONArray attendees) throws JSONException { int length = attendees.length(); ContentValues[] array = new ContentValues[length]; HashMap<String, String> imageUrls = new HashMap<>(); for (int i = 0; i < length; ++i) { JSONObject attendee = attendees.getJSONObject(i); array[i] = new ContentValues(); array[i].put(Table.Attendee.EVENT_ID, eventId); array[i].put(Table.Attendee.NAME, attendee.getString("name")); array[i].put(Table.Attendee.ID, attendee.getString("id")); array[i].put(Table.Attendee.EMAIL, attendee.getString("email")); String plusid = attendee.getString("plusid"); if (!TextUtils.isEmpty(plusid)) { array[i].put(Table.Attendee.PLUSID, plusid); imageUrls.put(plusid, "null"); } long checkinTime = attendee.getLong("checkinTime"); if (0 == checkinTime) { array[i].putNull(Table.Attendee.CHECKIN); } else { array[i].put(Table.Attendee.CHECKIN, checkinTime); } array[i].putNull(Table.Attendee.IMAGE_URL); } // Fetch all the Google+ Image URLs at once if necessary if (mApiClient != null && mApiClient.isConnected() && !imageUrls.isEmpty()) { People.LoadPeopleResult result = Plus.PeopleApi.load(mApiClient, imageUrls.keySet()).await(); PersonBuffer personBuffer = result.getPersonBuffer(); if (personBuffer != null) { // Copy URLs into the HashMap for (Person person : personBuffer) { if (person.hasImage()) { imageUrls.put(extractId(person.getUrl()), person.getImage().getUrl()); } } // Fill the missing URLs in the array of ContentValues for (ContentValues values : array) { if (values.containsKey(Table.Attendee.PLUSID)) { String plusId = values.getAsString(Table.Attendee.PLUSID); String imageUrl = imageUrls.get(plusId); if (!TextUtils.isEmpty(imageUrl)) { values.put(Table.Attendee.IMAGE_URL, imageUrl); } } } } } return array; }