-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename module library to mapzen-android-sdk * Rename module sample to mapzen-android-sdk-sample * Add core module * Add places module * Deploy places module * mapzen-android-sdk & mapzen-places-api depend on core module * Create places sample app module * Update sample app deploy scripts * Move sample projects into samples * Add GeoDataApi and autocomplete method * Add Places api and GeoDataApi implementation * Add LatLng * Add checkstyle task * Implement LatLngBounds methods * Better LatLng initialization * Add AutocompletePredictionResult * Return AutocompletePendingResult when GeoDataApi autocomplete called * Add AutocompletePrediction * Add DataBuffer interface * Update AutocompletePredictionBuffer to implement DataBuffer * Map pelias results to AutocompletePrediction objs * Checkstyle and javadocs * Add GeoDataApi autocomplete example * Add verify task to places * Rm gitignores * Fix test * dont abort on lint errors for places module
- Loading branch information
1 parent
61968d0
commit b38aa14
Showing
29 changed files
with
1,056 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
mapzen-places-api/src/main/java/com/mapzen/places/api/AutocompleteFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mapzen.places.api; | ||
|
||
/** | ||
* Filter for customizing autocomplete results from {@link GeoDataApi}. | ||
*/ | ||
public class AutocompleteFilter { | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
mapzen-places-api/src/main/java/com/mapzen/places/api/AutocompletePrediction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.mapzen.places.api; | ||
|
||
import android.support.annotation.Nullable; | ||
import android.text.style.CharacterStyle; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Represents a place returned from {@link GeoDataApi#getAutocompletePredictions( | ||
* com.mapzen.android.lost.api.LostApiClient, String, LatLngBounds, AutocompleteFilter)}. | ||
*/ | ||
public class AutocompletePrediction { | ||
|
||
private final String placeId; | ||
private final String primaryText; | ||
|
||
/** | ||
* Constructs a new prediction given an id an primary text. | ||
* @param id | ||
* @param text | ||
*/ | ||
public AutocompletePrediction(String id, String text) { | ||
placeId = id; | ||
primaryText = text; | ||
} | ||
|
||
/** | ||
* Not implemented yet. | ||
* @param characterStyle | ||
* @return | ||
*/ | ||
public CharSequence getFullText(@Nullable CharacterStyle characterStyle) { | ||
throw new RuntimeException("Not implemented yet"); | ||
} | ||
|
||
/** | ||
* Returns the prediction's primary text. | ||
* @param characterStyle | ||
* @return | ||
*/ | ||
public CharSequence getPrimaryText(@Nullable CharacterStyle characterStyle) { | ||
return primaryText; | ||
} | ||
|
||
/** | ||
* Not implemented yet. | ||
* @param characterStyle | ||
* @return | ||
*/ | ||
public CharSequence getSecondaryText(@Nullable CharacterStyle characterStyle) { | ||
throw new RuntimeException("Not implemented yet"); | ||
} | ||
|
||
/** | ||
* Return's the prediction's id. | ||
* @return | ||
*/ | ||
@Nullable | ||
public String getPlaceId() { | ||
return placeId; | ||
} | ||
|
||
/** | ||
* Not implemented yet. | ||
* @return | ||
*/ | ||
@Nullable | ||
public List<Integer> getPlaceTypes() { | ||
throw new RuntimeException("Not implemented yet"); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
mapzen-places-api/src/main/java/com/mapzen/places/api/AutocompletePredictionBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.mapzen.places.api; | ||
|
||
import com.mapzen.android.lost.api.Result; | ||
import com.mapzen.android.lost.api.Status; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Represents a list of autocomplete results. | ||
*/ | ||
public class AutocompletePredictionBuffer implements Result, DataBuffer<AutocompletePrediction> { | ||
|
||
private final Status status; | ||
private final List<AutocompletePrediction> predictions; | ||
|
||
/** | ||
* Constructs a new buffer given a status and list of autocomplete results. | ||
* @param status | ||
* @param predictions | ||
*/ | ||
public AutocompletePredictionBuffer(Status status, List<AutocompletePrediction> predictions) { | ||
this.status = status; | ||
this.predictions = predictions; | ||
} | ||
|
||
@Override public Status getStatus() { | ||
return status; | ||
} | ||
|
||
@Override public int getCount() { | ||
if (predictions == null) { | ||
return 0; | ||
} | ||
return predictions.size(); | ||
} | ||
|
||
@Override public AutocompletePrediction get(int index) { | ||
if (predictions == null || index < 0 || index > predictions.size() - 1) { | ||
return null; | ||
} | ||
return predictions.get(index); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
mapzen-places-api/src/main/java/com/mapzen/places/api/DataBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.mapzen.places.api; | ||
|
||
/** | ||
* Generic interface for representing data contained in a buffer. | ||
* @param <T> | ||
*/ | ||
public interface DataBuffer<T> { | ||
/** | ||
* Returns the number of objects in the buffer. | ||
* @return | ||
*/ | ||
int getCount(); | ||
|
||
/** | ||
* Returns the object at a given index. | ||
* @param index | ||
* @return | ||
*/ | ||
T get(int index); | ||
} |
20 changes: 20 additions & 0 deletions
20
mapzen-places-api/src/main/java/com/mapzen/places/api/GeoDataApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.mapzen.places.api; | ||
|
||
import com.mapzen.android.lost.api.LostApiClient; | ||
import com.mapzen.android.lost.api.PendingResult; | ||
|
||
/** | ||
* Main entry point for the Mapzen Places Geo Data API. | ||
*/ | ||
public interface GeoDataApi { | ||
/** | ||
* Returns an object which can be used to retrieve autocomplete results. | ||
* @param client | ||
* @param query | ||
* @param bounds | ||
* @param filter | ||
* @return | ||
*/ | ||
PendingResult<AutocompletePredictionBuffer> getAutocompletePredictions(LostApiClient client, | ||
String query, LatLngBounds bounds, AutocompleteFilter filter); | ||
} |
46 changes: 46 additions & 0 deletions
46
mapzen-places-api/src/main/java/com/mapzen/places/api/LatLng.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.mapzen.places.api; | ||
|
||
/** | ||
* Represents a pair of coordinates as degrees. | ||
*/ | ||
public class LatLng { | ||
|
||
private static final double LAT_MIN = -90; | ||
private static final double LAT_MAX = 90; | ||
private static final double LNG_MIN = -180; | ||
private static final double LNG_MAX = 180; | ||
private static final double ALL_LNGS = 360; | ||
|
||
private final double latitude; | ||
private final double longitude; | ||
|
||
/** | ||
* Constructs a new object given a latitude and longitude in degrees. | ||
* @param lat | ||
* @param lng | ||
*/ | ||
public LatLng(double lat, double lng) { | ||
if (LNG_MIN <= lng && lng < LNG_MAX) { | ||
this.longitude = lng; | ||
} else { | ||
this.longitude = ((lng - LNG_MAX) % ALL_LNGS + ALL_LNGS) % ALL_LNGS - LNG_MAX; | ||
} | ||
this.latitude = Math.max(LAT_MIN, Math.min(LAT_MAX, lat)); | ||
} | ||
|
||
/** | ||
* Latitude, in degrees. This value is in the range [-90, 90]. | ||
* @return | ||
*/ | ||
public double getLatitude() { | ||
return latitude; | ||
} | ||
|
||
/** | ||
* Longitude, in degrees. This value is in the range [-180, 180]. | ||
* @return | ||
*/ | ||
public double getLongitude() { | ||
return longitude; | ||
} | ||
} |
Oops, something went wrong.