How i can't do swipe on tablet phone by katalon studio? - katalon-studio

I can't find the correct "X" and "Y" coordinate. when I enter the "X" and "Y" coordinate it will scroll the top menu bar.now I am using tablet phone.

This might help for iOS swipe function
https://medium.com/#manishboricha308/ios-mobile-swipe-action-in-katalon-studio-4911199679e
For Android you can create another #Keyword custom
#Keyword
def swipeLeft(){
TouchAction touch = new TouchAction(getCurrentSessionMobileDriver())
int device_Height, device_Width
device_Height = Mobile.getDeviceHeight()
println device_Height
device_Width = Mobile.getDeviceWidth()
println device_Width
int midheight = device_Height/2
println midheight
int midwidth = device_Width/2
println midwidth
int startX,startY,endX,endY
startX = device_Width-100
startY = midheight
endX = -startX
endY = 0
Mobile.swipe(startX,startY,endX,endY)
touch.tap(startX, startY).perform()
}

When You SpyMobile Your device, and mark object You want to swipe or scroll on You will notice properties window filed.
There are X and Y also Height (H) and Width (W).
X and Y are absolute co-ordinates to the top left corner of the object.
H and W are the size of an object. So You do a simple calculation to see
co-ordinates for rest of corners of the object.
With this You know space You want to swipe or scroll on.
Hope it works for You.

Related

JavaFX 8, how to get center location of Scrollpane's Viewport

The Problem
I'm trying to figure out a way to get at which point in the content node the scroll pane's viewport is centered on.
To elaborate on the picture above, the big rectangle is the content (let's say a large image), and the small rectangle is the portion that is shown by the scroll pane. I'm trying to find x and y which would be coordinates from the top left of the content.
What I've Tried
My first thought was to use the getViewportBounds() method of the scroll pane and use its minX and maxX properties to determine the center x point:
Bounds b = scrollPane.getViewportBounds();
double centerX = (b.getMinX() + b.getMaxX()) / 2;
double centerY = (b.getMinY() + b.getMaxY()) / 2;
However, this doesn't work because these numbers are negative and don't seem to accurately describe the x and y I'm looking for anyways.
My next thought was to use the scroll pane's hValue and vValue to get the top left corner of the viewport relative to the content:
Bounds b = scrollPane.getViewportBounds();
double centerX = scrollPane.getHvalue() + b.getWidth() / 2;
double centerY = scrollPane.getVvalue() + b.getHeight() / 2;
This didn't work either though as the hValue and vValue seem to be way too large (when scrolled in only a few pixels, I'm getting numbers like 1600).
My Questions
I seem to have a fundamental misunderstanding of how the viewport works with a scroll pane.
What am I doing wrong here? Can someone explain where these numbers come from? How do I find x and y like in the picture above?
Let (x, y) be the be coordinates of the top, left point shown in the viewport. You can write this as
((contentWidth - viewportWidth) * hValueRel, (contentHeight - viewportHeight) * vValueRel)
vValueRel = vValue / vMax
hValueRel = hValue / hMax
This means assuming hmin and vmin remain 0 you can keep a circle in the center of like this:
// update circle position to be centered in the viewport
private void update() {
Bounds viewportBounds = scrollPane.getViewportBounds();
Bounds contentBounds = content.getBoundsInLocal();
double hRel = scrollPane.getHvalue() / scrollPane.getHmax();
double vRel = scrollPane.getVvalue() / scrollPane.getVmax();
double x = Math.max(0, (contentBounds.getWidth() - viewportBounds.getWidth()) * hRel) + viewportBounds.getWidth() / 2;
double y = Math.max(0, (contentBounds.getHeight() - viewportBounds.getHeight()) * vRel) + viewportBounds.getHeight() / 2;
Point2D localCoordinates = content.parentToLocal(x, y);
circle.setCenterX(localCoordinates.getX());
circle.setCenterY(localCoordinates.getY());
}
private Circle circle;
private Pane content;
private ScrollPane scrollPane;
#Override
public void start(Stage primaryStage) {
// create ui
circle = new Circle(10);
content = new Pane(circle);
content.setPrefSize(4000, 4000);
scrollPane = new ScrollPane(content);
Scene scene = new Scene(scrollPane, 400, 400);
// add listener to properties that may change
InvalidationListener l = o -> update();
content.layoutBoundsProperty().addListener(l);
scrollPane.viewportBoundsProperty().addListener(l);
scrollPane.hvalueProperty().addListener(l);
scrollPane.vvalueProperty().addListener(l);
scrollPane.hmaxProperty().addListener(l);
scrollPane.vmaxProperty().addListener(l);
scrollPane.hminProperty().addListener(l);
scrollPane.vminProperty().addListener(l);
primaryStage.setScene(scene);
primaryStage.show();
}

Converting from world coordinates to tile location

me and a friend are trying to build an android app for class that uses google maps and we have been spending days on this one error.
Ideally the app receives updates of the user's location, stores them, and paints over any stored coordinate. That turned out to be a nightmare to implement so right now we're just trying to paint over the entire tile if that tile contains a coordinate that the user has visited. However we think something's wrong with our conversion from coordinate to tile location because the higher the zoom the more our painted tile moves north and a little west from the actual coordinate.
private boolean isCoordInTileForZoom(int tileX, int tileY, int zoom)
{
//coordinate to check if they are in the current tile
float lon = WILF_TEST_COOR.x;
float lat = WILF_TEST_COOR.y;
//coordinates in terms of map length and map height
float mapX = lon + 180;
float mapY = (lat * -1) + 150;
//number of tiles in a row or column (2^zoom)
int tiles = (int) Math.pow(2,zoom);
//the height and width of a single tile
double tileWidth = 360.0/tiles;
double tileHeight = 180.0/tiles;
int mapCol = (int) (mapX/tileWidth);
int mapRow = (int) (mapY/tileHeight);
Log.d("Minimap.mapGridDetails"," \n" + "Zoom level: " + zoom + "\nMap Rows: " + tiles + "\nTile Width: " + tileWidth + "\nTile Height: " + tileHeight);
if (mapCol == tileX && mapRow == tileY)
{
return true;
}
else
{
return false;
}
}
Now we're assuming the world is 360 degrees across and 180 degrees tall which means, at zoom level 2, each tile should be 90x45 (a 4x4 grid). And it works at zoom 2 and I think 3 but at zoom 4 and beyond the painted tile jumps north of the expected spot.
My feeling is that the problem lies in our assumption of how coordinate conversion works (we're assuming Google's world map is a nicely laid out flat surface which is perhaps exceptionally naive of us) or maybe the google map is actually taller than 180 degrees. Either way, this thing is due in a few days so we thank you in advance for any advice.
Have you seen this: https://developers.google.com/maps/documentation/javascript/examples/map-coordinates ?
Although its JavaScript, it shows the principle of the correct coordinate conversion.
You may also check my answer to this SO question. The class TileProjection I provided there should answer your question. You may e.g. use its method getTileBounds, to check whether your coordinates are inside the tile, or you may use the method latLngToPoint and check, whether x and y of the point are both in the range 0 - TILE_SIZE.

Converting coordinates from Image to screen

I'm working on a project where i detect finger movement in order to move the cursor on the screen so i have to translate the coordinates i get from the image to coordinates on the screen and move the cursor there.
example: the finger is detected on (128,127) i want to find the equivalent of that point on the screen. Image is (640 x 480) and the screen is (1366 x 768).
Can anybody help me with this. tried different methods but nothing is satisfying some of them i found on stack-overflow.
thanks in advance.
Try this:
ScreenX = event.X / PhoneWidth * ScreenWidth
ScreenY = event.Y / PhoneHeight * ScreenHeight
Where event.X would be the X coordinate where the user touched the screen.
Try using a map function.
In c language it could look like this:
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Reactive Extensions(RX) Rotation angle

