summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMert Tümer <merttumer7@gmail.com>2018-03-14 19:19:56 +0300
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2018-03-15 00:28:31 +0100
commite5bc7fa4e83b33fc3eee343e560a4f8cb91eacd6 (patch)
treeb58bf53390777dfd79ab36c62cd2d437625ad114 /android
parentb951cd126d0bcc950c71c069c7d2f4c210c4bcaf (diff)
tdf#96796 - Added clipboard actions for the Android Viewer
Change-Id: I52e134532ab70e765b6ccd929f189be84f9c9a90 Signed-off-by: Mert Tümer <merttumer7@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/51286 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'android')
-rw-r--r--android/Bootstrap/src/org/libreoffice/kit/Document.java15
-rw-r--r--android/source/res/drawable/ic_content_copy_black_24dp.xml9
-rw-r--r--android/source/res/drawable/ic_content_cut_black_24dp.xml9
-rw-r--r--android/source/res/drawable/ic_content_paste_black_24dp.xml9
-rw-r--r--android/source/res/menu/main.xml29
-rw-r--r--android/source/res/values/strings.xml7
-rw-r--r--android/source/src/java/org/libreoffice/InvalidationHandler.java3
-rw-r--r--android/source/src/java/org/libreoffice/LOKitTileProvider.java21
-rw-r--r--android/source/src/java/org/libreoffice/TileProvider.java13
-rw-r--r--android/source/src/java/org/libreoffice/ToolbarController.java70
10 files changed, 185 insertions, 0 deletions
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 e411770976c9..eb22f6c8f3d3 100644
--- a/android/source/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java
@@ -452,6 +452,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) {
@@ -462,6 +463,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 df5a7d780b78..4a8720cb9d01 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -604,6 +604,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 71c27146e6f1..10d578337680 100644
--- a/android/source/src/java/org/libreoffice/TileProvider.java
+++ b/android/source/src/java/org/libreoffice/TileProvider.java
@@ -136,6 +136,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;
}