[Libreoffice-commits] core.git: android/Bootstrap android/source desktop/source
Mert Tümer
merttumer7 at gmail.com
Tue Mar 13 23:35:47 UTC 2018
android/Bootstrap/src/org/libreoffice/kit/Document.java | 15 ++
android/source/res/drawable/ic_content_copy_black_24dp.xml | 9 +
android/source/res/drawable/ic_content_cut_black_24dp.xml | 9 +
android/source/res/drawable/ic_content_paste_black_24dp.xml | 9 +
android/source/res/menu/main.xml | 29 ++++
android/source/res/values/strings.xml | 7 +
android/source/src/java/org/libreoffice/InvalidationHandler.java | 3
android/source/src/java/org/libreoffice/LOKitTileProvider.java | 21 +++
android/source/src/java/org/libreoffice/TileProvider.java | 13 +
android/source/src/java/org/libreoffice/ToolbarController.java | 70 ++++++++++
desktop/source/lib/lokandroid.cxx | 17 ++
11 files changed, 202 insertions(+)
New commits:
commit 31e939c9f4b29fb2b2e63eb096450cf3da35d67f
Author: Mert Tümer <merttumer7 at gmail.com>
Date: Mon Mar 5 02:39:36 2018 +0300
tdf#96796 - Added clipboard actions for the Android Viewer
Change-Id: I2779ef9a9f68dcf08c3072ffe83b9f2450b7257e
Signed-off-by: Mert Tümer <merttumer7 at gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/50757
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 6a1f402970ea..f0c5e7a6f99a 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -232,6 +232,21 @@ public class Document {
public native void setGraphicSelection(int type, int x, int y);
/**
+ * Get selected text
+ * @param mimeType
+ * @return
+ */
+ public native String getTextSelection(String mimeType);
+
+ /**
+ * paste
+ * @param mimeType
+ * @param data
+ * @return
+ */
+ public native boolean paste(String mimeType, String data);
+
+ /**
* Reset current (any kind of) selection.
*/
public native void resetSelection();
diff --git a/android/source/res/drawable/ic_content_copy_black_24dp.xml b/android/source/res/drawable/ic_content_copy_black_24dp.xml
new file mode 100644
index 000000000000..8a894a3bcd73
--- /dev/null
+++ b/android/source/res/drawable/ic_content_copy_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/>
+</vector>
diff --git a/android/source/res/drawable/ic_content_cut_black_24dp.xml b/android/source/res/drawable/ic_content_cut_black_24dp.xml
new file mode 100644
index 000000000000..1c0f96a37b42
--- /dev/null
+++ b/android/source/res/drawable/ic_content_cut_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M9.64,7.64c0.23,-0.5 0.36,-1.05 0.36,-1.64 0,-2.21 -1.79,-4 -4,-4S2,3.79 2,6s1.79,4 4,4c0.59,0 1.14,-0.13 1.64,-0.36L10,12l-2.36,2.36C7.14,14.13 6.59,14 6,14c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4c0,-0.59 -0.13,-1.14 -0.36,-1.64L12,14l7,7h3v-1L9.64,7.64zM6,8c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM6,20c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM12,12.5c-0.28,0 -0.5,-0.22 -0.5,-0.5s0.22,-0.5 0.5,-0.5 0.5,0.22 0.5,0.5 -0.22,0.5 -0.5,0.5zM19,3l-6,6 2,2 7,-7L22,3z"/>
+</vector>
diff --git a/android/source/res/drawable/ic_content_paste_black_24dp.xml b/android/source/res/drawable/ic_content_paste_black_24dp.xml
new file mode 100644
index 000000000000..a902d9a856a0
--- /dev/null
+++ b/android/source/res/drawable/ic_content_paste_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z"/>
+</vector>
diff --git a/android/source/res/menu/main.xml b/android/source/res/menu/main.xml
index 229c20aed68c..7fba5f46e380 100644
--- a/android/source/res/menu/main.xml
+++ b/android/source/res/menu/main.xml
@@ -47,6 +47,35 @@
android:enabled="false" />
</group>
+ <group android:id="@+id/group_edit_clipboard"
+ android:visible="false"
+ tools:visible="true">
+
+ <item android:id="@+id/action_back"
+ android:title="@string/action_back"
+ app:showAsAction="always"
+ android:icon="@drawable/ic_arrow_back_black_24dp"
+ android:orderInCategory="1"/>
+
+ <item android:id="@+id/action_copy"
+ android:title="@string/action_copy"
+ app:showAsAction="always"
+ android:icon="@drawable/ic_content_copy_black_24dp"
+ android:orderInCategory="2"/>
+
+ <item android:id="@+id/action_cut"
+ android:title="@string/action_cut"
+ app:showAsAction="always"
+ android:icon="@drawable/ic_content_cut_black_24dp"
+ android:orderInCategory="3"/>
+
+ <item android:id="@+id/action_paste"
+ android:title="@string/action_paste"
+ app:showAsAction="always"
+ android:icon="@drawable/ic_content_paste_black_24dp"
+ android:orderInCategory="4"/>
+
+ </group>
<item android:id="@+id/action_search"
android:title="@string/action_search"
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index 2e885fee5e1a..2a4ca0ab4e21 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -173,4 +173,11 @@
<string name="compress_photo_no_compress">Don\'t Compress</string>
<string name="compress_photo_title">Do you want to compress the photo?</string>
+ <!-- Clipboard Actions -->
+ <string name="action_copy">Copy</string>
+ <string name="action_paste">Paste</string>
+ <string name="action_cut">Cut</string>
+ <string name="action_back">Back</string>
+ <string name="action_text_copied">Text copied to the clipboard</string>
+
</resources>
diff --git a/android/source/src/java/org/libreoffice/InvalidationHandler.java b/android/source/src/java/org/libreoffice/InvalidationHandler.java
index 5dcb572af6c4..6c582550ff81 100644
--- a/android/source/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java
@@ -443,6 +443,7 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes
if (mContext.isSpreadsheet()) {
mDocumentOverlay.showHeaderSelection(null);
}
+ mContext.getToolbarController().showHideClipboardCutAndCopy(false);
} else {
List<RectF> rectangles = convertPayloadToRectangles(payload);
if (mState != OverlayState.SELECTION) {
@@ -453,6 +454,8 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes
if (mContext.isSpreadsheet()) {
mDocumentOverlay.showHeaderSelection(rectangles.get(0));
}
+ String selectedText = mContext.getTileProvider().getTextSelection("");
+ mContext.getToolbarController().showClipboardActions(selectedText);
}
}
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index be16d8d1ebbe..24456ebf9cb1 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -598,6 +598,27 @@ class LOKitTileProvider implements TileProvider {
}
/**
+ * @param mimeType
+ * @return
+ */
+ @Override
+ public String getTextSelection(String mimeType) {
+ return mDocument.getTextSelection(mimeType);
+ }
+
+ /**
+ * paste
+ * @param mimeType
+ * @param data
+ * @return
+ */
+ @Override
+ public boolean paste(String mimeType, String data) {
+ return mDocument.paste(mimeType, data);
+ }
+
+
+ /**
* @see org.libreoffice.TileProvider#setGraphicSelectionStart(android.graphics.PointF)
*/
@Override
diff --git a/android/source/src/java/org/libreoffice/TileProvider.java b/android/source/src/java/org/libreoffice/TileProvider.java
index e84127cb0715..609fb62c708a 100644
--- a/android/source/src/java/org/libreoffice/TileProvider.java
+++ b/android/source/src/java/org/libreoffice/TileProvider.java
@@ -135,6 +135,19 @@ public interface TileProvider {
void setTextSelectionEnd(PointF documentCoordinate);
/**
+ * get selected text
+ * @param mimeType
+ */
+ String getTextSelection(String mimeType);
+
+ /**
+ * copy
+ * @param mimeType
+ * @param data
+ * @return
+ */
+ boolean paste(String mimeType, String data);
+ /**
* Send text selection reset coordinate.
* @param documentCoordinate
*/
diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java
index 87a84f0878d1..21e3e5ca7be2 100644
--- a/android/source/src/java/org/libreoffice/ToolbarController.java
+++ b/android/source/src/java/org/libreoffice/ToolbarController.java
@@ -8,8 +8,12 @@
*/
package org.libreoffice;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
@@ -25,6 +29,9 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
private final Menu mMainMenu;
private boolean isEditModeOn = false;
+ private String clipboardText = null;
+ ClipboardManager clipboardManager;
+ ClipData clipData;
public ToolbarController(LibreOfficeMainActivity context, Toolbar toolbarTop) {
mToolbarTop = toolbarTop;
@@ -35,6 +42,7 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
switchToViewMode();
mMainMenu = mToolbarTop.getMenu();
+ clipboardManager = (ClipboardManager)mContext.getSystemService(Context.CLIPBOARD_SERVICE);
}
public void disableMenuItem(final int menuItemId, final boolean disabled) {
@@ -78,6 +86,48 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
}
/**
+ * Show clipboard Actions on the toolbar
+ * */
+ void showClipboardActions(final String value){
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ if(value != null){
+ mMainMenu.setGroupVisible(R.id.group_edit_actions, false);
+ mMainMenu.setGroupVisible(R.id.group_edit_clipboard, true);
+ if(getEditModeStatus()){
+ showHideClipboardCutAndCopy(true);
+ } else {
+ mMainMenu.findItem(R.id.action_cut).setVisible(false);
+ mMainMenu.findItem(R.id.action_paste).setVisible(false);
+ }
+ clipboardText = value;
+ }
+ }
+ });
+ }
+
+ void hideClipboardActions(){
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ mMainMenu.setGroupVisible(R.id.group_edit_actions, getEditModeStatus());
+ mMainMenu.setGroupVisible(R.id.group_edit_clipboard, false);
+ }
+ });
+ }
+
+ void showHideClipboardCutAndCopy(final boolean option){
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ mMainMenu.findItem(R.id.action_copy).setVisible(option);
+ mMainMenu.findItem(R.id.action_cut).setVisible(option);
+ }
+ });
+ }
+
+ /**
* Change the toolbar to view mode.
*/
void switchToViewMode() {
@@ -141,6 +191,26 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
case R.id.action_add_worksheet:
mContext.addPart();
return true;
+ case R.id.action_back:
+ hideClipboardActions();
+ return true;
+ case R.id.action_copy:
+ LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Copy"));
+ clipData = ClipData.newPlainText("clipboard data", clipboardText);
+ clipboardManager.setPrimaryClip(clipData);
+ Toast.makeText(mContext, mContext.getResources().getString(R.string.action_text_copied), Toast.LENGTH_SHORT).show();
+ return true;
+ case R.id.action_paste:
+ clipData = clipboardManager.getPrimaryClip();
+ ClipData.Item clipItem = clipData.getItemAt(0);
+ mContext.setDocumentChanged(true);
+ return mContext.getTileProvider().paste("text/plain;charset=utf-16", clipItem.getText().toString());
+ case R.id.action_cut:
+ clipData = ClipData.newPlainText("clipboard data", clipboardText);
+ clipboardManager.setPrimaryClip(clipData);
+ LOKitShell.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
+ mContext.setDocumentChanged(true);
+ return true;
}
return false;
}
diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index b85619d3dad8..43286a93aea0 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -370,6 +370,23 @@ extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Document_getT
return pEnv->NewStringUTF(pSelection);
}
+extern "C" SAL_JNI_EXPORT jboolean JNICALL Java_org_libreoffice_kit_Document_paste
+ (JNIEnv* pEnv, jobject aObject, jstring mimeType, jstring data)
+{
+ LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
+
+ const char* pMimeType = pEnv->GetStringUTFChars(mimeType, NULL);
+ const char* pData = pEnv->GetStringUTFChars(data, NULL);
+ const size_t nSize = pEnv->GetStringLength(data);
+
+ LibreOfficeKitDocumentClass* pcls = pDocument->pClass;
+ bool result = pcls->paste(pDocument, pMimeType, pData, nSize);
+ pEnv->ReleaseStringUTFChars(mimeType, pMimeType);
+ pEnv->ReleaseStringUTFChars(pData, data);
+
+ return result;
+}
+
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setGraphicSelection
(JNIEnv* pEnv, jobject aObject, jint type, jint x, jint y)
{
More information about the Libreoffice-commits
mailing list