[core, android] reduce jni interface

This commit is contained in:
ExMix 2014-10-24 14:15:02 +03:00 committed by Alex Zolotarev
parent 901928079d
commit bf964bf405
9 changed files with 107 additions and 102 deletions

View file

@ -6,6 +6,7 @@
#include "country_helper.hpp"
using namespace storage_utils;
using namespace storage;
extern "C"
{
@ -21,39 +22,52 @@ extern "C"
return GetMapLayout().GetCountInGroup(ToGroup(group));
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountryStatus(JNIEnv * env, jclass clazz, jint group, jint position)
JNIEXPORT jobject JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountryItem(JNIEnv * env, jclass clazz, jint group, jint position)
{
return static_cast<jint>(GetMapLayout().GetCountryStatus(ToGroup(group), position));
ActiveMapsLayout & layout = GetMapLayout();
ActiveMapsLayout::TGroup coreGroup = ToGroup(group);
int corePosition = static_cast<int>(position);
jstring name = jni::ToJavaString(env, layout.GetCountryName(coreGroup, corePosition));
jint status = static_cast<jint>(layout.GetCountryStatus(coreGroup, corePosition));
jint options = static_cast<jint>(layout.GetCountryOptions(coreGroup, corePosition));
jclass createClass = env->FindClass("com/mapswithme/country/CountryItem");
ASSERT(createClass, ());
jmethodID createMethodId = env->GetMethodID(createClass, "<init>", "(Ljava/lang/String;IIZ)V");
ASSERT(methodId, ());
return env->NewObject(createClass, createMethodId,
name, status, options, JNI_FALSE);
}
JNIEXPORT jstring JNICALL Java_com_mapswithme_country_ActiveCountryTree_getCountryName(JNIEnv * env, jclass clazz, jint group, jint position)
JNIEXPORT jlong JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountrySize(JNIEnv * env, jclass clazz, jint group, jint position, jint options, jboolean isLocal)
{
return jni::ToJavaString(env, GetMapLayout().GetCountryName(ToGroup(group), position));
}
ActiveMapsLayout & layout = GetMapLayout();
ActiveMapsLayout::TGroup coreGroup = ToGroup(group);
int pos = static_cast<int>(position);
int local = (isLocal == JNI_TRUE) ? true : false;
TMapOptions opt = ToOptions(options);
JNIEXPORT jint JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountryOptions(JNIEnv * env, jclass clazz, jint group, jint position)
{
return static_cast<jint>(GetMapLayout().GetCountryOptions(ToGroup(group), position));
}
if (options == -1 || local)
{
LocalAndRemoteSizeT sizes = options == -1 ? layout.GetDownloadableCountrySize(coreGroup, pos)
: layout.GetCountrySize(coreGroup, pos, opt);
return local ? sizes.first : sizes.second;
}
JNIEXPORT jlongArray JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountrySize(JNIEnv * env, jclass clazz, jint group, jint position, jint options)
{
return ToArray(env, GetMapLayout().GetCountrySize(ToGroup(group), position, ToOptions(options)));
}
JNIEXPORT jlongArray JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getRemoteCountrySizes(JNIEnv * env, jclass clazz, jint group, jint position)
{
return ToArray(env, GetMapLayout().GetRemoteCountrySizes(ToGroup(group), position));
}
JNIEXPORT jlongArray JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getDownloadableCountrySize(JNIEnv * env, jclass clazz, jint group, jint position)
{
return ToArray(env, GetMapLayout().GetDownloadableCountrySize(ToGroup(group), position));
LocalAndRemoteSizeT sizes = layout.GetRemoteCountrySizes(coreGroup, pos);
switch (opt)
{
case TMapOptions::EMapOnly:
return sizes.first;
case TMapOptions::ECarRouting:
return sizes.second;
default:
return sizes.first + sizes.second;
}
}
JNIEXPORT void JNICALL

View file

@ -5,6 +5,7 @@
#include "country_helper.hpp"
using namespace storage_utils;
using namespace storage;
extern "C"
{
@ -44,28 +45,24 @@ extern "C"
return GetTree().GetChildCount();
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_country_CountryTree_isLeaf(JNIEnv * env, jclass clazz, jint position)
JNIEXPORT jobject JNICALL
Java_com_mapswithme_country_CountryTree_getChildItem(JNIEnv * env, jclass clazz, jint position)
{
return GetTree().IsLeaf(position);
}
CountryTree & tree = GetTree();
int corePosition = static_cast<int>(position);
jboolean isLeaf = tree.IsLeaf(corePosition) ? JNI_TRUE : JNI_FALSE;
jstring name = jni::ToJavaString(env, tree.GetChildName(corePosition));
jint status = isLeaf == JNI_TRUE ? static_cast<jint>(tree.GetLeafStatus(corePosition)) : 0;
jint options = isLeaf == JNI_TRUE ? static_cast<jint>(tree.GetLeafOptions(corePosition)) : 0;
JNIEXPORT jstring JNICALL
Java_com_mapswithme_country_CountryTree_getChildName(JNIEnv * env, jclass clazz, jint position)
{
return jni::ToJavaString(env, GetTree().GetChildName(position));
}
jclass createClass = env->FindClass("com/mapswithme/country/CountryItem");
ASSERT(createClass, ());
JNIEXPORT jint JNICALL
Java_com_mapswithme_country_CountryTree_getLeafStatus(JNIEnv * env, jclass clazz, jint position)
{
return static_cast<jint>(GetTree().GetLeafStatus(position));
}
jmethodID createMethodId = env->GetMethodID(createClass, "<init>", "(Ljava/lang/String;IIZ)V");
ASSERT(methodId, ());
JNIEXPORT jint JNICALL
Java_com_mapswithme_country_CountryTree_getLeafOptions(JNIEnv * env, jclass clazz, jint position)
{
return static_cast<jint>(GetTree().GetLeafOptions(position));
return env->NewObject(createClass, createMethodId,
name, status, options, !isLeaf);
}
JNIEXPORT void JNICALL
@ -110,22 +107,30 @@ extern "C"
return NULL;
}
JNIEXPORT jlongArray JNICALL
Java_com_mapswithme_country_CountryTree_getDownloadableLeafSize(JNIEnv * env, jclass clazz, jint position)
JNIEXPORT jlong JNICALL
Java_com_mapswithme_country_CountryTree_getLeafSize(JNIEnv * env, jclass clazz, jint position, jint options, jboolean isLocal)
{
return ToArray(env, GetTree().GetDownloadableLeafSize(position));
}
CountryTree & tree = GetTree();
int pos = static_cast<int>(position);
int local = (isLocal == JNI_TRUE) ? true : false;
TMapOptions opt = ToOptions(options);
JNIEXPORT jlongArray JNICALL
Java_com_mapswithme_country_CountryTree_getLeafSize(JNIEnv * env, jclass clazz, jint position, jint options)
{
return ToArray(env, GetTree().GetLeafSize(position, ToOptions(options)));
}
if (options == -1 || local)
{
LocalAndRemoteSizeT sizes = options == -1 ? tree.GetDownloadableLeafSize(pos) : tree.GetLeafSize(pos, opt);
return local ? sizes.first : sizes.second;
}
JNIEXPORT jlongArray JNICALL
Java_com_mapswithme_country_CountryTree_getRemoteLeafSizes(JNIEnv * env, jclass clazz, jint position)
{
return ToArray(env, GetTree().GetRemoteLeafSizes(position));
LocalAndRemoteSizeT sizes = tree.GetRemoteLeafSizes(pos);
switch (opt)
{
case TMapOptions::EMapOnly:
return sizes.first;
case TMapOptions::ECarRouting:
return sizes.second;
default:
return sizes.first + sizes.second;
}
}
JNIEXPORT void JNICALL

View file

@ -26,19 +26,10 @@ public class ActiveCountryTree
public static native int getOutOfDateCount();
public static native int getCountInGroup(int group);
public static native int getCountryStatus(int group, int position);
public static native String getCountryName(int group, int position);
public static native int getCountryOptions(int group, int position);
public static native CountryItem getCountryItem(int group, int position);
// returns array of two elements : local and remote size.
public static native long[] getCountrySize(int group, int position, int options);
/// returns remote sizes for 2 options [map, map + route].
public static native long[] getRemoteCountrySizes(int group, int position);
public static native long[] getDownloadableCountrySize(int group, int position);
public static native long getCountrySize(int group, int position, int options, boolean isLocal);
public static native void cancelDownloading(int group, int position);

View file

@ -28,13 +28,7 @@ public class CountryTree
public static native int getChildCount();
public static native boolean isLeaf(int position);
public static native String getChildName(int position);
public static native int getLeafStatus(int position);
public static native int getLeafOptions(int position);
public static native CountryItem getChildItem(int position);
public static native void downloadCountry(int position, int options);
@ -46,12 +40,7 @@ public class CountryTree
public static native GuideInfo getLeafGuideInfo(int position);
public static native long[] getDownloadableLeafSize(int position);
public static native long[] getLeafSize(int position, int options);
/// returns remote sizes for 2 options [map, map + route].
public static native long[] getRemoteLeafSizes(int position);
public static native long getLeafSize(int position, int options, boolean isLocal);
public static native void setListener(CountryTreeListener listener);

View file

@ -38,8 +38,7 @@ class DownloadAdapter extends BaseDownloadAdapter implements CountryTree.Country
@Override
public CountryItem getItem(int position)
{
return new CountryItem(CountryTree.getChildName(position), CountryTree.getLeafStatus(position),
CountryTree.getLeafOptions(position), !CountryTree.isLeaf(position));
return CountryTree.getChildItem(position);
}
@Override
@ -76,19 +75,22 @@ class DownloadAdapter extends BaseDownloadAdapter implements CountryTree.Country
@Override
protected long[] getItemSizes(int position, int options)
{
return CountryTree.getLeafSize(position, options);
return new long[] { CountryTree.getLeafSize(position, options, true),
CountryTree.getLeafSize(position, options, false) };
}
@Override
protected long[] getRemoteItemSizes(int position)
{
return CountryTree.getRemoteLeafSizes(position);
long mapOnly = CountryTree.getLeafSize(position, StorageOptions.MAP_OPTION_MAP_ONLY, false);
return new long[] { mapOnly, mapOnly + CountryTree.getLeafSize(position, StorageOptions.MAP_OPTION_CAR_ROUTING, false) };
}
@Override
protected long[] getDownloadableItemSizes(int position)
{
return CountryTree.getDownloadableLeafSize(position);
return new long[] { CountryTree.getLeafSize(position, -1, true),
CountryTree.getLeafSize(position, -1, false) };
}
@Override

View file

@ -63,19 +63,22 @@ public class DownloadedAdapter extends BaseDownloadAdapter implements ActiveCoun
@Override
protected long[] getItemSizes(int position, int options)
{
return ActiveCountryTree.getCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position), options);
return new long[] { ActiveCountryTree.getCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position), options, true),
ActiveCountryTree.getCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position), options, false)};
}
@Override
protected long[] getRemoteItemSizes(int position)
{
return ActiveCountryTree.getRemoteCountrySizes(getGroupByAbsPosition(position), getPositionInGroup(position));
long mapOnly = ActiveCountryTree.getCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position), StorageOptions.MAP_OPTION_MAP_ONLY, false);
return new long[] { mapOnly, mapOnly + ActiveCountryTree.getCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position), StorageOptions.MAP_OPTION_CAR_ROUTING, false)};
}
@Override
protected long[] getDownloadableItemSizes(int position)
{
return ActiveCountryTree.getDownloadableCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position));
return new long[] { ActiveCountryTree.getCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position), -1, true),
ActiveCountryTree.getCountrySize(getGroupByAbsPosition(position), getPositionInGroup(position), -1, false)};
}
@Override
@ -95,10 +98,7 @@ public class DownloadedAdapter extends BaseDownloadAdapter implements ActiveCoun
final int group = getGroupByAbsPosition(position);
final int positionInGroup = getPositionInGroup(position);
return new CountryItem(ActiveCountryTree.getCountryName(group, positionInGroup),
ActiveCountryTree.getCountryStatus(group, positionInGroup),
ActiveCountryTree.getCountryOptions(group, positionInGroup),
false);
return ActiveCountryTree.getCountryItem(group, positionInGroup);
}
@Override

View file

@ -10,6 +10,7 @@ import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.mapswithme.country.CountryItem;
import com.mapswithme.maps.background.Notifier;
import com.mapswithme.maps.background.WorkerService;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
@ -64,7 +65,10 @@ public class MWMApplication extends android.app.Application implements ActiveCou
public void onCountryStatusChanged(int group, int position, int oldStatus, int newStatus)
{
if (newStatus == MapStorage.DOWNLOAD_FAILED)
Notifier.placeDownloadFailed(ActiveCountryTree.getCoreIndex(group, position), ActiveCountryTree.getCountryName(group, position));
{
CountryItem item = ActiveCountryTree.getCountryItem(group, position);
Notifier.placeDownloadFailed(ActiveCountryTree.getCoreIndex(group, position), item.getName());
}
}
@Override
@ -73,12 +77,13 @@ public class MWMApplication extends android.app.Application implements ActiveCou
@Override
public void onCountryOptionsChanged(int group, int position, int newOptions, int requestOptions)
{
if (ActiveCountryTree.getCountryStatus(group, position) != MapStorage.ON_DISK)
CountryItem item = ActiveCountryTree.getCountryItem(group, position);
if (item.getStatus() != MapStorage.ON_DISK)
return;
if (newOptions == requestOptions)
{
Notifier.placeDownloadCompleted(ActiveCountryTree.getCoreIndex(group, position), ActiveCountryTree.getCountryName(group, position));
Notifier.placeDownloadCompleted(ActiveCountryTree.getCoreIndex(group, position), item.getName());
tryNotifyGuideAvailable(group, position);
}
}

