From 83386129f5be002f2649db81bba4c468c7f6e4de Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Thu, 9 Oct 2014 20:50:35 +0200 Subject: 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 --- .../src/java/org/libreoffice/LOEvent.java | 6 +++++- .../src/java/org/libreoffice/LOEventFactory.java | 4 ++++ .../src/java/org/libreoffice/LOKitThread.java | 19 +++++++++++++------ .../org/libreoffice/LibreOfficeMainActivity.java | 22 ++++++++++------------ 4 files changed, 32 insertions(+), 19 deletions(-) (limited to 'android/experimental') diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java index 3f39257551ae..d9f3219ee40d 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java @@ -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; } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java index 90a358212f58..a63b5db3d2c7 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java @@ -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); } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 528f419d7c25..e5765e6ebdeb 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -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(); diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java index 1778e3597f88..6ca7b4dcf778 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -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(); } }); -- cgit v1.2.3