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