Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onDraw(Canvas canvas) {
- int w = canvas.getWidth();
- int h = canvas.getHeight();
- canvas.drawLine(w/2, 0, w/2, h-1, paint);
- // PAUSE FIVE SECONDS
- canvas.drawLine(0, h/2, w-1, h/2, paint);
- }
- boolean shouldDrawSecondLine = false;
- public void setDrawSecondLine(boolean flag) {
- shouldDrawSecondLine = flag;
- }
- public void onDraw(Canvas canvas) {
- int w = canvas.getWidth();
- int h = canvas.getHeight();
- canvas.drawLine(w/2, 0, w/2, h-1, paint);
- if (shouldDrawSecondLine) {
- canvas.drawLine(0, h/2, w-1, h/2, paint);
- }
- }
- final View view;
- // initialize the instance to your view
- // when it's drawn the second line will not be drawn
- // start async task to wait for 5 second that update the view
- AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- }
- return null;
- }
- @Override
- protected void onPostExecute(Void result) {
- view.setDrawSecondLine(true);
- view.invalidate();
- // invalidate cause your view to be redrawn it should be called in the UI thread
- }
- };
- task.execute((Void[])null);
- invalidate();
- pause/sleep();
- //set flag
- invalidate();
- public void onDraw(Canvas canvas) {
- int w = canvas.getWidth();
- int h = canvas.getHeight();
- canvas.drawLine(w/2, 0, w/2, h-1, paint);
- // PAUSE FIVE SECONDS
- new CountDownTimer(5000,1000){
- @Override
- public void onTick(long miliseconds){}
- @Override
- public void onFinish(){
- //after 5 seconds draw the second line
- canvas.drawLine(0, h/2, w-1, h/2, paint);
- }
- }.start();
- }
Add Comment
Please, Sign In to add comment