diff options
author | aleksandar-stefanovic <theonewithideas@gmail.com> | 2017-01-25 16:53:46 +0100 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2017-01-31 10:58:01 +0000 |
commit | 5f89da97dc7cc7c8f7e9255b6ad41e0a24bf3682 (patch) | |
tree | 31833281bdbbdb3f502fa2a88b45b5ed986055ac /android/source | |
parent | 01aa52b5e91bac740ad21c31968c834c1530831e (diff) |
Removed static context from LOKitThread
Moved LOKitThread back to LibreOfficeMainActivity, so that it could
use the context in the constructor. Once the Context became available
in LOKitThread, it was simply a matter of replacing static references
with the one passed in the constructor.
Also changed access levels of some methods in LOKitThread.
Change-Id: I0cc2c846c67b90907cbf3dce363666f9ab02d887
Reviewed-on: https://gerrit.libreoffice.org/33546
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Tested-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'android/source')
4 files changed, 22 insertions, 35 deletions
diff --git a/android/source/src/java/org/libreoffice/LOKitShell.java b/android/source/src/java/org/libreoffice/LOKitShell.java index 3eff5ce8f341..35a8fd009dc2 100644 --- a/android/source/src/java/org/libreoffice/LOKitShell.java +++ b/android/source/src/java/org/libreoffice/LOKitShell.java @@ -69,7 +69,7 @@ public class LOKitShell { * Make sure LOKitThread is running and send event to it. */ public static void sendEvent(LOEvent event) { - LibreOfficeApplication.getLoKitThread().queueEvent(event); + LibreOfficeMainActivity.loKitThread.queueEvent(event); } public static void sendThumbnailEvent(ThumbnailCreator.ThumbnailCreationTask task) { diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java index 7db16059a8ca..742b1cb6e34c 100644 --- a/android/source/src/java/org/libreoffice/LOKitThread.java +++ b/android/source/src/java/org/libreoffice/LOKitThread.java @@ -1,6 +1,5 @@ package org.libreoffice; -import android.content.Context; import android.graphics.Bitmap; import android.graphics.PointF; import android.graphics.RectF; @@ -21,7 +20,7 @@ import java.util.concurrent.LinkedBlockingQueue; * Thread that communicates with LibreOffice through LibreOfficeKit JNI interface. The thread * consumes events from other threads (mainly the UI thread) and acts accordingly. */ -public class LOKitThread extends Thread { +class LOKitThread extends Thread { private static final String LOGTAG = LOKitThread.class.getSimpleName(); private LinkedBlockingQueue<LOEvent> mEventQueue = new LinkedBlockingQueue<LOEvent>(); @@ -30,8 +29,10 @@ public class LOKitThread extends Thread { private InvalidationHandler mInvalidationHandler; private ImmutableViewportMetrics mViewportMetrics; private GeckoLayerClient mLayerClient; + private LibreOfficeMainActivity mContext; - public LOKitThread() { + LOKitThread(LibreOfficeMainActivity context) { + mContext = context; mInvalidationHandler = null; TileProviderFactory.initialize(); } @@ -160,21 +161,13 @@ public class LOKitThread extends Thread { private void resumeDocument(String filename, int partIndex){ - LibreOfficeMainActivity mainActivity = LibreOfficeMainActivity.mAppContext; + mLayerClient = mContext.getLayerClient(); - - mLayerClient = mainActivity.getLayerClient(); - - mInvalidationHandler = new InvalidationHandler(mainActivity); - mTileProvider = TileProviderFactory.create(mainActivity, mInvalidationHandler, filename); + mInvalidationHandler = new InvalidationHandler(mContext); + mTileProvider = TileProviderFactory.create(mContext, mInvalidationHandler, filename); if (mTileProvider.isReady()) { - LOKitShell.showProgressSpinner(mainActivity); - mTileProvider.changePart(partIndex); - mViewportMetrics = mLayerClient.getViewportMetrics(); - mLayerClient.setViewportMetrics(mViewportMetrics.scaleTo(0.9f, new PointF())); - refresh(); - LOKitShell.hideProgressSpinner(mainActivity); + changePart(partIndex); } else { closeDocument(); } @@ -186,12 +179,12 @@ public class LOKitThread extends Thread { * Change part of the document. */ private void changePart(int partIndex) { - LOKitShell.showProgressSpinner(LibreOfficeMainActivity.mAppContext); + LOKitShell.showProgressSpinner(mContext); mTileProvider.changePart(partIndex); mViewportMetrics = mLayerClient.getViewportMetrics(); mLayerClient.setViewportMetrics(mViewportMetrics.scaleTo(0.9f, new PointF())); refresh(); - LOKitShell.hideProgressSpinner(LibreOfficeMainActivity.mAppContext); + LOKitShell.hideProgressSpinner(mContext); } /** @@ -199,18 +192,16 @@ public class LOKitThread extends Thread { * @param filename - filename where the document is located */ private void loadDocument(String filename) { - //TODO remove static reference to context (causes memory leaks) - LibreOfficeMainActivity mMainActivity = LibreOfficeMainActivity.mAppContext; - mLayerClient = mMainActivity.getLayerClient(); + mLayerClient = mContext.getLayerClient(); - mInvalidationHandler = new InvalidationHandler(mMainActivity); - mTileProvider = TileProviderFactory.create(mMainActivity, mInvalidationHandler, filename); + mInvalidationHandler = new InvalidationHandler(mContext); + mTileProvider = TileProviderFactory.create(mContext, mInvalidationHandler, filename); if (mTileProvider.isReady()) { - LOKitShell.showProgressSpinner(mMainActivity); + LOKitShell.showProgressSpinner(mContext); refresh(); - LOKitShell.hideProgressSpinner(mMainActivity); + LOKitShell.hideProgressSpinner(mContext); } else { closeDocument(); } @@ -219,7 +210,7 @@ public class LOKitThread extends Thread { /** * Close the currently loaded document. */ - public void closeDocument() { + private void closeDocument() { if (mTileProvider != null) { mTileProvider.close(); mTileProvider = null; diff --git a/android/source/src/java/org/libreoffice/LibreOfficeApplication.java b/android/source/src/java/org/libreoffice/LibreOfficeApplication.java index 1c72aa89eeba..67655c7689cd 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeApplication.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeApplication.java @@ -16,19 +16,11 @@ import android.os.Handler; public class LibreOfficeApplication extends Application { private static Handler mainHandler; - private static LOKitThread loKitThread; public LibreOfficeApplication() { - loKitThread = new LOKitThread(); - loKitThread.start(); - mainHandler = new Handler(); } - public static LOKitThread getLoKitThread() { - return loKitThread; - } - public static Handler getMainHandler() { return mainHandler; } diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index b84f78bc94e6..4f0beb9767bd 100755 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -54,7 +54,10 @@ public class LibreOfficeMainActivity extends AppCompatActivity { private static final String ENABLE_EXPERIMENTAL_PREFS_KEY = "ENABLE_EXPERIMENTAL"; private static final String ASSETS_EXTRACTED_PREFS_KEY = "ASSETS_EXTRACTED"; + //TODO WIP: removing this static Context (in the following commits) public static LibreOfficeMainActivity mAppContext; + //TODO "public static" is a temporary workaround + public static LOKitThread loKitThread; private GeckoLayerClient mLayerClient; @@ -161,7 +164,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity { mDrawerList.setOnItemClickListener(new DocumentPartClickListener()); } - LibreOfficeApplication.getLoKitThread().clearQueue(); + loKitThread = new LOKitThread(this); + loKitThread.start(); mLayerClient = new GeckoLayerClient(this); mLayerClient.setZoomConstraints(new ZoomConstraints(true)); |