forked from organicmaps/organicmaps
[android] Added a local ad info class and JNI support for it
This commit is contained in:
parent
57e33973b1
commit
146fb4cda9
9 changed files with 136 additions and 21 deletions
|
@ -198,7 +198,7 @@ bool HandleJavaException(JNIEnv * env)
|
|||
const jthrowable e = env->ExceptionOccurred();
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
LOG(LERROR, (ToNativeString(env, e)));
|
||||
LOG(LWARNING, (ToNativeString(env, e)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -39,15 +39,17 @@ jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title,
|
|||
string const & secondaryTitle, string const & subtitle, double lat,
|
||||
double lon, string const & address, Metadata const & metadata,
|
||||
string const & apiId, jobjectArray jbanners, bool isReachableByTaxi,
|
||||
string const & bookingSearchUrl)
|
||||
string const & bookingSearchUrl, jobject const & localAdInfo)
|
||||
{
|
||||
// public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, double lat,
|
||||
// double lon, String address, String apiId, @NonNull Banner banner, boolean reachableByTaxi,
|
||||
// @Nullable String bookingSearchUrl)
|
||||
// public MapObject(@MapObjectType int mapObjectType, String title, String secondaryTitle,
|
||||
// String subtitle, double lat, double lon, String address, String apiId,
|
||||
// @NonNull Banner banner, boolean reachableByTaxi,
|
||||
// @Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo)
|
||||
static jmethodID const ctorId =
|
||||
jni::GetConstructorID(env, g_mapObjectClazz,
|
||||
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DDLjava/lang/"
|
||||
"String;[Lcom/mapswithme/maps/ads/Banner;ZLjava/lang/String;)V");
|
||||
"String;[Lcom/mapswithme/maps/ads/Banner;ZLjava/lang/String;"
|
||||
"Lcom/mapswithme/maps/ads/LocalAdInfo;)V");
|
||||
|
||||
jni::TScopedLocalRef jTitle(env, jni::ToJavaString(env, title));
|
||||
jni::TScopedLocalRef jSecondaryTitle(env, jni::ToJavaString(env, secondaryTitle));
|
||||
|
@ -58,7 +60,7 @@ jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title,
|
|||
jobject mapObject = env->NewObject(g_mapObjectClazz, ctorId, mapObjectType, jTitle.get(),
|
||||
jSecondaryTitle.get(), jSubtitle.get(), jAddress.get(), lat,
|
||||
lon, jApiId.get(), jbanners, isReachableByTaxi,
|
||||
jBookingSearchUrl.get());
|
||||
jBookingSearchUrl.get(), localAdInfo);
|
||||
|
||||
InjectMetadata(env, g_mapObjectClazz, mapObject, metadata);
|
||||
return mapObject;
|
||||
|
@ -70,6 +72,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
if (info.HasBanner())
|
||||
jbanners = ToBannersArray(env, info.GetBanners());
|
||||
|
||||
jobject const localAdInfo = CreateLocalAdInfo(env, info);
|
||||
|
||||
if (info.IsBookmark())
|
||||
{
|
||||
// public Bookmark(@IntRange(from = 0) int categoryId, @IntRange(from = 0) int bookmarkId,
|
||||
|
@ -91,7 +95,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
jobject mapObject =
|
||||
env->NewObject(g_bookmarkClazz, ctorId, static_cast<jint>(info.m_bac.m_categoryIndex),
|
||||
static_cast<jint>(info.m_bac.m_bookmarkIndex), jName.get(), jTitle.get(),
|
||||
jSecondaryTitle.get(), jbanners, info.IsReachableByTaxi(), jBookingSearchUrl.get());
|
||||
jSecondaryTitle.get(), jbanners, info.IsReachableByTaxi(),
|
||||
jBookingSearchUrl.get(), localAdInfo);
|
||||
if (info.IsFeature())
|
||||
InjectMetadata(env, g_mapObjectClazz, mapObject, info.GetMetadata());
|
||||
return mapObject;
|
||||
|
@ -106,17 +111,19 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
if (info.IsMyPosition())
|
||||
return CreateMapObject(env, kMyPosition, info.GetTitle(), info.GetSecondaryTitle(),
|
||||
info.GetSubtitle(), ll.lat, ll.lon, address.FormatAddress(), {}, "",
|
||||
jbanners, info.IsReachableByTaxi(), info.GetBookingSearchUrl());
|
||||
jbanners, info.IsReachableByTaxi(), info.GetBookingSearchUrl(),
|
||||
localAdInfo);
|
||||
|
||||
if (info.HasApiUrl())
|
||||
return CreateMapObject(env, kApiPoint, info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(),
|
||||
ll.lat, ll.lon, address.FormatAddress(), info.GetMetadata(),
|
||||
info.GetApiUrl(), jbanners, info.IsReachableByTaxi(), info.GetBookingSearchUrl());
|
||||
info.GetApiUrl(), jbanners, info.IsReachableByTaxi(),
|
||||
info.GetBookingSearchUrl(), localAdInfo);
|
||||
|
||||
return CreateMapObject(env, kPoi, info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(),
|
||||
ll.lat, ll.lon, address.FormatAddress(),
|
||||
info.IsFeature() ? info.GetMetadata() : Metadata(), "", jbanners,
|
||||
info.IsReachableByTaxi(), info.GetBookingSearchUrl());
|
||||
info.IsReachableByTaxi(), info.GetBookingSearchUrl(), localAdInfo);
|
||||
}
|
||||
|
||||
jobjectArray ToBannersArray(JNIEnv * env, vector<ads::Banner> const & banners)
|
||||
|
@ -126,4 +133,15 @@ jobjectArray ToBannersArray(JNIEnv * env, vector<ads::Banner> const & banners)
|
|||
return CreateBanner(env, item.m_bannerId, static_cast<jint>(item.m_type));
|
||||
});
|
||||
}
|
||||
|
||||
jobject CreateLocalAdInfo(JNIEnv * env, place_page::Info const & info)
|
||||
{
|
||||
static jclass const localAdInfoClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ads/LocalAdInfo");
|
||||
static jmethodID const ctorId = jni::GetConstructorID(env, localAdInfoClazz,
|
||||
"(ILjava/lang/String;)V");
|
||||
|
||||
jni::TScopedLocalRef jLocalAdUrl(env, jni::ToJavaString(env, info.GetLocalAdsUrl()));
|
||||
|
||||
return env->NewObject(localAdInfoClazz, ctorId, info.GetLocalAdsStatus(), jLocalAdUrl.get());
|
||||
}
|
||||
} // namespace usermark_helper
|
||||
|
|
|
@ -34,4 +34,6 @@ jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title, s
|
|||
jobject CreateMapObject(JNIEnv * env, place_page::Info const & info);
|
||||
|
||||
jobjectArray ToBannersArray(JNIEnv * env, vector<ads::Banner> const & banners);
|
||||
|
||||
jobject CreateLocalAdInfo(JNIEnv * env, place_page::Info const & info);
|
||||
} // namespace usermark_helper
|
||||
|
|
|
@ -1420,9 +1420,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
final RoutePoint from = data.mPoints[0];
|
||||
final RoutePoint to = data.mPoints[1];
|
||||
RoutingController.get().prepare(new MapObject(MapObject.API_POINT, from.mName, "", "", "",
|
||||
from.mLat, from.mLon, "", null, false, ""),
|
||||
from.mLat, from.mLon, "", null, false, "", null),
|
||||
new MapObject(MapObject.API_POINT, to.mName, "", "", "",
|
||||
to.mLat, to.mLon, "", null, false, ""));
|
||||
to.mLat, to.mLon, "", null, false, "", null));
|
||||
return true;
|
||||
case ParsedUrlMwmRequest.RESULT_SEARCH:
|
||||
final ParsedSearchRequest request = Framework.nativeGetParsedSearchRequest();
|
||||
|
|
82
android/src/com/mapswithme/maps/ads/LocalAdInfo.java
Normal file
82
android/src/com/mapswithme/maps/ads/LocalAdInfo.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package com.mapswithme.maps.ads;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class LocalAdInfo implements Parcelable
|
||||
{
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({ STATUS_NOT_AVAILABLE, STATUS_CANDIDATE, STATUS_CUSTOMER})
|
||||
|
||||
public @interface Status {}
|
||||
|
||||
private static final int STATUS_NOT_AVAILABLE = 0;
|
||||
private static final int STATUS_CANDIDATE = 1;
|
||||
private static final int STATUS_CUSTOMER = 2;
|
||||
|
||||
@Status
|
||||
private final int mStatus;
|
||||
@Nullable
|
||||
private final String mUrl;
|
||||
|
||||
private LocalAdInfo(@Status int status, @Nullable String url)
|
||||
{
|
||||
mUrl = url;
|
||||
mStatus = status;
|
||||
}
|
||||
|
||||
public boolean isAvailable()
|
||||
{
|
||||
return mStatus == STATUS_CUSTOMER || mStatus == STATUS_CANDIDATE;
|
||||
}
|
||||
|
||||
public boolean isCustomer()
|
||||
{
|
||||
return mStatus == STATUS_CUSTOMER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getUrl()
|
||||
{
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
private LocalAdInfo(Parcel in)
|
||||
{
|
||||
//noinspection WrongConstant
|
||||
this(in.readInt() /* mStatus */, in.readString() /* mUrl */);
|
||||
}
|
||||
|
||||
public static final Creator<LocalAdInfo> CREATOR = new Creator<LocalAdInfo>()
|
||||
{
|
||||
@Override
|
||||
public LocalAdInfo createFromParcel(Parcel in)
|
||||
{
|
||||
return new LocalAdInfo(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalAdInfo[] newArray(int size)
|
||||
{
|
||||
return new LocalAdInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeInt(mStatus);
|
||||
dest.writeString(mUrl);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import android.text.TextUtils;
|
|||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.ads.Banner;
|
||||
import com.mapswithme.maps.ads.LocalAdInfo;
|
||||
import com.mapswithme.util.Constants;
|
||||
|
||||
// TODO consider refactoring to remove hack with MapObject unmarshalling itself and Bookmark at the same time.
|
||||
|
@ -25,10 +26,10 @@ public class Bookmark extends MapObject
|
|||
|
||||
Bookmark(@IntRange(from = 0) int categoryId, @IntRange(from = 0) int bookmarkId, String title,
|
||||
@Nullable String secondaryTitle, @Nullable String objectTitle, @Nullable Banner[] banners,
|
||||
boolean reachableByTaxi, @Nullable String bookingSearchUrl)
|
||||
boolean reachableByTaxi, @Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo)
|
||||
{
|
||||
super(BOOKMARK, title, secondaryTitle, "", "", 0, 0, "", banners, reachableByTaxi,
|
||||
bookingSearchUrl);
|
||||
bookingSearchUrl, localAdInfo);
|
||||
|
||||
mCategoryId = categoryId;
|
||||
mBookmarkId = bookmarkId;
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.support.annotation.Nullable;
|
|||
import android.text.TextUtils;
|
||||
|
||||
import com.mapswithme.maps.ads.Banner;
|
||||
import com.mapswithme.maps.ads.LocalAdInfo;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -46,20 +47,22 @@ public class MapObject implements Parcelable
|
|||
private boolean mReachableByTaxi;
|
||||
@Nullable
|
||||
private String mBookingSearchUrl;
|
||||
@Nullable
|
||||
private LocalAdInfo mLocalAdInfo;
|
||||
|
||||
public MapObject(@MapObjectType int mapObjectType, String title, @Nullable String secondaryTitle,
|
||||
String subtitle, String address, double lat, double lon, String apiId,
|
||||
@Nullable Banner[] banners, boolean reachableByTaxi,
|
||||
@Nullable String bookingSearchUrl)
|
||||
@Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo)
|
||||
{
|
||||
this(mapObjectType, title, secondaryTitle, subtitle, address, lat, lon, new Metadata(),
|
||||
apiId, banners, reachableByTaxi, bookingSearchUrl);
|
||||
apiId, banners, reachableByTaxi, bookingSearchUrl, localAdInfo);
|
||||
}
|
||||
|
||||
public MapObject(@MapObjectType int mapObjectType, String title, @Nullable String secondaryTitle,
|
||||
String subtitle, String address, double lat, double lon, Metadata metadata,
|
||||
String apiId, @Nullable Banner[] banners, boolean reachableByTaxi,
|
||||
@Nullable String bookingSearchUrl)
|
||||
@Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo)
|
||||
{
|
||||
mMapObjectType = mapObjectType;
|
||||
mTitle = title;
|
||||
|
@ -72,6 +75,7 @@ public class MapObject implements Parcelable
|
|||
mApiId = apiId;
|
||||
mReachableByTaxi = reachableByTaxi;
|
||||
mBookingSearchUrl = bookingSearchUrl;
|
||||
mLocalAdInfo = localAdInfo;
|
||||
if (banners != null)
|
||||
mBanners = new ArrayList<>(Arrays.asList(banners));
|
||||
}
|
||||
|
@ -90,7 +94,8 @@ public class MapObject implements Parcelable
|
|||
source.readString(), // ApiId;
|
||||
null, // mBanners
|
||||
source.readByte() != 0, // ReachableByTaxi
|
||||
source.readString()); // BookingSearchUrl
|
||||
source.readString(), // BookingSearchUrl
|
||||
(LocalAdInfo) source.readParcelable(LocalAdInfo.class.getClassLoader())); // LocalAdInfo
|
||||
mBanners = readBanners(source);
|
||||
}
|
||||
|
||||
|
@ -225,6 +230,12 @@ public class MapObject implements Parcelable
|
|||
return mBookingSearchUrl;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LocalAdInfo getLocalAdInfo()
|
||||
{
|
||||
return mLocalAdInfo;
|
||||
}
|
||||
|
||||
private static MapObject readFromParcel(Parcel source)
|
||||
{
|
||||
@MapObjectType int type = source.readInt();
|
||||
|
@ -255,6 +266,7 @@ public class MapObject implements Parcelable
|
|||
dest.writeString(mApiId);
|
||||
dest.writeByte((byte) (mReachableByTaxi ? 1 : 0));
|
||||
dest.writeString(mBookingSearchUrl);
|
||||
dest.writeParcelable(mLocalAdInfo, 0);
|
||||
dest.writeTypedList(mBanners);
|
||||
}
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ public enum LocationHelper
|
|||
|
||||
if (mMyPosition == null)
|
||||
mMyPosition = new MapObject(MapObject.MY_POSITION, "", "", "", "", mSavedLocation.getLatitude(),
|
||||
mSavedLocation.getLongitude(), "", null, false, "");
|
||||
mSavedLocation.getLongitude(), "", null, false, "", null);
|
||||
|
||||
return mMyPosition;
|
||||
}
|
||||
|
|
|
@ -467,7 +467,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
{
|
||||
//noinspection ConstantConditions
|
||||
final MapObject point = new MapObject(MapObject.SEARCH, result.name, "",
|
||||
result.description.featureType, "", result.lat, result.lon, "", null, false, "");
|
||||
result.description.featureType, "", result.lat, result.lon, "", null, false, "", null);
|
||||
RoutingController.get().onPoiSelected(point);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue