Skip to content

Commit

Permalink
Add json conversion for directions route and set drawable bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jan 16, 2018
1 parent 0649afc commit 1477b0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
import com.google.gson.GsonBuilder;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.Geometry;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.gson.BoundingBoxDeserializer;
import com.mapbox.geojson.gson.GeoJsonAdapterFactory;
import com.mapbox.geojson.gson.GeometryDeserializer;
import com.mapbox.geojson.gson.PointDeserializer;
import com.mapbox.services.android.navigation.v5.navigation.NavigationConstants;

import java.util.HashMap;
Expand Down Expand Up @@ -68,9 +74,18 @@ public static void startNavigation(Activity activity, NavigationViewOptions opti
*/
static DirectionsRoute extractRoute(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String directionsRoute = preferences.getString(NavigationConstants.NAVIGATION_VIEW_ROUTE_KEY, "");
return new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create()
.fromJson(directionsRoute, DirectionsRoute.class);
String directionsRouteJson = preferences.getString(NavigationConstants.NAVIGATION_VIEW_ROUTE_KEY, "");
return directionsRouteFromJson(directionsRouteJson);
}

private static DirectionsRoute directionsRouteFromJson(String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapter(Point.class, new PointDeserializer());
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
gson.registerTypeAdapter(BoundingBox.class, new BoundingBoxDeserializer());
gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create());
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
return gson.create().fromJson(json, DirectionsRoute.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ BannerShieldInfo getShield() {
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// Create a new Drawable with intrinsic bounds
Drawable drawable = new BitmapDrawable(textView.getContext().getResources(), bitmap);
int right = textView.getLineHeight();
int bottom = right * bitmap.getWidth() / bitmap.getHeight();

// width == (right - left), and height == (bottom - top)
int bottom = textView.getLineHeight();
int right = bottom * bitmap.getWidth() / bitmap.getHeight();
drawable.setBounds(0, 0, right, bottom);

// Create and set a new ImageSpan at the given index with the Drawable
Expand Down

0 comments on commit 1477b0b

Please sign in to comment.