[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libreoffice-commits
Subject:    [Libreoffice-commits] core.git: android/source
From:       aleksandar-stefanovic <theonewithideas () gmail ! com>
Date:       2017-01-31 10:58:37
Message-ID: 20170131105837.8A183761A2 () kemper ! freedesktop ! org
[Download RAW message or body]

 android/source/src/java/org/libreoffice/LOKitShell.java              |    2 
 android/source/src/java/org/libreoffice/LOKitThread.java             |   41 \
+++-------  android/source/src/java/org/libreoffice/LibreOfficeApplication.java  |    \
8 -  android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java |    6 +
 4 files changed, 22 insertions(+), 35 deletions(-)

New commits:
commit 5f89da97dc7cc7c8f7e9255b6ad41e0a24bf3682
Author: aleksandar-stefanovic <theonewithideas@gmail.com>
Date:   Wed Jan 25 16:53:46 2017 +0100

    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>

diff --git a/android/source/src/java/org/libreoffice/LOKitShell.java \
b/android/source/src/java/org/libreoffice/LOKitShell.java index 3eff5ce..35a8fd0 \
                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 7db1605..742b1cb \
                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 \
                1c72aa8..67655c7 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 \
                b84f78b..4f0beb9 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));
_______________________________________________
Libreoffice-commits mailing list
Libreoffice-commits@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic