All types of Swipe in appium 1.9.1

Appium : 1.9.1
Xcode : 10.1

Pom dependencies :

	<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium-java</artifactId>
		<version>3.12.0</version>
	</dependency>

	<dependency>
		<groupId>org.testng</groupId>
		<artifactId>testng</artifactId>
		<version>6.9.9</version>
	</dependency>

	<dependency>
		<groupId>io.appium</groupId>
		<artifactId>java-client</artifactId>
		<version>6.1.0</version>
	</dependency>

import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;

public class Swipe {

// This method will get called in all the swipe methods because appium has depricated the swipe method in appium 1.9.1
public static void swipe(int fromX,int fromY,int toX,int toY) {

	TouchAction action = new TouchAction(driver);
	action.press(PointOption.point(fromX,fromY))
	.waitAction(new WaitOptions().withDuration(Duration.ofMillis(600))) //you can change wait durations as per your requirement
	.moveTo(PointOption.point(toX, toY))
	.release()
	.perform();
}		


public void swipeDown(int pixelsToSwipe) {

	try {
		Point value = null;

		value = driver.findElement(By.id("elementId")).getLocation();

		int x = value.x;
		int y = value.y;
		int y1 = value.y+pixelsToSwipe;

		swipe(x,y1,x,y);
	} catch(Exception e) {

		System.out.println(e.getMessage());
	}

}

public void swipeUp(int pixelsToSwipe) {

	try {
		Point value = null;

		value = driver.findElement(By.id("elementId")).getLocation();

		int x = value.x;
		int y = value.y;
		int y1 = value.y+pixelsToSwipe;

		swipe(x, y, x, y1);
	} catch(Exception e) {

		System.out.println(e.getMessage());
	}

}

public void swipeRight(int pixelsToSwipe) {

	try {
		Point value = null;

		value = driver.findElement(By.id("elementId")).getLocation();

		int x = value.x;
		int y = value.y;
		int x1 = value.x+pixelsToSwipe;

		swipe(x, y, x1, y);
	} catch(Exception e) {

		System.out.println(e.getMessage());
	}

}

public void swipeLeft(int pixelsToSwipe) {

	try {
		Point value = null;

		value = driver.findElement(By.id("elementId")).getLocation();

		int x = value.x;
		int y = value.y;
		int x1 = value.x-pixelsToSwipe;
		swipe(x, y, x1, y);
	} catch(Exception e) {

		System.out.println(e.getMessage());
	}

}

//This will help you from one element to another element
public void swipeFromTo(int pixelsToSwipe) {

	try {
		Point from = null;
		Point to = null;

		from = driver.findElement(By.id("elementId")).getLocation();
		to = driver.findElement(By.id("elementId")).getLocation();

		int x = fromElement.x;
		int y = fromElement.y;
		int x1 = toElement.x;
		int y1 = toElement.y;
		swipe(x, y, x1, y1);
	} catch(Exception e) {

		System.out.println(e.getMessage());
	}

}

}