We have all seen the nice RX handling of mouse drag n drop.
I want something similar but outputting the change in angle to the centre of the screen.
Like if the user hits the mouse button and circles the screen twice I would get values from 0 to 720 degrees.
Essentially rotating the thing on screen.
How would one do that?
This will give you the angle in radians from the center of the object. It will only operate in the range (-Pi, Pi] however. If you rotate three times, you won't get a value higher than a single rotation.
var mousedown = from evt in Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseDown")
select evt.EventArgs.GetPosition(this);
var mouseup = from evt in Observable.FromEventPattern<MouseEventArgs>(this, "MouseUp")
select evt.EventArgs.GetPosition(this);
var mousemove = from evt in Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove")
select evt.EventArgs.GetPosition(this);
Vector center = new Vector(this.Width / 2, this.Height / 2);
var radian = from start in mousedown
from pos in mousemove.StartWith(start).TakeUntil(mouseup)
select Math.Atan2((pos - center).Y, (pos -center).X);
EDIT
If you are after the change in angle, the following should work:
var angle = from start in mousedown
from pos in mousemove.StartWith(start).TakeUntil(mouseup)
select Vector.AngleBetween(pos - center, start - center);
Thanks for your help. Ive figured out the last bit myself:
var down = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseDown").Select(e=>e.EventArgs.GetPosition(this));
var move = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove").Select(e => e.EventArgs.GetPosition(this));
var up = Observable.FromEventPattern<MouseEventArgs>(this, "MouseUp").Select(e => e.EventArgs.GetPosition(this));
Vector center = new Vector(this.Width / 2, this.Height / 2);
var f = from start in down
from pos in move.StartWith(start).TakeUntil(up).Buffer(2, 1)
where pos.Count == 2
select Vector.AngleBetween(new Vector(pos[0].X, pos[0].Y) - center, new Vector(pos[1].X, pos[1].Y) - center);
f.ObserveOnDispatcher().Subscribe(p => {
game.Player.Angle += p;
});

MotionEvent coordinates to Scene coordinates

I am developing an application using multi-touch in AndEngine. To get the coordinates of touching fingers I use pSceneTouchEvent.getMotionEvent().getX([pointer index]) because TouchEvent doesn't have an equivalent getter, only pSceneTouchEvent.getX().
The problem is that MotionEvent returns coordinates on the screen while TouchEvent returns coordinates on the Scene. When I zoom in or out, the screen and Scene coordinates do not match, so I need to convert the screen coordinates to Scene coordinates. How can I do that?
Faced with the same problem and have a solution. First I want to explain it and then will paste the convert method.
The problem
Coordinates you want to have is scene coordinates which are related to your scene start point (0,0) (i.e. AndEngine anchorCenter is bottom-left). Bounds: from (0,0) to [Camera.getSurfaceWidth(), Camera.getSurfaceHeight()].
Coordinates you've got from MotionEvent is screen coordinates with bounds from (0,0) to [displayMetrix.widthPixels, displayMetrix.heightPixels] and they're independat of zoom or camera-to-scene-position.
Solution explanation
For the abscissa (in general x) you must translate screen corrdinates to relevant scene coordinates (bounded with camera width) and sum the up to the camera left corner position (on the scene). In formula it looks like:
x = cameraStartX + screenX * camera.width / display.width
cameraStartX - the camera left corner x position on the scene
screenX - x you get from MotionEvent
camera.width - just getWidth() from your camera method
display.width - display width from DisplayMetrics
For the ordinate (in general y) you have to do the same as for the abscissa but remember that it has a different direction. So the formula will be a bit changed:
y = cameraStartY+(display.heigth-screenY)*camera.height/display.heigth
cameraStartY - camera left corner y position on the scene
screenX - y you get from MotionEvent
camera.height - just getHeight() from your camera method
display.height - display height from DisplayMetrics
The method implementation example
public static void convertScreenToSurfaceCoordinates(
final Camera camera,
final Context context,
final float[] screenCoordinates,
final float[] surfaceCoordinates) {
//you may want to have a separate methods and fields for display metrics
//and no Context as a method param
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
float displayWidth = Math.max(metrics.widthPixels, metrics.heightPixels);
loat displayHeight = Math.min(metrics.widthPixels, metrics.heightPixels);
//abscissa
surfaceCoordinates[Constants.VERTEX_INDEX_X] = camera.getXMin()
+ screenCoordinates[Constants.VERTEX_INDEX_X] * camera.getWidth()
/ displayWidth;
//ordinate
surfaceCoordinates[Constants.VERTEX_INDEX_Y] = camera.getYMin()
+ (displayHeight - screenCoordinates[Constants.VERTEX_INDEX_Y])
* camera.getHeight() / displayHeight;
}
Solution found. Andengine handles touch events in a different way to Android so there is no history of touch coordinates. I simply store them myself in private variables before handling the event:
if (pSceneTouchEvent.getPointerID() == 0) {
pointer0LastX = pSceneTouchEvent.getX();
pointer0LastY = pSceneTouchEvent.getY();
}
if (pSceneTouchEvent.getPointerID() == 1) {
pointer1LastX = pSceneTouchEvent.getX();
pointer1LastY = pSceneTouchEvent.getY();
}
Then I just access these instead of getting the values from the TouchEvent.
You can access the original MotionEvent from the TouchEvent.