From 0d1923592623624c52b643f59864b7acaf397a1b Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Thu, 22 Aug 2019 18:24:18 +0300 Subject: [PATCH] [bookmarks][android] Type icons. --- .../maps/bookmarks/data/Bookmark.cpp | 15 +- android/res/values/dimens.xml | 1 + .../mapswithme/maps/bookmarks/Holders.java | 8 +- .../maps/bookmarks/IconsAdapter.java | 4 +- .../maps/bookmarks/data/Bookmark.java | 9 +- .../maps/bookmarks/data/BookmarkInfo.java | 2 +- .../maps/bookmarks/data/BookmarkManager.java | 28 +--- .../mapswithme/maps/bookmarks/data/Icon.java | 152 ++++++++++++++++-- .../placepage/EditBookmarkFragment.java | 2 +- android/src/com/mapswithme/util/Graphics.java | 24 +++ map/bookmark_helpers.hpp | 1 + map/bookmark_manager.hpp | 1 + 12 files changed, 201 insertions(+), 46 deletions(-) diff --git a/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp b/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp index d27dd4ba4f..a0eea6df0b 100644 --- a/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp +++ b/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp @@ -2,6 +2,7 @@ #include "com/mapswithme/core/jni_helper.hpp" +#include "kml/types.hpp" namespace { @@ -10,11 +11,6 @@ namespace Bookmark const * getBookmark(jlong bokmarkId) { Bookmark const * pBmk = frm()->GetBookmarkManager().GetBookmark(static_cast(bokmarkId)); - if (!pBmk) - { - int i = 0; - ++i; - } ASSERT(pBmk, ("Bookmark not found, id", bokmarkId)); return pBmk; } @@ -45,6 +41,15 @@ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetColor( : frm()->LastEditedBMColor()); } +JNIEXPORT jint JNICALL +Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetIcon( + JNIEnv * env, jobject thiz, jlong bmk) +{ + auto const * mark = getBookmark(bmk); + return static_cast(mark != nullptr ? mark->GetData().m_icon + : kml::BookmarkIcon::None); +} + JNIEXPORT void JNICALL Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeSetBookmarkParams( JNIEnv * env, jobject thiz, jlong bmk, diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index 40b4a72a6f..3ba550505c 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -2,6 +2,7 @@ -1 40dp + 24dp 2dp diff --git a/android/src/com/mapswithme/maps/bookmarks/Holders.java b/android/src/com/mapswithme/maps/bookmarks/Holders.java index 23dfa6e729..9634939460 100644 --- a/android/src/com/mapswithme/maps/bookmarks/Holders.java +++ b/android/src/com/mapswithme/maps/bookmarks/Holders.java @@ -279,7 +279,13 @@ public class Holders loc.getLongitude(), 0.0); mDistance.setText(distanceValue); UiUtils.hideIf(TextUtils.isEmpty(distanceValue), mDistance); - mIcon.setImageResource(bookmark.getIcon().getSelectedResId()); + mIcon.setImageResource(bookmark.getIcon().getResId()); + + Drawable circle = Graphics.drawCircleAndImage(bookmark.getIcon().argb(), + R.dimen.track_circle_size, + bookmark.getIcon().getResId(), + mIcon.getContext().getResources()); + mIcon.setImageDrawable(circle); } } diff --git a/android/src/com/mapswithme/maps/bookmarks/IconsAdapter.java b/android/src/com/mapswithme/maps/bookmarks/IconsAdapter.java index 9a31173e2b..4e7d524e85 100644 --- a/android/src/com/mapswithme/maps/bookmarks/IconsAdapter.java +++ b/android/src/com/mapswithme/maps/bookmarks/IconsAdapter.java @@ -37,9 +37,9 @@ public class IconsAdapter extends ArrayAdapter final Icon icon = getItem(position); if (icon.getColor() == mCheckedIconColor) - holder.icon.setImageResource(getItem(position).getSelectedResId()); + holder.icon.setImageResource(getItem(position).getCheckedResId()); else - holder.icon.setImageResource(getItem(position).getResId()); + holder.icon.setImageResource(getItem(position).getUncheckedResId()); return convertView; } diff --git a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java index 2914c7fe1a..2960170253 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java @@ -65,6 +65,7 @@ public class Bookmark extends MapObject dest.writeLong(mCategoryId); dest.writeLong(mBookmarkId); dest.writeInt(mIcon.getColor()); + dest.writeInt(mIcon.getType()); dest.writeDouble(mMerX); dest.writeDouble(mMerY); } @@ -77,7 +78,7 @@ public class Bookmark extends MapObject super(type, source); mCategoryId = source.readLong(); mBookmarkId = source.readLong(); - mIcon = BookmarkManager.INSTANCE.getIconByColor(source.readInt()); + mIcon = new Icon(source.readInt(), source.readInt()); mMerX = source.readDouble(); mMerY = source.readDouble(); initXY(); @@ -96,7 +97,7 @@ public class Bookmark extends MapObject private Icon getIconInternal() { - return BookmarkManager.INSTANCE.getIconByColor(nativeGetColor(mBookmarkId)); + return new Icon(nativeGetColor(mBookmarkId), nativeGetIcon(mBookmarkId)); } public Icon getIcon() @@ -168,8 +169,12 @@ public class Bookmark extends MapObject public static native ParcelablePointD nativeGetXY(@IntRange(from = 0) long bookmarkId); + @Icon.PredefinedColor public static native int nativeGetColor(@IntRange(from = 0) long bookmarkId); + @Icon.BookmarkIconType + public static native int nativeGetIcon(@IntRange(from = 0) long bookmarkId); + private native String nativeGetBookmarkDescription(@IntRange(from = 0) long bookmarkId); private native double nativeGetScale(@IntRange(from = 0) long bookmarkId); diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkInfo.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkInfo.java index 94cf53ed94..9085998f72 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkInfo.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkInfo.java @@ -21,7 +21,7 @@ public class BookmarkInfo mCategoryId = categoryId; mBookmarkId = bookmarkId; mTitle = Bookmark.nativeGetName(mBookmarkId); - mIcon = BookmarkManager.INSTANCE.getIconByColor(Bookmark.nativeGetColor(mBookmarkId)); + mIcon = new Icon(Bookmark.nativeGetColor(mBookmarkId), Bookmark.nativeGetIcon(mBookmarkId)); final ParcelablePointD ll = Bookmark.nativeGetXY(mBookmarkId); mMerX = ll.x; mMerY = ll.y; diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java index faa013153c..39b4356b83 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java @@ -86,26 +86,14 @@ public enum BookmarkManager static { - ICONS.add(new Icon("placemark-red", Icon.PREDEFINED_COLOR_RED, R.drawable.ic_bookmark_marker_red_off, R.drawable.ic_bookmark_marker_red_on)); - ICONS.add(new Icon("placemark-blue", Icon.PREDEFINED_COLOR_BLUE, R.drawable.ic_bookmark_marker_blue_off, R.drawable.ic_bookmark_marker_blue_on)); - ICONS.add(new Icon("placemark-purple", Icon.PREDEFINED_COLOR_PURPLE, R.drawable.ic_bookmark_marker_purple_off, R.drawable.ic_bookmark_marker_purple_on)); - ICONS.add(new Icon("placemark-yellow", Icon.PREDEFINED_COLOR_YELLOW, R.drawable.ic_bookmark_marker_yellow_off, R.drawable.ic_bookmark_marker_yellow_on)); - ICONS.add(new Icon("placemark-pink", Icon.PREDEFINED_COLOR_PINK, R.drawable.ic_bookmark_marker_pink_off, R.drawable.ic_bookmark_marker_pink_on)); - ICONS.add(new Icon("placemark-brown", Icon.PREDEFINED_COLOR_BROWN, R.drawable.ic_bookmark_marker_brown_off, R.drawable.ic_bookmark_marker_brown_on)); - ICONS.add(new Icon("placemark-green", Icon.PREDEFINED_COLOR_GREEN, R.drawable.ic_bookmark_marker_green_off, R.drawable.ic_bookmark_marker_green_on)); - ICONS.add(new Icon("placemark-orange", Icon.PREDEFINED_COLOR_ORANGE, R.drawable.ic_bookmark_marker_orange_off, R.drawable.ic_bookmark_marker_orange_on)); - } - - @NonNull - Icon getIconByColor(@Icon.PredefinedColor int color) - { - for (Icon icon : ICONS) - { - if (icon.getColor() == color) - return icon; - } - // return default icon - return ICONS.get(0); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_RED, Icon.BOOKMARK_ICON_TYPE_NONE)); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_BLUE, Icon.BOOKMARK_ICON_TYPE_NONE)); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_PURPLE, Icon.BOOKMARK_ICON_TYPE_NONE)); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_YELLOW, Icon.BOOKMARK_ICON_TYPE_NONE)); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_PINK, Icon.BOOKMARK_ICON_TYPE_NONE)); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_BROWN, Icon.BOOKMARK_ICON_TYPE_NONE)); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_GREEN, Icon.BOOKMARK_ICON_TYPE_NONE)); + ICONS.add(new Icon(Icon.PREDEFINED_COLOR_ORANGE, Icon.BOOKMARK_ICON_TYPE_NONE)); } public void toggleCategoryVisibility(long catId) diff --git a/android/src/com/mapswithme/maps/bookmarks/data/Icon.java b/android/src/com/mapswithme/maps/bookmarks/data/Icon.java index 5ae7ac73ff..66de4a8729 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/Icon.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/Icon.java @@ -2,6 +2,8 @@ package com.mapswithme.maps.bookmarks.data; import android.support.annotation.IntDef; +import com.mapswithme.maps.R; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -23,18 +25,125 @@ public class Icon public static final int PREDEFINED_COLOR_GREEN = 7; public static final int PREDEFINED_COLOR_ORANGE = 8; - private final String mName; + public static final String[] PREDEFINED_COLOR_NAMES = { "placemark-red", "placemark-red", + "placemark-blue", "placemark-purple", + "placemark-yellow", "placemark-pink", + "placemark-brown", "placemark-green", + "placemark-orange" }; + + public static final int[] COLOR_ICONS_ON = { R.drawable.ic_bookmark_marker_red_on, + R.drawable.ic_bookmark_marker_red_on, + R.drawable.ic_bookmark_marker_blue_on, + R.drawable.ic_bookmark_marker_purple_on, + R.drawable.ic_bookmark_marker_yellow_on, + R.drawable.ic_bookmark_marker_pink_on, + R.drawable.ic_bookmark_marker_brown_on, + R.drawable.ic_bookmark_marker_green_on, + R.drawable.ic_bookmark_marker_orange_on }; + + public static final int[] COLOR_ICONS_OFF = { R.drawable.ic_bookmark_marker_red_off, + R.drawable.ic_bookmark_marker_red_off, + R.drawable.ic_bookmark_marker_blue_off, + R.drawable.ic_bookmark_marker_purple_off, + R.drawable.ic_bookmark_marker_yellow_off, + R.drawable.ic_bookmark_marker_pink_off, + R.drawable.ic_bookmark_marker_brown_off, + R.drawable.ic_bookmark_marker_green_off, + R.drawable.ic_bookmark_marker_orange_off }; + + static int shift(int v, int bitCount) { return v << bitCount; } + static int toARGB(int r, int g, int b) + { + return shift(255, 24) + shift(r, 16) + shift(g, 8) + b; + } + + public static final int[] ARGB_COLORS = { toARGB(229, 27, 35), + toARGB(229, 27, 35), + toARGB(0, 110, 199), + toARGB(156, 39, 176), + toARGB(255, 200, 0), + toARGB(255, 65, 130), + toARGB(121, 85, 72), + toARGB(56, 142, 60), + toARGB(255, 160, 0) }; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({ BOOKMARK_ICON_TYPE_NONE, + BOOKMARK_ICON_TYPE_HOTEL, + BOOKMARK_ICON_TYPE_ANIMALS, + BOOKMARK_ICON_TYPE_BUDDHISM, + BOOKMARK_ICON_TYPE_BUILDING, + BOOKMARK_ICON_TYPE_CHRISTIANITY, + BOOKMARK_ICON_TYPE_ENTERTAINMENT, + BOOKMARK_ICON_TYPE_EXCHANGE, + BOOKMARK_ICON_TYPE_FOOD, + BOOKMARK_ICON_TYPE_GAS, + BOOKMARK_ICON_TYPE_JUDAISM, + BOOKMARK_ICON_TYPE_MEDICINE, + BOOKMARK_ICON_TYPE_MOUNTAIN, + BOOKMARK_ICON_TYPE_MUSEUM, + BOOKMARK_ICON_TYPE_ISLAM, + BOOKMARK_ICON_TYPE_PARK, + BOOKMARK_ICON_TYPE_PARKING, + BOOKMARK_ICON_TYPE_SHOP, + BOOKMARK_ICON_TYPE_SIGHTS, + BOOKMARK_ICON_TYPE_SWIM, + BOOKMARK_ICON_TYPE_WATER }) + public @interface BookmarkIconType {} + + public static final int BOOKMARK_ICON_TYPE_NONE = 0; + public static final int BOOKMARK_ICON_TYPE_HOTEL = 1; + public static final int BOOKMARK_ICON_TYPE_ANIMALS = 2; + public static final int BOOKMARK_ICON_TYPE_BUDDHISM = 3; + public static final int BOOKMARK_ICON_TYPE_BUILDING = 4; + public static final int BOOKMARK_ICON_TYPE_CHRISTIANITY = 5; + public static final int BOOKMARK_ICON_TYPE_ENTERTAINMENT = 6; + public static final int BOOKMARK_ICON_TYPE_EXCHANGE = 7; + public static final int BOOKMARK_ICON_TYPE_FOOD = 8; + public static final int BOOKMARK_ICON_TYPE_GAS = 9; + public static final int BOOKMARK_ICON_TYPE_JUDAISM = 10; + public static final int BOOKMARK_ICON_TYPE_MEDICINE = 11; + public static final int BOOKMARK_ICON_TYPE_MOUNTAIN = 12; + public static final int BOOKMARK_ICON_TYPE_MUSEUM = 13; + public static final int BOOKMARK_ICON_TYPE_ISLAM = 14; + public static final int BOOKMARK_ICON_TYPE_PARK = 15; + public static final int BOOKMARK_ICON_TYPE_PARKING = 16; + public static final int BOOKMARK_ICON_TYPE_SHOP = 17; + public static final int BOOKMARK_ICON_TYPE_SIGHTS = 18; + public static final int BOOKMARK_ICON_TYPE_SWIM = 19; + public static final int BOOKMARK_ICON_TYPE_WATER = 20; + + public static final int[] TYPE_ICONS = { R.drawable.ic_bookmark_none, + R.drawable.ic_bookmark_hotel, + R.drawable.ic_bookmark_animals, + R.drawable.ic_bookmark_buddhism, + R.drawable.ic_bookmark_building, + R.drawable.ic_bookmark_christianity, + R.drawable.ic_bookmark_entertainment, + R.drawable.ic_bookmark_money, + R.drawable.ic_bookmark_food, + R.drawable.ic_bookmark_gas, + R.drawable.ic_bookmark_judaism, + R.drawable.ic_bookmark_medicine, + R.drawable.ic_bookmark_mountain, + R.drawable.ic_bookmark_museum, + R.drawable.ic_bookmark_islam, + R.drawable.ic_bookmark_park, + R.drawable.ic_bookmark_parking, + R.drawable.ic_bookmark_shop, + R.drawable.ic_bookmark_sights, + R.drawable.ic_bookmark_swim, + R.drawable.ic_bookmark_water }; + @PredefinedColor private final int mColor; - private final int mResId; - private final int mSelectedResId; + @BookmarkIconType + private final int mType; - public Icon(String Name, @PredefinedColor int color, int resId, int selectedResId) + public Icon(@PredefinedColor int color, int type) { - mName = Name; mColor = color; - mResId = resId; - mSelectedResId = selectedResId; + mType = type; } @PredefinedColor @@ -45,17 +154,32 @@ public class Icon public String getName() { - return mName; + return PREDEFINED_COLOR_NAMES[mColor]; + } + + public int getCheckedResId() + { + return COLOR_ICONS_ON[mColor]; + } + + public int getUncheckedResId() + { + return COLOR_ICONS_OFF[mColor]; + } + + public int argb() + { + return ARGB_COLORS[mColor]; + } + + public int getType() + { + return mType; } public int getResId() { - return mResId; - } - - public int getSelectedResId() - { - return mSelectedResId; + return TYPE_ICONS[mType]; } @Override diff --git a/android/src/com/mapswithme/maps/widget/placepage/EditBookmarkFragment.java b/android/src/com/mapswithme/maps/widget/placepage/EditBookmarkFragment.java index 32afdbaa80..42992610f6 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/EditBookmarkFragment.java +++ b/android/src/com/mapswithme/maps/widget/placepage/EditBookmarkFragment.java @@ -209,7 +209,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. private void refreshColorMarker() { if (mIcon != null) - mIvColor.setImageResource(mIcon.getSelectedResId()); + mIvColor.setImageResource(mIcon.getCheckedResId()); } private void refreshCategory() diff --git a/android/src/com/mapswithme/util/Graphics.java b/android/src/com/mapswithme/util/Graphics.java index 06e7d8d640..1c8c03dd50 100644 --- a/android/src/com/mapswithme/util/Graphics.java +++ b/android/src/com/mapswithme/util/Graphics.java @@ -36,6 +36,30 @@ public final class Graphics return new BitmapDrawable(res, bmp); } + public static Drawable drawCircleAndImage(int color, int sizeResId, + int imageResId, int sizeImgResId, Resources res) + { + final int size = res.getDimensionPixelSize(sizeResId); + final Bitmap bmp = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); + + final Paint paint = new Paint(); + paint.setColor(color); + paint.setAntiAlias(true); + + final Canvas c = new Canvas(bmp); + final float radius = size / 2.0f; + c.drawCircle(radius, radius, radius, paint); + + Drawable imgD = res.getDrawable(imageResId); + imgD.mutate(); + final int sizeImg = res.getDimensionPixelSize(sizeImgResId); + int offset = (size - sizeImg) / 2; + imgD.setBounds(offset, offset, size - offset, size - offset); + imgD.draw(c); + + return new BitmapDrawable(res, bmp); + } + public static void tint(TextView view) { tint(view, R.attr.iconTint); diff --git a/map/bookmark_helpers.hpp b/map/bookmark_helpers.hpp index a80365efb7..27841263dc 100644 --- a/map/bookmark_helpers.hpp +++ b/map/bookmark_helpers.hpp @@ -43,6 +43,7 @@ struct BookmarkGroupInfo kml::MarkIdCollection m_bookmarkIds; }; +// Do not change the order. enum class BookmarkBaseType : uint16_t { None = 0, diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index f1886680b2..de44f89552 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -197,6 +197,7 @@ public: kml::MarkIdSet const & GetUserMarkIds(kml::MarkGroupId groupId) const; kml::TrackIdSet const & GetTrackIds(kml::MarkGroupId groupId) const; + // Do not change the order. enum class SortingType { ByType,