[Libreoffice-commits] core.git: Branch 'distro/collabora/viewer' - 3 commits - android/experimental

Siqi Liu me at siqi.fr
Thu Mar 5 01:16:07 PST 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java                 |    2 
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java              |    8 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java             |   14 ++
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java       |   20 +++
 android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java |   13 ++
 android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java        |    8 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java    |   62 ++++++++++
 android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java            |   11 +
 8 files changed, 138 insertions(+)

New commits:
commit db4209bf18ce52a825ccebd2fe78ead599a494b5
Author: Siqi Liu <me at siqi.fr>
Date:   Sat Feb 28 22:07:36 2015 +0100

    remove unused boolean (propagating touchEvent instead of intercepting it)
    
    Change-Id: If05cf04414572fea809104c7fed309afb2438bfd

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
index 1dc33f6..b1ee37e 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
@@ -27,7 +27,6 @@ public class OnSlideSwipeListener implements OnTouchListener {
 
         @Override
         public boolean onFling(MotionEvent e1, MotionEvent e2, float velX, float velY) {
-            boolean result = false;
             try {
                 float diffY = e2.getY() - e1.getY();
                 float diffX = e2.getX() - e1.getX();
@@ -40,7 +39,6 @@ public class OnSlideSwipeListener implements OnTouchListener {
                             onSwipeLeft();
                         }
                     }
-                    result = true;
                 }
             } catch (Exception exception) {
                 exception.printStackTrace();
commit d694ec67967d2ac29ca4d7106f68af48fa32fc21
Author: Siqi Liu <me at siqi.fr>
Date:   Sat Feb 28 21:50:12 2015 +0100

    implement swiping gesture as a generic event
    
    Conflicts:
    	android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
    	android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
    
    Change-Id: I024db339bada34a544fdcc1def107c7b06332847

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index 807d0d0..c7babde 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -21,6 +21,8 @@ public class LOEvent implements Comparable<LOEvent> {
     public static final int TILE_INVALIDATION = 9;
     public static final int TOUCH = 10;
     public static final int KEY_EVENT = 11;
+    public static final int SWIPE_RIGHT = 12;
+    public static final int SWIPE_LEFT = 13;
 
     public final int mType;
     public int mPriority = 0;
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index 2037e9d..ec0d701 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -101,6 +101,14 @@ public class LOKitShell {
         LOKitShell.sendEvent(new LOEvent(LOEvent.SIZE_CHANGED, width, height));
     }
 
+    public static void sendSwipeRightEvent() {
+        LOKitShell.sendEvent(new LOEvent(LOEvent.SWIPE_RIGHT));
+    }
+
+    public static void sendSwipeLeftEvent() {
+        LOKitShell.sendEvent(new LOEvent(LOEvent.SWIPE_LEFT));
+    }
+
     public static void sendChangePartEvent(int part) {
         LOKitShell.sendEvent(new LOEvent(LOEvent.CHANGE_PART, part));
     }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 9ec76be..63ee8e7 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -198,6 +198,12 @@ public class LOKitThread extends Thread {
             case LOEvent.TILE_REEVALUATION_REQUEST:
                 tileReevaluationRequest(event.mComposedTileLayer);
                 break;
+            case LOEvent.SWIPE_LEFT:
+                onSwipeLeft();
+                break;
+            case LOEvent.SWIPE_RIGHT:
+                onSwipeRight();
+                break;
         }
     }
 
@@ -214,6 +220,14 @@ public class LOKitThread extends Thread {
         mTileProvider.sendKeyEvent(keyEvent);
     }
 
+    private void onSwipeLeft() {
+        mTileProvider.onSwipeLeft();
+    }
+
+    private void onSwipeRight() {
+        mTileProvider.onSwipeRight();
+    }
+
     /**
      * Processes touch events.
      */
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 539d4f9..c37fdff 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -91,30 +91,6 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
 
         // Writer documents always have one part, so hide the navigation drawer.
         if (mDocument.getDocumentType() != Document.DOCTYPE_TEXT) {
-
-            // Set left/right swipe listener for presentation only.
-            if (mDocument.getDocumentType() == Document.DOCTYPE_PRESENTATION) {
-                LayerView layerView = mLayerClient.getView();
-                layerView.setOnTouchListener(new OnSlideSwipeListener(LibreOfficeMainActivity.mAppContext) {
-                    @Override
-                    public void onSwipeRight() {
-                        if (getCurrentPartNumber() < mDocument.getParts()-1) {
-                            LOKitShell.sendChangePartEvent(getCurrentPartNumber()+1);
-                        }
-                    }
-
-                @Override
-                public void onSwipeLeft() {
-                    if (getCurrentPartNumber() > 0) {
-                        LOKitShell.sendChangePartEvent(getCurrentPartNumber()-1);
-                    }
-                }
-                });
-            } else {
-                // Unregister touch listener when loading another document.
-                mLayerClient.getView().setOnTouchListener(null);
-            }
-
             for (int i = 0; i < parts; i++) {
                 String partName = mDocument.getPartName(i);
                 if (partName.isEmpty()) {
@@ -167,6 +143,24 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
         return (input / dpi) * 1440.0f;
     }
 
+    @Override
+    public void onSwipeLeft() {
+        Log.d(LOGTAG, "onSwipeLeft received");
+        if (mDocument.getDocumentType() == Document.DOCTYPE_PRESENTATION
+                && getCurrentPartNumber() < mDocument.getParts()-1) {
+            LOKitShell.sendChangePartEvent(getCurrentPartNumber()+1);
+        }
+    }
+
+    @Override
+    public void onSwipeRight() {
+        Log.d(LOGTAG, "onSwipeRight received");
+        if (mDocument.getDocumentType() == Document.DOCTYPE_PRESENTATION
+                && getCurrentPartNumber() > 0) {
+            LOKitShell.sendChangePartEvent(getCurrentPartNumber()-1);
+        }
+    }
+
     private boolean checkDocument() {
         String error = null;
         boolean ret;
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 13225c3..d19d483 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -145,6 +145,19 @@ public class LibreOfficeMainActivity extends LOAbout {
         LayerView layerView = (LayerView) findViewById(R.id.layer_view);
         mLayerClient.setView(layerView);
         layerView.setInputConnectionHandler(new LOKitInputConnectionHandler());
+        layerView.setOnTouchListener(new OnSlideSwipeListener(this) {
+            @Override
+            public void onSwipeRight() {
+                Log.d(LOGTAG, "onSwipeRight");
+                LOKitShell.sendSwipeRightEvent();
+            }
+
+            @Override
+            public void onSwipeLeft() {
+                Log.d(LOGTAG, "onSwipeLeft");
+                LOKitShell.sendSwipeLeftEvent();
+            }
+        });
         mLayerClient.notifyReady();
     }
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
index fe934a1..cb86ef0 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
@@ -112,4 +112,12 @@ public class MockTileProvider implements TileProvider {
     public int getCurrentPartNumber() {
         return 0;
     }
+
+    @Override
+    public void onSwipeLeft() {
+    }
+
+    @Override
+    public void onSwipeRight() {
+    }
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
index 82d18a0e..1dc33f6 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
@@ -22,7 +22,7 @@ public class OnSlideSwipeListener implements OnTouchListener {
 
         @Override
         public boolean onDown(MotionEvent e) {
-            return true;
+            return false;
         }
 
         @Override
@@ -39,13 +39,13 @@ public class OnSlideSwipeListener implements OnTouchListener {
                         } else {
                             onSwipeLeft();
                         }
-                            }
+                    }
                     result = true;
                 }
             } catch (Exception exception) {
                 exception.printStackTrace();
             }
-            return result;
+            return false;
         }
     }
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
index ea868bd..15a66dd 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
@@ -75,6 +75,17 @@ public interface TileProvider {
      */
     void mouseButtonDown(PointF documentCoordinate, int numberOfClicks);
 
+
+    /**
+     * Trigger a swipe left event.
+     */
+    void onSwipeLeft();
+
+    /**
+     * Trigger a swipe left event.
+     */
+    void onSwipeRight();
+
     /**
      * Trigger a mouse button up event.
      *
commit 63d283dddae20ae45f1eb7ea263f988c11e30bc0
Author: Siqi Liu <me at siqi.fr>
Date:   Sat Feb 28 19:04:25 2015 +0100

    add swipe support for presentation
    
    Change-Id: I650d661a1656388e50e5d4e3a003b8eb4f032382

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 679f8b4..539d4f9 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -10,12 +10,14 @@ import org.libreoffice.kit.DirectBufferAllocator;
 import org.libreoffice.kit.Document;
 import org.libreoffice.kit.LibreOfficeKit;
 import org.libreoffice.kit.Office;
+
 //import org.mozilla.gecko.TextSelection;
 //import org.mozilla.gecko.TextSelectionHandle;
 import org.mozilla.gecko.gfx.BufferedCairoImage;
 import org.mozilla.gecko.gfx.CairoImage;
 import org.mozilla.gecko.gfx.GeckoLayerClient;
 import org.mozilla.gecko.gfx.IntSize;
+import org.mozilla.gecko.gfx.LayerView;
 
 import java.nio.ByteBuffer;
 
@@ -89,6 +91,30 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
 
         // Writer documents always have one part, so hide the navigation drawer.
         if (mDocument.getDocumentType() != Document.DOCTYPE_TEXT) {
+
+            // Set left/right swipe listener for presentation only.
+            if (mDocument.getDocumentType() == Document.DOCTYPE_PRESENTATION) {
+                LayerView layerView = mLayerClient.getView();
+                layerView.setOnTouchListener(new OnSlideSwipeListener(LibreOfficeMainActivity.mAppContext) {
+                    @Override
+                    public void onSwipeRight() {
+                        if (getCurrentPartNumber() < mDocument.getParts()-1) {
+                            LOKitShell.sendChangePartEvent(getCurrentPartNumber()+1);
+                        }
+                    }
+
+                @Override
+                public void onSwipeLeft() {
+                    if (getCurrentPartNumber() > 0) {
+                        LOKitShell.sendChangePartEvent(getCurrentPartNumber()-1);
+                    }
+                }
+                });
+            } else {
+                // Unregister touch listener when loading another document.
+                mLayerClient.getView().setOnTouchListener(null);
+            }
+
             for (int i = 0; i < parts; i++) {
                 String partName = mDocument.getPartName(i);
                 if (partName.isEmpty()) {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
new file mode 100644
index 0000000..82d18a0e
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/OnSlideSwipeListener.java
@@ -0,0 +1,64 @@
+package org.libreoffice;
+
+import android.content.Context;
+import android.view.GestureDetector;
+import android.view.GestureDetector.SimpleOnGestureListener;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnTouchListener;
+
+public class OnSlideSwipeListener implements OnTouchListener {
+
+    private final GestureDetector mGestureDetector;
+
+    public OnSlideSwipeListener(Context ctx){
+        mGestureDetector = new GestureDetector(ctx, new GestureListener());
+    }
+
+    private final class GestureListener extends SimpleOnGestureListener {
+
+        private static final int SWIPE_THRESHOLD = 100;
+        private static final int SWIPE_VELOCITY_THRESHOLD = 100;
+
+        @Override
+        public boolean onDown(MotionEvent e) {
+            return true;
+        }
+
+        @Override
+        public boolean onFling(MotionEvent e1, MotionEvent e2, float velX, float velY) {
+            boolean result = false;
+            try {
+                float diffY = e2.getY() - e1.getY();
+                float diffX = e2.getX() - e1.getX();
+                if (Math.abs(diffX) > Math.abs(diffY)) {
+                    if (Math.abs(diffX) > SWIPE_THRESHOLD
+                            && Math.abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
+                        if (diffX > 0) {
+                            onSwipeRight();
+                        } else {
+                            onSwipeLeft();
+                        }
+                            }
+                    result = true;
+                }
+            } catch (Exception exception) {
+                exception.printStackTrace();
+            }
+            return result;
+        }
+    }
+
+    public void onSwipeRight() {
+    }
+
+    public void onSwipeLeft() {
+    }
+
+    @Override
+    public boolean onTouch(View v, MotionEvent me) {
+        return mGestureDetector.onTouchEvent(me);
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list