Kaydet (Commit) 9a6cf486 authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez

LOAndroid3: Prevent crash when opening a nonexistent file

Change-Id: Ic0fbe955dfdb8f044d7bf0f45215a632a111eae2
üst 0a6d7d6e
......@@ -86,22 +86,24 @@ public class LOKitThread extends Thread {
return true;
}
private void initialize() {
private boolean initialize() {
mApplication = LibreOfficeMainActivity.mAppContext;
mTileProvider = new LOKitTileProvider(mApplication.getLayerController(), mInputFile);
return mTileProvider.isReady();
}
public void run() {
initialize();
try {
boolean drawn = false;
while (true) {
if (!mEvents.isEmpty()) {
processEvent(mEvents.poll());
if (initialize()) {
try {
boolean drawn = false;
while (true) {
if (!mEvents.isEmpty()) {
processEvent(mEvents.poll());
}
Thread.sleep(100L);
}
Thread.sleep(100L);
} catch (InterruptedException ex) {
}
} catch (InterruptedException ex) {
}
}
......
......@@ -56,6 +56,11 @@ public class LOKitTileProvider implements TileProvider {
return (int) twipToPixel(mDocument.getDocumentHeight(), mDPI);
}
@Override
public boolean isReady() {
return mDocument != null;
}
public SubTile createTile(int x, int y) {
ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4);
Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888);
......
......@@ -25,6 +25,11 @@ public class MockTileProvider implements TileProvider {
return 630*5;
}
@Override
public boolean isReady() {
return true;
}
@Override
public SubTile createTile(int x, int y) {
int tiles = (getPageWidth() / TILE_SIZE) + 1;
......
......@@ -7,5 +7,7 @@ public interface TileProvider {
int getPageWidth();
int getPageHeight();
boolean isReady();
SubTile createTile(int x, int y);
}
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