[and] Fixes for mwm integration.
This commit is contained in:
parent
045a44ea0d
commit
b3724d5d20
5 changed files with 55 additions and 20 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "../../storage/storage.hpp"
|
||||
|
||||
#include "../../env/reader.hpp"
|
||||
#include "../../env/latlon.hpp"
|
||||
|
||||
#include <android/asset_manager_jni.h>
|
||||
|
||||
|
@ -148,6 +149,12 @@ JNIEXPORT jobject JNICALL Java_com_example_travelguide_cpp_Storage_getArticleInf
|
|||
return NativeArticle2JavaArticle(env, STORAGE.GetArticleInfoByUrl(JString2StdString(env, url)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_example_travelguide_cpp_Storage_isValidLatLon
|
||||
(JNIEnv * env, jclass clazz, jdouble lat, jdouble lon)
|
||||
{
|
||||
return ll::ValidLat(lat) && ll::ValidLon(lon) ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -67,8 +67,18 @@ public class ArticleInfoListActivity extends FragmentActivity implements Article
|
|||
handleIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent)
|
||||
{
|
||||
super.onNewIntent(intent);
|
||||
handleIntent(intent);
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent)
|
||||
{
|
||||
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0)
|
||||
return;
|
||||
|
||||
final MWMResponse mwmResponse = MWMResponse.extractFromIntent(this, intent);
|
||||
final MWMPoint point = mwmResponse.getPoint();
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ package com.example.travelguide;
|
|||
import static com.example.travelguide.util.Utils.hideIf;
|
||||
import static com.example.travelguide.util.Utils.hideView;
|
||||
import static com.example.travelguide.util.Utils.showView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
|
@ -261,6 +264,7 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Storage> loader, Storage result)
|
||||
{
|
||||
|
@ -315,23 +319,32 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
// TODO: show about dialog
|
||||
}
|
||||
else if (v.getId() == mShowMapForAll.getId())
|
||||
openInMwm();
|
||||
}
|
||||
|
||||
private void openInMwm()
|
||||
{
|
||||
final int count = Storage.getResultSize();
|
||||
if (count < 1)
|
||||
return;
|
||||
|
||||
final ArrayList<MWMPoint> points = new ArrayList<MWMPoint>();
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
final int count = Storage.getResultSize();
|
||||
MWMPoint points[] = new MWMPoint[count];
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
final ArticleInfo info = Storage.getArticleInfoByIndex(i);
|
||||
final String url = info.getArticleId();
|
||||
final String id = url.substring(0, url.lastIndexOf('.'));
|
||||
points[i] = new MWMPoint(info.getLat(), info.getLon(), info.getName(), id);
|
||||
}
|
||||
|
||||
final Activity a = getActivity();
|
||||
final Intent intent = new Intent(a, ArticleInfoListActivity.class);
|
||||
final PendingIntent pi = PendingIntent.getActivity(a, 0, intent, 0);
|
||||
MapsWithMeApi.showPointsOnMap(a, "Hello, my articles!", pi, points);
|
||||
final ArticleInfo info = Storage.getArticleInfoByIndex(i);
|
||||
final String url = info.getArticleId();
|
||||
final String id = url.substring(0, url.lastIndexOf('.'));
|
||||
if (info.isValidLatLon())
|
||||
points.add(new MWMPoint(info.getLat(), info.getLon(), info.getName(), id));
|
||||
}
|
||||
if (points.size() < 1)
|
||||
return;
|
||||
|
||||
final Activity a = getActivity();
|
||||
final Intent intent = new Intent(a, ArticleInfoListActivity.class);
|
||||
final PendingIntent pi = PendingIntent.getActivity(a, 0, intent, 0);
|
||||
MapsWithMeApi.showPointsOnMap
|
||||
(a, "Hello, my articles!", pi, points.toArray(new MWMPoint[points.size()]));
|
||||
}
|
||||
|
||||
private Location getLocation()
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.example.travelguide.article;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.example.travelguide.cpp.Storage;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ArticleInfo implements Serializable
|
||||
{
|
||||
|
@ -12,7 +14,7 @@ public class ArticleInfo implements Serializable
|
|||
this.mArticleUrl = articleUrl;
|
||||
this.mIconUrl = iconUrl;
|
||||
this.mTitle = title;
|
||||
|
||||
|
||||
this.mParent = parent;
|
||||
this.mLat = lat;
|
||||
this.mLon = lon;
|
||||
|
@ -20,16 +22,18 @@ public class ArticleInfo implements Serializable
|
|||
private final String mArticleUrl;
|
||||
private final String mIconUrl;
|
||||
private final String mTitle;
|
||||
|
||||
|
||||
private final String mParent;
|
||||
private final double mLat;
|
||||
private final double mLon;
|
||||
|
||||
|
||||
public String getName() { return mTitle; }
|
||||
public String getIconUrl() { return mIconUrl; }
|
||||
public String getArticleId() { return mArticleUrl; }
|
||||
public String getParent() { return mParent; }
|
||||
|
||||
|
||||
public double getLat() { return mLat; }
|
||||
public double getLon() { return mLon; }
|
||||
|
||||
public boolean isValidLatLon() { return Storage.isValidLatLon(mLat, mLon); }
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public class Storage
|
|||
|
||||
public native static ArticleInfo getArticleInfoByIndex(int index);
|
||||
|
||||
native private static void nativeInitIndex(AssetManager am);
|
||||
private native static void nativeInitIndex(AssetManager am);
|
||||
|
||||
public native static boolean isValidLatLon(double lat, double lon);
|
||||
}
|
||||
|
|
Reference in a new issue