diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-10-04 15:51:02 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-10-04 17:53:07 +0200 |
commit | 67be577f163831e460e19aee958bdcf7187b8a56 (patch) | |
tree | 03d4d98895ed3a8e41e11906be0c1f79146ad02e /android | |
parent | androdi: set TileProvider only when document is ready (diff) | |
download | core-67be577f163831e460e19aee958bdcf7187b8a56.tar.gz core-67be577f163831e460e19aee958bdcf7187b8a56.zip |
android: assure document close, introduce message box for errors
Change-Id: I4d5607d5568ebf73a61067975c21e740020cc8f7
Diffstat (limited to 'android')
3 files changed, 62 insertions, 10 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index c904942bbb00..bd1b27bddc24 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -8,7 +8,6 @@ import org.libreoffice.kit.LibreOfficeKit; import org.libreoffice.kit.Office; import org.mozilla.gecko.gfx.BufferedCairoImage; import org.mozilla.gecko.gfx.CairoImage; -import org.mozilla.gecko.gfx.FloatSize; import org.mozilla.gecko.gfx.IntSize; import org.mozilla.gecko.gfx.LayerController; @@ -16,13 +15,14 @@ import java.nio.ByteBuffer; public class LOKitTileProvider implements TileProvider { private static final String LOGTAG = LOKitTileProvider.class.getSimpleName(); - public static int TILE_SIZE = 256; - public final Office mOffice; - public final Document mDocument; + private static int TILE_SIZE = 256; + private final Office mOffice; + private Document mDocument; private final LayerController mLayerController; private final float mTileWidth; private final float mTileHeight; private final String mInputFile; + private boolean mIsReady = false; private float mDPI; private float mWidthTwip; @@ -70,6 +70,8 @@ public class LOKitTileProvider implements TileProvider { LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().notifyDataSetChanged(); } }); + + mIsReady = true; } } @@ -108,8 +110,15 @@ public class LOKitTileProvider implements TileProvider { mWidthTwip = mDocument.getDocumentWidth(); mHeightTwip = mDocument.getDocumentHeight(); - if (mWidthTwip == 0 && mHeightTwip == 0) { + if (mWidthTwip == 0 || mHeightTwip == 0) { Log.e(LOGTAG, "Document size zero - last error: " + mOffice.getError()); + LOKitShell.getMainHandler().post(new Runnable() { + @Override + public void run() { + LibreOfficeMainActivity.mAppContext.showAlertDialog("Document has no size!"); + } + }); + return false; } else { Log.i(LOGTAG, "Document size: " + mDocument.getDocumentWidth() + " x " + mDocument.getDocumentHeight()); } @@ -129,7 +138,7 @@ public class LOKitTileProvider implements TileProvider { @Override public boolean isReady() { - return mDocument != null; + return mIsReady; } @Override @@ -143,7 +152,7 @@ public class LOKitTileProvider implements TileProvider { float twipWidth = mTileWidth / zoom; float twipHeight = mTileHeight / zoom; long start = System.currentTimeMillis(); - Log.i(LOGTAG, "paintTile TOP @ " + start + "(" + tileSize.width + " " + tileSize.height + " " + (int)twipX + " " + (int)twipY + " " + (int) twipWidth + " " + (int) twipHeight + ")"); + Log.i(LOGTAG, "paintTile TOP @ " + start + "(" + tileSize.width + " " + tileSize.height + " " + (int) twipX + " " + (int) twipY + " " + (int) twipWidth + " " + (int) twipHeight + ")"); mDocument.paintTile(buffer, tileSize.width, tileSize.height, (int) twipX, (int) twipY, (int) twipWidth, (int) twipHeight); long stop = System.currentTimeMillis(); Log.i(LOGTAG, "paintTile TAIL @ " + stop + " - elapsed: " + (stop - start) + " "); @@ -173,6 +182,8 @@ public class LOKitTileProvider implements TileProvider { widthPixel = (int) (heightPixel * ratio); } + Log.w(LOGTAG, "Thumbnail size: " + getPageWidth() + " " + getPageHeight() + " " + widthPixel + " " + heightPixel); + ByteBuffer buffer = ByteBuffer.allocateDirect(widthPixel * heightPixel * 4); mDocument.paintTile(buffer, widthPixel, heightPixel, 0, 0, (int) mWidthTwip, (int) mHeightTwip); @@ -189,10 +200,17 @@ public class LOKitTileProvider implements TileProvider { Log.i(LOGTAG, "Document destroyed: " + mInputFile); if (mDocument != null) { mDocument.destroy(); + mDocument = null; } } @Override + protected void finalize() throws Throwable { + close(); + super.finalize(); + } + + @Override public void changePart(int partIndex) { mDocument.setPart(partIndex); } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java index aa4f70c1eea9..c5ecccb20285 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -2,6 +2,7 @@ package org.libreoffice; import android.app.Activity; import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -132,7 +133,7 @@ public class LibreOfficeMainActivity extends Activity { mLayerController = new LayerController(this); mLayerController.setZoomConstraints(new ZoomConstraints(true)); mLayerClient = new GeckoLayerClient(this); - LayerView layerView = (LayerView)findViewById(R.id.layer_view); + LayerView layerView = (LayerView) findViewById(R.id.layer_view); mLayerController.setView(layerView); mLayerController.setLayerClient(mLayerClient); @@ -147,10 +148,28 @@ public class LibreOfficeMainActivity extends Activity { @Override protected void onPause() { - Log.i(LOGTAG, "Pause.."); + Log.i(LOGTAG, "onPause.."); super.onPause(); } + @Override + protected void onStart() { + Log.i(LOGTAG, "onStart.."); + super.onStop(); + } + + @Override + protected void onStop() { + Log.i(LOGTAG, "onStop.."); + super.onStop(); + } + + @Override + protected void onDestroy() { + Log.i(LOGTAG, "onDestroy.."); + super.onDestroy(); + } + public LOKitThread getLOKitThread() { return sLOKitThread; } @@ -212,6 +231,22 @@ public class LibreOfficeMainActivity extends Activity { findViewById(R.id.loadingPanel).setVisibility(View.GONE); } + public void showAlertDialog(String s) { + + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(LibreOfficeMainActivity.this); + + alertDialogBuilder.setTitle("Error"); + alertDialogBuilder.setMessage(s); + alertDialogBuilder.setNeutralButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + finish(); + } + }); + + AlertDialog alertDialog = alertDialogBuilder.create(); + alertDialog.show(); + } + private class DocumentPartClickListener implements android.widget.AdapterView.OnItemClickListener { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java index 5de6a82a0d0e..583773b46075 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java @@ -4,7 +4,6 @@ import android.graphics.Bitmap; import org.mozilla.gecko.gfx.BufferedCairoImage; import org.mozilla.gecko.gfx.CairoImage; -import org.mozilla.gecko.gfx.FloatSize; import org.mozilla.gecko.gfx.IntSize; import org.mozilla.gecko.gfx.LayerController; |