Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. @Override
  2. protected void onDraw(Canvas canvas) {
  3. for (int i=0; i < GlobalVars.getInstance().WHITE_COUNT; i++) {
  4. canvas.drawRect(whites.get(i).rect, i == 23 ? downKeyColor : whiteKeyColor);
  5. canvas.drawLine(whites.get(i).rect.left, top_pad, whites.get(i).rect.left, height, blackLineColor);
  6. }
  7. canvas.drawLine(0, top_pad, width, top_pad, blackLineColor);
  8. canvas.drawLine(0, height, width, height, blackLineColor);
  9.  
  10. for (Key k : blacks) {
  11. canvas.drawRect(k.rect, blackKeyColor);
  12. }
  13.  
  14. canvas.drawRect(0, 0, keyWidth * GlobalVars.getInstance().START_WITH, height, rectColor);
  15. canvas.drawRect(keyWidth * (GlobalVars.getInstance().START_WITH + GlobalVars.getInstance().DISPLAY_COUNT), 0, width, height, rectColor);
  16.  
  17. canvas.drawRect(0, 0, 10, height, borderColor);
  18. canvas.drawRect(width - 10, 0, width, height, borderColor);
  19. canvas.drawRect(0, 0, width, 10, borderColor);
  20. canvas.drawRect(0, height - 10, width, height, borderColor);
  21. }
  22.  
  23. @Override
  24. public boolean onTouchEvent(MotionEvent event) {
  25. int action = MotionEventCompat.getActionMasked(event);
  26. boolean isDownAction = action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE || action == MotionEvent.ACTION_POINTER_DOWN;
  27. boolean isUp = action == MotionEvent.ACTION_UP || MotionEvent.ACTION_POINTER_UP == action;
  28.  
  29. double x = event.getX(event.getActionIndex()) - keyWidth * (GlobalVars.getInstance().DISPLAY_COUNT / 2);
  30. if (x < 0)
  31. x = 0;
  32. if (x > keyWidth * (GlobalVars.getInstance().WHITE_COUNT - GlobalVars.getInstance().DISPLAY_COUNT))
  33. x = keyWidth * (GlobalVars.getInstance().WHITE_COUNT - GlobalVars.getInstance().DISPLAY_COUNT);
  34. x = x / keyWidth;
  35. KeyboardView k = MainActivity.getInstance().findViewById(R.id.keyboardView);
  36. RunAnimation thread = new RunAnimation(k, this, GlobalVars.getInstance().START_WITH, (float) Math.floor(x));
  37. thread.start();
  38. return true;
  39. }
  40.  
  41. public void Animate(final KeyboardView k, final KeyboardViewSmall ks){
  42. MainActivity.getInstance().runOnUiThread(new Runnable() {
  43. @Override
  44. public void run() {
  45. k.onSizeChanged(k.width, k.height, k.width, k.height);
  46. k.invalidate();
  47. ks.invalidate();
  48. }
  49. });
  50. }
  51.  
  52. class RunAnimation extends Thread {
  53. private KeyboardView k;
  54. private KeyboardViewSmall ks;
  55. private float start, end;
  56. public RunAnimation(KeyboardView k, KeyboardViewSmall ks, float start, float end) {
  57. this.k = k;
  58. this.ks = ks;
  59. this.start = start;
  60. this.end = end;
  61. }
  62.  
  63. @Override
  64. public void run() {
  65.  
  66. try {
  67. float s = start;
  68. while (abs(s - end) > 0.01) {
  69. if (s > end)
  70. s -= 0.2;
  71. else
  72. s += 0.2;
  73. GlobalVars.getInstance().START_WITH = s;
  74. Animate(k, ks);
  75. sleep(1);
  76. }
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. }
  80. GlobalVars.getInstance().START_WITH = end;
  81. MainActivity.getInstance().SaveVariables();
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement