Kaydet (Commit) 4460f406 authored tarafından Miklos Vajna's avatar Miklos Vajna

android: don't load the document after every rotation

Change-Id: I0af154bc5bc6cc79ab45a85a5a06e4539442ec81
üst fd910198
...@@ -108,6 +108,7 @@ import com.sun.star.view.XRenderable; ...@@ -108,6 +108,7 @@ import com.sun.star.view.XRenderable;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.ArrayList;
import org.libreoffice.android.Bootstrap; import org.libreoffice.android.Bootstrap;
...@@ -127,9 +128,7 @@ public class DocumentLoader ...@@ -127,9 +128,7 @@ public class DocumentLoader
private static final int PAGECACHE_SIZE = PAGECACHE_PLUSMINUS*2 + 1; private static final int PAGECACHE_SIZE = PAGECACHE_PLUSMINUS*2 + 1;
BootstrapContext bootstrapContext; BootstrapContext bootstrapContext;
Object doc; DocumentContext documentContext;
int pageCount;
XRenderable renderable;
GestureDetector.OnGestureListener gestureListener; GestureDetector.OnGestureListener gestureListener;
GestureDetector gestureDetector; GestureDetector gestureDetector;
...@@ -151,7 +150,7 @@ public class DocumentLoader ...@@ -151,7 +150,7 @@ public class DocumentLoader
{ {
Log.i(TAG, "onFling: " + event1 + " " + event2); Log.i(TAG, "onFling: " + event1 + " " + event2);
if (event1.getX() - event2.getX() > 120) { if (event1.getX() - event2.getX() > 120) {
if (((PageViewer)flipper.getCurrentView()).currentPageNumber == pageCount-1) if (((PageViewer)flipper.getCurrentView()).currentPageNumber == documentContext.pageCount-1)
return false; return false;
Animation inFromRight = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0, Animation inFromRight = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0,
...@@ -612,7 +611,7 @@ public class DocumentLoader ...@@ -612,7 +611,7 @@ public class DocumentLoader
// getRenderer returns a set of properties that include the PageSize // getRenderer returns a set of properties that include the PageSize
long t0 = System.currentTimeMillis(); long t0 = System.currentTimeMillis();
PropertyValue rendererProps[] = renderable.getRenderer(number, doc, renderProps); PropertyValue rendererProps[] = documentContext.renderable.getRenderer(number, documentContext.doc, renderProps);
long t1 = System.currentTimeMillis(); long t1 = System.currentTimeMillis();
Log.i(TAG, "getRenderer took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms"); Log.i(TAG, "getRenderer took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
...@@ -692,7 +691,7 @@ public class DocumentLoader ...@@ -692,7 +691,7 @@ public class DocumentLoader
renderProps[1].Value = device; renderProps[1].Value = device;
t0 = System.currentTimeMillis(); t0 = System.currentTimeMillis();
renderable.render(number, doc, renderProps); documentContext.renderable.render(number, documentContext.doc, renderProps);
t1 = System.currentTimeMillis(); t1 = System.currentTimeMillis();
Log.i(TAG, "Rendering page " + number + " took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms"); Log.i(TAG, "Rendering page " + number + " took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
...@@ -727,7 +726,7 @@ public class DocumentLoader ...@@ -727,7 +726,7 @@ public class DocumentLoader
Log.i(TAG, "doInBackground(" + number + ")"); Log.i(TAG, "doInBackground(" + number + ")");
if (number >= pageCount) if (number >= documentContext.pageCount)
return -1; return -1;
state = PageState.LOADING; state = PageState.LOADING;
...@@ -811,11 +810,11 @@ public class DocumentLoader ...@@ -811,11 +810,11 @@ public class DocumentLoader
loadProps[2].Value = new Boolean(true); loadProps[2].Value = new Boolean(true);
long t0 = System.currentTimeMillis(); long t0 = System.currentTimeMillis();
doc = bootstrapContext.componentLoader.loadComponentFromURL(url, "_blank", 0, loadProps); documentContext.doc = bootstrapContext.componentLoader.loadComponentFromURL(url, "_blank", 0, loadProps);
long t1 = System.currentTimeMillis(); long t1 = System.currentTimeMillis();
Log.i(TAG, "Loading took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms"); Log.i(TAG, "Loading took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
renderable = (XRenderable) UnoRuntime.queryInterface(XRenderable.class, doc); documentContext.renderable = (XRenderable) UnoRuntime.queryInterface(XRenderable.class, documentContext.doc);
PropertyValue renderProps[] = new PropertyValue[3]; PropertyValue renderProps[] = new PropertyValue[3];
renderProps[0] = new PropertyValue(); renderProps[0] = new PropertyValue();
...@@ -829,9 +828,9 @@ public class DocumentLoader ...@@ -829,9 +828,9 @@ public class DocumentLoader
renderProps[2].Value = new MyXController(); renderProps[2].Value = new MyXController();
t0 = System.currentTimeMillis(); t0 = System.currentTimeMillis();
pageCount = renderable.getRendererCount(doc, renderProps); documentContext.pageCount = documentContext.renderable.getRendererCount(documentContext.doc, renderProps);
t1 = System.currentTimeMillis(); t1 = System.currentTimeMillis();
Log.i(TAG, "getRendererCount: " + pageCount + ", took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms"); Log.i(TAG, "getRendererCount: " + documentContext.pageCount + ", took " + ((t1-t0)-bootstrapContext.timingOverhead) + " ms");
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(System.err); e.printStackTrace(System.err);
...@@ -855,6 +854,18 @@ public class DocumentLoader ...@@ -855,6 +854,18 @@ public class DocumentLoader
public XDevice dummySmallDevice; public XDevice dummySmallDevice;
} }
/**
* This class contains the state that is specific to a document, but
* independent from a view.
*/
class DocumentContext
{
public Object doc;
public int pageCount;
public XRenderable renderable;
public String input;
}
static void dumpUNOObject(String objectName, Object object) static void dumpUNOObject(String objectName, Object object)
{ {
Log.i(TAG, objectName + " is " + (object != null ? object.toString() : "null")); Log.i(TAG, objectName + " is " + (object != null ? object.toString() : "null"));
...@@ -924,7 +935,10 @@ public class DocumentLoader ...@@ -924,7 +935,10 @@ public class DocumentLoader
@Override @Override
public Object onRetainNonConfigurationInstance() { public Object onRetainNonConfigurationInstance() {
return bootstrapContext; ArrayList ret = new ArrayList(2);
ret.add(bootstrapContext);
ret.add(documentContext);
return ret;
} }
private void initBootstrapContext() private void initBootstrapContext()
...@@ -982,12 +996,25 @@ public class DocumentLoader ...@@ -982,12 +996,25 @@ public class DocumentLoader
} }
} }
private void initDocumentContext(String input)
{
documentContext = new DocumentContext();
documentContext.input = input;
// Load the wanted document
new DocumentLoadTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, "file://" + input);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
bootstrapContext = (BootstrapContext)getLastNonConfigurationInstance(); ArrayList contexts = (ArrayList)getLastNonConfigurationInstance();
if (contexts != null)
{
bootstrapContext = (BootstrapContext)contexts.get(0);
documentContext = (DocumentContext)contexts.get(1);
}
extras = getIntent().getExtras(); extras = getIntent().getExtras();
...@@ -1011,8 +1038,8 @@ public class DocumentLoader ...@@ -1011,8 +1038,8 @@ public class DocumentLoader
if (bootstrapContext == null) if (bootstrapContext == null)
initBootstrapContext(); initBootstrapContext();
// Load the wanted document if (documentContext == null || !documentContext.input.equals(input))
new DocumentLoadTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, "file://" + input); initDocumentContext(input);
flipper = new ViewFlipper(this); flipper = new ViewFlipper(this);
......
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