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,13 +86,14 @@ public class LOKitThread extends Thread { ...@@ -86,13 +86,14 @@ public class LOKitThread extends Thread {
return true; return true;
} }
private void initialize() { private boolean initialize() {
mApplication = LibreOfficeMainActivity.mAppContext; mApplication = LibreOfficeMainActivity.mAppContext;
mTileProvider = new LOKitTileProvider(mApplication.getLayerController(), mInputFile); mTileProvider = new LOKitTileProvider(mApplication.getLayerController(), mInputFile);
return mTileProvider.isReady();
} }
public void run() { public void run() {
initialize(); if (initialize()) {
try { try {
boolean drawn = false; boolean drawn = false;
while (true) { while (true) {
...@@ -104,6 +105,7 @@ public class LOKitThread extends Thread { ...@@ -104,6 +105,7 @@ public class LOKitThread extends Thread {
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
} }
} }
}
private void processEvent(LOEvent event) throws InterruptedException { private void processEvent(LOEvent event) throws InterruptedException {
switch (event.mType) { switch (event.mType) {
......
...@@ -56,6 +56,11 @@ public class LOKitTileProvider implements TileProvider { ...@@ -56,6 +56,11 @@ public class LOKitTileProvider implements TileProvider {
return (int) twipToPixel(mDocument.getDocumentHeight(), mDPI); return (int) twipToPixel(mDocument.getDocumentHeight(), mDPI);
} }
@Override
public boolean isReady() {
return mDocument != null;
}
public SubTile createTile(int x, int y) { public SubTile createTile(int x, int y) {
ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4); ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4);
Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888); Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888);
......
...@@ -25,6 +25,11 @@ public class MockTileProvider implements TileProvider { ...@@ -25,6 +25,11 @@ public class MockTileProvider implements TileProvider {
return 630*5; return 630*5;
} }
@Override
public boolean isReady() {
return true;
}
@Override @Override
public SubTile createTile(int x, int y) { public SubTile createTile(int x, int y) {
int tiles = (getPageWidth() / TILE_SIZE) + 1; int tiles = (getPageWidth() / TILE_SIZE) + 1;
......
...@@ -7,5 +7,7 @@ public interface TileProvider { ...@@ -7,5 +7,7 @@ public interface TileProvider {
int getPageWidth(); int getPageWidth();
int getPageHeight(); int getPageHeight();
boolean isReady();
SubTile createTile(int x, int y); 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