cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [4/5] android commit: Update to purity, adding better touch support
Date Tue, 29 Jan 2013 23:21:01 GMT
Update to purity, adding better touch support


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/31055bb3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/31055bb3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/31055bb3

Branch: refs/heads/master
Commit: 31055bb30340499d0a6c582c2d6180588ef06bfd
Parents: 1adf268
Author: Joe Bowser <bowserj@apache.org>
Authored: Fri Jan 25 14:39:44 2013 -0800
Committer: Joe Bowser <bowserj@apache.org>
Committed: Fri Jan 25 14:39:44 2013 -0800

----------------------------------------------------------------------
 test/src/org/apache/cordova/test/util/Purity.java |   62 +++++++++++++++-
 1 files changed, 61 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/31055bb3/test/src/org/apache/cordova/test/util/Purity.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/util/Purity.java b/test/src/org/apache/cordova/test/util/Purity.java
index 0e7ced8..7171338 100644
--- a/test/src/org/apache/cordova/test/util/Purity.java
+++ b/test/src/org/apache/cordova/test/util/Purity.java
@@ -40,6 +40,7 @@ public class Purity {
     int width, height;
     float density;
     Bitmap state;
+    boolean fingerDown = false;
    
     public Purity(Context ctx, Instrumentation i)
     {
@@ -77,8 +78,61 @@ public class Purity {
         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 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 = 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)
@@ -106,6 +160,12 @@ public class Purity {
     
     public void clearBitmap()
     {
-        state.recycle();
+        if(state != null)
+            state.recycle();
+    }
+    
+    protected void finalize()
+    {
+            clearBitmap();
     }
 }


Mime
View raw message