Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. private void displayColors(final int quantity) {
  2. runOnUiThread(new Runnable() {
  3. @Override
  4. public void run() {
  5. delta=0;
  6. final ImageView[] displayingColors = new ImageView[quantity];
  7. final RelativeLayout.LayoutParams displayingColorsLayoutParams[] = new RelativeLayout.LayoutParams[k];
  8. for (int count = 0; count < quantity; count++) {
  9. displayingColors[count] = new ImageView(getApplicationContext());
  10. displayingColorsLayoutParams[count] = new RelativeLayout.LayoutParams(height, width);
  11. displayingColorsLayoutParams[count].setMargins(marginLeft, marginTop, 0, 0);
  12. }
  13. for (int count = 0; count < quantity; count++) {
  14. final int index = count;
  15. handler.postDelayed(new Runnable() {
  16. @Override
  17. public void run() {
  18. displayingColors[index].setImageResource(a random image);
  19. gameBoard.addView(displayingColors[index], displayingColorsLayoutParams[index]); //colors appearing
  20. if (index >= 1)
  21. colorsGameBoard.removeView(displayingColors[index - 1]); //colors disappearing
  22. }
  23. }, 1000 * (index + 1));
  24. }
  25. handler.postDelayed(new Runnable() {
  26. @Override
  27. public void run() {
  28. colorsGameBoard.removeView(displayingColors[colorsNumber - 1]);
  29. chooseColorsFromList(colorsNumber);
  30. delta=100;
  31. }
  32. }, 1000 * (k + 1));
  33. }
  34. });
  35. }
  36.  
  37. private class CheckTime implements Runnable {
  38.  
  39. @Override
  40. public void run() {
  41. while (timeAmount > 0) {
  42. try {
  43. Thread.sleep(100);
  44. timeAmount = timeAmount - delta;
  45. } catch (InterruptedException e) {
  46. e.printStackTrace();
  47. }
  48. if (timeAmount <= 0)
  49. runOnUiThread(new Runnable() {
  50. @Override
  51. public void run() {
  52. //Game Over UI process
  53. }
  54. });
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement