Advertisement
Guest User

asd

a guest
Dec 13th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. package com.example.l2gesty;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.constraintlayout.widget.ConstraintLayout;
  5.  
  6. import android.graphics.Color;
  7. import android.os.Bundle;
  8. import android.view.GestureDetector;
  9. import android.view.MotionEvent;
  10. import android.widget.TextView;
  11.  
  12. public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener{
  13.  
  14. GestureDetector detektorGestow;
  15. ConstraintLayout tlo;
  16. TextView licznik;
  17. int x=0;
  18. int skladowa=0;
  19. float pj;
  20. int xmax,ymax,dx,dy;
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25. detektorGestow = new GestureDetector(this, this);
  26. licznik = findViewById(R.id.textView01);
  27. tlo = findViewById(R.id.tlo);
  28. xmax = tlo.getMaxWidth();
  29. //ymax = tlo.getMaxHeight();
  30. }
  31.  
  32. @Override
  33. public boolean onTouchEvent(MotionEvent event) {
  34. detektorGestow.onTouchEvent(event);
  35. return super.onTouchEvent(event);
  36. }
  37.  
  38. @Override
  39. public boolean onDown(MotionEvent e) {
  40. return false;
  41. }
  42.  
  43. @Override
  44. public void onShowPress(MotionEvent e) {
  45.  
  46. }
  47.  
  48. @Override
  49. public boolean onSingleTapUp(MotionEvent e) {
  50. tlo.setBackgroundColor(Color.argb(255,100,40,50));
  51. return false;
  52. }
  53.  
  54. @Override
  55. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
  56. ymax = tlo.getHeight();
  57. pj = e2.getY()/ymax;
  58. licznik.setText(String.valueOf(pj));
  59. tlo.setBackgroundColor(Color.argb(255,Math.round(255*pj),Math.round(255*pj),Math.round(255*pj)));
  60. return false;
  61. }
  62.  
  63. @Override
  64. public void onLongPress(MotionEvent e) {
  65. licznik.setText("0");
  66. }
  67.  
  68. @Override
  69. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
  70. //licznik.setText(String.valueOf(velocityX)+" ; "+String.valueOf(velocityY));
  71. //if(velocityX*velocityX>velocityY*velocityY) {
  72. // / if (velocityX > 0) {
  73. // x+=1;
  74. // licznik.setText(String.valueOf(x));
  75. // }
  76. // else {
  77. // x-=1;
  78. // licznik.setText(String.valueOf(x));}
  79. //}
  80. //else {
  81. // if (velocityY > 0) {
  82. // x+=10;
  83. // licznik.setText(String.valueOf(x));
  84. // } else {
  85. // x-=10;
  86. // licznik.setText(String.valueOf(x));
  87. // }
  88. //}
  89. return false;
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement