[Libreoffice-commits] .: 3 commits - android/experimental odk/examples
Tor Lillqvist
tml at kemper.freedesktop.org
Wed Jun 20 05:22:51 PDT 2012
android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java | 81 ++++++----
odk/examples/java/DocumentHandling/test/test1.odt |binary
2 files changed, 50 insertions(+), 31 deletions(-)
New commits:
commit 785221e74ceeea4bb227356139b8aad96ace605a
Author: Tor Lillqvist <tlillqvist at suse.com>
Date: Wed Jun 20 15:11:17 2012 +0300
Use actual view size instead of 1024x1024
Change-Id: I66ae59fe88411f3f0d2423fd6f1412f7ac0e1a36
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 a059bfc..cf042a4 100644
--- a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
+++ b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -253,20 +253,35 @@ public class DocumentLoader
}
// Create a new device with the correct scale and offset
- ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024*4);
+ ByteBuffer bb = ByteBuffer.allocateDirect(flipper.getWidth()*flipper.getHeight()*4);
long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
XDevice device;
if (pageWidth == 0) {
// Huh?
- device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, 1, 1, 0, 0, wrapped_bb);
+ device = toolkit.createScreenCompatibleDeviceUsingBuffer(flipper.getWidth(), flipper.getHeight(), 1, 1, 0, 0, wrapped_bb);
} else {
+
// Scale so that it fits our device which has a resolution of 96/in (see
// SvpSalGraphics::GetResolution()). The page size returned from getRenderer() is in 1/mm * 100.
- int scaleDenumerator = Math.max(pageWidth, pageHeight) / 2540 * 96;
- Log.i(TAG, "Scaling with 1024/" + scaleDenumerator);
- device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, 1024, scaleDenumerator, 0, 0, wrapped_bb);
+ int scaleNumerator, scaleDenominator;
+
+ // If the view has a wider aspect ratio than the page, fit
+ // height; otherwise, fit width
+ if ((double) flipper.getWidth() / flipper.getHeight() > (double) pageWidth / pageHeight) {
+ scaleNumerator = flipper.getHeight();
+ scaleDenominator = pageHeight / 2540 * 96;
+ } else {
+ scaleNumerator = flipper.getWidth();
+ scaleDenominator = pageWidth / 2540 * 96;
+ }
+ Log.i(TAG, "Scaling with " + scaleNumerator + "/" + scaleDenominator);
+
+ device = toolkit.createScreenCompatibleDeviceUsingBuffer(flipper.getWidth(), flipper.getHeight(),
+ scaleNumerator, scaleDenominator,
+ 0, 0,
+ wrapped_bb);
}
// Update the property that points to the device
@@ -277,7 +292,7 @@ public class DocumentLoader
t1 = System.currentTimeMillis();
Log.i(TAG, "Rendering page " + number + " took " + ((t1-t0)-timingOverhead) + " ms");
- Bootstrap.force_full_alpha_bb(bb, 0, 1024 * 1024 * 4);
+ Bootstrap.force_full_alpha_bb(bb, 0, flipper.getWidth() * flipper.getHeight() * 4);
return bb;
}
@@ -312,7 +327,7 @@ public class DocumentLoader
state = PageState.LOADING;
currentPageNumber = number;
ByteBuffer bb = renderPage(currentPageNumber);
- bm = Bitmap.createBitmap(1024, 1024, Bitmap.Config.ARGB_8888);
+ bm = Bitmap.createBitmap(flipper.getWidth(), flipper.getHeight(), Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(bb);
return currentPageNumber;
commit 20e027fdaa8902f8893bc8fd4bb0312f0ff95a03
Author: Tor Lillqvist <tlillqvist at suse.com>
Date: Wed Jun 20 14:02:54 2012 +0300
More pages
Change-Id: Ib89b2d30be207ea1664e688c3da608c2973f28a6
diff --git a/odk/examples/java/DocumentHandling/test/test1.odt b/odk/examples/java/DocumentHandling/test/test1.odt
index 2f13b4b..1025907 100644
Binary files a/odk/examples/java/DocumentHandling/test/test1.odt and b/odk/examples/java/DocumentHandling/test/test1.odt differ
commit 08a1763147ea1284144d25dc6f5a6e1efa90718f
Author: Tor Lillqvist <tlillqvist at suse.com>
Date: Wed Jun 20 14:01:55 2012 +0300
Parametrize the page cache size
Change-Id: Ia3d5538feaf1fc0aad4a0f1d901ae7bd22eae61d
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 7605ec9..a059bfc 100644
--- a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
+++ b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -75,13 +75,24 @@ import org.libreoffice.android.Bootstrap;
public class DocumentLoader
extends Activity
{
- private static String TAG = "DocumentLoader";
+ private static final String TAG = "DocumentLoader";
+
+ // Size of a small virtual (bitmap) device used to find out page count and
+ // page sizes
+ private static final int SMALLSIZE = 128;
+
+ // We pre-render this many pages preceding and succeeding the currently
+ // viewed one, i.e. the total number of rendered pages kept is
+ // PAGECACHE_PLUSMINUS*2+1.
+ private static final int PAGECACHE_PLUSMINUS = 2;
+ private static final int PAGECACHE_SIZE = PAGECACHE_PLUSMINUS*2 + 1;
long timingOverhead;
XComponentContext context;
XMultiComponentFactory mcf;
XComponentLoader componentLoader;
XToolkit2 toolkit;
+ XDevice dummySmallDevice;
Object doc;
int pageCount;
XRenderable renderable;
@@ -118,7 +129,7 @@ public class DocumentLoader
flipper.showNext();
- ((PageViewer)flipper.getChildAt((flipper.getDisplayedChild() + 1) % 3)).display(((PageViewer)flipper.getCurrentView()).currentPageNumber + 1);
+ ((PageViewer)flipper.getChildAt((flipper.getDisplayedChild() + PAGECACHE_PLUSMINUS) % PAGECACHE_SIZE)).display(((PageViewer)flipper.getCurrentView()).currentPageNumber + PAGECACHE_PLUSMINUS);
return true;
} else if (event2.getX() - event1.getX() > 120) {
if (((PageViewer)flipper.getCurrentView()).currentPageNumber == 0)
@@ -136,7 +147,7 @@ public class DocumentLoader
flipper.showPrevious();
- ((PageViewer)flipper.getChildAt((flipper.getDisplayedChild() + 2) % 3)).display(((PageViewer)flipper.getCurrentView()).currentPageNumber - 1);
+ ((PageViewer)flipper.getChildAt((flipper.getDisplayedChild() + PAGECACHE_SIZE - PAGECACHE_PLUSMINUS) % PAGECACHE_SIZE)).display(((PageViewer)flipper.getCurrentView()).currentPageNumber - PAGECACHE_PLUSMINUS);
return true;
}
@@ -212,11 +223,8 @@ public class DocumentLoader
ByteBuffer renderPage(int number)
{
try {
- // A small device with no scale of offset just to find out the paper size of this page
-
- ByteBuffer smallbb = ByteBuffer.allocateDirect(128*128*4);
- long wrapped_smallbb = Bootstrap.new_byte_buffer_wrapper(smallbb);
- XDevice device = toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, 1, 1, 0, 0, wrapped_smallbb);
+ // Use dummySmallDevice with no scale of offset just to find out
+ // the paper size of this page.
PropertyValue renderProps[] = new PropertyValue[3];
renderProps[0] = new PropertyValue();
@@ -224,7 +232,7 @@ public class DocumentLoader
renderProps[0].Value = new Boolean(true);
renderProps[1] = new PropertyValue();
renderProps[1].Name = "RenderDevice";
- renderProps[1].Value = device;
+ renderProps[1].Value = dummySmallDevice;
renderProps[2] = new PropertyValue();
renderProps[2].Name = "View";
renderProps[2].Value = new MyXController();
@@ -248,6 +256,7 @@ public class DocumentLoader
ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024*4);
long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
+ XDevice device;
if (pageWidth == 0) {
// Huh?
device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 1024, 1, 1, 0, 0, wrapped_bb);
@@ -297,7 +306,7 @@ public class DocumentLoader
{
int number = params[0];
- if (number == pageCount)
+ if (number >= pageCount)
return -1;
state = PageState.LOADING;
@@ -385,21 +394,17 @@ public class DocumentLoader
long t1 = System.currentTimeMillis();
Log.i(TAG, "Loading took " + ((t1-t0)-timingOverhead) + " ms");
- dumpUNOObject("doc", doc);
-
Object toolkitService = mcf.createInstanceWithContext
("com.sun.star.awt.Toolkit", context);
-
- dumpUNOObject("toolkitService", toolkitService);
-
toolkit = (XToolkit2) UnoRuntime.queryInterface(XToolkit2.class, toolkitService);
- dumpUNOObject("toolkit", toolkit);
renderable = (XRenderable) UnoRuntime.queryInterface(XRenderable.class, doc);
- ByteBuffer smallbb = ByteBuffer.allocateDirect(128*128*4);
+ // Set up dummySmallDevice and use it to find out the number
+ // of pages ("renderers").
+ ByteBuffer smallbb = ByteBuffer.allocateDirect(SMALLSIZE*SMALLSIZE*4);
long wrapped_smallbb = Bootstrap.new_byte_buffer_wrapper(smallbb);
- XDevice smalldevice = toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, 1, 1, 0, 0, wrapped_smallbb);
+ dummySmallDevice = toolkit.createScreenCompatibleDeviceUsingBuffer(SMALLSIZE, SMALLSIZE, 1, 1, 0, 0, wrapped_smallbb);
PropertyValue renderProps[] = new PropertyValue[3];
renderProps[0] = new PropertyValue();
@@ -407,7 +412,7 @@ public class DocumentLoader
renderProps[0].Value = new Boolean(true);
renderProps[1] = new PropertyValue();
renderProps[1].Name = "RenderDevice";
- renderProps[1].Value = smalldevice;
+ renderProps[1].Value = dummySmallDevice;
renderProps[2] = new PropertyValue();
renderProps[2].Name = "View";
renderProps[2].Value = new MyXController();
@@ -434,9 +439,6 @@ public class DocumentLoader
XTypeProvider typeProvider = (XTypeProvider)
UnoRuntime.queryInterface(XTypeProvider.class, object);
-
- Log.i(TAG, "typeProvider is " + (typeProvider != null ? typeProvider.toString() : "null"));
-
if (typeProvider == null)
return;
@@ -556,8 +558,10 @@ public class DocumentLoader
matchParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
flipper.addView(new PageViewer(0), 0, matchParent);
- flipper.addView(new PageViewer(1), 1, matchParent);
- flipper.addView(new PageViewer(-1), 2, matchParent);
+ for (int i = 0; i < PAGECACHE_PLUSMINUS; i++)
+ flipper.addView(new PageViewer(i+1), i+1, matchParent);
+ for (int i = 0; i < PAGECACHE_PLUSMINUS; i++)
+ flipper.addView(new PageViewer(-1), PAGECACHE_PLUSMINUS + i+1, matchParent);
setContentView(flipper);
}
More information about the Libreoffice-commits
mailing list