Jni methods modifications.

This commit is contained in:
Dmitry Yunitsky 2014-07-31 17:36:27 +03:00 committed by Alex Zolotarev
parent 45248f35a2
commit 7a704babd8
10 changed files with 78 additions and 54 deletions

View file

@ -250,19 +250,6 @@ extern "C"
return ERR_FILE_IN_PROGRESS;
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_DownloadResourcesActivity_findIndexByPos(JNIEnv * env, jobject thiz,
jdouble lat, jdouble lon)
{
storage::TIndex const idx = g_framework->GetCountryIndex(lat, lon);
// Important thing. Return 0 if no any country.
if (idx.IsValid())
return storage::ToJava(idx);
else
return 0;
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_DownloadResourcesActivity_loadKMZFile(
JNIEnv * env, jobject thiz, jstring path)

View file

@ -176,11 +176,19 @@ namespace android
return m_work.GetCountryStatusDisplay();
}
void Framework::ShowCountry(storage::TIndex const & idx)
void Framework::ShowCountry(storage::TIndex const & idx, bool zoomToDownloadButton)
{
m_doLoadState = false;
m_work.ShowCountry(idx);
if (zoomToDownloadButton)
{
m2::RectD const rect = m_work.GetCountryBounds(idx);
double const lon = MercatorBounds::XToLon(rect.Center().x);
double const lat = MercatorBounds::YToLat(rect.Center().y);
m_work.ShowRect(lat, lon, 10);
}
else
m_work.ShowCountry(idx);
}
storage::TStatus Framework::GetCountryStatus(storage::TIndex const & idx) const
@ -1127,4 +1135,39 @@ extern "C"
UserMark const * mark = fr->GetUserMark(pxPoint, true);
fr->GetBalloonManager().OnShowMark(mark);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_Framework_nativeGetCountryNameIfAbsent(JNIEnv * env, jobject thiz,
jdouble lat, jdouble lon)
{
string const name = g_framework->GetCountryNameIfAbsent(MercatorBounds::FromLatLon(lat, lon));
return (name.empty() ? 0 : jni::ToJavaString(env, name));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_Framework_nativeGetViewportCountryNameIfAbsent(JNIEnv * env, jobject thiz)
{
string const name = g_framework->GetCountryNameIfAbsent(g_framework->GetViewportCenter());
return (name.empty() ? 0 : jni::ToJavaString(env, name));
}
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeGetCountryIndex(JNIEnv * env, jobject thiz,
jdouble lat, jdouble lon)
{
storage::TIndex const idx = g_framework->GetCountryIndex(lat, lon);
// Return 0 if no any country.
if (idx.IsValid())
return storage::ToJava(idx);
else
return 0;
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeShowCountry(JNIEnv * env, jobject thiz, jobject idx, jboolean zoomToDownloadButton)
{
g_framework->ShowCountry(storage::ToNative(idx), (bool) zoomToDownloadButton);
}
}

View file

@ -65,7 +65,7 @@ namespace android
storage::Storage & Storage();
CountryStatusDisplay * GetCountryStatusDisplay();
void ShowCountry(storage::TIndex const & idx);
void ShowCountry(storage::TIndex const & idx, bool zoomToDownloadButton);
storage::TStatus GetCountryStatus(storage::TIndex const & idx) const;
void DeleteCountry(storage::TIndex const & idx);

View file

@ -110,12 +110,6 @@ extern "C"
return 0;
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MapStorage_showCountry(JNIEnv * env, jobject thiz, jobject idx)
{
g_framework->ShowCountry(IndexBinding(idx).toNative());
}
void ReportChangeCountryStatus(shared_ptr<jobject> const & obj, storage::TIndex const & idx)
{
JNIEnv * env = jni::GetEnv();

View file

@ -286,22 +286,6 @@ Java_com_mapswithme_maps_SearchActivity_nativeGetResult(
}
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_SearchActivity_getCountryNameIfAbsent(JNIEnv * env, jobject thiz,
jdouble lat, jdouble lon)
{
string const name = g_framework->GetCountryNameIfAbsent(MercatorBounds::FromLatLon(lat, lon));
return (name.empty() ? 0 : jni::ToJavaString(env, name));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_SearchActivity_getViewportCountryNameIfAbsent(JNIEnv * env, jobject thiz)
{
string const name = g_framework->GetCountryNameIfAbsent(g_framework->GetViewportCenter());
return (name.empty() ? 0 : jni::ToJavaString(env, name));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_SearchActivity_getLastQuery(JNIEnv * env, jobject thiz)
{

View file

@ -555,7 +555,7 @@ class DownloadAdapter extends BaseAdapter
private void showCountry(final Index countryIndex)
{
mStorage.showCountry(countryIndex);
Framework.nativeShowCountry(countryIndex, false);
mContext.finish();
}

View file

@ -83,7 +83,8 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
new OpenCountryTaskProcessor(),
};
public static String EXTRA_COUNTRY_INDEX = ".extra.index";
public static final String EXTRA_COUNTRY_INDEX = ".extra.index";
public static final String EXTRA_AUTODOWNLOAD_CONTRY = ".extra.autodownload";
private void setDownloadMessage(int bytesToDownload)
{
@ -560,7 +561,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
final double lon = l.getLongitude();
Log.i(TAG, "Searching for country name at location lat=" + lat + ", lon=" + lon);
mCountryIndex = findIndexByPos(lat, lon);
mCountryIndex = Framework.nativeGetCountryIndex(lat, lon);
if (mCountryIndex != null)
{
mLocationMsgView.setVisibility(View.VISIBLE);
@ -777,7 +778,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
public boolean processIntent(Intent intent)
{
final Index index = (Index) intent.getSerializableExtra(EXTRA_COUNTRY_INDEX);
mMapTaskToForward = new MWMActivity.ShowCountryTask(index);
mMapTaskToForward = new MWMActivity.ShowCountryTask(index, intent.getBooleanExtra(EXTRA_AUTODOWNLOAD_CONTRY, false));
return true;
}
}
@ -786,8 +787,6 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
private native int startNextFileDownload(Object observer);
private native Index findIndexByPos(double lat, double lon);
private native void cancelCurrentFile();
private native boolean loadKMZFile(String path);

View file

@ -132,9 +132,11 @@ public class Framework
//
public static native String nativeGetCountryNameIfAbsent(double lat, double lon);
public native static String nativeGetCountryNameIfAbsent(double lat, double lon);
public static native Index nativeGetIndex(double lat, double lon);
public native static Index nativeGetCountryIndex(double lat, double lon);
public static native String nativeGetViewportCountryNameIfAbsent();
public native static String nativeGetViewportCountryNameIfAbsent();
public native static void nativeShowCountry(Index idx, boolean zoomToDownloadButton);
}

View file

@ -73,6 +73,7 @@ public class MWMActivity extends NvEventQueueActivity
private final static String SCREENSHOTS_TASK_PPP = "show_place_page";
private final static String EXTRA_LAT = "lat";
private final static String EXTRA_LON = "lon";
private final static String EXTRA_COUNTRY_INDEX = "country_index";
// Need it for search
private static final String EXTRA_SEARCH_RES_SINGLE = "search_res_index";
// Map tasks that we run AFTER rendering initialized
@ -94,10 +95,11 @@ public class MWMActivity extends NvEventQueueActivity
private ViewGroup mVerticalToolbar;
private ViewGroup mToolbar;
public static Intent createShowMapIntent(Context context, Index index)
public static Intent createShowMapIntent(Context context, Index index, boolean doAutoDownload)
{
return new Intent(context, DownloadResourcesActivity.class)
.putExtra(DownloadResourcesActivity.EXTRA_COUNTRY_INDEX, index);
.putExtra(DownloadResourcesActivity.EXTRA_COUNTRY_INDEX, index)
.putExtra(DownloadResourcesActivity.EXTRA_AUTODOWNLOAD_CONTRY, doAutoDownload);
}
public static void startWithSearchResult(Context context, boolean single)
@ -1049,7 +1051,11 @@ public class MWMActivity extends NvEventQueueActivity
private void stopWatchingExternalStorage()
{
mPathManager.stopExternalStorageWatching();
mExternalStorageReceiver = null;
if (mExternalStorageReceiver != null)
{
unregisterReceiver(mExternalStorageReceiver);
mExternalStorageReceiver = null;
}
}
@Override
@ -1314,16 +1320,27 @@ public class MWMActivity extends NvEventQueueActivity
{
private static final long serialVersionUID = 1L;
private final Index mIndex;
private final boolean mDoAutoDownload;
public ShowCountryTask(Index index)
public ShowCountryTask(Index index, boolean doAutoDownload)
{
mIndex = index;
mDoAutoDownload = doAutoDownload;
}
@Override
public boolean run(MWMActivity target)
{
target.getMapStorage().showCountry(mIndex);
final MapStorage storage = target.getMapStorage();
if (mDoAutoDownload)
{
storage.downloadCountry(mIndex);
// set zoom level so that download process is visible
Framework.nativeShowCountry(mIndex, true);
}
else
Framework.nativeShowCountry(mIndex, false);
return true;
}
}

View file

@ -154,8 +154,6 @@ public class MapStorage
public native Index findIndexByFile(String name);
public native void showCountry(Index idx);
public native int subscribe(Listener l);
public native void unsubscribe(int slotId);