Fix FID
This commit is contained in:
parent
cb243a0012
commit
c06fbdd286
1 changed files with 41 additions and 3 deletions
|
@ -8,11 +8,11 @@ import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Paint.Style;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
@ -25,8 +25,13 @@ public class FavoriteImageDrawable extends Drawable {
|
||||||
private Bitmap favIcon;
|
private Bitmap favIcon;
|
||||||
private Bitmap favBackground;
|
private Bitmap favBackground;
|
||||||
private Resources resources;
|
private Resources resources;
|
||||||
|
private boolean withShadow;
|
||||||
|
private Paint paintOuter;
|
||||||
|
private Paint paintInnerCircle;
|
||||||
|
private Drawable listDrawable;
|
||||||
|
|
||||||
public FavoriteImageDrawable(Context ctx, int color, boolean withShadow) {
|
public FavoriteImageDrawable(Context ctx, int color, boolean withShadow) {
|
||||||
|
this.withShadow = withShadow;
|
||||||
this.resources = ctx.getResources();
|
this.resources = ctx.getResources();
|
||||||
this.color = color;
|
this.color = color;
|
||||||
paintIcon = new Paint();
|
paintIcon = new Paint();
|
||||||
|
@ -35,6 +40,30 @@ public class FavoriteImageDrawable extends Drawable {
|
||||||
paintBackground = new Paint();
|
paintBackground = new Paint();
|
||||||
favIcon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_favorite);
|
favIcon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_favorite);
|
||||||
favBackground = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_white_favorite_shield);
|
favBackground = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_white_favorite_shield);
|
||||||
|
|
||||||
|
|
||||||
|
listDrawable = getResources().getDrawable(R.drawable.ic_action_fav_dark);
|
||||||
|
paintOuter = new Paint();
|
||||||
|
paintOuter.setAntiAlias(true);
|
||||||
|
paintOuter.setStyle(Style.FILL_AND_STROKE);
|
||||||
|
paintInnerCircle = new Paint();
|
||||||
|
paintInnerCircle.setStyle(Style.FILL_AND_STROKE);
|
||||||
|
paintOuter.setColor(color == 0 || color == Color.BLACK ? 0x88555555 : color);
|
||||||
|
paintInnerCircle.setColor(color == 0 || color == Color.BLACK ? getResources().getColor(R.color.color_favorite)
|
||||||
|
: color);
|
||||||
|
paintInnerCircle.setAntiAlias(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onBoundsChange(Rect bounds) {
|
||||||
|
super.onBoundsChange(bounds);
|
||||||
|
|
||||||
|
if (!withShadow) {
|
||||||
|
Rect bs = new Rect(bounds);
|
||||||
|
// FIXME
|
||||||
|
// bs.inset((int) (4 * density), (int) (4 * density));
|
||||||
|
listDrawable.setBounds(bs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,8 +87,17 @@ public class FavoriteImageDrawable extends Drawable {
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
Rect bs = getBounds();
|
Rect bs = getBounds();
|
||||||
|
if(withShadow) {
|
||||||
canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground);
|
canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground);
|
||||||
canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon);
|
canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon);
|
||||||
|
} else {
|
||||||
|
int min = Math.min(bs.width(), bs.height());
|
||||||
|
int r = (int) (min / 2);
|
||||||
|
int rs = (int) (min / 2 - 1);
|
||||||
|
canvas.drawCircle(min / 2, min / 2, r, paintOuter);
|
||||||
|
canvas.drawCircle(min / 2, min / 2, rs, paintInnerCircle);
|
||||||
|
listDrawable.draw(canvas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawBitmapInCenter(Canvas canvas, int x, int y) {
|
public void drawBitmapInCenter(Canvas canvas, int x, int y) {
|
||||||
|
|
Loading…
Reference in a new issue