Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. public void loadPlaceImage(final ImageView imageView, String placeId) {
  2.  
  3. /**
  4. * Load a bitmap from the photos API asynchronously
  5. * by using buffers and result callbacks.
  6. */
  7.  
  8. Places.GeoDataApi.getPlacePhotos(mGoogleApiClient, placeId)
  9. .setResultCallback(new ResultCallback<PlacePhotoMetadataResult>() {
  10.  
  11.  
  12. @Override
  13. public void onResult(PlacePhotoMetadataResult photos) {
  14. if (!photos.getStatus().isSuccess()) {
  15. Log.d(TAG, "Couldn't receive photos bundle successfully.");
  16. return;
  17. }
  18.  
  19. Log.d(TAG, "Photo bundle received successfully");
  20.  
  21. PlacePhotoMetadataBuffer photoMetadataBuffer = photos.getPhotoMetadata();
  22. if (photoMetadataBuffer.getCount() > 0) {
  23. // Display the first bitmap in an ImageView in the size of the view
  24. photoMetadataBuffer.get(0)
  25. .getScaledPhoto(mGoogleApiClient, imageView.getWidth(),
  26. imageView.getHeight())
  27. .setResultCallback(new ResultCallback<PlacePhotoResult>() {
  28. @Override
  29. public void onResult(PlacePhotoResult placePhotoResult) {
  30. if (!placePhotoResult.getStatus().isSuccess()) {
  31. Log.d(TAG, "Couldn't retrieve the photo successfully.");
  32. return;
  33. }
  34.  
  35. Log.d(TAG, "Successfully retrieved photo from photo bundle.");
  36.  
  37. imageView.setImageBitmap(placePhotoResult.getBitmap());
  38. }
  39. });
  40. } else {
  41. Log.d(TAG, "0 images in the buffer.");
  42. }
  43. photoMetadataBuffer.release();
  44. }
  45. });
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement