-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to Solo for stylus input.
- Loading branch information
Showing
4 changed files
with
404 additions
and
249 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
robotium-solo/src/main/java/com/robotium/solo/Illustration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
77
robotium-solo/src/main/java/com/robotium/solo/Illustrator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
robotium-solo/src/main/java/com/robotium/solo/PressurePoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.