Update to purity, adding better touch support

This commit is contained in:
Joe Bowser 2013-01-25 14:39:44 -08:00
parent 1adf268e71
commit 31055bb303

View File

@ -40,6 +40,7 @@ public class Purity {
int width, height; int width, height;
float density; float density;
Bitmap state; Bitmap state;
boolean fingerDown = false;
public Purity(Context ctx, Instrumentation i) public Purity(Context ctx, Instrumentation i)
{ {
@ -71,6 +72,22 @@ public class Purity {
} }
public void touch(int x, int y) public void touch(int x, int y)
{
int realX = getRealCoord(x);
int realY = getRealCoord(y);
long downTime = SystemClock.uptimeMillis();
// event time MUST be retrieved only by this way!
long eventTime = SystemClock.uptimeMillis();
if(!fingerDown)
{
MotionEvent downEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0);
inst.sendPointerSync(downEvent);
}
MotionEvent upEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, realX, realY, 0);
inst.sendPointerSync(upEvent);
}
public void touchStart(int x, int y)
{ {
int realX = getRealCoord(x); int realX = getRealCoord(x);
int realY = getRealCoord(y); int realY = getRealCoord(y);
@ -79,6 +96,43 @@ public class Purity {
long eventTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0); MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0);
inst.sendPointerSync(event); inst.sendPointerSync(event);
fingerDown = true;
}
//Move from the touch start
public void touchMove(int x, int y)
{
if(!fingerDown)
touchStart(x,y);
else
{
int realX = getRealCoord(x);
int realY = getRealCoord(y);
long downTime = SystemClock.uptimeMillis();
// event time MUST be retrieved only by this way!
long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, realX, realY, 0);
inst.sendPointerSync(event);
}
}
public void touchEnd(int x, int y)
{
if(!fingerDown)
{
touch(x, y);
}
else
{
int realX = getRealCoord(x);
int realY = getRealCoord(y);
long downTime = SystemClock.uptimeMillis();
// event time MUST be retrieved only by this way!
long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0);
inst.sendPointerSync(event);
fingerDown = false;
}
} }
public void setBitmap(WebView view) public void setBitmap(WebView view)
@ -106,6 +160,12 @@ public class Purity {
public void clearBitmap() public void clearBitmap()
{ {
state.recycle(); if(state != null)
state.recycle();
}
protected void finalize()
{
clearBitmap();
} }
} }