Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean stop;
- float x1,x2;
- float y1, y2;
- public void ImageLoopForward(){
- final Handler handler = new Handler();
- runnable = new Runnable() {
- int i = a;
- public void run() {
- imageView.setImageResource(imageArray[i]);
- i++;
- if(stop==true)return;
- a = i;
- if (i > imageArray.length - 1) {
- i = 0;
- }
- handler.post(this);
- }
- };
- handler.post(runnable);
- }
- public void ImageLoopBack(){
- final Handler handler = new Handler();
- runnable = new Runnable() {
- int i = a;
- public void run() {
- imageView.setImageResource(imageArray[i]);
- i--;
- if(stop==true)return;
- a = i;
- if (i == 0) {
- i = imageArray.length-1;
- }
- handler.post(this);
- }
- };
- handler.post(runnable);
- }
- public boolean onTouchEvent(MotionEvent touchevent)
- {
- switch (touchevent.getAction()) {
- // when user first touches the screen we get x and y coordinate
- case MotionEvent.ACTION_DOWN: {
- x1 = touchevent.getX();
- y1 = touchevent.getY();
- }
- case MotionEvent.ACTION_MOVE: {
- x2 = touchevent.getX();
- y2 = touchevent.getY();
- //if left to right sweep event on screen
- if (x1 < x2) {
- ImageLoopForward();
- }
- // if right to left sweep event on screen
- if (x1 > x2) {
- ImageLoopBack();
- }
- }
- case MotionEvent.ACTION_UP:{
- stop = true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement