private
class
PhotoTask
extends
AsyncTask<String, Void, PhotoTask.AttributedPhoto> {
private
int
mHeight;
private
int
mWidth;
public
PhotoTask(
int
width,
int
height) {
mHeight = height;
mWidth = width;
}
@Override
protected
AttributedPhoto doInBackground(String... params) {
if
(params.length !=
1
) {
return
null
;
}
final
String placeId = params[
0
];
AttributedPhoto attributedPhoto =
null
;
PlacePhotoMetadataResult result = Places.GeoDataApi
.getPlacePhotos(mGoogleApiClient, placeId).await();
if
(result.getStatus().isSuccess()) {
PlacePhotoMetadataBuffer photoMetadataBuffer = result.getPhotoMetadata();
if
(photoMetadataBuffer.getCount() >
0
&& !isCancelled()) {
PlacePhotoMetadata photo = photoMetadataBuffer.get(
0
);
CharSequence attribution = photo.getAttributions();
Bitmap image = photo.getScaledPhoto(mGoogleApiClient, mWidth, mHeight).await()
.getBitmap();
attributedPhoto =
new
AttributedPhoto(attribution, image);
}
photoMetadataBuffer.release();
}
return
attributedPhoto;
}
@Override
protected
void
onPostExecute(AttributedPhoto attributedPhoto) {
if
(attributedPhoto !=
null
) {
GoogleImage = attributedPhoto.bitmap;
}
}
class
AttributedPhoto {
public
final
CharSequence attribution;
public
final
Bitmap bitmap;
public
AttributedPhoto(CharSequence attribution, Bitmap bitmap) {
this
.attribution = attribution;
this
.bitmap = bitmap;
}
}
}