mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-06 04:24:29 +00:00
[android] Fixed getting drawable icons.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
8493ed369a
commit
a39b3a9921
@@ -9,6 +9,7 @@ import androidx.lifecycle.ProcessLifecycleOwner;
|
|||||||
import app.organicmaps.R;
|
import app.organicmaps.R;
|
||||||
import app.organicmaps.routing.RoutingController;
|
import app.organicmaps.routing.RoutingController;
|
||||||
import app.organicmaps.sdk.bookmarks.data.BookmarkManager;
|
import app.organicmaps.sdk.bookmarks.data.BookmarkManager;
|
||||||
|
import app.organicmaps.sdk.bookmarks.data.Icon;
|
||||||
import app.organicmaps.sdk.downloader.Android7RootCertificateWorkaround;
|
import app.organicmaps.sdk.downloader.Android7RootCertificateWorkaround;
|
||||||
import app.organicmaps.sdk.editor.OsmOAuth;
|
import app.organicmaps.sdk.editor.OsmOAuth;
|
||||||
import app.organicmaps.sdk.location.LocationHelper;
|
import app.organicmaps.sdk.location.LocationHelper;
|
||||||
@@ -96,6 +97,8 @@ public final class OrganicMaps implements DefaultLifecycleObserver
|
|||||||
|
|
||||||
Android7RootCertificateWorkaround.initializeIfNeeded(mContext);
|
Android7RootCertificateWorkaround.initializeIfNeeded(mContext);
|
||||||
|
|
||||||
|
Icon.loadDefaultIcons(mContext.getResources(), mContext.getPackageName());
|
||||||
|
|
||||||
mSensorHelper = new SensorHelper(mContext);
|
mSensorHelper = new SensorHelper(mContext);
|
||||||
mLocationHelper = new LocationHelper(mContext, mSensorHelper);
|
mLocationHelper = new LocationHelper(mContext, mSensorHelper);
|
||||||
mIsolinesManager = new IsolinesManager(mContext);
|
mIsolinesManager = new IsolinesManager(mContext);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package app.organicmaps.sdk.bookmarks.data;
|
package app.organicmaps.sdk.bookmarks.data;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
@@ -18,7 +19,7 @@ public class Icon implements Parcelable
|
|||||||
static final int BOOKMARK_ICON_TYPE_NONE = 0;
|
static final int BOOKMARK_ICON_TYPE_NONE = 0;
|
||||||
|
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
private static final int[] TYPE_ICONS = GetTypeIcons();
|
private static int[] sTypeIcons = null;
|
||||||
|
|
||||||
@PredefinedColors.Color
|
@PredefinedColors.Color
|
||||||
private final int mColor;
|
private final int mColor;
|
||||||
@@ -69,7 +70,9 @@ public class Icon implements Parcelable
|
|||||||
@DrawableRes
|
@DrawableRes
|
||||||
public int getResId()
|
public int getResId()
|
||||||
{
|
{
|
||||||
return TYPE_ICONS[mType];
|
// loadDefaultIcons should be called
|
||||||
|
assert (sTypeIcons != null);
|
||||||
|
return sTypeIcons[mType];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -100,30 +103,25 @@ public class Icon implements Parcelable
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@NonNull
|
static public void loadDefaultIcons(@NonNull Resources resources, @NonNull String packageName)
|
||||||
@DrawableRes
|
|
||||||
private static int[] GetTypeIcons()
|
|
||||||
{
|
{
|
||||||
final String[] names = nativeGetBookmarkIconNames();
|
final String[] names = nativeGetBookmarkIconNames();
|
||||||
int[] icons = new int[names.length];
|
int[] icons = new int[names.length];
|
||||||
for (int i = 0; i < names.length; i++)
|
for (int i = 0; i < names.length; i++)
|
||||||
{
|
{
|
||||||
final String name = StringUtils.toSnakeCase(names[i]);
|
final String name = StringUtils.toSnakeCase(names[i]);
|
||||||
try
|
icons[i] = resources.getIdentifier("ic_bookmark_" + name, "drawable", packageName);
|
||||||
{
|
if (icons[i] == 0)
|
||||||
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);
|
Logger.e(TAG, "Error getting icon for " + name);
|
||||||
// Force devs to add an icon for each bookmark type.
|
// Force devs to add an icon for each bookmark type.
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
throw new RuntimeException("Error getting icon for " + name, e);
|
throw new RuntimeException("Error getting icon for " + name);
|
||||||
icons[i] = app.organicmaps.sdk.R.drawable.ic_bookmark_none; // Fallback icon
|
icons[i] = app.organicmaps.sdk.R.drawable.ic_bookmark_none; // Fallback icon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return icons;
|
sTypeIcons = icons;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FastNative
|
@FastNative
|
||||||
|
|||||||
Reference in New Issue
Block a user