summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-11-20 09:42:41 +0100
committerMiklos Vajna <vmiklos@suse.cz>2012-11-20 11:02:25 +0100
commit4c359c22e12a8cd6b6b40af60e1a39261737ad2a (patch)
tree3502d0c668501318c1fa7f33af5157ad11085499 /android
parent9b3d96fddd214b808f241197c42af0434c6bba82 (diff)
android: don't bootstrap after every rotation in DocumentLoader
It seems that previously onCreate served 3 different purposes: 1) bootstrap UNO machinery 2) load the document 3) create the view Ideally it should do the first two only if not done already -- as a first step, this commit extracts 1) and does only once. Change-Id: I087a6b934c05295263080f571c95ef152e4602cb
Diffstat (limited to 'android')
-rw-r--r--android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java100
1 files changed, 66 insertions, 34 deletions
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 806fcabd49ff..3837a04b0f03 100644
--- a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
+++ b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -126,10 +126,7 @@ public class DocumentLoader
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;
+ BootstrapContext bootstrapContext;
XToolkitExperimental toolkit;
XDevice dummySmallDevice;
Object doc;
@@ -619,7 +616,7 @@ public class DocumentLoader
long t0 = System.currentTimeMillis();
PropertyValue rendererProps[] = renderable.getRenderer(number, doc, renderProps);
long t1 = System.currentTimeMillis();
- Log.i(TAG, "getRenderer took " + ((t1-t0)-timingOverhead) + " ms");
+ Log.i(TAG, "getRenderer took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
int pageWidth = 0, pageHeight = 0;
for (int i = 0; i < rendererProps.length; i++) {
@@ -699,7 +696,7 @@ public class DocumentLoader
t0 = System.currentTimeMillis();
renderable.render(number, doc, renderProps);
t1 = System.currentTimeMillis();
- Log.i(TAG, "Rendering page " + number + " took " + ((t1-t0)-timingOverhead) + " ms");
+ Log.i(TAG, "Rendering page " + number + " took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
Bootstrap.force_full_alpha_bb(bb, 0, flipper.getWidth() * flipper.getHeight() * 4);
@@ -816,12 +813,12 @@ public class DocumentLoader
loadProps[2].Value = new Boolean(true);
long t0 = System.currentTimeMillis();
- doc = componentLoader.loadComponentFromURL(url, "_blank", 0, loadProps);
+ doc = bootstrapContext.componentLoader.loadComponentFromURL(url, "_blank", 0, loadProps);
long t1 = System.currentTimeMillis();
- Log.i(TAG, "Loading took " + ((t1-t0)-timingOverhead) + " ms");
+ Log.i(TAG, "Loading took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
- Object toolkitService = mcf.createInstanceWithContext
- ("com.sun.star.awt.Toolkit", context);
+ Object toolkitService = bootstrapContext.mcf.createInstanceWithContext
+ ("com.sun.star.awt.Toolkit", bootstrapContext.componentContext);
toolkit = (XToolkitExperimental) UnoRuntime.queryInterface(XToolkitExperimental.class, toolkitService);
renderable = (XRenderable) UnoRuntime.queryInterface(XRenderable.class, doc);
@@ -846,7 +843,7 @@ public class DocumentLoader
t0 = System.currentTimeMillis();
pageCount = renderable.getRendererCount(doc, renderProps);
t1 = System.currentTimeMillis();
- Log.i(TAG, "getRendererCount: " + pageCount + ", took " + ((t1-t0)-timingOverhead) + " ms");
+ Log.i(TAG, "getRendererCount: " + pageCount + ", took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
}
catch (Exception e) {
e.printStackTrace(System.err);
@@ -856,6 +853,18 @@ public class DocumentLoader
}
}
+ /**
+ * This class contains the state that is initialized once and never changes
+ * (not specific to a document or a view).
+ */
+ class BootstrapContext
+ {
+ public long timingOverhead;
+ public XComponentContext componentContext;
+ public XMultiComponentFactory mcf;
+ public XComponentLoader componentLoader;
+ }
+
static void dumpUNOObject(String objectName, Object object)
{
Log.i(TAG, objectName + " is " + (object != null ? object.toString() : "null"));
@@ -924,19 +933,19 @@ public class DocumentLoader
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
-
- extras = getIntent().getExtras();
+ public Object onRetainNonConfigurationInstance() {
+ return bootstrapContext;
+ }
- gestureListener = new GestureListener();
- gestureDetector = new GestureDetector(this, gestureListener);
+ private void initBootstrapContext()
+ {
+ try
+ {
+ bootstrapContext = new BootstrapContext();
- try {
long t0 = System.currentTimeMillis();
long t1 = System.currentTimeMillis();
- timingOverhead = t1 - t0;
+ bootstrapContext.timingOverhead = t1 - t0;
Bootstrap.setup(this);
@@ -946,14 +955,45 @@ public class DocumentLoader
// Log.i(TAG, "Sleeping NOW");
// Thread.sleep(20000);
- context = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext();
+ bootstrapContext.componentContext = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext();
+
+ Log.i(TAG, "context is" + (bootstrapContext.componentContext!=null ? " not" : "") + " null");
- Log.i(TAG, "context is" + (context!=null ? " not" : "") + " null");
+ bootstrapContext.mcf = bootstrapContext.componentContext.getServiceManager();
- mcf = context.getServiceManager();
+ Log.i(TAG, "mcf is" + (bootstrapContext.mcf!=null ? " not" : "") + " null");
- Log.i(TAG, "mcf is" + (mcf!=null ? " not" : "") + " null");
+ Bootstrap.initVCL();
+
+ Object desktop = bootstrapContext.mcf.createInstanceWithContext
+ ("com.sun.star.frame.Desktop", bootstrapContext.componentContext);
+ Log.i(TAG, "desktop is" + (desktop!=null ? " not" : "") + " null");
+
+ bootstrapContext.componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
+
+ Log.i(TAG, "componentLoader is" + (bootstrapContext.componentLoader!=null ? " not" : "") + " null");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.err);
+ finish();
+ }
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ bootstrapContext = (BootstrapContext)getLastNonConfigurationInstance();
+
+ extras = getIntent().getExtras();
+
+ gestureListener = new GestureListener();
+ gestureDetector = new GestureDetector(this, gestureListener);
+
+ try {
String input = getIntent().getStringExtra("input");
if (input == null)
input = "/assets/test1.odt";
@@ -967,16 +1007,8 @@ public class DocumentLoader
Bootstrap.setCommandArgs(argv);
- Bootstrap.initVCL();
-
- Object desktop = mcf.createInstanceWithContext
- ("com.sun.star.frame.Desktop", context);
-
- Log.i(TAG, "desktop is" + (desktop!=null ? " not" : "") + " null");
-
- componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
-
- Log.i(TAG, "componentLoader is" + (componentLoader!=null ? " not" : "") + " null");
+ if (bootstrapContext == null)
+ initBootstrapContext();
// Load the wanted document
new DocumentLoadTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, "file://" + input);