|
6 | 6 | import android.support.v7.widget.GridLayoutManager; |
7 | 7 | import android.support.v7.widget.RecyclerView; |
8 | 8 | import android.support.v7.widget.Toolbar; |
| 9 | +import android.util.Log; |
9 | 10 |
|
10 | 11 | import com.mapbox.services.Constants; |
11 | 12 | import com.mapbox.services.android.testapp.R; |
12 | 13 | import com.mapbox.services.android.testapp.Utils; |
| 14 | +import com.mapbox.services.commons.ServicesException; |
13 | 15 | import com.mapbox.services.staticimage.v1.MapboxStaticImage; |
14 | 16 |
|
15 | 17 | public class StaticImageActivity extends AppCompatActivity { |
@@ -76,25 +78,35 @@ private String[] buildDataset() { |
76 | 78 | int i = 0; |
77 | 79 | for (double[] place: PLACES) { |
78 | 80 | for (String style: MAPBOX_STYLES) { |
79 | | - MapboxStaticImage staticImage = new MapboxStaticImage.Builder() |
80 | | - .setAccessToken(Utils.getMapboxAccessToken(this)) |
81 | | - .setUsername(Constants.MAPBOX_USER) |
82 | | - .setStyleId(style) |
83 | | - .setLon(place[1]) |
84 | | - .setLat(place[0]) |
85 | | - .setZoom(16) |
86 | | - .setBearing(45) |
87 | | - .setPitch(60) |
88 | | - .setWidth(500) |
89 | | - .setHeight(500) |
90 | | - .setRetina(isRetina) |
91 | | - .build(); |
92 | | - dataset[i] = staticImage.getUrl().toString(); |
93 | | - i++; |
| 81 | + String imageUrl = null; |
| 82 | + try { |
| 83 | + imageUrl = getImageUrl(style, place, isRetina); |
| 84 | + dataset[i] = imageUrl; |
| 85 | + i++; |
| 86 | + } catch (ServicesException e) { |
| 87 | + Log.e(LOG_TAG, "Error: " + e.getMessage()); |
| 88 | + e.printStackTrace(); |
| 89 | + } |
94 | 90 | } |
95 | 91 | } |
96 | 92 |
|
97 | 93 | return dataset; |
98 | 94 | } |
99 | 95 |
|
| 96 | + private String getImageUrl(String style, double[] place, boolean isRetina) throws ServicesException { |
| 97 | + MapboxStaticImage staticImage = new MapboxStaticImage.Builder() |
| 98 | + .setAccessToken(Utils.getMapboxAccessToken(this)) |
| 99 | + .setUsername(Constants.MAPBOX_USER) |
| 100 | + .setStyleId(style) |
| 101 | + .setLon(place[1]) |
| 102 | + .setLat(place[0]) |
| 103 | + .setZoom(16) |
| 104 | + .setBearing(45) |
| 105 | + .setPitch(60) |
| 106 | + .setWidth(500) |
| 107 | + .setHeight(500) |
| 108 | + .setRetina(isRetina) |
| 109 | + .build(); |
| 110 | + return staticImage.getUrl().toString(); |
| 111 | + } |
100 | 112 | } |
0 commit comments