diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index c16ec1d5ca..b1086ee788 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -5,6 +5,7 @@ #include "com/mapswithme/opengl/androidoglcontextfactory.hpp" #include "com/mapswithme/platform/Platform.hpp" +#include "map/chart_generator.hpp" #include "map/user_mark.hpp" #include "search/everywhere_search_params.hpp" @@ -891,6 +892,51 @@ Java_com_mapswithme_maps_Framework_nativeGetRouteFollowingInfo(JNIEnv * env, jcl return result; } +JNIEXPORT jintArray JNICALL +Java_com_mapswithme_maps_Framework_nativeGenerateRouteAltitudeChartBits(JNIEnv * env, jclass, jint width, jint height) +{ + ::Framework * fr = frm(); + ASSERT(fr, ()); + vector imageRGBAData; + + if (!fr->GenerateRouteAltitudeChart(width, height, imageRGBAData)) + { + LOG(LWARNING, ("Cann't generate route altitude image.")); + return nullptr; + } + + size_t const imageRGBADataSize = imageRGBAData.size(); + if (imageRGBADataSize == 0) + { + LOG(LWARNING, ("GenerateRouteAltitudeChart returns true but the vector with altitude image bits is empty.")); + return nullptr; + } + + size_t const pxlCount = width * height; + if (maps::kAlitudeChartBPP * pxlCount != imageRGBAData.size()) + { + LOG(LWARNING, ("Wrong size of vector with altitude image bits. Expected size:", pxlCount, ". Real size:", imageRGBAData.size())); + return nullptr; + } + + jintArray imageRGBADataArray = env->NewIntArray(imageRGBADataSize); + ASSERT(imageRGBADataArray, ()); + jint * arrayElements = env->GetIntArrayElements(imageRGBADataArray, 0); + ASSERT(arrayElements, ()); + + for (size_t i = 0; i < imageRGBADataSize; ++i) + { + size_t const shiftInBytes = i * maps::kAlitudeChartBPP; + arrayElements[i] = (imageRGBAData[shiftInBytes + 3] << 24) /* alpha */ + | (imageRGBAData[shiftInBytes] << 16) /* red */ + | (imageRGBAData[shiftInBytes + 1] << 8) /* green */ + | (imageRGBAData[shiftInBytes + 2]); /* blue */ + } + env->ReleaseIntArrayElements(imageRGBADataArray, arrayElements, 0); + + return imageRGBADataArray; +} + JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeShowCountry(JNIEnv * env, jclass, jstring countryId, jboolean zoomToDownloadButton) { diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index 35eb79b54c..cd9c5437b9 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -1,5 +1,6 @@ package com.mapswithme.maps; +import android.graphics.Bitmap; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -68,6 +69,25 @@ public class Framework return nativeGetGe0Url(lat, lon, zoomLevel, name).replaceFirst(Constants.Url.GE0_PREFIX, Constants.Url.HTTP_GE0_PREFIX); } + /** + * Generates Bitmap with route altitude image chart taking into account current map style. + * @param width is width of the image. + * @param height is height of the image. + * @return Bitmap if there's pedestrian of bicycle route and null otherwise. + */ + @Nullable + public static Bitmap GenerateRouteAltitudeChart(int width, int height) + { + if (width <= 0 || height <= 0) + return null; + + final int[] altitudeChartBits = Framework.nativeGenerateRouteAltitudeChartBits(width, height); + if (altitudeChartBits == null) + return null; + + return Bitmap.createBitmap(altitudeChartBits, width, height, Bitmap.Config.ARGB_8888); + } + public static native void nativeShowTrackRect(int category, int track); public static native int nativeGetDrawScale(); @@ -144,6 +164,9 @@ public class Framework @Nullable public static native RoutingInfo nativeGetRouteFollowingInfo(); + @Nullable + public static native final int [] nativeGenerateRouteAltitudeChartBits(int width, int height); + // When an end user is going to a turn he gets sound turn instructions. // If C++ part wants the client to pronounce an instruction nativeGenerateTurnNotifications returns // an array of one of more strings. C++ part assumes that all these strings shall be pronounced by the client's TTS.