Advertisement
Guest User

Untitled

a guest
Jan 8th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. boolean stop;
  2. float x1,x2;
  3. float y1, y2;
  4.  
  5. public void ImageLoopForward(){
  6. final Handler handler = new Handler();
  7. runnable = new Runnable() {
  8. int i = a;
  9.  
  10. public void run() {
  11. imageView.setImageResource(imageArray[i]);
  12. i++;
  13. if(stop==true)return;
  14. a = i;
  15. if (i > imageArray.length - 1) {
  16. i = 0;
  17. }
  18. handler.post(this);
  19. }
  20. };
  21. handler.post(runnable);
  22. }
  23.  
  24. public void ImageLoopBack(){
  25. final Handler handler = new Handler();
  26. runnable = new Runnable() {
  27. int i = a;
  28.  
  29. public void run() {
  30. imageView.setImageResource(imageArray[i]);
  31. i--;
  32. if(stop==true)return;
  33. a = i;
  34. if (i == 0) {
  35. i = imageArray.length-1;
  36. }
  37.  
  38. handler.post(this);
  39. }
  40. };
  41. handler.post(runnable);
  42. }
  43.  
  44. public boolean onTouchEvent(MotionEvent touchevent)
  45. {
  46. switch (touchevent.getAction()) {
  47. // when user first touches the screen we get x and y coordinate
  48. case MotionEvent.ACTION_DOWN: {
  49. x1 = touchevent.getX();
  50. y1 = touchevent.getY();
  51. }
  52. case MotionEvent.ACTION_MOVE: {
  53. x2 = touchevent.getX();
  54. y2 = touchevent.getY();
  55. //if left to right sweep event on screen
  56. if (x1 < x2) {
  57. ImageLoopForward();
  58. }
  59. // if right to left sweep event on screen
  60. if (x1 > x2) {
  61. ImageLoopBack();
  62. }
  63. }
  64. case MotionEvent.ACTION_UP:{
  65. stop = true;
  66. }
  67. }
  68. return false;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement