android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java | 153 ++++------ 1 file changed, 74 insertions(+), 79 deletions(-)
New commits: commit 89a75eee710208f4997d052c272c12c22405496b Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jan 15 21:08:26 2020 +0100 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Thu Jan 16 00:59:15 2020 +0100 android: clipboard is sync. so exec. in the thread is not needed As we changed the clipboard to be synchronous now, it's not needed to execute copy/cut/paste actions in a separate thread anymore. Also change WebView message interception, so we can execute actions after a we send WebView a message. This is needed when we copy/cut something and need to push the content to the android clipboard and clipboard file. Change-Id: I08b6ee55ca8bd7b958d348e257c19395ea39ac80 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/86882 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Michael Meeks <michael.me...@collabora.com> Tested-by: Michael Meeks <michael.me...@collabora.com> diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java index 7698c9368..9c7729ef9 100644 --- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java +++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java @@ -520,8 +520,11 @@ public class LOActivity extends AppCompatActivity { public void postMobileMessage(String message) { Log.d(TAG, "postMobileMessage: " + message); - if (interceptMsgFromWebView(message)) { + String[] messageAndParameterArray= message.split(" ", 2); // the command and the rest (that can potentially contain spaces too) + + if (beforeMessageFromWebView(messageAndParameterArray)) { postMobileMessageNative(message); + afterMessageFromWebView(messageAndParameterArray); } // Going back to document browser on BYE (called when pressing the top left exit button) @@ -568,8 +571,7 @@ public class LOActivity extends AppCompatActivity { /** * return true to pass the message to the native part or false to block the message */ - boolean interceptMsgFromWebView(String message) { - String[] messageAndParam = message.split(" ", 2); // the command and the rest (that can potentially contain spaces too) + private boolean beforeMessageFromWebView(String[] messageAndParam) { switch (messageAndParam[0]) { case "PRINT": mainHandler.post(new Runnable() { @@ -589,10 +591,6 @@ public class LOActivity extends AppCompatActivity { switch (messageAndParam[1]) { case ".uno:Paste": return performPaste(); - case ".uno:Copy": - case ".uno:Cut": - populateClipboard(); - break; default: break; } @@ -630,6 +628,23 @@ public class LOActivity extends AppCompatActivity { return true; } + private void afterMessageFromWebView(String[] messageAndParameterArray) { + switch (messageAndParameterArray[0]) { + case "uno": + switch (messageAndParameterArray[1]) { + case ".uno:Copy": + case ".uno:Cut": + populateClipboard(); + break; + default: + break; + } + break; + default: + break; + } + } + private void initiatePrint() { PrintManager printManager = (PrintManager) getSystemService(PRINT_SERVICE); PrintDocumentAdapter printAdapter = new PrintAdapter(LOActivity.this); @@ -689,45 +704,39 @@ public class LOActivity extends AppCompatActivity { /// Needs to be executed after the .uno:Copy / Paste has executed public final void populateClipboard() { - /// FIXME: in theory we can do better with URIs to temporary files and so on... - nativeHandler.post(new Runnable() { - @Override - public void run() { - File clipboardFile = new File(getApplicationContext().getCacheDir(), CLIPBOARD_FILE_PATH); - if (clipboardFile.exists()) - clipboardFile.delete(); - - LokClipboardData clipboardData = new LokClipboardData(); - if (!LOActivity.this.getClipboardContent(clipboardData)) - Log.e(TAG, "no clipboard to copy"); - else - { - clipboardData.writeToFile(clipboardFile); - - String text = clipboardData.getText(); - String html = clipboardData.getHtml(); - - if (html != null) { - int idx = html.indexOf("<meta name=\"generator\" content=\""); - - if (idx < 0) - idx = html.indexOf("<meta http-equiv=\"content-type\" content=\"text/html;"); - - if (idx >= 0) { // inject our magic - StringBuffer newHtml = new StringBuffer(html); - newHtml.insert(idx, "<meta name=\"origin\" content=\"" + getClipboardMagic() + "\"/>\n"); - html = newHtml.toString(); - } - - if (text == null || text.length() == 0) - Log.i(TAG, "set text to clipoard with: text '" + text + "' and html '" + html + "'"); - - clipData = ClipData.newHtmlText(ClipDescription.MIMETYPE_TEXT_HTML, text, html); - clipboardManager.setPrimaryClip(clipData); - } - } + File clipboardFile = new File(getApplicationContext().getCacheDir(), CLIPBOARD_FILE_PATH); + if (clipboardFile.exists()) + clipboardFile.delete(); + + LokClipboardData clipboardData = new LokClipboardData(); + if (!LOActivity.this.getClipboardContent(clipboardData)) + Log.e(TAG, "no clipboard to copy"); + else + { + clipboardData.writeToFile(clipboardFile); + + String text = clipboardData.getText(); + String html = clipboardData.getHtml(); + + if (html != null) { + int idx = html.indexOf("<meta name=\"generator\" content=\""); + + if (idx < 0) + idx = html.indexOf("<meta http-equiv=\"content-type\" content=\"text/html;"); + + if (idx >= 0) { // inject our magic + StringBuffer newHtml = new StringBuffer(html); + newHtml.insert(idx, "<meta name=\"origin\" content=\"" + getClipboardMagic() + "\"/>\n"); + html = newHtml.toString(); } - }); + + if (text == null || text.length() == 0) + Log.i(TAG, "set text to clipoard with: text '" + text + "' and html '" + html + "'"); + + clipData = ClipData.newHtmlText(ClipDescription.MIMETYPE_TEXT_HTML, text, html); + clipboardManager.setPrimaryClip(clipData); + } + } } /// Do the paste, and return true if we should short-circuit the paste locally @@ -746,47 +755,33 @@ public class LOActivity extends AppCompatActivity { return true; } else { Log.i(TAG, "clipboard comes from us - other instance: paste from clipboard file"); - nativeHandler.post(new Runnable() { - @Override - public void run() { - File clipboardFile = new File(getApplicationContext().getCacheDir(), CLIPBOARD_FILE_PATH); - LokClipboardData clipboardData = null; - if (clipboardFile.exists()) { - clipboardData = new LokClipboardData(); - clipboardData.loadFromFile(clipboardFile); - } - if (clipboardData != null) { - LOActivity.this.setClipboardContent(clipboardData); - LOActivity.this.postUnoCommand(".uno:Paste", null, false); - } else { - // Couldn't get data from the clipboard file, but we can still paste html - byte[] htmlByteArray = html.getBytes(Charset.forName("UTF-8")); - LOActivity.this.paste("text/html", htmlByteArray); - } - } - }); - } - } else { - Log.i(TAG, "foreign html '" + html + "'"); - nativeHandler.post(new Runnable() { - @Override - public void run() { + + File clipboardFile = new File(getApplicationContext().getCacheDir(), CLIPBOARD_FILE_PATH); + LokClipboardData clipboardData = null; + if (clipboardFile.exists()) { + clipboardData = new LokClipboardData(); + clipboardData.loadFromFile(clipboardFile); + } + if (clipboardData != null) { + LOActivity.this.setClipboardContent(clipboardData); + LOActivity.this.postUnoCommand(".uno:Paste", null, false); + } else { + // Couldn't get data from the clipboard file, but we can still paste html byte[] htmlByteArray = html.getBytes(Charset.forName("UTF-8")); LOActivity.this.paste("text/html", htmlByteArray); } - }); + } + } else { + Log.i(TAG, "foreign html '" + html + "'"); + byte[] htmlByteArray = html.getBytes(Charset.forName("UTF-8")); + LOActivity.this.paste("text/html", htmlByteArray); } } else if (clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { final ClipData.Item clipItem = clipData.getItemAt(0); - nativeHandler.post(new Runnable() { - @Override - public void run() { - String text = clipItem.getText().toString(); - byte[] textByteArray = text.getBytes(Charset.forName("UTF-16")); - LOActivity.this.paste("text/plain;charset=utf-16", textByteArray); - } - }); + String text = clipItem.getText().toString(); + byte[] textByteArray = text.getBytes(Charset.forName("UTF-16")); + LOActivity.this.paste("text/plain;charset=utf-16", textByteArray); } } return false; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits