summaryrefslogtreecommitdiffstats
path: root/android/source/src/java/org/libreoffice/LOKitThread.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/source/src/java/org/libreoffice/LOKitThread.java')
-rw-r--r--android/source/src/java/org/libreoffice/LOKitThread.java41
1 files changed, 13 insertions, 28 deletions
diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java
index a4d5ba99f1a2..fd40c3089102 100644
--- a/android/source/src/java/org/libreoffice/LOKitThread.java
+++ b/android/source/src/java/org/libreoffice/LOKitThread.java
@@ -184,9 +184,11 @@ class LOKitThread extends Thread {
private void updateZoomConstraints() {
if (mTileProvider == null) return;
mLayerClient = mContext.getLayerClient();
- // Set min zoom to the page width so that you cannot zoom below page width
- final float minZoom = mLayerClient.getViewportMetrics().getWidth()/mTileProvider.getPageWidth();
- mLayerClient.setZoomConstraints(new ZoomConstraints(true, 1f, minZoom, 0f));
+ // Set default zoom to the page width and min zoom so that the whole page is visible
+ final float pageHeightZoom = mLayerClient.getViewportMetrics().getHeight() / mTileProvider.getPageHeight();
+ final float pageWidthZoom = mLayerClient.getViewportMetrics().getWidth() / mTileProvider.getPageWidth();
+ final float minZoom = Math.min(pageWidthZoom, pageHeightZoom);
+ mLayerClient.setZoomConstraints(new ZoomConstraints(pageWidthZoom, minZoom, 0f));
}
/**
@@ -204,8 +206,9 @@ class LOKitThread extends Thread {
/**
* Handle load document event.
* @param filePath - filePath to where the document is located
+ * @return Whether the document has been loaded successfully.
*/
- private void loadDocument(String filePath) {
+ private boolean loadDocument(String filePath) {
mLayerClient = mContext.getLayerClient();
mInvalidationHandler = new InvalidationHandler(mContext);
@@ -214,18 +217,12 @@ class LOKitThread extends Thread {
if (mTileProvider.isReady()) {
LOKitShell.showProgressSpinner(mContext);
updateZoomConstraints();
- LOKitShell.getMainHandler().post(new Runnable() {
- @Override
- public void run() {
- // synchronize to avoid deletion while loading
- synchronized (LOKitThread.this) {
- refresh(true);
- }
- }
- });
+ refresh(true);
LOKitShell.hideProgressSpinner(mContext);
+ return true;
} else {
closeDocument();
+ return false;
}
}
@@ -235,20 +232,9 @@ class LOKitThread extends Thread {
* @param fileType - fileType what type of new document is to be loaded
*/
private void loadNewDocument(String filePath, String fileType) {
- mLayerClient = mContext.getLayerClient();
-
- mInvalidationHandler = new InvalidationHandler(mContext);
- mTileProvider = TileProviderFactory.create(mContext, mInvalidationHandler, fileType);
-
- if (mTileProvider.isReady()) {
- LOKitShell.showProgressSpinner(mContext);
- updateZoomConstraints();
- refresh(true);
- LOKitShell.hideProgressSpinner(mContext);
-
+ boolean ok = loadDocument(fileType);
+ if (ok) {
mTileProvider.saveDocumentAs(filePath, true);
- } else {
- closeDocument();
}
}
@@ -266,8 +252,7 @@ class LOKitThread extends Thread {
/**
* Close the currently loaded document.
*/
- // needs to be synchronized to not destroy doc while it's loaded
- private synchronized void closeDocument() {
+ private void closeDocument() {
if (mTileProvider != null) {
mTileProvider.close();
mTileProvider = null;