[new downloader][android] fix: Downloader JNI interface updated and documented.

This commit is contained in:
Alexander Marchuk 2016-02-05 14:27:55 +03:00 committed by Sergey Yershov
parent be5ac2852f
commit 5a9bb5c83c
21 changed files with 342 additions and 594 deletions

View file

@ -65,8 +65,6 @@ LOCAL_HEADER_FILES := \
com/mapswithme/core/logging.hpp \
com/mapswithme/maps/Framework.hpp \
com/mapswithme/platform/Platform.hpp \
com/mapswithme/platform/MethodRef.hpp \
com/mapswithme/platform/http_thread_android.hpp \
com/mapswithme/opengl/android_gl_utils.hpp \
com/mapswithme/opengl/androidoglcontext.hpp \
com/mapswithme/opengl/androidoglcontextfactory.hpp \
@ -94,7 +92,6 @@ LOCAL_SRC_FILES := \
com/mapswithme/platform/Platform.cpp \
com/mapswithme/platform/HttpThread.cpp \
com/mapswithme/platform/Language.cpp \
com/mapswithme/platform/MethodRef.cpp \
com/mapswithme/platform/PThreadImpl.cpp \
com/mapswithme/util/StringUtils.cpp \
com/mapswithme/util/Config.cpp \

View file

