android/app/src/main/java/org/libreoffice/androidapp/JavaScriptInterface.java 
|   22 --------
 android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java        
|   26 +++++++++
 loleaflet/html/loleaflet.html.m4                                              
|   27 +++++++---
 loleaflet/js/global.js                                                        
|    4 -
 loleaflet/js/toolbar.js                                                       
|    2 
 loleaflet/src/control/Control.Menubar.js                                      
|    2 
 loleaflet/src/core/Socket.js                                                  
|    4 -
 loleaflet/src/map/handler/Map.FileInserter.js                                 
|    6 +-
 loleaflet/util/create-l10n-all-js.pl                                          
|    2 
 9 files changed, 55 insertions(+), 40 deletions(-)

New commits:
commit 7604f9b21813c19a0644ae28ac987a541bebd699
Author:     Jan Holesovsky <ke...@collabora.com>
AuthorDate: Wed Feb 13 21:16:42 2019 +0100
Commit:     Jan Holesovsky <ke...@collabora.com>
CommitDate: Wed Feb 13 21:18:57 2019 +0100

    android: Pass the messages from JS to the MainActivity.
    
    Change-Id: Id2d5bac0f67668305ed47276614fde590d461901

diff --git 
a/android/app/src/main/java/org/libreoffice/androidapp/JavaScriptInterface.java 
b/android/app/src/main/java/org/libreoffice/androidapp/JavaScriptInterface.java
deleted file mode 100644
index c1d28c8ed..000000000
--- 
a/android/app/src/main/java/org/libreoffice/androidapp/JavaScriptInterface.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package org.libreoffice.androidapp;
-
-import android.webkit.JavascriptInterface;
-
-public class JavaScriptInterface {
-
-    @JavascriptInterface
-    public String getString(String aString) {
-        return aString + " -> came from JAVA";
-    }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git 
a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java 
b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
index 504b7592a..ae27334c6 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java
@@ -10,7 +10,9 @@
 package org.libreoffice.androidapp;
 
 import android.os.Bundle;
+import android.util.Log;
 import android.view.View;
+import android.webkit.JavascriptInterface;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
@@ -19,6 +21,7 @@ import android.widget.Button;
 import androidx.appcompat.app.AppCompatActivity;
 
 public class MainActivity extends AppCompatActivity {
+    final static String TAG = "MainActivity";
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -32,7 +35,7 @@ public class MainActivity extends AppCompatActivity {
 
         WebSettings browserSettings = browser.getSettings();
         browserSettings.setJavaScriptEnabled(true);
-        browser.addJavascriptInterface(new JavaScriptInterface(), 
"MainHandler");
+        browser.addJavascriptInterface(this, "LOOLMessageHandler");
 
         browser.loadUrl("file:///android_asset/dist/loleaflet.html?file_path=" 
+
                 "file:///android_asset/dist/hello-world.odt" + // TODO the 
real URL here
@@ -53,6 +56,27 @@ public class MainActivity extends AppCompatActivity {
         System.loadLibrary("androidapp");
     }
     public native void createLOOLWSD();
+
+    /** Passing messages from JS (instead of the websocket communication). */
+    @JavascriptInterface
+    public void postMobileMessage(String message)
+    {
+        Log.d(TAG, "postMobileMessage: " + message);
+    }
+
+    /** Passing messages from JS (instead of the websocket communication). */
+    @JavascriptInterface
+    public void postMobileError(String message)
+    {
+        Log.d(TAG, "postMobileError: " + message);
+    }
+
+    /** Passing messages from JS (instead of the websocket communication). */
+    @JavascriptInterface
+    public void postMobileDebug(String message)
+    {
+        Log.d(TAG, "postMobileDebug: " + message);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index fbfa87b03..8c8eadd50 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -178,17 +178,30 @@ ifelse(MOBILEAPP,[true],
 dnl# For use in conditionals in JS: window.ThisIsAMobileApp, 
window.ThisIsTheiOSApp,
 dnl# and window.ThisIsTheGtkApp
 ifelse(MOBILEAPP,[true],
-  [window.ThisIsAMobileApp = true;
-   window.MobileAppName='MOBILEAPPNAME'],
-  [window.ThisIsAMobileApp = false;]
+  [   window.ThisIsAMobileApp = true;
+   window.MobileAppName='MOBILEAPPNAME';],
+  [   window.ThisIsAMobileApp = false;]
 )
 ifelse(IOSAPP,[true],
-  [window.ThisIsTheiOSApp = true;],
-  [window.ThisIsTheiOSApp = false;]
+  [   window.ThisIsTheiOSApp = true;
+   window.postMobileMessage = function(msg) { 
window.webkit.messageHandlers.lool.postMessage.postMessage(msg, '*'); };
+   window.postMobileError   = function(msg) { 
window.webkit.messageHandlers.error.postMessage(msg, '*'); };
+   window.postMobileDebug   = function(msg) { 
window.webkit.messageHandlers.debug.postMessage(msg, '*'); };],
+  [   window.ThisIsTheiOSApp = false;]
 )
 ifelse(GTKAPP,[true],
-  [window.ThisIsTheGtkApp = true;],
-  [window.ThisIsTheGtkApp = false;]
+  [   window.ThisIsTheGtkApp = true;
+   window.postMobileMessage = function(msg) { 
window.webkit.messageHandlers.lool.postMessage.postMessage(msg, '*'); };
+   window.postMobileError   = function(msg) { 
window.webkit.messageHandlers.error.postMessage(msg, '*'); };
+   window.postMobileDebug   = function(msg) { 
window.webkit.messageHandlers.debug.postMessage(msg, '*'); };],
+  [   window.ThisIsTheGtkApp = false;]
+)
+ifelse(ANDROIDAPP,[true],
+  [   window.ThisIsTheAndroidApp = true;
+   window.postMobileMessage = function(msg) { 
window.LOOLMessageHandler.postMobileMessage(msg); };
+   window.postMobileError   = function(msg) { 
window.LOOLMessageHandler.postMobileError(msg); };
+   window.postMobileDebug   = function(msg) { 
window.LOOLMessageHandler.postMobileDebug(msg); };],
+  [   window.ThisIsTheAndroidApp = false;]
 )
   </script>
 
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index c7fed9b39..53f58d659 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -33,14 +33,14 @@ global._ = function (string) {
        if (window.ThisIsTheiOSApp) {
                // We use another approach just for iOS for now.
                if (window.LOCALIZATIONS.hasOwnProperty(string)) {
-                       // window.webkit.messageHandlers.debug.postMessage('_(' 
+ string + '): YES: ' + window.LOCALIZATIONS[string]);
+                       // window.postMobileDebug('_(' + string + '): YES: ' + 
window.LOCALIZATIONS[string]);
                        var result = window.LOCALIZATIONS[string];
                        if (window.LANG === 'de-CH') {
                                result = result.replace(/ß/g, 'ss');
                        }
                        return result;
                } else {
-                       // window.webkit.messageHandlers.debug.postMessage('_(' 
+ string + '): NO');
+                       // window.postMobileDebug('_(' + string + '): NO');
                        return string;
                }
        } else if (window.ThisIsAMobileApp) {
diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js
index b6673b5e0..a90b5169c 100644
--- a/loleaflet/js/toolbar.js
+++ b/loleaflet/js/toolbar.js
@@ -291,7 +291,7 @@ function onClick(e, id, item, subItem) {
        }
        else if (id === 'close' || id === 'closemobile') {
                if (window.ThisIsAMobileApp) {
-                       window.webkit.messageHandlers.lool.postMessage('BYE', 
'*');
+                       window.postMobileMessage('BYE');
                } else {
                        map.fire('postMessage', {msgId: 'close', args: 
{EverModified: map._everModified, Deprecated: true}});
                        map.fire('postMessage', {msgId: 'UI_Close', args: 
{EverModified: map._everModified}});
diff --git a/loleaflet/src/control/Control.Menubar.js 
b/loleaflet/src/control/Control.Menubar.js
index 8e2c7b680..2c3d45b2a 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -772,7 +772,7 @@ L.Control.Menubar = L.Control.extend({
                        this._map.fire('postMessage', {msgId: 
'UI_FileVersions'});
                } else if (id === 'closedocument') {
                        if (window.ThisIsAMobileApp) {
-                               
window.webkit.messageHandlers.lool.postMessage('BYE', '*');
+                               window.postMobileMessage('BYE');
                        } else {
                                this._map.fire('postMessage', {msgId: 'close', 
args: {EverModified: this._map._everModified, Deprecated: true}});
                                this._map.fire('postMessage', {msgId: 
'UI_Close', args: {EverModified: this._map._everModified}});
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 741cfe3a7..19c49ddef 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -29,7 +29,7 @@ FakeWebSocket.prototype.close = function() {
 
 FakeWebSocket.prototype.send = function(data) {
        this.sendCounter++;
-       window.webkit.messageHandlers.lool.postMessage(data, '*');
+       window.postMobileMessage(data);
 }
 
 L.Socket = L.Class.extend({
@@ -95,7 +95,7 @@ L.Socket = L.Class.extend({
                        // map.options.doc, as in the websocketURI above? On 
the other hand, the app
                        // code that handles this special message knows the 
document to be edited
                        // anyway, and can send it on as necessary to the 
Online code.
-                       window.webkit.messageHandlers.lool.postMessage('HULLO', 
'*');
+                       window.postMobileMessage('HULLO');
                        // A FakeWebSocket is immediately open.
                        this.socket.onopen();
                }
diff --git a/loleaflet/src/map/handler/Map.FileInserter.js 
b/loleaflet/src/map/handler/Map.FileInserter.js
index 63c94a63e..91a51e786 100644
--- a/loleaflet/src/map/handler/Map.FileInserter.js
+++ b/loleaflet/src/map/handler/Map.FileInserter.js
@@ -85,15 +85,15 @@ L.Map.FileInserter = L.Handler.extend({
                                        for (var i = 0; i < byteBuffer.length; 
i++) {
                                                strBytes += 
String.fromCharCode(byteBuffer[i]);
                                        }
-                                       
window.webkit.messageHandlers.lool.postMessage('insertfile name=' + aFile.name 
+ ' type=graphic' +
+                                       window.postMobileMessage('insertfile 
name=' + aFile.name + ' type=graphic' +
                                                                                
       ' data=' + window.btoa(strBytes));
                                };
                        })(file);
                        reader.onerror = function(e) {
-                               
window.webkit.messageHandlers.error.postMessage('Error when reading file: ' + 
e);
+                               window.postMobileError('Error when reading 
file: ' + e);
                        };
                        reader.onprogress = function(e) {
-                               
window.webkit.messageHandlers.debug.postMessage('FileReader progress: ' + 
Math.round(e.loaded*100 / e.total) + '%');
+                               window.postMobileDebug('FileReader progress: ' 
+ Math.round(e.loaded*100 / e.total) + '%');
                        };
                        reader.readAsArrayBuffer(file);
                } else {
diff --git a/loleaflet/util/create-l10n-all-js.pl 
b/loleaflet/util/create-l10n-all-js.pl
index 293cdb1e9..013f340b3 100644
--- a/loleaflet/util/create-l10n-all-js.pl
+++ b/loleaflet/util/create-l10n-all-js.pl
@@ -30,7 +30,7 @@ sub insert($) {
 
 print "\
 window.LANG = window.getParameterByName('lang');
-window.webkit.messageHandlers.debug.postMessage('LANG is ' + window.LANG);
+window.postMobileDebug('LANG is ' + window.LANG);
 
 var onlylang = window.LANG;
 var hyphen = onlylang.indexOf('-');
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to