forked from organicmaps/organicmaps
[android] statistic for banners
This commit is contained in:
parent
5cc6d69f57
commit
d90ede288c
4 changed files with 79 additions and 36 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "map/place_page_info.hpp"
|
||||
|
||||
#include "base/string_utils.hpp"
|
||||
|
||||
namespace usermark_helper
|
||||
{
|
||||
using search::AddressInfo;
|
||||
|
@ -22,23 +24,25 @@ void InjectMetadata(JNIEnv * env, jclass const clazz, jobject const mapObject, f
|
|||
}
|
||||
}
|
||||
|
||||
jobject CreateBanner(JNIEnv * env, string const & bannerTitleId, string const & bannerMessageId,
|
||||
string const & bannerIconId, string const & bannerUrl)
|
||||
jobject CreateBanner(JNIEnv * env, string const & id, string const & titleId,
|
||||
string const & messageId, string const & iconId,
|
||||
string const & url, vector<string> const & sourceTypes)
|
||||
{
|
||||
auto const types = strings::JoinStrings(sourceTypes, ", ");
|
||||
static jmethodID const bannerCtorId = jni::GetConstructorID(
|
||||
env, g_bannerClazz,
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
|
||||
"Ljava/lang/String;)V");
|
||||
|
||||
return env->NewObject(g_bannerClazz, bannerCtorId, jni::ToJavaString(env, bannerTitleId),
|
||||
jni::ToJavaString(env, bannerMessageId),
|
||||
jni::ToJavaString(env, bannerIconId), jni::ToJavaString(env, bannerUrl));
|
||||
return env->NewObject(g_bannerClazz, bannerCtorId, jni::ToJavaString(env, id),
|
||||
jni::ToJavaString(env, titleId), jni::ToJavaString(env, messageId),
|
||||
jni::ToJavaString(env, iconId), jni::ToJavaString(env, url),
|
||||
jni::ToJavaString(env, types));
|
||||
}
|
||||
|
||||
jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title,
|
||||
string const & subtitle, double lat, double lon, string const & address,
|
||||
Metadata const & metadata, string const & apiId, bool hasBanner,
|
||||
string const & bannerTitleId, string const & bannerMessageId,
|
||||
string const & bannerIconId, string const & bannerUrl,
|
||||
Metadata const & metadata, string const & apiId, jobject jbanner,
|
||||
bool isReachableByTaxi)
|
||||
{
|
||||
// public MapObject(@MapObjectType int mapObjectType, String title, String subtitle, double lat,
|
||||
|
@ -48,10 +52,6 @@ jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title,
|
|||
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;DDLjava/lang/"
|
||||
"String;Lcom/mapswithme/maps/bookmarks/data/Banner;Z)V");
|
||||
|
||||
jobject jbanner = nullptr;
|
||||
if (hasBanner)
|
||||
jbanner = CreateBanner(env, bannerTitleId, bannerMessageId, bannerIconId, bannerUrl);
|
||||
|
||||
jobject mapObject =
|
||||
env->NewObject(g_mapObjectClazz, ctorId, mapObjectType, jni::ToJavaString(env, title),
|
||||
jni::ToJavaString(env, subtitle), jni::ToJavaString(env, address), lat, lon,
|
||||
|
@ -63,6 +63,11 @@ jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title,
|
|||
|
||||
jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
||||
{
|
||||
jobject jbanner = nullptr;
|
||||
if (info.HasBanner())
|
||||
jbanner = CreateBanner(env, info.GetBannerId(), info.GetBannerTitleId(),
|
||||
info.GetBannerMessageId(), info.GetBannerIconId(),
|
||||
info.GetBannerUrl(), info.GetRawTypes());
|
||||
if (info.IsBookmark())
|
||||
{
|
||||
// public Bookmark(@IntRange(from = 0) int categoryId, @IntRange(from = 0) int bookmarkId,
|
||||
|
@ -70,11 +75,6 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
static jmethodID const ctorId = jni::GetConstructorID(
|
||||
env, g_bookmarkClazz, "(IILjava/lang/String;Lcom/mapswithme/maps/bookmarks/data/Banner;Z)V");
|
||||
|
||||
jobject jbanner = nullptr;
|
||||
if (info.HasBanner())
|
||||
jbanner = CreateBanner(env, info.GetBannerTitleId(), info.GetBannerMessageId(),
|
||||
info.GetBannerIconId(), info.GetBannerUrl());
|
||||
|
||||
auto const & bac = info.GetBookmarkAndCategory();
|
||||
BookmarkCategory * cat = g_framework->NativeFramework()->GetBmCategory(bac.m_categoryIndex);
|
||||
BookmarkData const & data =
|
||||
|
@ -98,20 +98,16 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
|
|||
// TODO(yunikkk): Should we pass localized strings here and in other methods as byte arrays?
|
||||
if (info.IsMyPosition())
|
||||
return CreateMapObject(env, kMyPosition, info.GetTitle(), info.GetSubtitle(), ll.lat, ll.lon,
|
||||
address.FormatAddress(), {}, "", info.HasBanner(),
|
||||
info.GetBannerTitleId(), info.GetBannerMessageId(),
|
||||
info.GetBannerIconId(), info.GetBannerUrl(), info.IsReachableByTaxi());
|
||||
address.FormatAddress(), {}, "", jbanner, info.IsReachableByTaxi());
|
||||
|
||||
if (info.HasApiUrl())
|
||||
return CreateMapObject(env, kApiPoint, info.GetTitle(), info.GetSubtitle(), ll.lat, ll.lon,
|
||||
address.FormatAddress(), info.GetMetadata(), info.GetApiUrl(),
|
||||
info.HasBanner(), info.GetBannerTitleId(), info.GetBannerMessageId(),
|
||||
info.GetBannerIconId(), info.GetBannerUrl(), info.IsReachableByTaxi());
|
||||
jbanner, info.IsReachableByTaxi());
|
||||
|
||||
return CreateMapObject(env, kPoi, info.GetTitle(), info.GetSubtitle(), ll.lat, ll.lon,
|
||||
address.FormatAddress(),
|
||||
info.IsFeature() ? info.GetMetadata() : Metadata(), "", info.HasBanner(),
|
||||
info.GetBannerTitleId(), info.GetBannerMessageId(), info.GetBannerIconId(),
|
||||
info.GetBannerUrl(), info.IsReachableByTaxi());
|
||||
info.IsFeature() ? info.GetMetadata() : Metadata(), "", jbanner,
|
||||
info.IsReachableByTaxi());
|
||||
}
|
||||
} // namespace usermark_helper
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.support.annotation.Nullable;
|
|||
|
||||
public final class Banner implements Parcelable
|
||||
{
|
||||
public static final Banner EMPTY = new Banner("", "", "", "");
|
||||
public static final Banner EMPTY = new Banner(null, null, null, null, null, null);
|
||||
|
||||
public static final Creator<Banner> CREATOR = new Creator<Banner>()
|
||||
{
|
||||
|
@ -23,6 +23,8 @@ public final class Banner implements Parcelable
|
|||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
private final String mId;
|
||||
@Nullable
|
||||
private final String mTitle;
|
||||
@Nullable
|
||||
|
@ -31,22 +33,34 @@ public final class Banner implements Parcelable
|
|||
private final String mIconUrl;
|
||||
@Nullable
|
||||
private final String mUrl;
|
||||
@Nullable
|
||||
private final String mTypes;
|
||||
|
||||
public Banner(@Nullable String title, @Nullable String message,
|
||||
@Nullable String iconUrl, @Nullable String url)
|
||||
public Banner(@Nullable String id, @Nullable String title, @Nullable String message,
|
||||
@Nullable String iconUrl, @Nullable String url, @Nullable String types)
|
||||
{
|
||||
mId = id;
|
||||
mTitle = title;
|
||||
mMessage = message;
|
||||
mIconUrl = iconUrl;
|
||||
mUrl = url;
|
||||
mTypes = types;
|
||||
}
|
||||
|
||||
protected Banner(Parcel in)
|
||||
{
|
||||
mId = in.readString();
|
||||
mTitle = in.readString();
|
||||
mMessage = in.readString();
|
||||
mIconUrl = in.readString();
|
||||
mUrl = in.readString();
|
||||
mTypes = in.readString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getId()
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -73,6 +87,12 @@ public final class Banner implements Parcelable
|
|||
return mUrl;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTypes()
|
||||
{
|
||||
return mTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
|
@ -82,9 +102,11 @@ public final class Banner implements Parcelable
|
|||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeString(mId);
|
||||
dest.writeString(mTitle);
|
||||
dest.writeString(mMessage);
|
||||
dest.writeString(mIconUrl);
|
||||
dest.writeString(mUrl);
|
||||
dest.writeString(mTypes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.bookmarks.data.Banner;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
import static com.mapswithme.util.SharedPropertiesUtils.isShowcaseSwitchedOnLocal;
|
||||
|
@ -54,7 +55,7 @@ final class BannerController implements View.OnClickListener
|
|||
@NonNull
|
||||
private final Resources mResources;
|
||||
|
||||
private boolean mIsOpened = false;
|
||||
private boolean mOpened = false;
|
||||
|
||||
@Nullable
|
||||
private ValueAnimator mIconAnimator;
|
||||
|
@ -62,6 +63,7 @@ final class BannerController implements View.OnClickListener
|
|||
BannerController(@NonNull View bannerView, @Nullable OnBannerClickListener listener)
|
||||
{
|
||||
mFrame = bannerView;
|
||||
mFrame.setOnClickListener(this);
|
||||
mListener = listener;
|
||||
mResources = mFrame.getResources();
|
||||
mCloseFrameHeight = mResources.getDimension(R.dimen.placepage_banner_height);
|
||||
|
@ -100,6 +102,12 @@ final class BannerController implements View.OnClickListener
|
|||
|
||||
if (UiUtils.isLandscape(mFrame.getContext()))
|
||||
open();
|
||||
else
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.PP_BANNER_SHOW,
|
||||
Statistics.params()
|
||||
.add("tags:", mBanner.getTypes())
|
||||
.add("banner:", mBanner.getId())
|
||||
.add("state:", "0"));
|
||||
}
|
||||
|
||||
boolean isShowing()
|
||||
|
@ -109,10 +117,10 @@ final class BannerController implements View.OnClickListener
|
|||
|
||||
void open()
|
||||
{
|
||||
if (!isShowing() || mBanner == null || mIsOpened)
|
||||
if (!isShowing() || mBanner == null || mOpened)
|
||||
return;
|
||||
|
||||
mIsOpened = true;
|
||||
mOpened = true;
|
||||
setFrameHeight(WRAP_CONTENT);
|
||||
setIconParams(mOpenIconSize, 0, mMarginBase, new Runnable()
|
||||
{
|
||||
|
@ -125,15 +133,20 @@ final class BannerController implements View.OnClickListener
|
|||
UiUtils.show(mMessage, mAdMarker);
|
||||
if (mTitle != null)
|
||||
mTitle.setMaxLines(2);
|
||||
mFrame.setOnClickListener(this);
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.PP_BANNER_SHOW,
|
||||
Statistics.params()
|
||||
.add("tags:", mBanner.getTypes())
|
||||
.add("banner:", mBanner.getId())
|
||||
.add("state:", "1"));
|
||||
}
|
||||
|
||||
boolean close()
|
||||
{
|
||||
if (!isShowing() || mBanner == null || !mIsOpened)
|
||||
if (!isShowing() || mBanner == null || !mOpened)
|
||||
return false;
|
||||
|
||||
mIsOpened = false;
|
||||
mOpened = false;
|
||||
setFrameHeight((int) mCloseFrameHeight);
|
||||
setIconParams(mCloseIconSize, mMarginBase, mMarginHalfPlus, new Runnable()
|
||||
{
|
||||
|
@ -146,6 +159,7 @@ final class BannerController implements View.OnClickListener
|
|||
UiUtils.hide(mMessage, mAdMarker);
|
||||
if (mTitle != null)
|
||||
mTitle.setMaxLines(1);
|
||||
|
||||
mFrame.setOnClickListener(null);
|
||||
|
||||
return true;
|
||||
|
@ -254,8 +268,17 @@ final class BannerController implements View.OnClickListener
|
|||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (mListener != null && mBanner != null)
|
||||
if (mListener == null || mBanner == null)
|
||||
return;
|
||||
|
||||
if (mOpened)
|
||||
mListener.onBannerClick(mBanner);
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.PP_BANNER_CLICK,
|
||||
Statistics.params()
|
||||
.add("tags:", mBanner.getTypes())
|
||||
.add("banner:", mBanner.getId())
|
||||
.add("state:", mOpened ? "1" : "0"));
|
||||
}
|
||||
|
||||
interface OnBannerClickListener
|
||||
|
|
|
@ -78,6 +78,8 @@ public enum Statistics
|
|||
public static final String PP_DIRECTION_ARROW = "PP. DirectionArrow";
|
||||
public static final String PP_DIRECTION_ARROW_CLOSE = "PP. DirectionArrowClose";
|
||||
public static final String PP_METADATA_COPY = "PP. CopyMetadata";
|
||||
public static final String PP_BANNER_CLICK = "Placepage_Banner_click";
|
||||
public static final String PP_BANNER_SHOW = "Placepage_Banner_show";
|
||||
|
||||
// toolbar actions
|
||||
public static final String TOOLBAR_MY_POSITION = "Toolbar. MyPosition";
|
||||
|
|
Loading…
Add table
Reference in a new issue