Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
I have java class extends view. I draw a simple circle on canvas. The requirements is to make this circle blink or flash. I have tried many things and searched alot with no luck. It's pretty easy to make textView or image blink by adding animation, but the circle I have to draw then make it blink.
Any help will be appreciated

What I have tried:

Here is my circle:
Java
mCircle = new Paint();
mCircle.setARGB(255, 100, 255, 255);
mCircle.setShadowLayer(100, 0, 0, Color.BLUE);
canvas.drawCircle(x, y, value, mCircle);
setLayerType(1, mCircle);

I have tried what's said in this link[^] but not working
Posted
Updated 30-Aug-18 7:19am
Comments
Richard MacCutchan 30-Aug-18 12:48pm    
It is the same as making text blink, you need animation. Draw the circle in one colour, pause for some short time, draw it in a different colour, repeat.
Samira Radwan 30-Aug-18 13:20pm    
thanks, i did pretty much as you suggested, please check my answer and if you have any other thoughts, let me know.
Richard MacCutchan 30-Aug-18 15:41pm    
Does it work?
Samira Radwan 6-Sep-18 13:33pm    
yes it does work. apology for late answer

Blinking or "strobing" can cause epileptic fits in certain individuals and is therefore not recommended.

It's grouped in with "web sites that suck".

("Rotating" is better IMO).
 
Share this answer
 
Comments
Samira Radwan 30-Aug-18 13:16pm    
I understand your point. but how to make rotation look like blink? any link or starting code would be really appreciated.
In my case I would like to make the circle blink in certain condition for short time to indicate to the user he has to tap/touch here.
I have created a method to switch between 2 colors every X time.
I called this method on the class constructor (the class extends View)
The method:
Java
private void setCircleAnimation(){
        final int color1 = Color.parseColor("#3399ff");
        final int color2 = Color.parseColor("#84c1ff");
        circleColor = color1;
        postDelayed(new Runnable() {
            @Override
            public void run() {
                circleColor = (circleColor == color1) ? color2 : color1;
                invalidate();
                postDelayed(this, 300);
            }
        }, 300);
    }

after calling this function on the constructor. I draw the circle like in my code snippet in the question.
Not sure it's the best way to do it, but it works for the moment.
Any other suggestions or corrections are very welcome.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900