[android] Minor copy/paste fixes.

This commit is contained in:
vng 2013-08-28 22:33:36 +03:00 committed by Alex Zolotarev
parent 006f01d897
commit 1e0e9b8187
5 changed files with 56 additions and 47 deletions

View file

@ -1,5 +1,6 @@
#include "Framework.hpp"
#include "VideoTimer.hpp"
#include "MapStorage.hpp"
#include "../core/jni_helper.hpp"
#include "../core/render_context.hpp"
@ -26,9 +27,12 @@
#include "../../../../../platform/preferred_languages.hpp"
namespace
{
const unsigned LONG_TOUCH_MS = 1000;
const unsigned SHORT_TOUCH_MS = 250;
const double DOUBLE_TOUCH_S = SHORT_TOUCH_MS / 1000.0;
}
android::Framework * g_framework = 0;
@ -772,33 +776,63 @@ extern "C"
g_framework->NativeFramework()->UpdateSavedDataVersion();
}
namespace
{
class GuideNative2Java
{
JNIEnv * m_env;
jclass m_giClass;
jmethodID m_methodID;
string m_lang;
public:
GuideNative2Java(JNIEnv * env) : m_env(env)
{
m_giClass = m_env->FindClass("com/mapswithme/maps/guides/GuideInfo");
m_methodID = m_env->GetMethodID(m_giClass,
"<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
m_lang = languages::CurrentLanguage();
}
jclass GetClass() const { return m_giClass; }
jobject GetGuide(guides::GuideInfo const & info) const
{
return m_env->NewObject(m_giClass, m_methodID,
jni::ToJavaString(m_env, info.GetAppID()),
jni::ToJavaString(m_env, info.GetURL()),
jni::ToJavaString(m_env, info.GetAdTitle(m_lang)),
jni::ToJavaString(m_env, info.GetAdMessage(m_lang)));
}
};
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_getGuideInfoForIndex(JNIEnv * env, jclass clazz, jobject index)
{
guides::GuideInfo info;
if (g_framework->NativeFramework()->GetGuideInfo(storage::ToNative(index), info))
return GuideNative2Java(env).GetGuide(info);
return NULL;
}
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_Framework_getGuideInfosForDownloadedMaps(JNIEnv * env, jclass clazz)
{
vector<guides::GuideInfo> infos;
g_framework->NativeFramework()->GetGuidesInfosWithDownloadedMaps(infos);
const size_t mapsFound = infos.size();
LOG(LDEBUG, ("Got maps:", infos));
size_t const mapsFound = infos.size();
if (mapsFound > 0)
{
const jclass giClass = env->FindClass("com/mapswithme/maps/guides/GuideInfo");
const jmethodID methodID = env->GetMethodID(giClass, "<init>",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
const string lang = languages::CurrentLanguage();
jobjectArray jInfos = env->NewObjectArray(mapsFound, giClass, NULL);
GuideNative2Java getter(env);
jobjectArray jInfos = env->NewObjectArray(mapsFound, getter.GetClass(), NULL);
for (size_t i = 0; i < mapsFound; ++i)
{
const guides::GuideInfo & info = infos[i];
jobject jGuideInfo = env->NewObject(giClass, methodID,
jni::ToJavaString(env, info.GetAppID()),
jni::ToJavaString(env, info.GetURL()), jni::ToJavaString(env, info.GetAdTitle(lang)),
jni::ToJavaString(env, info.GetAdMessage(lang)));
env->SetObjectArrayElement(jInfos, i, jGuideInfo);
}
env->SetObjectArrayElement(jInfos, i, getter.GetGuide(infos[i]));
return jInfos;
}

View file

@ -6,7 +6,6 @@
*/
#include "Framework.hpp"
#include "MapStorage.hpp"
#include "../core/jni_helper.hpp"
@ -17,7 +16,6 @@
#include "../../../../../map/dialog_settings.hpp"
#include "../../../../../platform/settings.hpp"
#include "../../../../../platform/preferred_languages.hpp"
extern "C"
@ -141,25 +139,4 @@ extern "C"
{
(void)Settings::Set(jni::ToNativeString(env, name), value);
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_MWMApplication_getGuideInfoForIndex(JNIEnv * env, jclass clazz, jobject index)
{
guides::GuideInfo info;
if (g_framework->NativeFramework()->GetGuideInfo(storage::ToNative(index), info))
{
const jclass giClass = env->FindClass("com/mapswithme/maps/guides/GuideInfo");
const jmethodID methodID = env->GetMethodID(giClass,
"<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
string const lang = languages::CurrentLanguage();
return env->NewObject(giClass, methodID,
jni::ToJavaString(env, info.GetAppID()),
jni::ToJavaString(env, info.GetURL()),
jni::ToJavaString(env, info.GetAdTitle(lang)),
jni::ToJavaString(env, info.GetAdMessage(lang)));
}
return 0;
}
}

View file

@ -566,12 +566,11 @@ public class DownloadUI extends MapsWithMeBaseListActivity implements MapStorage
}
if (mHasGoogleStore)
{
{
final CountryItem item = getItem(position);
if (item.getType() == TYPE_COUNTRY_IN_PROCESS || item.getType() == TYPE_COUNTRY_READY)
{
final GuideInfo gi = MWMApplication.get().getGuideInfoForIndex(item.mIdx);
final GuideInfo gi = Framework.getGuideInfoForIndex(item.mIdx);
if (gi != null)
{
UiUtils.hide(holder.mFlag);
@ -596,7 +595,6 @@ public class DownloadUI extends MapsWithMeBaseListActivity implements MapStorage
}
}
return convertView;
}

View file

@ -1,5 +1,6 @@
package com.mapswithme.maps;
import com.mapswithme.maps.MapStorage.Index;
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
import com.mapswithme.maps.guides.GuideInfo;
@ -79,6 +80,7 @@ public class Framework
nativeUpdateSavedDataVersion();
}
public native static GuideInfo getGuideInfoForIndex(Index idx);
public native static GuideInfo[] getGuideInfosForDownloadedMaps();
public native static void setWasAdvertised(String appId);
public native static boolean wasAdvertised(String appId);

View file

@ -84,13 +84,11 @@ public class MWMApplication extends android.app.Application implements MapStorag
}
}
public native GuideInfo getGuideInfoForIndex(Index idx);
private void tryNotifyGuideAvailable(Index idx)
{
if (Utils.hasAnyGoogleStoreInstalled())
{
final GuideInfo info = getGuideInfoForIndex(idx);
final GuideInfo info = Framework.getGuideInfoForIndex(idx);
if (info != null && !GuidesUtils.isGuideInstalled(info.mAppId, this))
{
final Notifier notifier = new Notifier(this);