@ -1,160 +0,0 @@
#include <jni.h>
#include "../maps/Framework.hpp"
#include "../maps/MapStorage.hpp"
#include "../core/jni_helper.hpp"
#include "country_helper.hpp"
using namespace storage_utils;
using namespace storage;
extern "C"
{
JNIEXPORT jint JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getOutOfDateCount(JNIEnv * env, jclass clazz)
{
return (g_framework->NeedMigrate() ? 0 : GetMapLayout().GetOutOfDateCount());
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountInGroup(JNIEnv * env, jclass clazz, jint group)
{
return GetMapLayout().GetCountInGroup(ToGroup(group));
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountryItem(JNIEnv * env, jclass clazz, jint group, jint 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(createMethodId, ());
return env->NewObject(createClass, createMethodId,
name, status, options, JNI_FALSE);
}
JNIEXPORT jlong JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCountrySize(JNIEnv * env, jclass clazz, jint group, jint position, jint options, jboolean isLocal)
{
ActiveMapsLayout & layout = GetMapLayout();
ActiveMapsLayout::TGroup coreGroup = ToGroup(group);
int pos = static_cast<int>(position);
bool const local = isLocal == JNI_TRUE;
MapOptions opt = ToOptions(options);
if (options == -1 || local)
{
LocalAndRemoteSizeT sizes = options == -1 ? layout.GetDownloadableCountrySize(coreGroup, pos)
: layout.GetCountrySize(coreGroup, pos, opt);
return local ? sizes.first : sizes.second;
}
LocalAndRemoteSizeT sizes = layout.GetRemoteCountrySizes(coreGroup, pos);
switch (opt)
{
case MapOptions::Map:
return sizes.first;
case MapOptions::CarRouting:
return sizes.second;
default:
return sizes.first + sizes.second;
}
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_cancelDownloading(JNIEnv * env, jclass clazz, jint group, jint position)
{
GetMapLayout().CancelDownloading(ToGroup(group), position);
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_country_ActiveCountryTree_isDownloadingActive(JNIEnv * env, jclass clazz)
{
return GetMapLayout().IsDownloadingActive();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_retryDownloading(JNIEnv * env, jclass clazz, jint group, jint position)
{
GetMapLayout().RetryDownloading(ToGroup(group), position);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_downloadMap(JNIEnv * env, jclass clazz, jint group, jint position, jint options)
{
GetMapLayout().DownloadMap(ToGroup(group), position, ToOptions(options));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_deleteMap(JNIEnv * env, jclass clazz, jint group, jint position, jint options)
{
GetMapLayout().DeleteMap(ToGroup(group), position, ToOptions(options));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_showOnMap(JNIEnv * env, jclass clazz, jint group, jint position)
{
g_framework->PostDrapeTask([group, position]()
{
GetMapLayout().ShowMap(ToGroup(group), position);
});
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_updateAll(JNIEnv * env, jclass clazz)
{
GetMapLayout().UpdateAll();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_cancelAll(JNIEnv * env, jclass clazz)
{
GetMapLayout().CancelAll();
}
JNIEXPORT int JNICALL
Java_com_mapswithme_country_ActiveCountryTree_addListener(JNIEnv * env, jclass clazz, jobject listener)
{
return g_framework->AddActiveMapsListener(jni::make_global_ref(listener));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_removeListener(JNIEnv * env, jclass clazz, jint slotID)
{
g_framework->RemoveActiveMapsListener(slotID);
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_country_ActiveCountryTree_getCoreIndex(JNIEnv * env, jclass clazz, jint group, jint position)
{
return storage::ToJava(GetMapLayout().GetCoreIndex(static_cast<storage::ActiveMapsLayout::TGroup>(group),
static_cast<int>(position)));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_downloadMapForIndex(JNIEnv * env, jclass clazz, jobject index, jint options)
{
GetMapLayout().DownloadMap(storage::ToNative(index), ToOptions(options));
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_country_ActiveCountryTree_isLegacyMode(JNIEnv * env, jclass clazz)
{
return g_framework->NeedMigrate();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_ActiveCountryTree_migrate(JNIEnv * env, jclass clazz)
{
g_framework->Migrate();
}
}

View file

@ -1,150 +0,0 @@
#include <jni.h>
#include "../maps/Framework.hpp"
#include "../core/jni_helper.hpp"
#include "country_helper.hpp"
using namespace storage_utils;
using namespace storage;
extern "C"
{
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_setDefaultRoot(JNIEnv * env, jclass clazz)
{
GetTree().SetDefaultRoot();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_setParentAsRoot(JNIEnv * env, jclass clazz)
{
GetTree().SetParentAsRoot();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_setChildAsRoot(JNIEnv * env, jclass clazz, jint position)
{
GetTree().SetChildAsRoot(position);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_resetRoot(JNIEnv * env, jclass clazz)
{
GetTree().ResetRoot();
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_country_CountryTree_hasParent(JNIEnv * env, jclass clazz)
{
return GetTree().HasParent();
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_country_CountryTree_getChildCount(JNIEnv * env, jclass clazz)
{
return GetTree().GetChildCount();
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_country_CountryTree_getChildItem(JNIEnv * env, jclass clazz, jint position)
{
CountryTree & tree = GetTree();
int corePosition = static_cast<int>(position);
bool const isLeaf = tree.IsLeaf(corePosition);
jstring name = jni::ToJavaString(env, tree.GetChildName(corePosition));
jint status = isLeaf ? static_cast<jint>(tree.GetLeafStatus(corePosition)) : 0;
jint options = isLeaf ? static_cast<jint>(tree.GetLeafOptions(corePosition)) : 0;
jclass createClass = env->FindClass("com/mapswithme/country/CountryItem");
ASSERT(createClass, ());
jmethodID createMethodId = env->GetMethodID(createClass, "<init>", "(Ljava/lang/String;IIZ)V");
ASSERT(createMethodId, ());
return env->NewObject(createClass, createMethodId,
name, status, options, (!isLeaf) == true ? JNI_TRUE : JNI_FALSE);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_downloadCountry(JNIEnv * env, jclass clazz, jint position, jint options)
{
GetTree().DownloadCountry(position, ToOptions(options));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_deleteCountry(JNIEnv * env, jclass clazz, jint position, jint options)
{
GetTree().DeleteCountry(position, ToOptions(options));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_cancelDownloading(JNIEnv * env, jclass clazz, jint position)
{
GetTree().CancelDownloading(position);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_retryDownloading(JNIEnv * env, jclass clazz, jint position)
{
GetTree().RetryDownloading(position);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_showLeafOnMap(JNIEnv * env, jclass clazz, jint position)
{
g_framework->PostDrapeTask([position]()
{
GetTree().ShowLeafOnMap(position);
});
}
JNIEXPORT jlong JNICALL
Java_com_mapswithme_country_CountryTree_getLeafSize(JNIEnv * env, jclass clazz, jint position, jint options, jboolean isLocal)
{
CountryTree & tree = GetTree();
int pos = static_cast<int>(position);
bool const local = (isLocal == JNI_TRUE) ? true : false;
MapOptions opt = ToOptions(options);
if (options == -1 || local)
{
LocalAndRemoteSizeT sizes = options == -1 ? tree.GetDownloadableLeafSize(pos) : tree.GetLeafSize(pos, opt);
return local ? sizes.first : sizes.second;
}
LocalAndRemoteSizeT sizes = tree.GetRemoteLeafSizes(pos);
switch (opt)
{
case MapOptions::Map:
return sizes.first;
case MapOptions::CarRouting:
return sizes.second;
default:
return sizes.first + sizes.second;
}
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_setListener(JNIEnv * env, jclass clazz, jobject listener)
{
g_framework->SetCountryTreeListener(jni::make_global_ref(listener));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_resetListener(JNIEnv * env, jclass clazz, jobject listener)
{
g_framework->ResetCountryTreeListener();
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_country_CountryTree_isDownloadableGroup(JNIEnv * env, jclass clazz)
{
return GetTree().IsDownloadAllAvailable();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_country_CountryTree_downloadGroup(JNIEnv * env, jclass clazz)
{
GetTree().DownloadAll();
}
}

View file

@ -1,23 +0,0 @@
#include "country_helper.hpp"
namespace storage_utils
{
::Framework * frm() { return g_framework->NativeFramework(); }
storage::ActiveMapsLayout & GetMapLayout() { return frm()->GetCountryTree().GetActiveMapLayout(); }
storage::CountryTree & GetTree() { return frm()->GetCountryTree(); }
storage::ActiveMapsLayout::TGroup ToGroup(int group) { return static_cast<storage::ActiveMapsLayout::TGroup>(group); }
MapOptions ToOptions(int options) { return static_cast<MapOptions>(options); }
jlongArray ToArray(JNIEnv * env, storage::LocalAndRemoteSizeT const & size)
{
jlongArray result = env->NewLongArray(2);
jlong * arr = env->GetLongArrayElements(result, NULL);
arr[0] = size.first;
arr[1] = size.second;
env->ReleaseLongArrayElements(result, arr, 0);
return result;
}
}

View file

@ -1,19 +0,0 @@
#pragma once
#include "../core/jni_helper.hpp"
#include "../maps/MapStorage.hpp"
#include "../maps/Framework.hpp"
#include "platform/country_defines.hpp"
namespace storage_utils
{
::Framework * frm();
storage::ActiveMapsLayout & GetMapLayout();
storage::CountryTree & GetTree();
storage::ActiveMapsLayout::TGroup ToGroup(int group);
MapOptions ToOptions(int options);
jlongArray ToArray(JNIEnv * env, storage::LocalAndRemoteSizeT const & sizes);
}

View file

@ -1,5 +1,4 @@
#include "Framework.hpp"
#include "MapStorage.hpp"
#include "defines.hpp"
@ -15,6 +14,8 @@
#include "base/logging.hpp"
#include "base/string_utils.hpp"
#include "com/mapswithme/core/jni_helper.hpp"
#include "std/vector.hpp"
#include "std/string.hpp"
#include "std/bind.hpp"
@ -51,18 +52,25 @@ static shared_ptr<HttpRequest> g_currentRequest;
extern "C"
{
int HasSpaceForFiles(Platform & pl, string const & sdcardPath, size_t fileSize)
typedef HttpRequest::CallbackT CallbackT;
static int HasSpaceForFiles(Platform & pl, string const & sdcardPath, size_t fileSize)
{
switch (pl.GetWritableStorageStatus(fileSize))
{
case Platform::STORAGE_DISCONNECTED: return ERR_STORAGE_DISCONNECTED;
case Platform::NOT_ENOUGH_SPACE: return ERR_NOT_ENOUGH_FREE_SPACE;
default: return fileSize;
case Platform::STORAGE_DISCONNECTED:
return ERR_STORAGE_DISCONNECTED;
case Platform::NOT_ENOUGH_SPACE:
return ERR_NOT_ENOUGH_FREE_SPACE;
default:
return fileSize;
}
}
// Check if we need to download mandatory resource file.
bool NeedToDownload(Platform & pl, string const & name, int size)
static bool NeedToDownload(Platform & pl, string const & name, int size)
{
try
{
@ -80,7 +88,7 @@ extern "C"
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_DownloadResourcesActivity_getBytesToDownload(JNIEnv * env, jobject thiz)
Java_com_mapswithme_maps_DownloadResourcesActivity_nativeGetBytesToDownload(JNIEnv * env, jclass clazz)
{
// clear all
g_filesToDownload.clear();
@ -107,7 +115,7 @@ extern "C"
if (NeedToDownload(pl, name, size))
{
LOG(LDEBUG, ("Should download", name, "sized", size, "bytes"));
LOG(LDEBUG, ("Should download", name, "size", size, "bytes"));
FileToDownload f;
f.m_pathOnSdcard = path + name;
@ -130,7 +138,7 @@ extern "C"
return res;
}
void DownloadFileFinished(shared_ptr<jobject> obj, HttpRequest const & req)
static void DownloadFileFinished(shared_ptr<jobject> obj, HttpRequest const & req)
{
HttpRequest::StatusT const status = req.Status();
ASSERT_NOT_EQUAL(status, HttpRequest::EInProgress, ());
@ -144,11 +152,9 @@ extern "C"
if (errorCode == ERR_DOWNLOAD_SUCCESS)
{
FileToDownload & curFile = g_filesToDownload.back();
LOG(LDEBUG, ("finished downloading", curFile.m_fileName, "sized", curFile.m_fileSize, "bytes"));
LOG(LDEBUG, ("finished downloading", curFile.m_fileName, "size", curFile.m_fileSize, "bytes"));
g_totalDownloadedBytes += curFile.m_fileSize;
LOG(LDEBUG, ("totalDownloadedBytes:", g_totalDownloadedBytes));
g_filesToDownload.pop_back();
@ -156,33 +162,20 @@ extern "C"
JNIEnv * env = jni::GetEnv();
jmethodID methodID = jni::GetMethodID(env, *obj.get(), "onDownloadFinished", "(I)V");
jmethodID methodID = jni::GetMethodID(env, *obj.get(), "onFinish", "(I)V");
env->CallVoidMethod(*obj.get(), methodID, errorCode);
}
void DownloadFileProgress(shared_ptr<jobject> obj, HttpRequest const & req)
static void DownloadFileProgress(shared_ptr<jobject> listener, HttpRequest const & req)
{
//LOG(LDEBUG, (req.Progress().first, "bytes for", g_filesToDownload.back().m_fileName, "was downloaded"));
FileToDownload & curFile = g_filesToDownload.back();
jint curTotal = req.Progress().second;
jint curProgress = req.Progress().first;
jint glbTotal = g_totalBytesToDownload;
jint glbProgress = g_totalDownloadedBytes + req.Progress().first;
JNIEnv * env = jni::GetEnv();
jmethodID methodID = jni::GetMethodID(env, *obj.get(), "onDownloadProgress", "(IIII)V");
env->CallVoidMethod(*obj.get(), methodID,
curTotal, curProgress,
glbTotal, glbProgress);
static jmethodID methodID = jni::GetMethodID(env, *listener.get(), "onProgress", "(I)V");
env->CallVoidMethod(*listener.get(), methodID, static_cast<jint>(g_totalDownloadedBytes + req.Progress().first));
}
typedef HttpRequest::CallbackT CallbackT;
void DownloadURLListFinished(HttpRequest const & req,
CallbackT const & onFinish, CallbackT const & onProgress)
static void DownloadURLListFinished(HttpRequest const & req, CallbackT const & onFinish, CallbackT const & onProgress)
{
FileToDownload & curFile = g_filesToDownload.back();
@ -197,22 +190,11 @@ extern "C"
LOG(LDEBUG, (curFile.m_urls[i]));
}
g_currentRequest.reset(HttpRequest::GetFile(
curFile.m_urls, curFile.m_pathOnSdcard, curFile.m_fileSize,
onFinish, onProgress,
512 * 1024, false));
g_currentRequest.reset(HttpRequest::GetFile(curFile.m_urls, curFile.m_pathOnSdcard, curFile.m_fileSize, onFinish, onProgress, 512 * 1024, false));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_DownloadResourcesActivity_cancelCurrentFile(JNIEnv * env, jobject thiz)
{
LOG(LDEBUG, ("cancelCurrentFile, currentRequest=", g_currentRequest.get()));
g_currentRequest.reset();
}
JNIEXPORT int JNICALL
Java_com_mapswithme_maps_DownloadResourcesActivity_startNextFileDownload(JNIEnv * env,
jobject thiz, jobject observer)
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_DownloadResourcesActivity_nativeStartNextFileDownload(JNIEnv * env, jclass clazz, jobject listener)
{
if (g_filesToDownload.empty())
return ERR_NO_MORE_FILES;
@ -221,13 +203,18 @@ extern "C"
LOG(LDEBUG, ("downloading", curFile.m_fileName, "sized", curFile.m_fileSize, "bytes"));
CallbackT onFinish(bind(&DownloadFileFinished, jni::make_global_ref(observer), _1));
CallbackT onProgress(bind(&DownloadFileProgress, jni::make_global_ref(observer), _1));
g_currentRequest.reset(HttpRequest::PostJson(
GetPlatform().ResourcesMetaServerUrl(), curFile.m_fileName,
bind(&DownloadURLListFinished, _1, onFinish, onProgress)));
CallbackT onFinish(bind(&DownloadFileFinished, jni::make_global_ref(listener), _1));
CallbackT onProgress(bind(&DownloadFileProgress, jni::make_global_ref(listener), _1));
g_currentRequest.reset(HttpRequest::PostJson(GetPlatform().ResourcesMetaServerUrl(), curFile.m_fileName,
bind(&DownloadURLListFinished, _1, onFinish, onProgress)));
return ERR_FILE_IN_PROGRESS;
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_DownloadResourcesActivity_nativeCancelCurrentFile(JNIEnv * env, jclass clazz)
{
LOG(LDEBUG, ("cancelCurrentFile, currentRequest=", g_currentRequest.get()));
g_currentRequest.reset();
}
}

View file

@ -441,9 +441,9 @@ void Framework::SetupMeasurementSystem()
}
//////////////////////////////////////////////////////////////////////////////////////////
/* TODO (trashkalmar): remove old downloader's stuff
void Framework::ItemStatusChanged(int childPosition)
{
/* TODO (trashkalmar): remove old downloader's stuff
if (m_javaCountryListener == NULL)
return;
@ -452,10 +452,9 @@ void Framework::ItemStatusChanged(int childPosition)
"onItemStatusChanged", "(I)V");
ASSERT ( methodID, () );
env->CallVoidMethod(*m_javaCountryListener, methodID, childPosition);*/
env->CallVoidMethod(*m_javaCountryListener, methodID, childPosition);
}
/* TODO (trashkalmar): remove old downloader's stuff
void Framework::ItemProgressChanged(int childPosition, LocalAndRemoteSizeT const & sizes)
{
if (m_javaCountryListener == NULL)
@ -1017,9 +1016,9 @@ extern "C"
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeShowCountry(JNIEnv * env, jobject thiz, jobject countryId, jboolean zoomToDownloadButton)
Java_com_mapswithme_maps_Framework_nativeShowCountry(JNIEnv * env, jobject thiz, jstring countryId, jboolean zoomToDownloadButton)
{
g_framework->ShowCountry(ToNative(countryId), (bool) zoomToDownloadButton);
g_framework->ShowCountry(jni::ToNativeString(env, countryId), (bool) zoomToDownloadButton);
}
JNIEXPORT void JNICALL

View file

@ -177,10 +177,10 @@ namespace android
void Migrate();
public:
/* TODO (trashkalmar): remove old downloader's stuff
virtual void ItemStatusChanged(int childPosition);
virtual void ItemProgressChanged(int childPosition, storage::LocalAndRemoteSizeT const & sizes);
/* TODO (trashkalmar): remove old downloader's stuff
virtual void CountryGroupChanged(storage::ActiveMapsLayout::TGroup const & oldGroup, int oldPosition,
storage::ActiveMapsLayout::TGroup const & newGroup, int newPosition);
virtual void CountryStatusChanged(storage::ActiveMapsLayout::TGroup const & group, int position,

View file

@ -1,5 +1,4 @@
#include "Framework.hpp"
#include "MapStorage.hpp"
#include "../core/jni_helper.hpp"
@ -12,8 +11,6 @@
#include "platform/file_logging.hpp"
#include "platform/settings.hpp"
using namespace storage;
using namespace storage_utils;
extern "C"
{

View file

@ -17,17 +17,7 @@ enum ItemCategory : uint32_t
{
NEAR_ME,
DOWNLOADED,
OTHER,
};
enum ItemStatus : uint32_t
{
UPDATABLE,
DOWNLOADABLE,
ENQUEUED,
DONE,
PROGRESS,
FAILED,
ALL,
};
jclass g_listClass;
@ -49,7 +39,7 @@ void PrepareClassRefs(JNIEnv * env)
g_countryItemClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/downloader/CountryItem");
}
string GetLocalizedName(string const & id)
string GetLocalizedName(TCountryId const & id)
{
// TODO
return id;
@ -67,18 +57,31 @@ using namespace data;
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeIsLegacyMode(JNIEnv * env, jclass clazz)
{
// TODO (trashkalmar): use appropriate method
return version::IsSingleMwm(g_framework->Storage().GetCurrentDataVersion());
return g_framework->NeedMigrate();
}
// static void nativeMigrate();
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeMigrate(JNIEnv * env, jclass clazz)
{
g_framework->Migrate();
}
// static String nativeGetRootNode();
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetRootNode(JNIEnv * env, jclass clazz)
{
return jni::ToJavaString(env, Storage().GetRootId());
}
// static @Nullable UpdateInfo nativeGetUpdateInfo();
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetUpdateInfo(JNIEnv * env, jclass clazz)
{
// FIXME (trashkalmar): Uncomment after Storage::GetUpdateInfo() is implemented
static Storage::UpdateInfo info = { 0 };
//if (!GetStorage().GetUpdateInfo(info))
// return nullptr;
// FIXME (trashkalmar): GetUpdateInfo()'s signature might be changed in the near future.
if (!GetStorage().GetUpdateInfo(nullptr, info))
return nullptr;
static jclass const infoClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/downloader/UpdateInfo");
ASSERT(infoClass, (jni::DescribeException()));
@ -88,30 +91,55 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeGetUpdateInfo(JNIEnv * env,
return env->NewObject(infoClass, ctor, info.m_numberOfMwmFilesToUpdate, info.m_totalUpdateSizeInBytes);
}
static void PutItemsToList(JNIEnv * env, jobject const list, vector<TCountryId> const & children, TCountryId const & parent, function<void (jobject const)> const & callback)
static void UpdateItem(JNIEnv * env, jobject item, NodeAttrs const & attrs)
{
static jmethodID const countryItemCtor = env->GetMethodID(g_countryItemClass, "<init>", "()V");
static jfieldID const countryItemFieldId = env->GetFieldID(g_countryItemClass, "id", "Ljava/lang/String;");
static jfieldID const countryItemFieldParentId = env->GetFieldID(g_countryItemClass, "parentId", "Ljava/lang/String;");
static jfieldID const countryItemFieldName = env->GetFieldID(g_countryItemClass, "name", "Ljava/lang/String;");
static jfieldID const countryItemFieldParentName = env->GetFieldID(g_countryItemClass, "parentName", "Ljava/lang/String;");
static jfieldID const countryItemFieldSize = env->GetFieldID(g_countryItemClass, "size", "J");
static jfieldID const countryItemFieldTotalSize = env->GetFieldID(g_countryItemClass, "totalSize", "J");
static jfieldID const countryItemFieldChildCount = env->GetFieldID(g_countryItemClass, "childCount", "I");
static jfieldID const countryItemFieldTotalChildCount = env->GetFieldID(g_countryItemClass, "totalChildCount", "I");
static jfieldID const countryItemFieldStatus = env->GetFieldID(g_countryItemClass, "status", "I");
static jfieldID const countryItemFieldErrorCode = env->GetFieldID(g_countryItemClass, "errorCode", "I");
// Localized name
jstring name = jni::ToJavaString(env, attrs.m_nodeLocalName);
env->SetObjectField(item, countryItemFieldName, name);
env->DeleteLocalRef(name);
// Sizes
env->SetLongField(item, countryItemFieldSize, attrs.m_localMwmSize);
env->SetLongField(item, countryItemFieldTotalSize, attrs.m_mwmSize);
// Child counts
env->SetIntField(item, countryItemFieldChildCount, attrs.m_localMwmCounter);
env->SetIntField(item, countryItemFieldTotalChildCount, attrs.m_mwmCounter);
// Status and error code
env->SetIntField(item, countryItemFieldStatus, static_cast<jint>(attrs.m_status));
env->SetIntField(item, countryItemFieldErrorCode, static_cast<jint>(attrs.m_error));
}
static void PutItemsToList(JNIEnv * env, jobject const list, vector<TCountryId> const & children, TCountryId const & parent,
int category, function<void (jobject const)> const & callback)
{
static jmethodID const countryItemCtor = env->GetMethodID(g_countryItemClass, "<init>", "(Ljava/lang/String;)V");
static jfieldID const countryItemFieldCategory = env->GetFieldID(g_countryItemClass, "category", "I");
static jfieldID const countryItemFieldParentId = env->GetFieldID(g_countryItemClass, "parentId", "Ljava/lang/String;");
jstring parentId = jni::ToJavaString(env, parent);
jstring parentName = jni::ToJavaString(env, GetLocalizedName(parent));
NodeAttrs attrs;
for (TCountryId const & child : children)
{
jobject item = env->NewObject(g_countryItemClass, countryItemCtor);
GetStorage().GetNodeAttrs(child, attrs);
// ID and parent`s ID
jstring id = jni::ToJavaString(env, child);
env->SetObjectField(item, countryItemFieldId, id);
jobject item = env->NewObject(g_countryItemClass, countryItemCtor, id);
env->SetIntField(item, countryItemFieldCategory, category);
env->SetObjectField(item, countryItemFieldParentId, parentId);
// Localized name and parent`s name
jstring name = jni::ToJavaString(env, GetLocalizedName(child));
env->SetObjectField(item, countryItemFieldName, name);
env->SetObjectField(item, countryItemFieldParentName, parentName);
UpdateItem(env, item, attrs);
// Let the caller do special processing
callback(item);
@ -122,7 +150,6 @@ static void PutItemsToList(JNIEnv * env, jobject const list, vector<TCountryId>
// Drop local refs
env->DeleteLocalRef(item);
env->DeleteLocalRef(id);
env->DeleteLocalRef(name);
}
}
@ -135,13 +162,19 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeListItems(JNIEnv * env, jcl
Storage const & storage = GetStorage();
TCountryId const parentId = (parent ? jni::ToNativeString(env, parent) : storage.GetRootId());
static jfieldID const countryItemFieldParentId = env->GetFieldID(g_countryItemClass, "parentId", "Ljava/lang/String;");
static jfieldID const countryItemFieldParentName = env->GetFieldID(g_countryItemClass, "parentName", "Ljava/lang/String;");
if (parent)
{
vector<TCountryId> children;
storage.GetChildren(parentId, children);
PutItemsToList(env, result, children, parentId, [](jobject const item)
{
jstring parentName = jni::ToJavaString(env, GetLocalizedName(parentId));
PutItemsToList(env, result, children, parentId, ItemCategory::ALL, [env, parent, parentName](jobject const item)
{
env->SetObjectField(item, countryItemFieldParentId, parent);
env->SetObjectField(item, countryItemFieldParentName, parentName);
});
}
else
@ -151,47 +184,97 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeListItems(JNIEnv * env, jcl
// Downloaded
vector<TCountryId> children;
storage.GetDownloadedChildren(parentId, children);
PutItemsToList(env, result, children, parentId, ItemCategory::DOWNLOADED, [env](jobject const item)
{
PutItemsToList(env, result, children, parentId, [](jobject const item)
});
// All
storage.GetChildren(parentId, children);
PutItemsToList(env, result, children, parentId, ItemCategory::ALL, [env](jobject const item)
{
});
//
}
//vector<TCountryId> const children = storage::GetChildren(parentId);
}
// static boolean nativeStartDownload(String countryId);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeStartDownload(JNIEnv * env, jclass clazz, jstring countryId)
// static void nativeUpdateItem(CountryItem item);
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeGetAttributes(JNIEnv * env, jclass clazz, jobject item)
{
// FIXME (trashkalmar): Uncomment after Storage::DownloadNode() is implemented
return true;//GetStorage().DownloadNode(jni::ToNativeString(env, countryId));
PrepareClassRefs(env);
NodeAttrs attrs;
static jfieldID countryItemFieldId = env->GetFieldID(g_countryItemClass, "id", "Ljava/lang/String;");
jstring id = static_cast<jstring>(env->GetObjectField(item, countryItemFieldId));
GetStorage().GetNodeAttrs(jni::ToNativeString(env, id), attrs);
UpdateItem(env, item, attrs);
}
// static boolean nativeCancelDownload(String countryId);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeCancelDownload(JNIEnv * env, jclass clazz, jstring countryId)
// static @Nullable String nativeFindCountry(double lat, double lon);
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeFindCountry(JNIEnv * env, jclass clazz, jdouble lat, jdouble lon)
{
// FIXME (trashkalmar): Uncomment after Storage::DeleteNode() is implemented
return true;//GetStorage().DeleteNode(jni::ToNativeString(env, countryId));
return jni::ToJavaString(env, g_framework->NativeFramework()->CountryInfoGetter().GetRegionCountryId(MercatorBounds::FromLatLon(lat, lon)));
}
// static boolean nativeIsDownloading();
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeIsDownloading(JNIEnv * env, jclass clazz)
{
return GetStorage().IsDownloadInProgress();
}
// static boolean nativeDownload(String root);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeDownload(JNIEnv * env, jclass clazz, jstring root)
{
return GetStorage().DownloadNode(jni::ToNativeString(env, root));
}
// static boolean nativeUpdate(String root);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeUpdate(JNIEnv * env, jclass clazz, jstring root)
{
// FIXME (trashkalmar): Uncomment after method is implemented.
//return GetStorage().UpdateNode(jni::ToNativeString(env, root));
return true;
}
// static boolean nativeCancel(String root);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeCancel(JNIEnv * env, jclass clazz, jstring root)
{
return GetStorage().CancelDownloadNode(jni::ToNativeString(env, root));
}
// static boolean nativeDelete(String root);
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeDelete(JNIEnv * env, jclass clazz, jstring root)
{
return GetStorage().DeleteNode(jni::ToNativeString(env, root));
}
static void StatusChangedCallback(shared_ptr<jobject> const & listenerRef, TCountryId const & countryId)
{
JNIEnv * env = jni::GetEnv();
jmethodID const methodID = jni::GetJavaMethodID(env, *listenerRef.get(), "onStatusChanged", "(Ljava/lang/String;)V");
env->CallVoidMethod(*listenerRef.get(), methodID, jni::ToJavaString(env, countryId));
// TODO: The core will do this itself
NodeAttrs attrs;
GetStorage().GetNodeAttrs(countryId, attrs);
static jmethodID const methodID = jni::GetMethodID(env, *listenerRef.get(), "onStatusChanged", "(Ljava/lang/String;I)V");
env->CallVoidMethod(*listenerRef.get(), methodID, jni::ToJavaString(env, countryId), attrs.m_status);
}
static void ProgressChangedCallback(shared_ptr<jobject> const & listenerRef, TCountryId const & countryId, LocalAndRemoteSizeT const & sizes)
static void ProgressChangedCallback(shared_ptr<jobject> const & listenerRef, TCountryId const & countryId, TLocalAndRemoteSize const & sizes)
{
JNIEnv * env = jni::GetEnv();
jmethodID const methodID = jni::GetJavaMethodID(env, *listenerRef.get(), "onProgress", "(Ljava/lang/String;JJ)V");
static jmethodID const methodID = jni::GetMethodID(env, *listenerRef.get(), "onProgress", "(Ljava/lang/String;JJ)V");
env->CallVoidMethod(*listenerRef.get(), methodID, jni::ToJavaString(env, countryId), sizes.first, sizes.second);
}
@ -199,6 +282,7 @@ static void ProgressChangedCallback(shared_ptr<jobject> const & listenerRef, TCo
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_downloader_MapManager_nativeSubscribe(JNIEnv * env, jclass clazz, jobject listener)
{
PrepareClassRefs(env);
return GetStorage().Subscribe(bind(&StatusChangedCallback, jni::make_global_ref(listener), _1),
bind(&ProgressChangedCallback, jni::make_global_ref(listener), _1, _2));
}
@ -210,4 +294,4 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeUnsubscribe(JNIEnv * env, j
GetStorage().Unsubscribe(slot);
}
} // extern "C"
} // extern "C"

View file

@ -21,7 +21,7 @@ public:
JNIEnv * env = jni::GetEnv();
ASSERT ( env, () );
jclass klass = env->FindClass("com/mapswithme/maps/downloader/DownloadChunkTask");
jclass klass = env->FindClass("com/mapswithme/maps/downloader/ChunkTask");
ASSERT ( klass, () );
static jmethodID initMethodId = env->GetMethodID(klass, "<init>", "(JLjava/lang/String;JJJ[BLjava/lang/String;)V");
@ -101,8 +101,7 @@ namespace downloader
extern "C"
{
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_downloader_DownloadChunkTask_onWrite(JNIEnv * env, jobject thiz,
jlong httpCallbackID, jlong beg, jbyteArray data, jlong size)
Java_com_mapswithme_maps_downloader_ChunkTask_nativeOnWrite(JNIEnv * env, jclass clazz, jlong httpCallbackID, jlong beg, jbyteArray data, jlong size)
{
downloader::IHttpThreadCallback * cb = reinterpret_cast<downloader::IHttpThreadCallback*>(httpCallbackID);
jbyte * buf = env->GetByteArrayElements(data, 0);
@ -114,8 +113,7 @@ extern "C"
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_downloader_DownloadChunkTask_onFinish(JNIEnv * env, jobject thiz,
jlong httpCallbackID, jlong httpCode, jlong beg, jlong end)
Java_com_mapswithme_maps_downloader_ChunkTask_nativeOnFinish(JNIEnv * env, jclass clazz, jlong httpCallbackID, jlong httpCode, jlong beg, jlong end)
{
downloader::IHttpThreadCallback * cb = reinterpret_cast<downloader::IHttpThreadCallback*>(httpCallbackID);
cb->OnFinish(httpCode, beg, end);

View file

@ -1,38 +0,0 @@
#include "MethodRef.hpp"
#include <base/assert.hpp>
#include <base/logging.hpp>
MethodRef::MethodRef(char const * name, char const * signature)
: m_name(name)
, m_signature(signature)
, m_methodID(nullptr)
, m_object(nullptr)
{
LOG(LDEBUG, ("Name = ", name));
}
MethodRef::~MethodRef()
{
if (m_object != nullptr)
jni::GetEnv()->DeleteGlobalRef(m_object);
}
void MethodRef::Init(jobject obj)
{
JNIEnv * env = jni::GetEnv();
m_object = env->NewGlobalRef(obj);
jclass const k = env->GetObjectClass(m_object);
m_methodID = env->GetMethodID(k, m_name, m_signature);
ASSERT(m_object != nullptr, ());
ASSERT(m_methodID != nullptr, ());
}
void MethodRef::CallVoid(jlong arg)
{
JNIEnv * jniEnv = jni::GetEnv();
ASSERT(jniEnv != nullptr, ());
ASSERT(m_object != nullptr, ());
ASSERT(m_methodID != nullptr, ());
jniEnv->CallVoidMethod(m_object, m_methodID, arg);
}

View file

@ -1,19 +0,0 @@
#pragma once
#include "../core/jni_helper.hpp"
class MethodRef
{
public:
MethodRef(char const * name, char const * signature);
~MethodRef();
void Init(jobject obj);
void CallVoid(jlong arg);
private:
char const * m_name;
char const * m_signature;
jmethodID m_methodID;
jobject m_object;
};

View file

@ -90,17 +90,17 @@ Platform::EConnectionType Platform::ConnectionStatus()
namespace android
{
Platform::Platform()
: m_runOnUI("runNativeFunctorOnUiThread", "(J)V")
{
}
void Platform::Initialize(JNIEnv * env,
jobject functorProcessObject,
jstring apkPath, jstring storagePath,
jstring tmpPath, jstring obbGooglePath,
jstring flavorName, jstring buildType,
bool isYota, bool isTablet)
{
m_functorProcessObject = env->NewGlobalRef(functorProcessObject);
jclass const functorProcessClass = env->GetObjectClass(functorProcessObject);
m_functorProcessMethod = env->GetMethodID(functorProcessClass, "processFunctor", "(J)V");
string const flavor = jni::ToNativeString(env, flavorName);
string const build = jni::ToNativeString(env, buildType);
LOG(LINFO, ("Flavor name:", flavor));
@ -145,12 +145,7 @@ namespace android
(void) ConnectionStatus();
}
void Platform::InitAppMethodRefs(jobject appObject)
{
m_runOnUI.Init(appObject);
}
void Platform::CallNativeFunctor(jlong functionPointer)
void Platform::ProcessFunctor(jlong functionPointer)
{
TFunctor * fn = reinterpret_cast<TFunctor *>(functionPointer);
(*fn)();
@ -191,7 +186,9 @@ namespace android
void Platform::RunOnGuiThread(TFunctor const & fn)
{
m_runOnUI.CallVoid(reinterpret_cast<jlong>(new TFunctor(fn)));
// Pointer will be deleted in Platform::ProcessFunctor
TFunctor * functor = new TFunctor(fn);
jni::GetEnv()->CallVoidMethod(m_functorProcessObject, m_functorProcessMethod, reinterpret_cast<jlong>(functor));
}
}

View file

@ -2,8 +2,6 @@
#include <jni.h>
#include "MethodRef.hpp"
#include "platform/platform.hpp"
namespace android
@ -11,15 +9,15 @@ namespace android
class Platform : public ::Platform
{
public:
Platform();
Platform() {}
void Initialize(JNIEnv * env,
jobject functorProcessObject,
jstring apkPath, jstring storagePath,
jstring tmpPath, jstring obbGooglePath,
jstring flavorName, jstring buildType,
bool isYota, bool isTablet);
void InitAppMethodRefs(jobject appObject);
void CallNativeFunctor(jlong functionPointer);
void ProcessFunctor(jlong functionPointer);
void OnExternalStorageStatusChanged(bool isAvailable);
@ -34,6 +32,7 @@ namespace android
static Platform & Instance();
private:
MethodRef m_runOnUI;
jobject m_functorProcessObject;
jmethodID m_functorProcessMethod;
};
}

View file

@ -19,9 +19,9 @@ import com.mapswithme.util.StringUtils;
import com.mapswithme.util.Utils;
@SuppressWarnings("unused")
class DownloadChunkTask extends AsyncTask<Void, byte[], Boolean>
class ChunkTask extends AsyncTask<Void, byte[], Boolean>
{
private static final String TAG = "DownloadChunkTask";
private static final String TAG = "ChunkTask";
private static final int TIMEOUT_IN_SECONDS = 60;
@ -44,12 +44,8 @@ class DownloadChunkTask extends AsyncTask<Void, byte[], Boolean>
private static final Executor sExecutors = Executors.newFixedThreadPool(4);
native boolean onWrite(long httpCallbackID, long beg, byte[] data, long size);
native void onFinish(long httpCallbackID, long httpCode, long beg, long end);
public DownloadChunkTask(long httpCallbackID, String url, long beg, long end,
long expectedFileSize, byte[] postBody, String userAgent)
public ChunkTask(long httpCallbackID, String url, long beg, long end,
long expectedFileSize, byte[] postBody, String userAgent)
{
mHttpCallbackID = httpCallbackID;
mUrl = url;
@ -61,11 +57,12 @@ class DownloadChunkTask extends AsyncTask<Void, byte[], Boolean>
}
@Override
protected void onPreExecute()
{
}
protected void onPreExecute() {}
private long getChunkID() { return mBeg; }
private long getChunkID()
{
return mBeg;
}
@Override
protected void onPostExecute(Boolean success)
@ -78,7 +75,7 @@ class DownloadChunkTask extends AsyncTask<Void, byte[], Boolean>
// start activity when no connection is present.
if (!isCancelled())
onFinish(mHttpCallbackID, success ? 200 : mHttpErrorCode, mBeg, mEnd);
nativeOnFinish(mHttpCallbackID, success ? 200 : mHttpErrorCode, mBeg, mEnd);
}
@Override
@ -87,13 +84,13 @@ class DownloadChunkTask extends AsyncTask<Void, byte[], Boolean>
if (!isCancelled())
{
// Use progress event to save downloaded bytes.
if (onWrite(mHttpCallbackID, mBeg + mDownloadedBytes, data[0], data[0].length))
if (nativeOnWrite(mHttpCallbackID, mBeg + mDownloadedBytes, data[0], data[0].length))
mDownloadedBytes += data[0].length;
else
{
// Cancel downloading and notify about error.
cancel(false);
onFinish(mHttpCallbackID, WRITE_ERROR, mBeg, mEnd);
nativeOnFinish(mHttpCallbackID, WRITE_ERROR, mBeg, mEnd);
}
}
}
@ -284,4 +281,7 @@ class DownloadChunkTask extends AsyncTask<Void, byte[], Boolean>
// -1 - means the end of the stream (success), else - some error occurred
return (readBytes == -1 ? 0 : -1);
}
private static native boolean nativeOnWrite(long httpCallbackID, long beg, byte[] data, long size);
private static native void nativeOnFinish(long httpCallbackID, long httpCode, long beg, long end);
}

View file

@ -1,42 +1,60 @@
package com.mapswithme.maps.downloader;
import java.util.Comparator;
import android.support.annotation.NonNull;
/**
* Class representing a single item in countries hierarchy.
* Fields are filled by native code.
*/
@SuppressWarnings("unused")
public final class CountryItem implements Comparator<CountryItem>
public final class CountryItem implements Comparable<CountryItem>
{
// Must correspond to ItemCategory in MapManager.cpp
public static final int CATEGORY_NEAR_ME = 0;
public static final int CATEGORY_DOWNLOADED = 1;
public static final int CATEGORY_OTHER = 2;
public static final int CATEGORY_ALL = 2;
// Must correspond to ItemStatus in MapManager.cpp
public static final int STATUS_UPDATABLE = 0;
public static final int STATUS_DOWNLOADABLE = 1;
public static final int STATUS_ENQUEUED = 2;
public static final int STATUS_DONE = 3;
// Must correspond to NodeStatus in storage_defines.hpp
public static final int STATUS_UNKNOWN = 0;
public static final int STATUS_FAILED = 1;
public static final int STATUS_DONE = 2;
public static final int STATUS_DOWNLOADABLE = 3;
public static final int STATUS_PROGRESS = 4;
public static final int STATUS_FAILED = 5;
public static final int STATUS_ENQUEUED = 5;
public static final int STATUS_UPDATABLE = 6;
public static final int STATUS_MIXED = 7;
// Must correspond to NodeErrorCode in storage_defines.hpp
public static final int ERROR_NONE = 0;
public static final int ERROR_UNKNOWN = 1;
public static final int ERROR_OOM = 2;
public static final int ERROR_NO_INTERNET = 3;
public String id;
public final String id;
public String parentId;
public String name;
public String parentName;
public long size;
public long totalSize;
public int childCount;
public int totalChildCount;
public int category;
public int status;
public int errorCode;
public int progress;
// Internal ID for grouping under headers in the list
public int headerId;
public CountryItem(String id)
{
this.id = id;
}
@Override
public int hashCode()
@ -57,8 +75,29 @@ public final class CountryItem implements Comparator<CountryItem>
}
@Override
public int compare(CountryItem lhs, CountryItem rhs)
public int compareTo(@NonNull CountryItem another)
{
return lhs.name.compareTo(rhs.name);
int catDiff = (category - another.category);
if (catDiff != 0)
return catDiff;
return name.compareTo(another.name);
}
}
@Override
public String toString()
{
return "{ id: \"" + id +
"\", parentId: \"" + parentId +
"\", category: " + category +
", status: " + status +
", headerId: " + headerId +
", name: \"" + name +
"\", parentName: \"" + parentName +
"\", size: " + size +
", totalSize: " + totalSize +
", childCount: " + childCount +
", totalChildCount: " + totalChildCount +
"}";
}
}

View file

@ -6,33 +6,94 @@ import java.util.List;
public final class MapManager
{
@SuppressWarnings("unused")
public interface StorageCallback
{
void onStatusChanged(String countryId);
void onStatusChanged(String countryId, int newStatus);
void onProgress(String countryId, long localSize, long remoteSize);
}
private MapManager() {}
// Determines whether the legacy (large MWMs) mode is used.
/**
* Determines whether the legacy (large MWMs) mode is used.
*/
public static native boolean nativeIsLegacyMode();
// Returns info about updatable data. Returns null on error.
/**
* Performs migration from old (large MWMs) mode.
*/
public static native void nativeMigrate();
/**
* Returns country ID of the root node.
*/
public static native String nativeGetRootNode();
/**
* Returns info about updatable data or null on error.
*/
public static native @Nullable UpdateInfo nativeGetUpdateInfo();
// Retrieves list of country items with its status info. Use root as parent if parent is null.
/**
* Retrieves list of country items with its status info. Uses root as parent if {@code root} is null.
*/
public static native void nativeListItems(@Nullable String root, List<CountryItem> result);
// Enqueue country in downloader.
public static native boolean nativeStartDownload(String countryId);
/**
* Sets following attributes of the given {@code item}:
* <pre>
* <ul>
* <li>name;</li>
* <li>size;</li>
* <li>totalSize;</li>
* <li>childCount;</li>
* <li>totalChildCount;</li>
* <li>status;</li>
* <li>errorCode</li>
* </ul>
* </pre>
*/
public static native void nativeGetAttributes(CountryItem item);
// Remove downloading country from downloader.
public static native boolean nativeCancelDownload(String countryId);
/**
* Returns country ID corresponding to given coordinates or {@code null} on error.
*/
public static native @Nullable String nativeFindCountry(double lat, double lon);
// Registers callback about storage status changed. Returns slot ID which is should be used to unsubscribe.
public static native int nativeSubscribe(StorageCallback listener);
/**
* Determines whether something is downloading now.
*/
public static native boolean nativeIsDownloading();
// Unregisters storage status changed callback.
/**
* Enqueues given {@code root} node and its children in downloader.
*/
public static native boolean nativeDownload(String root);
/**
* Enqueues given {@code root} node with its children in downloader.
*/
public static native boolean nativeUpdate(String root);
/**
* Removes given currently downloading {@code root} node and its children from downloader.
*/
public static native boolean nativeCancel(String root);
/**
* Deletes given installed {@code root} node with its children.
*/
public static native boolean nativeDelete(String root);
/**
* Registers {@code callback} of storage status changed. Returns slot ID which is should be used to unsubscribe in {@link #nativeUnsubscribe(int)}.
*/
public static native int nativeSubscribe(StorageCallback callback);
/**
* Unregisters storage status changed callback.
* @param slot Slot ID returned from {@link #nativeSubscribe(StorageCallback)} while registering.
*/
public static native void nativeUnsubscribe(int slot);
}
}

View file

@ -1,6 +0,0 @@
package com.mapswithme.util;
public interface Proc<T>
{
void invoke(T param);
}

View file

@ -40,6 +40,11 @@ public class Utils
{
private static final String TAG = "Utils";
public interface Proc<T>
{
void invoke(T param);
}
private Utils() {}
public static void closeStream(Closeable stream)

View file

@ -3,7 +3,7 @@ package com.mapswithme.util.concurrency;
import android.os.Handler;
import android.os.Looper;
import com.mapswithme.util.Proc;
import com.mapswithme.util.Utils;
public class UiThread
{
@ -26,7 +26,7 @@ public class UiThread
protected abstract void runUi();
}
public static abstract class UiProc<T> implements Proc<T>
public static abstract class UiProc<T> implements Utils.Proc<T>
{
@Override
public final void invoke(final T param)