summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-03-01 15:19:16 +0200
committerTor Lillqvist <tml@iki.fi>2013-03-02 21:00:01 +0200
commita8ee2fd020477ceee9ca91976e2ea90de45141af (patch)
treeeedfd72ecc408dcc1ac72b6f30715ffd81a16821 /android
parent5b1d2fd1e6c39d44ad65c3aec1b496c7a446b1ea (diff)
Start hacking on zooming
Change-Id: Ibc9aad490c4616d339e95352a0b8a7f7bed93070
Diffstat (limited to 'android')
-rw-r--r--android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java42
1 files changed, 40 insertions, 2 deletions
diff --git a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
index d4ded73ede61..7664bf88e715 100644
--- a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
+++ b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
@@ -50,6 +50,7 @@ public class Desktop
public static native void setViewSize(int width, int height);
public static native void key(char c, short timestamp);
public static native void touch(int action, int x, int y, short timestamp);
+ public static native void zoom(float scale, int x, int y);
/**
* This class contains the state that is initialized once and never changes
@@ -162,19 +163,55 @@ public class Desktop
Bitmap mBitmap;
boolean renderedOnce;
ScaleGestureDetector gestureDetector;
+ float scale = 1;
public BitmapView()
{
super(Desktop.this);
setFocusableInTouchMode(true);
+
+ // While a scale gesture (two-finger pinch / spread to
+ // zoom out / in) is in progress we just scale the bitmap
+ // view (UI elements too, which of course is a bit silly).
+ // When the scale gesture has finished, we ask LO to zoom
+ // the document (and reset the view scale, it will be
+ // replaced by one where the document (not UI elements) is
+ // displayed at a different zoom level).
+
+ // Is that sane? Would it be too slow to ask LO to zoom
+ // continuously while the gesture is in progress?
+
gestureDetector =
new ScaleGestureDetector(Desktop.this,
new ScaleGestureDetector.SimpleOnScaleGestureListener() {
+ @Override public boolean onScaleBegin(ScaleGestureDetector detector)
+ {
+ Log.i(TAG, "onScaleBegin: pivot=(" + detector.getFocusX() + ", " + detector.getFocusY() + ")");
+ setPivotX(detector.getFocusX());
+ setPivotY(detector.getFocusY());
+ return true;
+ }
+
@Override public boolean onScale(ScaleGestureDetector detector)
{
- Log.i(TAG, "onScale: " + detector.getScaleFactor());
+ float s = detector.getScaleFactor();
+ if (s > 0.95 && s < 1.05)
+ return false;
+ scale *= s;
+ Log.i(TAG, "onScale: " + s + " => " + scale);
+ setScaleX(scale);
+ setScaleY(scale);
return true;
}
+
+ @Override public void onScaleEnd(ScaleGestureDetector detector)
+ {
+ Log.i(TAG, "onScaleEnd: " + scale);
+ Desktop.zoom(scale, (int) detector.getFocusX(), (int) detector.getFocusY());
+ scale = 1;
+ setScaleX(scale);
+ setScaleY(scale);
+ }
});
}
@@ -226,7 +263,8 @@ public class Desktop
@Override public boolean onTouchEvent(MotionEvent event)
{
- gestureDetector.onTouchEvent(event);
+ if (gestureDetector.onTouchEvent(event))
+ return true;
if (!renderedOnce)
return super.onTouchEvent(event);