View file

@ -246,7 +246,7 @@ LocalAndRemoteSizeT const ActiveMapsLayout::GetRemoteCountrySizes(TIndex const &
{
CountryFile const & c = GetStorage().CountryByIndex(index).GetFile();
size_t const mapSize = c.GetRemoteSize(TMapOptions::EMapOnly);
return { mapSize, mapSize + c.GetRemoteSize(TMapOptions::ECarRouting) };
return { mapSize, c.GetRemoteSize(TMapOptions::ECarRouting) };
}
int ActiveMapsLayout::AddListener(ActiveMapsListener * listener)

View file

@ -346,16 +346,15 @@ void CountryStatusDisplay::SetContentForDownloadPropose()
ASSERT(m_primaryButton->isVisible(), ());
ASSERT(m_secondaryButton->isVisible(), ());
LocalAndRemoteSizeT mapOnlySize = m_activeMaps.GetCountrySize(m_countryIdx, TMapOptions::EMapOnly);
LocalAndRemoteSizeT withRouting = m_activeMaps.GetCountrySize(m_countryIdx, TMapOptions::EMapWithCarRouting);
LocalAndRemoteSizeT mapAndRoutingSize = m_activeMaps.GetRemoteCountrySizes(m_countryIdx);
m_label->setText(m_displayMapName);
uint64_t sizeToDownload;
string units;
FormatMapSize(mapOnlySize.second, units, sizeToDownload);
FormatMapSize(mapAndRoutingSize.first, units, sizeToDownload);
m_primaryButton->setText(FormatStatusMessage("country_status_download", &sizeToDownload, &units));
FormatMapSize(withRouting.second, units, sizeToDownload);
FormatMapSize(mapAndRoutingSize.first + mapAndRoutingSize.second, units, sizeToDownload);
m_secondaryButton->setText(FormatStatusMessage("country_status_download_routing", &sizeToDownload, &units));
}