Fix issues

This commit is contained in:
Victor Shcherb 2016-04-05 11:27:05 +03:00
parent 7f72ed8375
commit 22e1937334
5 changed files with 32 additions and 41 deletions

View file

@ -172,7 +172,7 @@ public class ContextMenuItem {
@DrawableRes @DrawableRes
private int mIcon = INVALID_ID; private int mIcon = INVALID_ID;
@ColorRes @ColorRes
private int mColor = INVALID_ID; private int mColorRes = INVALID_ID;
@DrawableRes @DrawableRes
private int mSecondaryIcon = INVALID_ID; private int mSecondaryIcon = INVALID_ID;
private Boolean mSelected = null; private Boolean mSelected = null;
@ -200,8 +200,8 @@ public class ContextMenuItem {
return this; return this;
} }
public ItemBuilder setColor(@ColorRes int color) { public ItemBuilder setColor(@ColorRes int colorRes) {
mColor = color; mColorRes = colorRes;
return this; return this;
} }
@ -261,7 +261,7 @@ public class ContextMenuItem {
} }
public ContextMenuItem createItem() { 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, mSelected, mProgress, mLayout, mLoading, mIsCategory, mPosition, mDescription,
mItemClickListener, mIntegerListener); mItemClickListener, mIntegerListener);
} }

View file

@ -37,55 +37,49 @@ public class IconsCache {
return new BitmapDrawable(app.getResources(), bitmapResized); return new BitmapDrawable(app.getResources(), bitmapResized);
} }
@Deprecated
private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId) { private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId) {
return getDrawable(resId, clrId, 0); long hash = ((long)resId << 31l) + clrId;
}
@Deprecated
private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId, float scale) {
long hash = ((long)resId << 31l) + clrId + (int)(scale * 10000f);
Drawable d = drawable.get(hash); Drawable d = drawable.get(hash);
if(d == null) { if (d == null) {
if (scale > 0) { d = ContextCompat.getDrawable(app, resId);
d = scaleImage(app.getResources().getDrawable(resId).mutate(), scale); d = DrawableCompat.wrap(d);
} else { d.mutate();
d = app.getResources().getDrawable(resId).mutate(); // d.clearColorFilter();
}
d.clearColorFilter();
if (clrId != 0) { 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); drawable.put(hash, d);
} }
return d; return d;
} }
@Deprecated
private Drawable getPaintedDrawable(@DrawableRes int resId, @ColorInt int color){ private Drawable getPaintedDrawable(@DrawableRes int resId, @ColorInt int color){
long hash = ((long)resId << 31l) + color; long hash = ((long)resId << 31l) + color;
Drawable d = drawable.get(hash); Drawable d = drawable.get(hash);
if(d == null) { if(d == null) {
d = app.getResources().getDrawable(resId).mutate(); d = ContextCompat.getDrawable(app, resId);
d.clearColorFilter(); d = DrawableCompat.wrap(d);
d.setColorFilter(color, PorterDuff.Mode.SRC_IN); 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); drawable.put(hash, d);
} }
return d; return d;
} }
@Deprecated
public Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color){ public Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color){
return getPaintedDrawable(id, color); return getPaintedDrawable(id, color);
} }
@Deprecated
public Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) { public Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) {
return getDrawable(id, colorId); return getDrawable(id, colorId);
} }
@Deprecated
public Drawable getIcon(@DrawableRes int backgroundId, @DrawableRes int id, @ColorRes int colorId) { public Drawable getIcon(@DrawableRes int backgroundId, @DrawableRes int id, @ColorRes int colorId) {
Drawable b = getDrawable(backgroundId, 0); Drawable b = getDrawable(backgroundId, 0);
Drawable f = getDrawable(id, colorId); Drawable f = getDrawable(id, colorId);
@ -95,40 +89,36 @@ public class IconsCache {
return new LayerDrawable(layers); return new LayerDrawable(layers);
} }
@Deprecated
public Drawable getContentIcon(@DrawableRes int id) { public Drawable getContentIcon(@DrawableRes int id) {
return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0); return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0);
} }
@Deprecated
public Drawable getContentIcon(@DrawableRes int id, boolean isLightContent) { public Drawable getContentIcon(@DrawableRes int id, boolean isLightContent) {
return getDrawable(id, isLightContent ? R.color.icon_color : 0); return getDrawable(id, isLightContent ? R.color.icon_color : 0);
} }
@Deprecated
public Drawable getIcon(@DrawableRes int id) { public Drawable getIcon(@DrawableRes int id) {
return getDrawable(id, 0); return getDrawable(id, 0);
} }
@Deprecated
public Drawable getIcon(@DrawableRes int id, boolean light) { public Drawable getIcon(@DrawableRes int id, boolean light) {
return getDrawable(id, light ? R.color.icon_color : 0); return getDrawable(id, light ? R.color.icon_color : 0);
} }
public static Drawable getContentIconCompat(Context context, @DrawableRes int id) { public Drawable getContentIconCompat(@DrawableRes int id) {
Drawable drawable = ContextCompat.getDrawable(context, id); Drawable drawable = ContextCompat.getDrawable(app, id);
@ColorInt int color = ContextCompat.getColor(context, getDefaultColorRes(context)); @ColorInt int color = ContextCompat.getColor(app, getDefaultColorRes(app));
drawable = DrawableCompat.wrap(drawable); drawable = DrawableCompat.wrap(drawable);
drawable.mutate(); drawable.mutate();
DrawableCompat.setTint(drawable, color); DrawableCompat.setTint(drawable, color);
return drawable; return drawable;
} }
public static void paintMenuItem(Context context, MenuItem menuItem) { public void paintMenuItem(MenuItem menuItem) {
Drawable drawable = menuItem.getIcon(); Drawable drawable = menuItem.getIcon();
drawable = DrawableCompat.wrap(drawable); drawable = DrawableCompat.wrap(drawable);
drawable.mutate(); drawable.mutate();
int color = ContextCompat.getColor(context, getDefaultColorRes(context)); int color = ContextCompat.getColor(app, getDefaultColorRes(app));
DrawableCompat.setTint(drawable, color); DrawableCompat.setTint(drawable, color);
} }

View file

@ -128,7 +128,7 @@ public class PluginActivity extends OsmandActionBarActivity {
Button getButton = (Button)findViewById(R.id.plugin_get); Button getButton = (Button)findViewById(R.id.plugin_get);
Button settingsButton = (Button)findViewById(R.id.plugin_settings); Button settingsButton = (Button)findViewById(R.id.plugin_settings);
settingsButton.setCompoundDrawablesWithIntrinsicBounds( settingsButton.setCompoundDrawablesWithIntrinsicBounds(
IconsCache.getContentIconCompat(this, R.drawable.ic_action_settings), getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_settings),
null, null, null); null, null, null);
View installHeader = findViewById(R.id.plugin_install_header); View installHeader = findViewById(R.id.plugin_install_header);
@ -138,7 +138,7 @@ public class PluginActivity extends OsmandActionBarActivity {
settingsButton.setVisibility(View.GONE); settingsButton.setVisibility(View.GONE);
installHeader.setVisibility(View.VISIBLE); installHeader.setVisibility(View.VISIBLE);
View worldGlobeIcon = installHeader.findViewById(R.id.ic_world_globe); 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); R.drawable.ic_world_globe_dark);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
worldGlobeIcon.setBackground(worldGlobeDrawable); worldGlobeIcon.setBackground(worldGlobeDrawable);

View file

@ -358,7 +358,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
// FAB // FAB
fabView = (ImageView) view.findViewById(R.id.context_menu_fab_view); fabView = (ImageView) view.findViewById(R.id.context_menu_fab_view);
if (menu.fabVisible()) { if (menu.fabVisible()) {
fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId(), 0, 0f)); fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId(), 0));
if (menu.isLandscapeLayout()) { if (menu.isLandscapeLayout()) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fabView.getLayoutParams(); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fabView.getLayoutParams();
params.setMargins(0, 0, dpToPx(28f), 0); params.setMargins(0, 0, dpToPx(28f), 0);

View file

@ -386,9 +386,10 @@ public class MapWidgetRegistry {
IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper); IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper);
MenuInflater inflater = popup.getMenuInflater(); MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.vidget_visibility_menu, popup.getMenu()); inflater.inflate(R.menu.vidget_visibility_menu, popup.getMenu());
IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_show)); IconsCache ic = mapActivity.getMyApplication().getIconsCache();
IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_hide)); ic.paintMenuItem(popup.getMenu().findItem(R.id.action_show));
IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_collapse)); ic.paintMenuItem(popup.getMenu().findItem(R.id.action_hide));
ic.paintMenuItem(popup.getMenu().findItem(R.id.action_collapse));
popup.setOnMenuItemClickListener( popup.setOnMenuItemClickListener(
new IconPopupMenu.OnMenuItemClickListener() { new IconPopupMenu.OnMenuItemClickListener() {
@Override @Override