2014-12-08

Practice Final Problem 4 .

// Induce this class with a Layout for Android

public class CustomDrawableView extends View {

    private ShapeDrawable letterX;
    private ShapeDrawable letterO;

    public static boolean isDrawX = true;

    public CustomDrawableView(Context context) {
            super(context);

            TimerTask toggleDraw =
            new TimerTask {
                    public run() {
                            runOnUiThread(new Runnable() {
               @Override
               public void run() {
                   isDrawX != isDrawX;
               }
           });
                    }
            };
            Timer timer = new Timer();
            timer.scheduleAtFixedRate(toggleDraw, 500);

            int x = 10;
            int y = 10;
            int width = 300;
            int height = 50;

            letterO = new ShapeDrawable(new OvalShape());
            letterO.getPaint().setColor(0xff000000);
            letterO.setBounds(x, y, x + width, y + height);

            Path pX = new Path();
            pX.moveTo(x,y);
            pX.lineTo(x+width, y+height);
            letterX = new ShapeDrawable(new PathShape(pX, width, height));
    }

    protected void onDraw(Canvas canvas) {
            if(isDrawX)
                    letterX.draw(canvas);
            else
                    letterO.draw(canvas);
    }

}

// John Miller, Katharine Brinker, Brandon Cruz, Mark Odell

// Induce this class with a Layout for Android public class CustomDrawableView extends View { private ShapeDrawable letterX; private ShapeDrawable letterO; public static boolean isDrawX = true; public CustomDrawableView(Context context) { super(context); TimerTask toggleDraw = new TimerTask { public run() { runOnUiThread(new Runnable() { @Override public void run() { isDrawX != isDrawX; } }); } }; Timer timer = new Timer(); timer.scheduleAtFixedRate(toggleDraw, 500); int x = 10; int y = 10; int width = 300; int height = 50; letterO = new ShapeDrawable(new OvalShape()); letterO.getPaint().setColor(0xff000000); letterO.setBounds(x, y, x + width, y + height); Path pX = new Path(); pX.moveTo(x,y); pX.lineTo(x+width, y+height); letterX = new ShapeDrawable(new PathShape(pX, width, height)); } protected void onDraw(Canvas canvas) { if(isDrawX) letterX.draw(canvas); else letterO.draw(canvas); } } // John Miller, Katharine Brinker, Brandon Cruz, Mark Odell
X