I have a ImageView where I put a Bitmap (left), sometimes I wanna see bitmap with a semitransparent blue layer (right). I try with a ColorFilter (LightingColorFilter and PorterDuffColorFilter) but I get a dark blue, how can I do this with ColorFilter or anything else?
Thanks.
EDIT (I tried this and other variants)
//ColorFilter filter = new PorterDuffColorFilter(color.wather, PorterDuff.Mode.DST_OVER);
ColorFilter filter = new LightingColorFilter(color.mul, color.wather);
// mul = 0xFFFFFFFF and wather = 0x7000FFFF
BitmapScaler scaler = new BitmapScaler();
imagen.setImageBitmap(scaler.getScaled());
imagen.setColorFilter(filter);
I tried diferents mul, add values and always get this:
I've already finds the mul, add values, I had a problem with color.xml because I used ID number instead the color RGB number, big mistake. Transparence (Alpha) are ignore but I can get the effect downing intensity of add value.
int mul = 0xFFFFFF;
int add = 0x005050;
filter = new LightingColorFilter(mul, add);
Thanks Elior for your help.
Related
I am setting the background of a TextViewin android as a pie diagram. I have used a LayerDrawable of ArcShape(s) to do so and set it as the background. Here is the code for that:
final ShapeDrawable arcGreen = new ShapeDrawable(new ArcShape(-90, correctAngle));
arcGreen.getPaint().setColor(ContextCompat.getColor(this, R.color.feedback_score_3));
final ShapeDrawable arcRed = new ShapeDrawable(new ArcShape(-90 + correctAngle, 360 - correctAngle));
arcRed.getPaint().setColor(ContextCompat.getColor(this, R.color.feedback_score_1));
final Drawable[] layer = {arcGreen, arcRed, mask};
final LayerDrawable ld = new LayerDrawable(layer);
mSvaraLayout.getChildAt(i).setBackground(ld);
Now, what I want to do is to animate this background when the value of correctAngle changes. One of the options that I see is to use ValueAnimator and go from the initial value to the new correctValue and each time inside the onAnimationUpdate() callback I create a new LayerDrawable object with the changed values and set it as a background. Other way could have been to get all the Drawables(s) in the background first(which are the ShapeDrawable(<ArcShape>)objects and then set the angles of the arcs. But I guess there is no way to do so. Is there any other way to achieve this?
I've been trying to change the style of my KML so KmlPoint would be represented with a custom marker of my choice.
Here are the markers I'm using:
I successfully made the wanted points show up with the respective markers, but they look like a color filter might be applied to them or the bitmap is simply corrupted and I don't know why.
Here is my code:
KmlDocument dryKmlDocument = new KmlDocument();
File f2 = new File(appPath + "/dry_hydrant.kml");
dryKmlDocument.parseKMLFile(f2);
Bitmap blueBitmap = ((BitmapDrawable)ResourcesCompat.getDrawable(getResources(), R.drawable.blue, null)).getBitmap();
Style dryStyle = new Style(blueBitmap, 0x901010AA, 1.0f, 0x20AA1010);
ZoneStyler dryZoneStyler = new ZoneStyler(dryStyle, dryKmlDocument, osmView);
dryKmlOverlay = (FolderOverlay)dryKmlDocument.mKmlRoot.buildOverlay(osmView, null, dryZoneStyler, dryKmlDocument);
KmlDocument fireKmlDocument = new KmlDocument();
File f3 = new File(appPath + "/fire_hydrant.kml");
fireKmlDocument.parseKMLFile(f3);
Bitmap redBitmap = ((BitmapDrawable)ResourcesCompat.getDrawable(getResources(), R.drawable.red, null)).getBitmap();
Style fireStyle = new Style(redBitmap, 0x00000000, 1.0f, 0x00000000);
ZoneStyler fireZoneStyler = new ZoneStyler(fireStyle, fireKmlDocument, osmView);
fireKmlOverlay = (FolderOverlay)fireKmlDocument.mKmlRoot.buildOverlay(osmView, null, fireZoneStyler, fireKmlDocument);
Can someone point me to what could be causing this?
EDIT: Imgur didn't want to show up my bmp marker images so I took a screenshot in windows explorer instead.
Use PNG format, and ensure the corners are fully transparent (you cannot do that with the Windows Paint, you need something like IcoFX, Gimp, PhotoShop,... ).
I don't understand why all the colors give the same result. All the textviews background draw in gray, although I have black, white and red. What is the problem here?
<color name="color1">#FFFFFF</color>
<color name="color2">#000000</color>
<color name="color3">#FF0000</color?
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(R.id.color1,R.color.color1);
map.put(R.id.color2,R.color.color2);
map.put(R.id.color3,R.color.color3);
GradientDrawable gradientDrawable;
TextView textView;
for (Map.Entry<Integer,Integer> entry : map.entrySet()) {
textView = findTextView(entry.getKey());
gradientDrawable = (GradientDrawable) textView.getBackground().mutate();
gradientDrawable.setColor(entry.getValue());
gradientDrawable.invalidateSelf();
}
Change it to:
gradientDrawable.setColor(getResources().getColor(entry.getValue()));
http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html#setColor(int)
The parameter it takes is:
argb The color used to fill the shape
By passing it the R resource int directly it's basically a random number generated by R. You need to "decode it" into a 0xAARRGGBB colour value using Resources.getColor()
http://developer.android.com/reference/android/content/res/Resources.html#getColor(int)
They probably all look the same because the ints are close to each other in value.
I need a little help with the thing that I want to achieve. I'm using BitmapShader in my application to draw on a canvas. I'm setting a custom png file as shader to my paint variable and I want to change the color of shader.
Here is an example code which I'm using :
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.particle_point);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
mPaint.setShader(shader);
ColorFilter filter = new LightingColorFilter(0xFFFFFFFF , 0x000000FF );
mPaint.setColorFilter(filter);
I find that I can change it's color by using :
ColorFilter filter = new LightingColorFilter(0xFFFFFFFF , 0x000000FF );
, but I need to be able to change it's color by using a custom color picker,which returns color code similar to this : -234423123.
So is there any way that I can use this color code and set it as color to my paint variable.
Thanks in advance!
The color you are getting converted to hex is: FFFFFFFFF206FCAD. So youst need to get rid of the 8 leading Fs:
int color = -234423123;//0xFFFFFFFFF206FCAD
int myColor = 0x00000000FFFFFFFF & color;
myColor should be ok.
Just to add a little bit more detailed to the Moss's answer. As he suggest you can use myColor as the value you want and to set the right value to your shader you have to add myColor to your LightingColorFilter like this :
ColorFilter filter = new LightingColorFilter(myColor , myColor );
And it should work.
To get the hex String:
"#"+Integer.toHexString(n));
But your color picker just returns the color's int value which should be enough to work with!
ColorFilter filter = new LightingColorFilter(0xFFFFFFFF , 0x000000FF );
Just change the value which represents the color to the int your colorpicker returns... (without 0x in front of it ofcourse)...
If I ain't wrong this should work just as fine!
I'm trying to create a dynamic icon menu for my android application.
The icon is made from 2 drawable, a 9-patch background image with the icon image overlay on it.
With reference to overlay two images in android to set an imageview, I've the following code which have the overlay nicely.
Resources res = parent.getResources();
Drawable icon_bg = res.getDrawable(R.drawable.menu_icon_bg);
Drawable icon = res.getDrawable(R.drawable.menu_icon);
// Not working
int int_icon_height = icon.getIntrinsicHeight();
int int_icon_width = icon.getIntrinsicWidth();
Rect rect_icon_bg_bound = new Rect();
rect_icon_bg_bound.left = 0;//(int) Math.round(int_icon_width*-1.5);
rect_icon_bg_bound.right = (int) Math.round(int_icon_width*1.5);
rect_icon_bg_bound.top = 0;//(int)Math.round(int_icon_height*-1.5);
rect_icon_bg_bound.bottom = (int)Math.round(int_icon_height*1.5);
icon_bg.setBounds(rect_icon_bg_bound);
Drawable[] layers = new Drawable[2];
layers[0] = icon_bg;
layers[1] = icon;
LayerDrawable layerDrawable = new LayerDrawable(layers);
ImageView iv_icon_combined = new ImageView(getApplicationContext());
iv_icon_combined.setImageDrawable(layerDrawable);
The problem I'm facing right now is adding a padding so that the icon will have some spacing within the background.
Hope to get some enlightenment here, thanks in advance.
I just ran into this same issue. Take a look at the setLayerInset method on LayerDrawable. It takes the layer level as an argument and then the modifiers for the left, top, right, bottom bounds of the drawable.