Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/java/se/walkercrou/places/GooglePlacesInterface.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package se.walkercrou.places;

import se.walkercrou.places.exception.GooglePlacesException;

import java.util.List;

import se.walkercrou.places.exception.GooglePlacesException;

/**
* A Java binding for the Google Places API:
* <a href="https://developers.google.com/places/">https://developers.google.com/places/</a>
Expand Down Expand Up @@ -107,6 +107,11 @@ public interface GooglePlacesInterface extends Types, Statuses {
*/
String ARRAY_ALT_IDS = "alt_ids";

/**
* Array of required HTML attributions on photos
*/
String ARRAY_HTML_ATTRIBUTIONS = "html_attributions";

/**
* If the place is opened now
*/
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/se/walkercrou/places/Photo.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package se.walkercrou.places;

import se.walkercrou.places.exception.GooglePlacesException;
import static se.walkercrou.places.GooglePlaces.MAX_PHOTO_SIZE;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.imageio.ImageIO;

import static se.walkercrou.places.GooglePlaces.MAX_PHOTO_SIZE;
import se.walkercrou.places.exception.GooglePlacesException;

/**
* Represents a referenced photo.
Expand All @@ -15,6 +18,7 @@ public class Photo {
private final Place place;
private final String reference;
private final int width, height;
private final List<String> htmlAttributions = new ArrayList<>();
private InputStream image;

protected Photo(Place place, String reference, int width, int height) {
Expand Down Expand Up @@ -96,4 +100,22 @@ public int getWidth() {
public int getHeight() {
return height;
}

/**
* Returns the HTML attributions of the photo. This array may be empty but is never null.
*
* @return photo attributions
*/
public List<String> getHtmlAttributions() {
return Collections.unmodifiableList(htmlAttributions);
}

/**
* Add an HTML attribution to the photo.
*
* @param attribution the attribution to add
*/
public void addHtmlAttribution(String attribution) {
htmlAttributions.add(attribution);
}
}
19 changes: 13 additions & 6 deletions src/main/java/se/walkercrou/places/Place.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package se.walkercrou.places;

import org.json.JSONArray;
import org.json.JSONObject;
import se.walkercrou.places.exception.GooglePlacesException;
import static se.walkercrou.places.GooglePlaces.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.imageio.ImageIO;

import static se.walkercrou.places.GooglePlaces.*;
import org.json.JSONArray;
import org.json.JSONObject;
import se.walkercrou.places.exception.GooglePlacesException;

/**
* Represents a place returned by Google Places API_
Expand Down Expand Up @@ -130,7 +130,14 @@ public static Place parseDetails(GooglePlaces client, String rawJson) {
JSONObject jsonPhoto = jsonPhotos.getJSONObject(i);
String photoReference = jsonPhoto.getString(STRING_PHOTO_REFERENCE);
int width = jsonPhoto.getInt(INTEGER_WIDTH), height = jsonPhoto.getInt(INTEGER_HEIGHT);
photos.add(new Photo(place, photoReference, width, height));
Photo photo = new Photo(place, photoReference, width, height);
JSONArray jsonAttributions = jsonPhoto.optJSONArray(ARRAY_HTML_ATTRIBUTIONS);
if (jsonAttributions != null) {
for (int j = 0; j < jsonAttributions.length(); j++) {
photo.addHtmlAttribution(jsonAttributions.getString(j));
}
}
photos.add(photo);
}
}

Expand Down