diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java index 0bf54d1bea..bad571f244 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java @@ -172,7 +172,7 @@ public class ContextMenuItem { @DrawableRes private int mIcon = INVALID_ID; @ColorRes - private int mColor = INVALID_ID; + private int mColorRes = INVALID_ID; @DrawableRes private int mSecondaryIcon = INVALID_ID; private Boolean mSelected = null; @@ -200,8 +200,8 @@ public class ContextMenuItem { return this; } - public ItemBuilder setColor(@ColorRes int color) { - mColor = color; + public ItemBuilder setColor(@ColorRes int colorRes) { + mColorRes = colorRes; return this; } @@ -261,7 +261,7 @@ public class ContextMenuItem { } public ContextMenuItem createItem() { - return new ContextMenuItem(mTitleId, mTitle, mIcon, mColor, mSecondaryIcon, + return new ContextMenuItem(mTitleId, mTitle, mIcon, mColorRes, mSecondaryIcon, mSelected, mProgress, mLayout, mLoading, mIsCategory, mPosition, mDescription, mItemClickListener, mIntegerListener); } diff --git a/OsmAnd/src/net/osmand/plus/IconsCache.java b/OsmAnd/src/net/osmand/plus/IconsCache.java index 256d628190..6572b5caa4 100644 --- a/OsmAnd/src/net/osmand/plus/IconsCache.java +++ b/OsmAnd/src/net/osmand/plus/IconsCache.java @@ -37,55 +37,49 @@ public class IconsCache { return new BitmapDrawable(app.getResources(), bitmapResized); } - @Deprecated private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId) { - return getDrawable(resId, clrId, 0); - } - - @Deprecated - private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId, float scale) { - long hash = ((long)resId << 31l) + clrId + (int)(scale * 10000f); + long hash = ((long)resId << 31l) + clrId; Drawable d = drawable.get(hash); - if(d == null) { - if (scale > 0) { - d = scaleImage(app.getResources().getDrawable(resId).mutate(), scale); - } else { - d = app.getResources().getDrawable(resId).mutate(); - } - d.clearColorFilter(); + if (d == null) { + d = ContextCompat.getDrawable(app, resId); + d = DrawableCompat.wrap(d); + d.mutate(); + // d.clearColorFilter(); if (clrId != 0) { - d.setColorFilter(app.getResources().getColor(clrId), PorterDuff.Mode.SRC_IN); + DrawableCompat.setTint(d, ContextCompat.getColor(app, clrId)); + // d.setColorFilter(ContextCompat.getColor(app, clrId), PorterDuff.Mode.SRC_IN); } drawable.put(hash, d); } return d; } - @Deprecated private Drawable getPaintedDrawable(@DrawableRes int resId, @ColorInt int color){ long hash = ((long)resId << 31l) + color; Drawable d = drawable.get(hash); if(d == null) { - d = app.getResources().getDrawable(resId).mutate(); - d.clearColorFilter(); - d.setColorFilter(color, PorterDuff.Mode.SRC_IN); + d = ContextCompat.getDrawable(app, resId); + d = DrawableCompat.wrap(d); + d.mutate(); + DrawableCompat.setTint(d, color); + +// d = app.getResources().getDrawable(resId).mutate(); +// d.clearColorFilter(); +// d.setColorFilter(color, PorterDuff.Mode.SRC_IN); drawable.put(hash, d); } return d; } - @Deprecated public Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color){ return getPaintedDrawable(id, color); } - @Deprecated public Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) { return getDrawable(id, colorId); } - @Deprecated public Drawable getIcon(@DrawableRes int backgroundId, @DrawableRes int id, @ColorRes int colorId) { Drawable b = getDrawable(backgroundId, 0); Drawable f = getDrawable(id, colorId); @@ -95,40 +89,36 @@ public class IconsCache { return new LayerDrawable(layers); } - @Deprecated public Drawable getContentIcon(@DrawableRes int id) { return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0); } - @Deprecated public Drawable getContentIcon(@DrawableRes int id, boolean isLightContent) { return getDrawable(id, isLightContent ? R.color.icon_color : 0); } - @Deprecated public Drawable getIcon(@DrawableRes int id) { return getDrawable(id, 0); } - @Deprecated public Drawable getIcon(@DrawableRes int id, boolean light) { return getDrawable(id, light ? R.color.icon_color : 0); } - public static Drawable getContentIconCompat(Context context, @DrawableRes int id) { - Drawable drawable = ContextCompat.getDrawable(context, id); - @ColorInt int color = ContextCompat.getColor(context, getDefaultColorRes(context)); + public Drawable getContentIconCompat(@DrawableRes int id) { + Drawable drawable = ContextCompat.getDrawable(app, id); + @ColorInt int color = ContextCompat.getColor(app, getDefaultColorRes(app)); drawable = DrawableCompat.wrap(drawable); drawable.mutate(); DrawableCompat.setTint(drawable, color); return drawable; } - public static void paintMenuItem(Context context, MenuItem menuItem) { + public void paintMenuItem(MenuItem menuItem) { Drawable drawable = menuItem.getIcon(); drawable = DrawableCompat.wrap(drawable); drawable.mutate(); - int color = ContextCompat.getColor(context, getDefaultColorRes(context)); + int color = ContextCompat.getColor(app, getDefaultColorRes(app)); DrawableCompat.setTint(drawable, color); } diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java index 14cfd3d100..2da5f2ad50 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java @@ -128,7 +128,7 @@ public class PluginActivity extends OsmandActionBarActivity { Button getButton = (Button)findViewById(R.id.plugin_get); Button settingsButton = (Button)findViewById(R.id.plugin_settings); settingsButton.setCompoundDrawablesWithIntrinsicBounds( - IconsCache.getContentIconCompat(this, R.drawable.ic_action_settings), + getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_settings), null, null, null); View installHeader = findViewById(R.id.plugin_install_header); @@ -138,7 +138,7 @@ public class PluginActivity extends OsmandActionBarActivity { settingsButton.setVisibility(View.GONE); installHeader.setVisibility(View.VISIBLE); View worldGlobeIcon = installHeader.findViewById(R.id.ic_world_globe); - Drawable worldGlobeDrawable = IconsCache.getContentIconCompat(this, + Drawable worldGlobeDrawable = getMyApplication().getIconsCache().getContentIcon( R.drawable.ic_world_globe_dark); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { worldGlobeIcon.setBackground(worldGlobeDrawable); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index da8e605e8f..633f3686ab 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -358,7 +358,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { // FAB fabView = (ImageView) view.findViewById(R.id.context_menu_fab_view); if (menu.fabVisible()) { - fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId(), 0, 0f)); + fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId(), 0)); if (menu.isLandscapeLayout()) { FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fabView.getLayoutParams(); params.setMargins(0, 0, dpToPx(28f), 0); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index babeb8642f..79d896f2b8 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -386,9 +386,10 @@ public class MapWidgetRegistry { IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.vidget_visibility_menu, popup.getMenu()); - IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_show)); - IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_hide)); - IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_collapse)); + IconsCache ic = mapActivity.getMyApplication().getIconsCache(); + ic.paintMenuItem(popup.getMenu().findItem(R.id.action_show)); + ic.paintMenuItem(popup.getMenu().findItem(R.id.action_hide)); + ic.paintMenuItem(popup.getMenu().findItem(R.id.action_collapse)); popup.setOnMenuItemClickListener( new IconPopupMenu.OnMenuItemClickListener() { @Override