com.google.android.gms.plus.model.people.Person Java Examples
The following examples show how to use
com.google.android.gms.plus.model.people.Person.
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: GPlusUserProfileBuilder.java From pubnub-android-chat with MIT License | 6 votes |
public UserProfile build() { UserProfile newUserProfile = new UserProfile(); String email = Plus.AccountApi.getAccountName(googleApiClient); newUserProfile.setEmail(email); if (Plus.PeopleApi.getCurrentPerson(googleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(googleApiClient); newUserProfile.setUserName(currentPerson.getDisplayName()); newUserProfile.setFirstName(currentPerson.getName().getGivenName()); newUserProfile.setLastName(currentPerson.getName().getFamilyName()); newUserProfile.setImageURL(currentPerson.getImage().getUrl()); return (newUserProfile); } return null; }
Example #2
Source File: MainActivity.java From android-google-accounts with Apache License 2.0 | 6 votes |
/** * Called when the Activity successfully connects to Google Play Services. When the function * is triggered, an account was selected on the device, the selected account has granted * requested permissions to the app, and the app has established a connection to Google Play * Services. * * @param connectionHint can be inspected for additional connection info */ @Override public void onConnected(Bundle connectionHint) { // Reaching onConnected means the user signed in via their Google Account and all APIs // previously specified are available. googleApiClientConnectionStateChange(true); // IMPORTANT NOTE: If you are storing any user data locally or even in a remote // application DO NOT associate it to the accountName (which is also an email address). // Associate the user data to the Google Account ID. Under some circumstances it is possible // for a Google Account to have the primary email address change. Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); // The logic below ensures you won't mix account data if a user switches between Google // Accounts. // TODO(developer): Check the account ID against any previous login locally. // TODO(developer): Delete the local data if the account ID differs. // TODO(developer): Construct local storage keyed on the account ID. onSignedIn(currentPerson); }
Example #3
Source File: MainActivity.java From cloud-cup-android with Apache License 2.0 | 5 votes |
public void join() { Intent intent = new Intent(this, BlankGameActivity.class); String codeValue = code.getText().toString(); String playerName; String imageUrl; if(mGoogleApiClient.isConnected()) { // Get data of current signed-in user Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); playerName = currentPerson.getName().getGivenName(); imageUrl = getUserImageUrl(currentPerson); } else { Random rand = new Random(); playerName = "Anonymous " + rand.nextInt(10); imageUrl = ""; } // Register player data in Firebase Firebase ref = firebase.child("room/" + codeValue + "/players"); Firebase pushRef = ref.push(); Map<String, Object> user = new HashMap<String, Object>(); user.put("name", playerName); user.put("imageUrl", imageUrl); user.put("score", 0); pushRef.setValue(user); String key = pushRef.getKey(); // Add intent data intent.putExtra("playerId", key); intent.putExtra("playerName", playerName); intent.putExtra("code", codeValue); // Start the intent startActivity(intent); }
Example #4
Source File: MainActivity.java From cloud-cup-android with Apache License 2.0 | 5 votes |
private String getUserImageUrl(Person person) { String imageUrl = person.getImage().getUrl(); // re-create the image URL with a larger size String sizeSplit = "sz="; String[] parts = imageUrl.split(sizeSplit); imageUrl = parts[0] + sizeSplit + "500"; return imageUrl; }
Example #5
Source File: MainActivity.java From cloud-cup-android with Apache License 2.0 | 5 votes |
public void onConnected(Bundle connectionHint) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); username.setText(currentPerson.getName().getGivenName()); new DownloadImageAsyncTask().execute(Uri.parse(getUserImageUrl(currentPerson))); code.requestFocus(); }
Example #6
Source File: RegistrationIntentService.java From friendlyping with Apache License 2.0 | 5 votes |
/** * Creates the registration bundle and fills it with user information. * * @param googleApiClient The connected api client. * @return A bundle with registration data. */ private Bundle createRegistrationBundle(GoogleApiClient googleApiClient) { // Get the current user's information for registration final Person currentPerson = Plus.PeopleApi.getCurrentPerson(googleApiClient); final String displayName; final String profilePictureUrl; Bundle registration = new Bundle(); if (currentPerson != null) { displayName = currentPerson.getDisplayName(); profilePictureUrl = currentPerson.getImage().getUrl(); } else { Log.e(TAG, "Couldn't load person. Falling back to default."); Log.d(TAG, "Make sure that the Google+ API is enabled for your project."); Log.d(TAG, "More information can be found here: " + "https://developers.google.com/+/mobile/android/" + "getting-started#step_1_enable_the_google_api"); displayName = "Anonymous Kitten"; profilePictureUrl = "http://placekitten.com/g/500/500"; } // Create the bundle for registration with the server. registration.putString(PingerKeys.ACTION, GcmAction.REGISTER_NEW_CLIENT); registration.putString(PingerKeys.NAME, displayName); registration.putString(PingerKeys.PICTURE_URL, profilePictureUrl); return registration; }
Example #7
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 #8
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 #9
Source File: SoomlaGooglePlus.java From android-profile with Apache License 2.0 | 5 votes |
private static UserProfile parseGoogleContact(Person googleContact){ String fullName = googleContact.getDisplayName(); String firstName = ""; String lastName = ""; if (!TextUtils.isEmpty(fullName)) { String[] splitName = fullName.split(" "); if (splitName.length > 0) { firstName = splitName[0]; if (splitName.length > 1) { lastName = splitName[1]; } } } UserProfile result = new UserProfile(RefProvider, parseGoogleContactInfo(googleContact.getId()), "", //TODO: user name "", //TODO: email firstName, lastName); result.setGender(parseGoogleContactInfo(googleContact.getGender())); result.setBirthday(parseGoogleContactInfo(googleContact.getBirthday())); result.setLanguage(parseGoogleContactInfo(googleContact.getLanguage())); result.setLocation(parseGoogleContactInfo(googleContact.getCurrentLocation())); result.setAvatarLink(parseGoogleContactInfo(googleContact.getImage().getUrl())); return result; }
Example #10
Source File: MainActivity.java From android-google-accounts with Apache License 2.0 | 5 votes |
/** * Update the UI to reflect that the user is signed into the app. */ protected void onSignedIn(Person currentPerson) { storeSignInState(true); mSignInButton.setEnabled(false); mSignOutButton.setEnabled(true); mRevokeButton.setEnabled(true); mStatus.setText(String.format(getResources().getString(R.string .signed_in_as), currentPerson.getDisplayName())); }
Example #11
Source File: MainActivity.java From android-google-accounts with Apache License 2.0 | 5 votes |
/** * Called when the Activity successfully connects to Google Play Services. When the function * is triggered, an account was selected on the device, the selected account has granted * requested permissions to the app, and the app has established a connection to Google Play * Services. * * @param connectionHint can be inspected for additional connection info */ @Override public void onConnected(Bundle connectionHint) { // Reaching onConnected means we consider the user signed in and all APIs previously // specified are available. Log.i(TAG, "onConnected"); // IMPORTANT NOTE: If you are storing any user data locally or even in a remote // application DO NOT associate it to the accountName (which is also an email address). // Associate the user data to the Google Account ID. Under some circumstances it is possible // for a Google Account to have the primary email address change. Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); // TODO(developer): Check the account ID against any previous login locally. // TODO(developer): Delete the local data if the account ID differs. // TODO(developer): Construct local storage keyed on the account ID. mStatus.setText(String.format(getResources().getString(R.string .signed_in_as), currentPerson.getDisplayName())); mSignInButton.setEnabled(false); mSignOutButton.setEnabled(true); mRevokeButton.setEnabled(true); // Indicate that the sign in process is complete. mSignInProgress = STATE_DEFAULT; }
Example #12
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; }
Example #13
Source File: GoogleApiClientBridge.java From friendspell with Apache License 2.0 | 4 votes |
private String getProfileImageUrl(Person person) { Person.Image image = person.getImage(); return image.hasUrl() ? image.getUrl() : null; }