[Libreoffice-commits] .: 3 commits - android/experimental odk/examples vcl/source
Tor Lillqvist
tml at kemper.freedesktop.org
Thu Jun 14 12:13:54 PDT 2012
android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java | 222 ++++++++--
odk/examples/java/DocumentHandling/test/test1.odt |binary
vcl/source/gdi/virdev.cxx | 8
3 files changed, 186 insertions(+), 44 deletions(-)
New commits:
commit 61c6c7f8f72bd9a4a9e92a16ebe31b1621343c43
Author: Tor Lillqvist <tlillqvist at suse.com>
Date: Thu Jun 14 21:59:52 2012 +0300
Experiment with ViewFlipper
Change-Id: I0b1523b5c898375b5cf23294b0a9462a6a651e32
diff --git a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
index 8e9e499..a458d02 100644
--- a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
+++ b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -32,7 +32,15 @@ import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.ViewGroup;
+import android.view.animation.AlphaAnimation;
+import android.view.animation.Animation;
+import android.view.animation.AnimationSet;
+import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
+import android.widget.ViewFlipper;
import com.polites.android.GestureImageView;
@@ -59,12 +67,75 @@ import java.nio.ByteOrder;
import org.libreoffice.android.Bootstrap;
public class DocumentLoader
- extends Activity {
-
+ extends Activity
+{
private static String TAG = "DocumentLoader";
+ long timingOverhead;
+ Object desktop;
+ XComponentLoader componentLoader;
+ XToolkit2 toolkit;
+ Object doc;
+ int pageCount;
+ XRenderable renderable;
+
+ PropertyValue[] loadProps;
+
+ GestureDetector gestureDetector;
+ ViewFlipper flipper;
+
+ class GestureListener
+ extends GestureDetector.SimpleOnGestureListener
+ {
+ @Override
+ public boolean onFling(MotionEvent event1,
+ MotionEvent event2,
+ float velocityX,
+ float velocityY)
+ {
+ Log.i(TAG, "onFling: " + event1 + " " + event2);
+ if (event1.getX() - event2.getX() > 120) {
+ AnimationSet leftIn = new AnimationSet(true);
+ leftIn.addAnimation(new AlphaAnimation(0.1f, 1.0f));
+ leftIn.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0));
+ leftIn.setDuration(500);
+ flipper.setInAnimation(leftIn);
+
+ AnimationSet leftOut = new AnimationSet(true);
+ leftOut.addAnimation(new AlphaAnimation(1f, 0.1f));
+ leftOut.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0));
+ leftOut.setDuration(500);
+ flipper.setOutAnimation(leftOut);
+
+ flipper.showNext();
+ return true;
+ } else if (event2.getX() - event1.getX() > 120) {
+ AnimationSet rightIn = new AnimationSet(true);
+ rightIn.addAnimation(new AlphaAnimation(0.1f, 1.0f));
+ rightIn.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0));
+ rightIn.setDuration(500);
+ flipper.setInAnimation(rightIn);
+
+ AnimationSet rightOut = new AnimationSet(true);
+ rightOut.addAnimation(new AlphaAnimation(1f, 0.1f));
+ rightOut.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0));
+ rightOut.setDuration(500);
+ flipper.setOutAnimation(rightOut);
+
+ flipper.showPrevious();
+ return true;
+ }
+ return false;
+ }
+ }
+
class MyXController
- implements XController {
+ implements XController
+ {
XFrame frame;
XModel model;
@@ -127,6 +198,62 @@ public class DocumentLoader
}
}
+ enum PageState { LOADING, READY };
+
+ ByteBuffer renderPage(int number)
+ {
+ ByteBuffer bb;
+
+ bb = ByteBuffer.allocateDirect(1024*1024*4);
+ long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
+ Log.i(TAG, "bb is " + bb);
+ XDevice device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, wrapped_bb);
+
+ dumpUNOObject("device", device);
+
+ PropertyValue renderProps[] = new PropertyValue[3];
+ renderProps[0] = new PropertyValue();
+ renderProps[0].Name = "IsPrinter";
+ renderProps[0].Value = new Boolean(true);
+ renderProps[1] = new PropertyValue();
+ renderProps[1].Name = "RenderDevice";
+ renderProps[1].Value = device;
+ renderProps[2] = new PropertyValue();
+ renderProps[2].Name = "View";
+ renderProps[2].Value = new MyXController();
+
+ try {
+ long t0 = System.currentTimeMillis();
+ renderable.render(number, doc, renderProps);
+ long t1 = System.currentTimeMillis();
+ Log.i(TAG, "Rendering page " + number + " took " + ((t1-t0)-timingOverhead) + " ms");
+ }
+ catch (Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ Bootstrap.force_full_alpha_bb(bb, 0, 1024 * 1024 * 4);
+
+ return bb;
+ }
+
+ class Page
+ {
+ int number;
+ PageState state = PageState.LOADING;
+ ByteBuffer bb;
+
+ Page(int number)
+ {
+ this.number = number;
+
+ bb = renderPage(number);
+
+ state = PageState.READY;
+ }
+ }
+
static void dumpUNOObject(String objectName, Object object)
{
Log.i(TAG, objectName + " is " + (object != null ? object.toString() : "null"));
@@ -195,7 +322,12 @@ public class DocumentLoader
{
super.onCreate(savedInstanceState);
+ gestureDetector = new GestureDetector(this, new GestureListener());
+
try {
+ long t0 = System.currentTimeMillis();
+ long t1 = System.currentTimeMillis();
+ timingOverhead = t1 - t0;
Bootstrap.setup(this);
@@ -211,15 +343,15 @@ public class DocumentLoader
Log.i(TAG, "Sleeping NOW");
Thread.sleep(20000);
- XComponentContext xContext = null;
+ XComponentContext context = null;
- xContext = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext();
+ context = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext();
- Log.i(TAG, "xContext is" + (xContext!=null ? " not" : "") + " null");
+ Log.i(TAG, "context is" + (context!=null ? " not" : "") + " null");
- XMultiComponentFactory xMCF = xContext.getServiceManager();
+ XMultiComponentFactory mcf = context.getServiceManager();
- Log.i(TAG, "xMCF is" + (xMCF!=null ? " not" : "") + " null");
+ Log.i(TAG, "mcf is" + (mcf!=null ? " not" : "") + " null");
String input = getIntent().getStringExtra("input");
if (input == null)
@@ -236,15 +368,14 @@ public class DocumentLoader
Bootstrap.initVCL();
- Object oDesktop = xMCF.createInstanceWithContext
- ("com.sun.star.frame.Desktop", xContext);
+ Object oDesktop = mcf.createInstanceWithContext
+ ("com.sun.star.frame.Desktop", context);
Log.i(TAG, "oDesktop is" + (oDesktop!=null ? " not" : "") + " null");
Bootstrap.initUCBHelper();
- XComponentLoader xCompLoader = (XComponentLoader)
- UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
+ XComponentLoader xCompLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
Log.i(TAG, "xCompLoader is" + (xCompLoader!=null ? " not" : "") + " null");
@@ -265,66 +396,69 @@ public class DocumentLoader
Log.i(TAG, "Attempting to load " + sUrl);
- Object oDoc =
- xCompLoader.loadComponentFromURL
- (sUrl, "_blank", 0, loadProps);
+ t0 = System.currentTimeMillis();
+ doc = xCompLoader.loadComponentFromURL(sUrl, "_blank", 0, loadProps);
+ t1 = System.currentTimeMillis();
+ Log.i(TAG, "Loading took " + ((t1-t0)-timingOverhead) + " ms");
- dumpUNOObject("oDoc", oDoc);
+ dumpUNOObject("doc", doc);
- Object toolkit = xMCF.createInstanceWithContext
- ("com.sun.star.awt.Toolkit", xContext);
-
- dumpUNOObject("toolkit", toolkit);
+ Object toolkitService = mcf.createInstanceWithContext
+ ("com.sun.star.awt.Toolkit", context);
- XToolkit2 xToolkit = (XToolkit2)
- UnoRuntime.queryInterface(XToolkit2.class, toolkit);
+ dumpUNOObject("toolkitService", toolkitService);
- ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024*4);
- long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
- XDevice device = xToolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, wrapped_bb);
+ toolkit = (XToolkit2) UnoRuntime.queryInterface(XToolkit2.class, toolkitService);
+ dumpUNOObject("toolkit", toolkit);
- dumpUNOObject("device", device);
+ renderable = (XRenderable) UnoRuntime.queryInterface(XRenderable.class, doc);
- XRenderable renderBabe = (XRenderable)
- UnoRuntime.queryInterface(XRenderable.class, oDoc);
+ ByteBuffer smallbb = ByteBuffer.allocateDirect(128*128*4);
+ long wrapped_smallbb = Bootstrap.new_byte_buffer_wrapper(smallbb);
+ XDevice smalldevice = toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, wrapped_smallbb);
- PropertyValue renderProps[] =
- new PropertyValue[3];
+ PropertyValue renderProps[] = new PropertyValue[3];
renderProps[0] = new PropertyValue();
renderProps[0].Name = "IsPrinter";
renderProps[0].Value = new Boolean(true);
renderProps[1] = new PropertyValue();
renderProps[1].Name = "RenderDevice";
- renderProps[1].Value = device;
+ renderProps[1].Value = smalldevice;
renderProps[2] = new PropertyValue();
renderProps[2].Name = "View";
renderProps[2].Value = new MyXController();
- Log.i(TAG, "getRendererCount: " + renderBabe.getRendererCount(oDoc, renderProps));
+ pageCount = renderable.getRendererCount(doc, renderProps);
+ Log.i(TAG, "getRendererCount: " + pageCount);
- renderBabe.render(0, oDoc, renderProps);
+ flipper = new ViewFlipper(this);
- Log.i(TAG, "Rendered:");
- dumpBytes("bb", bb, 0);
- Bootstrap.force_full_alpha_bb(bb, 0, 1024 * 1024 * 4);
- Log.i(TAG, "after force_full_alpha:");
- dumpBytes("bb", bb, 0);
+ flipper.setScaleY(-1);
- ImageView imageView = new GestureImageView(this);
- imageView.setScaleY(-1);
+ for (int i = 0; i < pageCount; i++) {
+ ByteBuffer bb = renderPage(i);
+ Bitmap bm = Bitmap.createBitmap(1024, 1024, Bitmap.Config.ARGB_8888);
+ bm.copyPixelsFromBuffer(bb);
- Bitmap bm = Bitmap.createBitmap(1024, 1024, Bitmap.Config.ARGB_8888);
- bm.copyPixelsFromBuffer(bb);
+ ImageView imageView = new ImageView(this);
+ imageView.setImageBitmap(bm);
- imageView.setImageBitmap(bm);
+ flipper.addView(imageView, i, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ }
- setContentView(imageView);
+ setContentView(flipper);
}
catch (Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
}
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event)
+ {
+ return gestureDetector.onTouchEvent(event);
+ }
}
// vim:set shiftwidth=4 softtabstop=4 expandtab:
commit c64156a11ffb568b652e44205a0476e5a9a34210
Author: Tor Lillqvist <tlillqvist at suse.com>
Date: Thu Jun 14 21:54:19 2012 +0300
Add note where scaling and offsetting could/should be added
Change-Id: I7adafa165a4724b0e193288d69c4c3f3815f11b2
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index 6c62819..93aec4f 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -370,6 +370,14 @@ sal_Bool VirtualDevice::SetOutputSizePixel( const Size& rNewSize, sal_Bool bEras
sal_Bool VirtualDevice::SetOutputSizePixelAndBuffer( const Size& rNewSize, const basebmp::RawMemorySharedArray &pBuffer )
{
+ // Is this the place to put in scaling and offsetting, passed in as parameters from createScreenCompatibleDeviceUsingBuffer?
+ // Bogus test just to see that something happens:
+ // if (pBuffer) {
+ // MapMode mm = GetMapMode();
+ // mm.SetScaleX(Fraction(4, 1));
+ // mm.SetScaleY(Fraction(4, 1));
+ // SetMapMode(mm);
+ //}
return ImplSetOutputSizePixel( rNewSize, sal_True, pBuffer);
}
commit 55e8343aef369d0fb8ec7460ddeb35425e9cc9bd
Author: Tor Lillqvist <tlillqvist at suse.com>
Date: Thu Jun 14 21:53:25 2012 +0300
Grow to multiple pages, one in landscape
Change-Id: I3987c79caffaae4cd354a58c25711b0e08f63560
diff --git a/odk/examples/java/DocumentHandling/test/test1.odt b/odk/examples/java/DocumentHandling/test/test1.odt
index e2978da..2f13b4b 100644
Binary files a/odk/examples/java/DocumentHandling/test/test1.odt and b/odk/examples/java/DocumentHandling/test/test1.odt differ
More information about the Libreoffice-commits
mailing list