Kaydet (Commit) 83386129 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

android: Fix the application lifecycle.

Now onStart() loads the file, and onStop() closes it again.  Fixes the case
when the user leaves the app by pressing Home, and starts it again;
previously, this caused a race.

Change-Id: I493a76eaf5e8ca8a68b53f70c7acd09b638f7e11
üst 2b85db8b
......@@ -13,7 +13,8 @@ public class LOEvent {
public static final int DRAW = 4;
public static final int CHANGE_PART = 5;
public static final int LOAD = 6;
public static final int REDRAW = 7;
public static final int CLOSE = 7;
public static final int REDRAW = 8;
public int mType;
private ImmutableViewportMetrics mViewportMetrics;
......@@ -58,6 +59,9 @@ public class LOEvent {
}
public String getTypeString() {
if (mTypeString == null) {
return "Event type: " + mType;
}
return mTypeString;
}
......
......@@ -31,6 +31,10 @@ public class LOEventFactory {
return new LOEvent(LOEvent.LOAD, inputFile);
}
public static LOEvent close() {
return new LOEvent(LOEvent.CLOSE);
}
public static LOEvent redraw() {
return new LOEvent(LOEvent.REDRAW);
}
......
......@@ -61,7 +61,7 @@ public class LOKitThread extends Thread {
LOKitShell.hideProgressSpinner();
}
private boolean load(String filename) {
private boolean loadDocument(String filename) {
if (mApplication == null) {
mApplication = LibreOfficeMainActivity.mAppContext;
}
......@@ -69,10 +69,6 @@ public class LOKitThread extends Thread {
mController = mApplication.getLayerController();
mLayerClient = mApplication.getLayerClient();
if (mTileProvider != null) {
mTileProvider.close();
}
mTileProvider = TileProviderFactory.create(mController, filename);
boolean isReady = mTileProvider.isReady();
if (isReady) {
......@@ -82,9 +78,16 @@ public class LOKitThread extends Thread {
refresh();
LOKitShell.hideProgressSpinner();
}
return isReady;
}
public void closeDocument() {
if (mTileProvider != null) {
mTileProvider.close();
}
}
public void run() {
try {
while (true) {
......@@ -95,9 +98,13 @@ public class LOKitThread extends Thread {
}
private void processEvent(LOEvent event) {
Log.i(LOGTAG, "processEvent: " + event.getTypeString());
switch (event.mType) {
case LOEvent.LOAD:
load(event.getFilename());
loadDocument(event.getFilename());
break;
case LOEvent.CLOSE:
closeDocument();
break;
case LOEvent.VIEWPORT:
mViewportMetrics = event.getViewport();
......
......@@ -136,8 +136,6 @@ public class LibreOfficeMainActivity extends Activity {
LayerView layerView = (LayerView) findViewById(R.id.layer_view);
mLayerController.setView(layerView);
mLayerController.setLayerClient(mLayerClient);
LOKitShell.sendEvent(LOEventFactory.load(mInputFile));
}
@Override
......@@ -156,11 +154,13 @@ public class LibreOfficeMainActivity extends Activity {
protected void onStart() {
Log.i(LOGTAG, "onStart..");
super.onStart();
LOKitShell.sendEvent(LOEventFactory.load(mInputFile));
}
@Override
protected void onStop() {
Log.i(LOGTAG, "onStop..");
LOKitShell.sendEvent(LOEventFactory.close());
super.onStop();
}
......@@ -199,21 +199,19 @@ public class LibreOfficeMainActivity extends Activity {
builder.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), LibreOfficeMainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setData(Uri.parse("file:///assets/license.txt"));
startActivity(intent);
public void onClick(DialogInterface dialog, int id) {
LOKitShell.sendEvent(LOEventFactory.close());
LOKitShell.sendEvent(LOEventFactory.load("/assets/license.txt"));
dialog.dismiss();
}
});
builder.setPositiveButton(R.string.about_notice, new DialogInterface.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), LibreOfficeMainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setData(Uri.parse("file:///assets/notice.txt"));
startActivity(intent);
public void onClick(DialogInterface dialog, int id) {
LOKitShell.sendEvent(LOEventFactory.close());
LOKitShell.sendEvent(LOEventFactory.load("/assets/notice.txt"));
dialog.dismiss();
}
});
......
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