-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from mg6maciej/feature/working_on_api_8_and_re…
…factoring Refactoring of demos. Change demo minSdkVersion to 8.
- Loading branch information
Showing
5 changed files
with
96 additions
and
95 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
35 changes: 35 additions & 0 deletions
35
demo/src/com/google/maps/android/utils/demo/MyItemReader.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,35 @@ | ||
package com.google.maps.android.utils.demo; | ||
|
||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import com.google.maps.android.utils.demo.model.MyItem; | ||
|
||
public class MyItemReader { | ||
|
||
/* | ||
* This matches only once in whole input, | ||
* so Scanner.next returns whole InputStream as a String. | ||
* http://stackoverflow.com/a/5445161/2183804 | ||
*/ | ||
private static final String REGEX_INPUT_BOUNDARY_BEGINNING = "\\A"; | ||
|
||
public List<MyItem> read(InputStream inputStream) throws JSONException { | ||
List<MyItem> items = new ArrayList<MyItem>(); | ||
String json = new Scanner(inputStream).useDelimiter(REGEX_INPUT_BOUNDARY_BEGINNING).next(); | ||
JSONArray array = new JSONArray(json); | ||
for (int i = 0; i < array.length(); i++) { | ||
JSONObject object = array.getJSONObject(i); | ||
double lat = object.getDouble("lat"); | ||
double lng = object.getDouble("lng"); | ||
items.add(new MyItem(lat, lng)); | ||
} | ||
return items; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
demo/src/com/google/maps/android/utils/demo/model/MyItem.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,23 @@ | ||
package com.google.maps.android.utils.demo.model; | ||
|
||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.MarkerOptions; | ||
import com.google.maps.android.clustering.ClusterItem; | ||
|
||
public class MyItem implements ClusterItem { | ||
private final LatLng mPosition; | ||
|
||
public MyItem(double lat, double lng) { | ||
mPosition = new LatLng(lat, lng); | ||
} | ||
|
||
@Override | ||
public LatLng getPosition() { | ||
return mPosition; | ||
} | ||
|
||
@Override | ||
public MarkerOptions getMarkerOptions() { | ||
return new MarkerOptions().position(mPosition); | ||
} | ||
} |