Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-06-26 12:54:58 +02:00
commit d983fb88b1
4 changed files with 39 additions and 48 deletions

View file

@ -156,7 +156,7 @@ public class OsmandRenderer {
public Shader getShader(String resId){
if(shaders.get(resId) == null){
Bitmap bmp = RenderingIcons.getIcon(context, resId);
Bitmap bmp = RenderingIcons.getIcon(context, resId, true);
if(bmp != null){
Shader sh = new BitmapShader(bmp, TileMode.REPEAT, TileMode.REPEAT);
shaders.put(resId, sh);
@ -319,7 +319,7 @@ public class OsmandRenderer {
for (IconDrawInfo icon : rc.iconsToDraw) {
if (icon.resId != null) {
Bitmap ico = RenderingIcons.getIcon(context, icon.resId);
Bitmap ico = RenderingIcons.getIcon(context, icon.resId, true);
if (ico != null) {
if (icon.y >= 0 && icon.y < rc.height && icon.x >= 0 && icon.x < rc.width) {
int visbleWidth = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getWidth();
@ -340,7 +340,7 @@ public class OsmandRenderer {
}
if (!intersects) {
Bitmap shield = icon.shieldId == null ? null : RenderingIcons.getIcon(context, icon.shieldId);
Bitmap shield = icon.shieldId == null ? null : RenderingIcons.getIcon(context, icon.shieldId, true);
if(shield != null) {
RectF shieldRf = calculateRect(rc, icon, shield.getWidth(), shield.getHeight());
if (coeff != 1f) {
@ -352,19 +352,19 @@ public class OsmandRenderer {
}
if (coeff != 1f) {
Rect src = new Rect(0, 0, ico.getWidth(), ico.getHeight());
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf, src);
drawBitmap(cv, ico, rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf, src);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf, src);
} else {
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf);
drawBitmap(cv, ico, rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf);
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf);
}
if(visibleRect != null) {
visibleRect.inset(-visibleRect.width() / 4, -visibleRect.height() / 4);

View file

@ -20,14 +20,14 @@ import android.graphics.drawable.Drawable;
public class RenderingIcons {
private static final Log log = PlatformUtil.getLog(RenderingIcons.class);
private static Map<String, Integer> icons = new LinkedHashMap<String, Integer>();
private static Map<String, Integer> shaderIcons = new LinkedHashMap<String, Integer>();
private static Map<String, Integer> smallIcons = new LinkedHashMap<String, Integer>();
private static Map<String, Integer> bigIcons = new LinkedHashMap<String, Integer>();
private static Map<String, Bitmap> iconsBmp = new LinkedHashMap<String, Bitmap>();
// private static DisplayMetrics dm;
public static boolean containsIcon(String s){
return icons.containsKey(s);
public static boolean containsSmallIcon(String s){
return smallIcons.containsKey(s);
}
public static boolean containsBigIcon(String s){
@ -35,9 +35,10 @@ public class RenderingIcons {
}
public static byte[] getIconRawData(Context ctx, String s) {
Integer resId = icons.get(s);
// Quite bad error
Integer resId = shaderIcons.get(s);
if(resId == null) {
resId = smallIcons.get(s);
}
if(resId == null)
return null;
@ -81,12 +82,15 @@ public class RenderingIcons {
return null;
}
public static Bitmap getIcon(Context ctx, String s) {
public static Bitmap getIcon(Context ctx, String s, boolean includeShader) {
if(s == null) {
return null;
}
if(includeShader && shaderIcons.containsKey(s)) {
s = "h_" + s;
}
if (!iconsBmp.containsKey(s)) {
Integer resId = icons.get(s);
Integer resId = s.startsWith("h_") ? shaderIcons.get(s.substring(2)) : smallIcons.get(s);
if (resId != null) {
Bitmap bmp = BitmapFactory.decodeResource(ctx.getResources(), resId, null);
iconsBmp.put(s, bmp);
@ -105,26 +109,14 @@ public class RenderingIcons {
public static void initIcons() {
Class<? extends drawable> cl = R.drawable.class;
for (Field f : cl.getDeclaredFields()) {
if (f.getName().startsWith("h_") || f.getName().startsWith("mm_")) {
try {
String id = f.getName().substring(f.getName().startsWith("mm_") ? 3 : 2);
int i = f.getInt(null);
// don't override shader or map icons (h)
if(f.getName().startsWith("h_") || !icons.containsKey(id)) {
icons.put(id, i);
}
if(f.getName().startsWith("mm_")) {
smallIcons.put(id, i);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
if (f.getName().startsWith("mx_") ) {
try {
if (f.getName().startsWith("h_")) {
shaderIcons.put(f.getName().substring(2), f.getInt(null));
} else if( f.getName().startsWith("mm_")) {
smallIcons.put(f.getName().substring(3), f.getInt(null));
} else if (f.getName().startsWith("mx_")) {
bigIcons.put(f.getName().substring(3), f.getInt(null));
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
@ -132,6 +124,5 @@ public class RenderingIcons {
}
}
}
}
}

View file

@ -268,7 +268,7 @@ public class TextRenderer {
private void drawShieldIcon(RenderingContext rc, Canvas cv, TextDrawInfo text, String sr) {
if (sr != null) {
float coef = rc.getDensityValue(rc.screenDensityRatio * rc.textScale);
Bitmap ico = RenderingIcons.getIcon(context, sr);
Bitmap ico = RenderingIcons.getIcon(context, sr, true);
if (ico != null) {
float left = text.centerX - ico.getWidth() / 2 * coef - 0.5f;
float top = text.centerY - ico.getHeight() / 2 * coef - paintText.descent() - 0.5f;

View file

@ -253,14 +253,14 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
String id = null;
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
if (st != null) {
if (RenderingIcons.containsIcon(st.getIconKeyName())) {
if (RenderingIcons.containsSmallIcon(st.getIconKeyName())) {
id = st.getIconKeyName();
} else if (RenderingIcons.containsIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
} else if (RenderingIcons.containsSmallIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
id = st.getOsmTag() + "_" + st.getOsmValue();
}
}
if (id != null) {
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id);
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id, false);
if (bmp != null) {
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
}