summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-01-28 13:50:40 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-02-09 08:09:26 +0100
commit17a5b8b8ec0ed706eddb1f7ddebc76dccee79918 (patch)
treeca5f9be4c491b05db5ef158b37e1cd510467054e /android
parentdd6e502745e9002d90c91f4c64642673d5a4d791 (diff)
android: key press to key event, use InputConnectionHandler
Change key press event in LOEvent to a more general key event to support key release. Use InputConnectionHandler to react on key events, create LOKitInputConnectionHandler as the implementation for LOKit. Change-Id: I4282aa06cdd85ad4d80330f4d2a9c43eb67df30a
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java7
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java41
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java9
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java8
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java29
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java11
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java5
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java8
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java4
9 files changed, 94 insertions, 28 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index 11bd72d511e7..a9600ea2433f 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -19,7 +19,7 @@ public class LOEvent implements Comparable<LOEvent> {
public static final int THUMBNAIL = 8;
public static final int TILE_RERENDER = 9;
public static final int TOUCH = 10;
- public static final int KEY_PRESS = 11;
+ public static final int KEY_EVENT = 11;
public final int mType;
public int mPriority = 0;
@@ -35,6 +35,7 @@ public class LOEvent implements Comparable<LOEvent> {
public String mTouchType;
public MotionEvent mMotionEvent;
public PointF mDocumentTouchCoordinate;
+ public String mKeyEventType;
public KeyEvent mKeyEvent;
public LOEvent(int type) {
@@ -91,8 +92,10 @@ public class LOEvent implements Comparable<LOEvent> {
mDocumentTouchCoordinate = documentTouchCoordinate;
}
- public LOEvent(int type, KeyEvent keyEvent) {
+ public LOEvent(int type, String keyEventType, KeyEvent keyEvent) {
mType = type;
+ mTypeString = "KeyEvent";
+ mKeyEventType = keyEventType;
mKeyEvent = keyEvent;
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java
new file mode 100644
index 000000000000..a63b28d7750a
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java
@@ -0,0 +1,41 @@
+package org.libreoffice;
+
+import android.view.KeyEvent;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputConnection;
+
+import org.mozilla.gecko.gfx.InputConnectionHandler;
+
+public class LOKitInputConnectionHandler implements InputConnectionHandler {
+ @Override
+ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
+ return null;
+ }
+
+ @Override
+ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
+ return false;
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ LOKitShell.sendKeyPressEvent(event);
+ return true;
+ }
+
+ @Override
+ public boolean onKeyLongPress(int keyCode, KeyEvent event) {
+ return false;
+ }
+
+ @Override
+ public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
+ return false;
+ }
+
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
+ LOKitShell.sendKeyReleaseEvent(event);
+ return false;
+ }
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index 0f606edff56d..dcb266c3440e 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -81,7 +81,14 @@ public class LOKitShell {
* Send key press event to LOKitThread.
*/
public static void sendKeyPressEvent(KeyEvent event) {
- LOKitShell.sendEvent(new LOEvent(LOEvent.KEY_PRESS, event));
+ LOKitShell.sendEvent(new LOEvent(LOEvent.KEY_EVENT, "KeyPress", event));
+ }
+
+ /**
+ * Send key release event to LOKitThread.
+ */
+ public static void sendKeyReleaseEvent(KeyEvent event) {
+ LOKitShell.sendEvent(new LOEvent(LOEvent.KEY_EVENT, "KeyRelease", event));
}
public static boolean isEditingEnabled() {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index a185d793c89b..c8bcc23d76a3 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -153,11 +153,15 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
}
touch(event.mTouchType, event.mMotionEvent, event.mDocumentTouchCoordinate);
break;
- case LOEvent.KEY_PRESS:
+ case LOEvent.KEY_EVENT:
if (!LOKitShell.isEditingEnabled()) {
return;
}
- mTileProvider.keyPress(event.mKeyEvent);
+ if (event.mKeyEventType == "KeyPress") {
+ mTileProvider.keyPress(event.mKeyEvent);
+ } else if (event.mKeyEventType.equals("KeyRelease")) {
+ mTileProvider.keyRelease(event.mKeyEvent);
+ }
break;
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 1ace50f408d0..357fa032861e 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -277,24 +277,29 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
this.tileInvalidationCallback = tileInvalidationCallback;
}
- @Override
- public void keyPress(KeyEvent keyEvent) {
- int code = 0;
+ private int getKeyCode(KeyEvent keyEvent) {
switch (keyEvent.getKeyCode())
{
- case KeyEvent.KEYCODE_DEL:
- code = com.sun.star.awt.Key.BACKSPACE;
- break;
- case KeyEvent.KEYCODE_ENTER:
- code = com.sun.star.awt.Key.RETURN;
- break;
- default:
- code = keyEvent.getUnicodeChar();
- break;
+ case KeyEvent.KEYCODE_DEL:
+ return com.sun.star.awt.Key.BACKSPACE;
+ case KeyEvent.KEYCODE_ENTER:
+ return com.sun.star.awt.Key.RETURN;
}
+ return keyEvent.getUnicodeChar();
+ }
+
+ @Override
+ public void keyPress(KeyEvent keyEvent) {
+ int code = getKeyCode(keyEvent);
mOffice.postKeyEvent(Office.KEY_PRESS, code);
}
+ @Override
+ public void keyRelease(KeyEvent keyEvent) {
+ int code = getKeyCode(keyEvent);
+ mOffice.postKeyEvent(Office.KEY_RELEASE, code);
+ }
+
private void mouseButton(int type, PointF inDocument) {
int x = (int) pixelToTwip(inDocument.x, mDPI);
int y = (int) pixelToTwip(inDocument.y, mDPI);
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 1b2032806d0b..bca8230d2458 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -128,6 +128,7 @@ public class LibreOfficeMainActivity extends LOAbout {
mLayerClient.setZoomConstraints(new ZoomConstraints(true));
LayerView layerView = (LayerView) findViewById(R.id.layer_view);
mLayerClient.setView(layerView);
+ layerView.setInputConnectionHandler(new LOKitInputConnectionHandler());
mLayerClient.notifyReady();
}
@@ -238,16 +239,6 @@ public class LibreOfficeMainActivity extends LOAbout {
mDrawerLayout.closeDrawer(mDrawerList);
}
}
-
-
- /**
- * Listen to key presses and send event to LOK.
- */
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- LOKitShell.sendKeyPressEvent(event);
- return super.onKeyDown(keyCode, event);
- }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
index f68678af2e2b..006ae90fb302 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
@@ -93,6 +93,11 @@ public class MockTileProvider implements TileProvider {
}
@Override
+ public void keyRelease(KeyEvent keyEvent) {
+
+ }
+
+ @Override
public void mouseButtonDown(PointF inDocument) {
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
index a411879a5bef..759ecadac027 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
@@ -63,11 +63,17 @@ public interface TileProvider {
/**
* Trigger a key press.
- * @param keyEvent - contains the
+ * @param keyEvent - contains information about key event
*/
void keyPress(KeyEvent keyEvent);
/**
+ * Trigger a key release.
+ * @param keyEvent - contains information about key event
+ */
+ void keyRelease(KeyEvent keyEvent);
+
+ /**
* Trigger a mouse button down event.
* @param documentCoordinate - coordinate relative to the document where the mouse button should be triggered
*/
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
index 167da849628e..345fa4da7b0d 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
@@ -147,6 +147,10 @@ public class LayerView extends FrameLayout {
});
}
+ public void setInputConnectionHandler(InputConnectionHandler inputConnectionHandler) {
+ mInputConnectionHandler = inputConnectionHandler;
+ }
+
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {