[Libreoffice-commits] core.git: android/Bootstrap android/source desktop/source

Mert Tümer merttumer7 at gmail.com
Tue Mar 27 14:26:21 UTC 2018


 android/Bootstrap/src/org/libreoffice/kit/Document.java              |    2 
 android/source/src/java/org/libreoffice/InvalidationHandler.java     |   17 +++
 android/source/src/java/org/libreoffice/LOEvent.java                 |   11 ++
 android/source/src/java/org/libreoffice/LOKitThread.java             |    6 +
 android/source/src/java/org/libreoffice/LOKitTileProvider.java       |   12 ++
 android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java |   45 +++-------
 android/source/src/java/org/libreoffice/TileProvider.java            |    8 +
 desktop/source/lib/lokandroid.cxx                                    |    5 -
 8 files changed, 72 insertions(+), 34 deletions(-)

New commits:
commit fc88892e9964554d4440637e11a7325c4200fedf
Author: Mert Tümer <merttumer7 at gmail.com>
Date:   Sun Mar 18 17:49:19 2018 +0300

    .uno:Save callback for the Android Viewer
    
    Change-Id: Ic2e16985e52869092faa2a31a59a85cb77b8e28c
    Signed-off-by: Mert Tümer <merttumer7 at gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/51506
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index f0c5e7a6f99a..855bdd2c5a2e 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -213,7 +213,7 @@ public class Document {
      * @param command - the command, like ".uno:Bold"
      * @param arguments
      */
-    public native void postUnoCommand(String command, String arguments);
+    public native void postUnoCommand(String command, String arguments, boolean notifyWhenFinished);
 
     /**
      * Change text selection.
diff --git a/android/source/src/java/org/libreoffice/InvalidationHandler.java b/android/source/src/java/org/libreoffice/InvalidationHandler.java
index eb22f6c8f3d3..b33f678de90f 100644
--- a/android/source/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java
@@ -62,6 +62,9 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes
             case Document.CALLBACK_INVALIDATE_TILES:
                 invalidateTiles(payload);
                 break;
+            case Document.CALLBACK_UNO_COMMAND_RESULT:
+                unoCommandResult(payload);
+                break;
             case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
                 invalidateCursor(payload);
                 break;
@@ -116,10 +119,24 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes
             case Document.CALLBACK_DOCUMENT_SIZE_CHANGED:
                 pageSizeChanged(payload);
             default:
+
                 Log.d(LOGTAG, "LOK_CALLBACK uncaught: " + messageID + " : " + payload);
         }
     }
 
+    private void unoCommandResult(String payload) {
+        try {
+            JSONObject payloadObject = new JSONObject(payload);
+            if (payloadObject.getString("commandName").equals(".uno:Save")) {
+                if (payloadObject.getString("success").equals("true")) {
+                    mContext.saveFilesToCloud();
+                }
+            }
+        }catch(JSONException e){
+            e.printStackTrace();
+        }
+    }
+
     private void cellFormula(final String payload) {
         LOKitShell.getMainHandler().post(new Runnable() {
             @Override
diff --git a/android/source/src/java/org/libreoffice/LOEvent.java b/android/source/src/java/org/libreoffice/LOEvent.java
index 979d8ba29ed7..7e15dea2b988 100644
--- a/android/source/src/java/org/libreoffice/LOEvent.java
+++ b/android/source/src/java/org/libreoffice/LOEvent.java
@@ -41,6 +41,8 @@ public class LOEvent implements Comparable<LOEvent> {
     public static final int UPDATE_CALC_HEADERS = 20;
     public static final int REFRESH = 21;
     public static final int PAGE_SIZE_CHANGED = 22;
+    public static final int UNO_COMMAND_NOTIFY = 23;
+
 
     public final int mType;
     public int mPriority = 0;
@@ -60,6 +62,7 @@ public class LOEvent implements Comparable<LOEvent> {
     public String mValue;
     public int mPageWidth;
     public int mPageHeight;
+    public boolean mNotify;
 
     public LOEvent(int type) {
         mType = type;
@@ -78,6 +81,14 @@ public class LOEvent implements Comparable<LOEvent> {
         mValue = null;
     }
 
+    public LOEvent(int type, String someString, boolean notify) {
+        mType = type;
+        mTypeString = "String";
+        mString = someString;
+        mValue = null;
+        mNotify = notify;
+    }
+
     public LOEvent(int type, String key, String value) {
         mType = type;
         mTypeString = "key / value";
diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java
index 63f49dc6253f..92303f588c2f 100644
--- a/android/source/src/java/org/libreoffice/LOKitThread.java
+++ b/android/source/src/java/org/libreoffice/LOKitThread.java
@@ -366,6 +366,12 @@ class LOKitThread extends Thread {
             case LOEvent.UPDATE_CALC_HEADERS:
                 updateCalcHeaders();
                 break;
+            case LOEvent.UNO_COMMAND_NOTIFY:
+                if (null == mTileProvider)
+                    Log.e(LOGTAG, "no mTileProvider when trying to process "+event.mValue+" from UNO_COMMAND "+event.mString);
+                else
+                    mTileProvider.postUnoCommand(event.mString, event.mValue, event.mNotify);
+                break;
             case LOEvent.REFRESH:
                 refresh();
                 break;
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index addbc16a9cf7..0f1e9f9e444e 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -584,7 +584,17 @@ class LOKitTileProvider implements TileProvider {
      */
     @Override
     public void postUnoCommand(String command, String arguments) {
-        mDocument.postUnoCommand(command, arguments);
+        postUnoCommand(command, arguments, false);
+    }
+
+    /**
+     * @param command
+     * @param arguments
+     * @param notifyWhenFinished
+     */
+    @Override
+    public void postUnoCommand(String command, String arguments, boolean notifyWhenFinished) {
+        mDocument.postUnoCommand(command, arguments, notifyWhenFinished);
     }
 
     private void setTextSelection(int type, PointF documentCoordinate) {
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 3d9e13f343ad..dee54d5ac2da 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -118,6 +118,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
     private boolean isSearchToolbarOpen = false;
     private static boolean isDocumentChanged = false;
     public boolean isNewDocument = false;
+    private long lastModified = 0;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         Log.w(LOGTAG, "onCreate..");
@@ -216,6 +218,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
             mDrawerList.setOnItemClickListener(new DocumentPartClickListener());
         }
 
+        lastModified = mInputFile.lastModified();
+
         mToolbarController.setupToolbars();
 
         TabHost host = findViewById(R.id.toolbarTabHost);
@@ -314,13 +318,15 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
         if (!mInputFile.exists()) {
             // Needed for handling null in case new document is not created.
             mInputFile = new File(DEFAULT_DOC_PATH);
+            lastModified = mInputFile.lastModified();
         }
-        final long lastModified = mInputFile.lastModified();
-        final Activity activity = LibreOfficeMainActivity.this;
         Toast.makeText(this, R.string.message_saving, Toast.LENGTH_SHORT).show();
         // local save
-        LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Save"));
+        LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND_NOTIFY, ".uno:Save", true));
+    }
 
+    public void saveFilesToCloud(){
+        final Activity activity = LibreOfficeMainActivity.this;
         final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
             @Override
             protected Void doInBackground(Void... params) {
@@ -348,35 +354,16 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
             protected void onPostExecute(Void param) {
                 Toast.makeText(activity, R.string.message_saved,
                         Toast.LENGTH_SHORT).show();
-                isDocumentChanged=false;
+                setDocumentChanged(false);
             }
         };
-        // Delay the call to document provider save operation and check the
-        // modification time periodically to ensure the local file has been saved.
-        // TODO: ideally the save operation should have a callback
-        Runnable runTask = new Runnable() {
-            private int timesRun = 0;
 
-            @Override
-            public void run() {
-                if (lastModified < mInputFile.lastModified()) {
-                    // we are sure local save is complete, push changes to cloud
-                    task.execute();
-                }
-                else {
-                    timesRun++;
-                    if(timesRun < 4) {
-                        new Handler().postDelayed(this, 5000);
-                    }
-                    else {
-                        // 20 seconds later, the local file has not changed,
-                        // maybe there were no changes at all
-                        Toast.makeText(activity, R.string.message_save_incomplete, Toast.LENGTH_LONG).show();
-                    }
-                }
-            }
-        };
-        new Handler().postDelayed(runTask, 5000);
+        if (lastModified < mInputFile.lastModified()) {
+            task.execute();
+            lastModified = mInputFile.lastModified();
+        } else {
+            Toast.makeText(activity, R.string.message_save_incomplete, Toast.LENGTH_LONG).show();
+        }
     }
 
     @Override
diff --git a/android/source/src/java/org/libreoffice/TileProvider.java b/android/source/src/java/org/libreoffice/TileProvider.java
index 10d578337680..240d3ce52057 100644
--- a/android/source/src/java/org/libreoffice/TileProvider.java
+++ b/android/source/src/java/org/libreoffice/TileProvider.java
@@ -124,6 +124,14 @@ public interface TileProvider {
     void postUnoCommand(String command, String arguments);
 
     /**
+     * This is the actual reference to the function in LOK, used for getting notified when uno:save event finishes
+     * @param command
+     * @param arguments
+     * @param notifyWhenFinished
+     */
+    void postUnoCommand(String command, String arguments, boolean notifyWhenFinished);
+
+    /**
      * Send text selection start coordinate.
      * @param documentCoordinate
      */
diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index 974366d845fc..d22c2585eb68 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -12,7 +12,6 @@
 
 #include <sal/types.h>
 #include <vcl/event.hxx>
-
 #include <android/log.h>
 
 #include <osl/detail/android-bootstrap.h>
@@ -330,7 +329,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postMou
 }
 
 extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postUnoCommand
-    (JNIEnv* pEnv, jobject aObject, jstring command, jstring arguments)
+    (JNIEnv* pEnv, jobject aObject, jstring command, jstring arguments, jboolean bNotifyWhenFinished)
 {
     LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
 
@@ -339,7 +338,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postUno
     if (arguments != NULL)
         pArguments = pEnv->GetStringUTFChars(arguments, NULL);
 
-    pDocument->pClass->postUnoCommand(pDocument, pCommand, pArguments, false);
+    pDocument->pClass->postUnoCommand(pDocument, pCommand, pArguments, bNotifyWhenFinished);
 
     pEnv->ReleaseStringUTFChars(command, pCommand);
     if (arguments != NULL)


More information about the Libreoffice-commits mailing list