diff options
author | Tor Lillqvist <tml@iki.fi> | 2013-03-05 21:24:59 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2013-03-05 21:36:31 +0200 |
commit | 0b10d7cf5059d6a8868864fd7625c4e58eda612c (patch) | |
tree | dacb3d35a38734f17fdbbcb27f6dd4dd90134cf0 /android | |
parent | 03c51284b9a23dabc9139504691d061ce38be279 (diff) |
Rework scaling once more
Don't ask the LO code to zoom while scaling in progress. That is way too
slow. Return to the idea of just scaling the already rendered bitmap
containing the "top-level window" from LO's perspective, UI elements and
all. (Obviously if we continue to work on thie demo app, the desktop style UI
elements need to disappear from the sides of the LO "window", so that the only
thing LO renders is the actual viewport of the document contents.)
This time, instead of scaling the View, which for some reason causes horrible
flickering glitches at least on my device, draw the bitmap scaled in
onDraw. Much smoother for some reason.
Of course when we then in onScaleEnd() ask LO to do the actual zoom, what
eventually results (remember that the LO code runs asynchronously in a
separate thread, and the zoom request only gets posted to that thread) is not
at all the same as what just drawing the bitmap at scale produced. (Especially
not as there is no way yet to have LO zoom centred on a specific pivot point.)
Change-Id: Id80576c99a03f5f8bf0d8039c6c7406322581956
Diffstat (limited to 'android')
-rw-r--r-- | android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java | 40 |
1 files changed, 17 insertions, 23 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 b30f74def2e4..065220a73304 100644 --- a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java +++ b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java @@ -131,10 +131,14 @@ public class Desktop { Bitmap mBitmap; boolean renderedOnce; - boolean scalingInProgress; + GestureDetector gestureDetector; ScaleGestureDetector scaleDetector; + boolean scalingInProgress; + float accumulatedScale = 1; + float pivotX = 0, pivotY = 0; + public BitmapView() { super(Desktop.this); @@ -156,46 +160,33 @@ public class Desktop } }); - // Is this sane? It is rather slow to ask LO to zoom - // continuously while the scaling gesture is in progress. - - // What we used to do was while a scale gesture was in - // progress to just scale the bitmap view (UI elements - // too, which of course was a bit silly). - scaleDetector = new ScaleGestureDetector(Desktop.this, new ScaleGestureDetector.SimpleOnScaleGestureListener() { - long lastGestureEventTime; @Override public boolean onScaleBegin(ScaleGestureDetector detector) { scalingInProgress = true; - lastGestureEventTime = System.currentTimeMillis(); return true; } @Override public boolean onScale(ScaleGestureDetector detector) { - long now = System.currentTimeMillis(); - if (now - lastGestureEventTime < 100) - return false; - float scale = detector.getScaleFactor(); - if (scale > 0.95 && scale < 1.05) - return false; - Log.i(TAG, "onScale: " + scale); - lastGestureEventTime = now; - Desktop.zoom(scale, (int) detector.getFocusX(), (int) detector.getFocusY()); + accumulatedScale *= detector.getScaleFactor();; + pivotX = detector.getFocusX(); + pivotY = detector.getFocusY(); + invalidate(); return true; } @Override public void onScaleEnd(ScaleGestureDetector detector) { - float scale = detector.getScaleFactor(); - Log.i(TAG, "onScaleEnd: " + scale); - if (!(scale > 0.95 && scale < 1.05)) - Desktop.zoom(scale, (int) detector.getFocusX(), (int) detector.getFocusY()); + accumulatedScale *= detector.getScaleFactor(); + Desktop.zoom(accumulatedScale, (int) pivotX, (int) pivotY); + accumulatedScale = 1; + pivotX = pivotY = 0; scalingInProgress = false; + invalidate(); } }); } @@ -208,7 +199,10 @@ public class Desktop setViewSize(getWidth(), getHeight()); } renderVCL(mBitmap); + canvas.save(); + canvas.scale(accumulatedScale, accumulatedScale, pivotX, pivotY); canvas.drawBitmap(mBitmap, 0, 0, null); + canvas.restore(); renderedOnce = true; // re-call ourselves a bit later ... |