Kaydet (Commit) a8ee2fd0 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Start hacking on zooming

Change-Id: Ibc9aad490c4616d339e95352a0b8a7f7bed93070
üst 5b1d2fd1
......@@ -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);
......
......@@ -971,4 +971,20 @@ Java_org_libreoffice_experimental_desktop_Desktop_touch(JNIEnv * /* env */,
LOGW("No focused frame to emit event on");
}
// public static native void zoom(float scale, int x, int y);
extern "C" SAL_JNI_EXPORT void JNICALL
Java_org_libreoffice_experimental_desktop_Desktop_zoom(JNIEnv * /* env */,
jobject /* clazz */,
jfloat scale,
jint x,
jint y)
{
(void) x;
(void) y;
if (scale > 1.05) {
} else if (scale < 0.95) {
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment