0

Im making an app that displays multiple random circles on the screen. I want to know if i can expand the radius WHILE it is displaying the circle then disapeers. I have already written the code to randomly display the circles here it is.

public class SplashLaunch extends View{
    Handler cool = new Handler();
    DrawingView v;
    ObjectAnimator aa = new ObjectAnimator();
    Paint newPaint = new Paint();
    int randomWidthOne = 0;
    int randomHeightOne = 0;
    private static int radiusOne = 300;
    final int redColorOne = Color.RED;
    final int greenColorOne = Color.GREEN;
    private static int lastColorOne;
    private final Random theRandom = new Random();
    public SplashLaunch(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    private final Runnable circleUpdater = new Runnable() {
        @SuppressLint("NewApi")
        @Override 
        public void run() {
            lastColorOne = theRandom.nextInt(2) == 1 ? redColorOne : greenColorOne;
            newPaint.setColor(lastColorOne);           
            cool.postDelayed(this, 500);
            int x = 0;
            while(x<=255){
                newPaint.setAlpha(x);
                x++;
                }
            invalidate();
        }
    };

    @Override
    protected void onAttachedToWindow(){
        super.onAttachedToWindow();
        cool.post(circleUpdater);
    }
    protected void onDetachedFromWindow(){
        super.onDetachedFromWindow();
        cool.removeCallbacks(circleUpdater);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);

        if(theRandom == null){
            randomWidthOne =(int) (theRandom.nextInt(Math.abs(getWidth()-radiusOne/2)) + radiusOne/2f);
            randomHeightOne = (theRandom.nextInt((int)Math.abs((getHeight()-radiusOne/2 + radiusOne/2f))));
        }else {
            randomWidthOne =(int) (theRandom.nextInt(Math.abs(getWidth()-radiusOne/2)) + radiusOne/2f);
            randomHeightOne = (theRandom.nextInt((int)Math.abs((getHeight()-radiusOne/2 + radiusOne/2f))));
        }
        canvas.drawCircle(randomWidthOne, randomHeightOne, radiusOne, newPaint);
    }

}
Paul Trueman
  • 149
  • 11

1 Answers1

1

I want to know if i can expand the radius WHILE it is displaying the circle then disappears

Yes you can. You simply animate the Scale of your view to a value greater than 1 to expand the view then back to 0 to make it "disappear".

freddieptf
  • 2,134
  • 2
  • 15
  • 16
  • canvas.drawCircle(randomWidthOne, randomHeightOne, radius.expand(), newPaint); – Paul Trueman Apr 25 '15 at 19:01
  • either way telling me to animate the Scale of my view doesn't answer my question at all you're not really showing me anything that i can use. I obviously don't know how to animate the scale of my view or else i wouldn't be asking the question. That like saying something to someone randomly expecting them to know what your talking about. – Paul Trueman Apr 25 '15 at 19:03
  • Sorry, but I have asked this question multiple times, and only one person has answered it. And the only answer I have gotten is garbage – Paul Trueman Apr 25 '15 at 19:05
  • Dude, i'm just giving some pointers here. I'll delete the answer if its really that annoying. The pop effect you're looking for definitely has something to do with animating the scale of your view (Yes, The circle is the view) probably using a ViewPropertyAnimator http://android-developers.blogspot.com/2011/05/introducing-viewpropertyanimator.html or ScaleAnimation http://stackoverflow.com/questions/7414065/android-scale-animation-on-view – freddieptf Apr 25 '15 at 19:18
  • and i'm not sure its possible to do that in the OnDraw – freddieptf Apr 25 '15 at 19:19
  • I said "Not sure" since changing the circles properties using an Animator would require the circle to be already drawn. – freddieptf Apr 25 '15 at 20:15
  • so the circle can't be drawn continuously? – Paul Trueman Apr 25 '15 at 20:17