Skip to content

Commit

Permalink
Added methods to Solo for stylus input.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekajjake committed Mar 12, 2015
1 parent 43480da commit bf8f3a8
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 249 deletions.
45 changes: 45 additions & 0 deletions robotium-solo/src/main/java/com/robotium/solo/Illustration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.robotium.solo;

import java.util.ArrayList;
import android.view.MotionEvent;

public class Illustration {

private int toolType = MotionEvent.TOOL_TYPE_STYLUS;
private ArrayList<PressurePoint> points = new ArrayList<PressurePoint>();

private Illustration(Builder builder) {
this.toolType = builder.builderToolType;
this.points = builder.builderPoints;
}

public static class Builder {

private int builderToolType;
private ArrayList<PressurePoint> builderPoints = new ArrayList<PressurePoint>();

public Builder setToolType(int toolType) {
builderToolType = toolType;
return this;
}

public Builder addPoint(float x, float y, float pressure) {
builderPoints.add(new PressurePoint(x, y, pressure));
return this;
}

public Illustration build() {
return new Illustration(this);
}
}

public ArrayList<PressurePoint> getPoints()
{
return points;
}

public int getToolType()
{
return toolType;
}
}
77 changes: 77 additions & 0 deletions robotium-solo/src/main/java/com/robotium/solo/Illustrator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.robotium.solo;

import java.util.ArrayList;
import android.view.MotionEvent;
import android.view.MotionEvent.PointerProperties;
import android.view.MotionEvent.PointerCoords;
import android.view.InputDevice;
import android.app.Instrumentation;
import android.os.SystemClock;

class Illustrator {

private Instrumentation inst;

public Illustrator(Instrumentation inst) {
this.inst = inst;
}

public void illustrate(Illustration illustration) {
MotionEvent event;
int currentAction;
PointerCoords[] coords = new PointerCoords[1];
PointerProperties[] properties = new PointerProperties[1];
PointerProperties prop = new PointerProperties();
prop.id = 0;
prop.toolType = illustration.getToolType();
properties[0] = prop;
ArrayList<PressurePoint> points = illustration.getPoints();
if (points.size() > 0) {
for (int i = 0; i < points.size(); i++) {
coords[0] = new PointerCoords();
coords[0].x = points.get(i).x;
coords[0].y = points.get(i).y;
coords[0].pressure = points.get(i).pressure;
coords[0].size = 1;

long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();

if (i == 0) currentAction = MotionEvent.ACTION_DOWN;
else currentAction = MotionEvent.ACTION_MOVE;

event = MotionEvent.obtain(downTime,
eventTime,
currentAction,
1,
properties,
coords,
0, 0, 1, 1, 0, 0,
InputDevice.SOURCE_TOUCHSCREEN,
0);
inst.sendPointerSync(event);
}
currentAction = MotionEvent.ACTION_UP;
coords[0] = new PointerCoords();
coords[0].x = points.get(points.size() - 1).x;
coords[0].y = points.get(points.size() - 1).y;
coords[0].pressure = points.get(points.size() - 1).pressure;
coords[0].size = 1;
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
event = MotionEvent.obtain(downTime,
eventTime,
currentAction,
1,
properties,
coords,
0, 0, 1, 1, 0, 0,
InputDevice.SOURCE_TOUCHSCREEN,
0);
inst.sendPointerSync(event);
}
else {
throw new RuntimeException("Illustration requires at least one point.");
}
}
}
13 changes: 13 additions & 0 deletions robotium-solo/src/main/java/com/robotium/solo/PressurePoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.robotium.solo;

class PressurePoint {
public final float x;
public final float y;
public final float pressure;

public PressurePoint(float x, float y, float pressure){
this.x = x;
this.y = y;
this.pressure = pressure;
}
}
Loading

0 comments on commit bf8f3a8

Please sign in to comment.