Kaydet (Commit) 5f89da97 authored tarafından aleksandar-stefanovic's avatar aleksandar-stefanovic Kaydeden (comit) Christian Lohmaier

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/33546Reviewed-by: 's avatarChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Tested-by: 's avatarChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>
üst 01aa52b5
......@@ -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) {
......
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;
......
......@@ -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;
}
......
......@@ -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));
......
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