Guest User

Untitled

a guest
Jul 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. public void onDraw(Canvas canvas) {
  2. int w = canvas.getWidth();
  3. int h = canvas.getHeight();
  4. canvas.drawLine(w/2, 0, w/2, h-1, paint);
  5. // PAUSE FIVE SECONDS
  6. canvas.drawLine(0, h/2, w-1, h/2, paint);
  7. }
  8.  
  9. boolean shouldDrawSecondLine = false;
  10.  
  11. public void setDrawSecondLine(boolean flag) {
  12. shouldDrawSecondLine = flag;
  13. }
  14.  
  15. public void onDraw(Canvas canvas) {
  16. int w = canvas.getWidth();
  17. int h = canvas.getHeight();
  18. canvas.drawLine(w/2, 0, w/2, h-1, paint);
  19. if (shouldDrawSecondLine) {
  20. canvas.drawLine(0, h/2, w-1, h/2, paint);
  21. }
  22. }
  23.  
  24. final View view;
  25. // initialize the instance to your view
  26. // when it's drawn the second line will not be drawn
  27.  
  28. // start async task to wait for 5 second that update the view
  29. AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
  30. @Override
  31. protected Void doInBackground(Void... params) {
  32. try {
  33. Thread.sleep(5000);
  34. } catch (InterruptedException e) {
  35. // TODO Auto-generated catch block
  36. }
  37. return null;
  38. }
  39.  
  40. @Override
  41. protected void onPostExecute(Void result) {
  42. view.setDrawSecondLine(true);
  43. view.invalidate();
  44. // invalidate cause your view to be redrawn it should be called in the UI thread
  45. }
  46. };
  47. task.execute((Void[])null);
  48.  
  49. invalidate();
  50. pause/sleep();
  51. //set flag
  52. invalidate();
  53.  
  54. public void onDraw(Canvas canvas) {
  55. int w = canvas.getWidth();
  56. int h = canvas.getHeight();
  57. canvas.drawLine(w/2, 0, w/2, h-1, paint);
  58. // PAUSE FIVE SECONDS
  59. new CountDownTimer(5000,1000){
  60.  
  61. @Override
  62. public void onTick(long miliseconds){}
  63.  
  64. @Override
  65. public void onFinish(){
  66. //after 5 seconds draw the second line
  67. canvas.drawLine(0, h/2, w-1, h/2, paint);
  68. }
  69. }.start();
  70.  
  71. }
Add Comment
Please, Sign In to add comment