[bookmarks][android] Type icons.

This commit is contained in:
Daria Volvenkova 2019-08-22 18:24:18 +03:00 committed by Aleksey Belousov
parent 1072e1d161
commit 0d19235926
12 changed files with 201 additions and 46 deletions

View file

@ -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<kml::MarkId>(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<jint>(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,

View file

@ -2,6 +2,7 @@
<resources>
<item name="match_parent" type="dimen">-1</item>
<dimen name="track_circle_size">40dp</dimen>
<dimen name="bookmark_icon_size">24dp</dimen>
<!-- margins -->
<dimen name="margin_eighth">2dp</dimen>

View file

@ -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);
}
}

View file

@ -37,9 +37,9 @@ public class IconsAdapter extends ArrayAdapter<Icon>
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;
}

View file

@ -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);

View file

@ -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;

View file

@ -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)

View file

@ -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

View file

@ -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()

View file

@ -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);

View file

@ -43,6 +43,7 @@ struct BookmarkGroupInfo
kml::MarkIdCollection m_bookmarkIds;
};
// Do not change the order.
enum class BookmarkBaseType : uint16_t
{
None = 0,

View file

@ -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,