mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-27 08:23:38 +00:00
[android] Load icon types from core
Signed-off-by: Andrei Shkrob <github@shkrob.dev>
This commit is contained in:
committed by
Konstantin Pastbin
parent
d9335c0b6c
commit
2ded7e5e2b
@@ -4,41 +4,21 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import app.organicmaps.sdk.R;
|
||||
import androidx.annotation.NonNull;
|
||||
import app.organicmaps.BuildConfig;
|
||||
import app.organicmaps.sdk.util.StringUtils;
|
||||
import app.organicmaps.sdk.util.log.Logger;
|
||||
import com.google.common.base.Objects;
|
||||
import dalvik.annotation.optimization.FastNative;
|
||||
|
||||
public class Icon implements Parcelable
|
||||
{
|
||||
private static final String TAG = Icon.class.getSimpleName();
|
||||
|
||||
static final int BOOKMARK_ICON_TYPE_NONE = 0;
|
||||
|
||||
/// @note Important! Should be synced with kml/types.hpp/BookmarkIcon
|
||||
/// @todo Can make better: take name-by-type from Core and make a concat: "R.drawable.ic_bookmark_" + name.
|
||||
// First icon should be "none" <-> BOOKMARK_ICON_TYPE_NONE.
|
||||
@DrawableRes
|
||||
private 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,
|
||||
R.drawable.ic_bookmark_bar, R.drawable.ic_bookmark_transport, R.drawable.ic_bookmark_viewpoint,
|
||||
R.drawable.ic_bookmark_sport,
|
||||
R.drawable.ic_bookmark_none, // pub
|
||||
R.drawable.ic_bookmark_none, // art
|
||||
R.drawable.ic_bookmark_none, // bank
|
||||
R.drawable.ic_bookmark_none, // cafe
|
||||
R.drawable.ic_bookmark_none, // pharmacy
|
||||
R.drawable.ic_bookmark_none, // stadium
|
||||
R.drawable.ic_bookmark_none, // theatre
|
||||
R.drawable.ic_bookmark_none, // information
|
||||
R.drawable.ic_bookmark_none, // ChargingStation
|
||||
R.drawable.ic_bookmark_none, // BicycleParking
|
||||
R.drawable.ic_bookmark_none, // BicycleParkingCovered
|
||||
R.drawable.ic_bookmark_none, // BicycleRental
|
||||
R.drawable.ic_bookmark_none // FastFood
|
||||
};
|
||||
private static final int[] TYPE_ICONS = GetTypeIcons();
|
||||
|
||||
@PredefinedColors.Color
|
||||
private final int mColor;
|
||||
@@ -119,4 +99,34 @@ public class Icon implements Parcelable
|
||||
return new Icon[size];
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
@DrawableRes
|
||||
private static int[] GetTypeIcons()
|
||||
{
|
||||
final String[] names = nativeGetBookmarkIconNames();
|
||||
int[] icons = new int[names.length];
|
||||
for (int i = 0; i < names.length; i++)
|
||||
{
|
||||
final String name = StringUtils.toSnakeCase(names[i]);
|
||||
try
|
||||
{
|
||||
icons[i] = app.organicmaps.sdk.R.drawable.class.getField("ic_bookmark_" + name).getInt(null);
|
||||
}
|
||||
catch (NoSuchFieldException | IllegalAccessException e)
|
||||
{
|
||||
Logger.e(TAG, "Error getting icon for " + name);
|
||||
// Force devs to add an icon for each bookmark type.
|
||||
if (BuildConfig.DEBUG)
|
||||
throw new RuntimeException("Error getting icon for " + name, e);
|
||||
icons[i] = app.organicmaps.sdk.R.drawable.ic_bookmark_none; // Fallback icon
|
||||
}
|
||||
}
|
||||
|
||||
return icons;
|
||||
}
|
||||
|
||||
@FastNative
|
||||
@NonNull
|
||||
private static native String[] nativeGetBookmarkIconNames();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ import java.util.Locale;
|
||||
|
||||
public class StringUtils
|
||||
{
|
||||
public static String toSnakeCase(String input)
|
||||
{
|
||||
return input.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase();
|
||||
}
|
||||
public static String formatUsingUsLocale(String pattern, Object... args)
|
||||
{
|
||||
return String.format(Locale.US, pattern, args);
|
||||
|
||||
Reference in New Issue
Block a user