[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - android/experimental
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Fri Jan 30 04:03:52 PST 2015
android/experimental/LOAndroid3/res/drawable/handle_end_level.xml | 14
android/experimental/LOAndroid3/res/drawable/handle_start_level.xml | 14
android/experimental/LOAndroid3/res/layout/text_selection_handles.xml | 4
android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java | 2
android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java | 6
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java | 146 ++--------
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java | 43 +-
7 files changed, 95 insertions(+), 134 deletions(-)
New commits:
commit f7c977ddc176cb45a577b09346565d493b3710c0
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Jan 30 20:59:05 2015 +0900
android: TextSelection improvements
Change-Id: I485976edda5e2bb41381ad3a90b8d2139ca7d5f4
diff --git a/android/experimental/LOAndroid3/res/drawable/handle_end_level.xml b/android/experimental/LOAndroid3/res/drawable/handle_end_level.xml
new file mode 100644
index 0000000..40a512b
--- /dev/null
+++ b/android/experimental/LOAndroid3/res/drawable/handle_end_level.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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/. -->
+
+<level-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <!-- LTR -->
+ <item android:maxLevel="0" android:drawable="@drawable/handle_end"/>
+
+ <!-- RTL -->
+ <item android:maxLevel="1" android:drawable="@drawable/handle_start"/>
+
+</level-list>
diff --git a/android/experimental/LOAndroid3/res/drawable/handle_start_level.xml b/android/experimental/LOAndroid3/res/drawable/handle_start_level.xml
new file mode 100644
index 0000000..2294513
--- /dev/null
+++ b/android/experimental/LOAndroid3/res/drawable/handle_start_level.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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/. -->
+
+<level-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <!-- LTR -->
+ <item android:maxLevel="0" android:drawable="@drawable/handle_start"/>
+
+ <!-- RTL -->
+ <item android:maxLevel="1" android:drawable="@drawable/handle_end"/>
+
+</level-list>
diff --git a/android/experimental/LOAndroid3/res/layout/text_selection_handles.xml b/android/experimental/LOAndroid3/res/layout/text_selection_handles.xml
index 1f0d816..c876b28 100644
--- a/android/experimental/LOAndroid3/res/layout/text_selection_handles.xml
+++ b/android/experimental/LOAndroid3/res/layout/text_selection_handles.xml
@@ -9,7 +9,7 @@
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/start_handle"
android:layout_width="@dimen/text_selection_handle_width"
android:layout_height="@dimen/text_selection_handle_height"
- android:src="@drawable/handle_start"
+ android:src="@drawable/handle_start_level"
android:visibility="gone"
gecko:handleType="start"/>
@@ -23,7 +23,7 @@
<org.mozilla.gecko.TextSelectionHandle android:id="@+id/end_handle"
android:layout_width="@dimen/text_selection_handle_width"
android:layout_height="@dimen/text_selection_handle_height"
- android:src="@drawable/handle_end"
+ android:src="@drawable/handle_end_level"
android:visibility="gone"
gecko:handleType="end"/>
</merge>
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 0bf9f1f..f416b45 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -11,6 +11,7 @@ import org.libreoffice.kit.Document;
import org.libreoffice.kit.LibreOfficeKit;
import org.libreoffice.kit.Office;
import org.mozilla.gecko.TextSelection;
+import org.mozilla.gecko.TextSelectionHandle;
import org.mozilla.gecko.gfx.BufferedCairoImage;
import org.mozilla.gecko.gfx.CairoImage;
import org.mozilla.gecko.gfx.GeckoLayerClient;
@@ -390,9 +391,10 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
Log.i(LOGTAG, "Invalidate visible cursor: " + payload);
RectF rect = convertCallbackMessageStringToRectF(payload);
if (rect != null) {
+ RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
- textSelection.positionHandle("MIDDLE", new RectF(rect.right,rect.bottom, rect.right, rect.bottom));
- textSelection.showHandle("MIDDLE");
+ textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, underSelection);
+ textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
}
break;
}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java
index f09e93a..241ce14 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java
@@ -16,6 +16,8 @@ import org.mozilla.gecko.gfx.Layer;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.util.FloatUtils;
+import static org.mozilla.gecko.TextSelectionHandle.HandleType.*;
+
public class TextSelection extends Layer {
private static final String LOGTAG = "GeckoTextSelection";
@@ -43,84 +45,6 @@ public class TextSelection extends Layer {
void destroy() {
}
- public void handleMessage(String event, JSONObject message) {
- try {
- if (event.equals("TextSelection:ShowHandles")) {
- final JSONArray handles = message.getJSONArray("handles");
- LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() {
- public void run() {
- try {
- for (int i=0; i < handles.length(); i++) {
- String handle = handles.getString(i);
-
- if (handle.equals("START"))
- mStartHandle.setVisibility(View.VISIBLE);
- else if (handle.equals("MIDDLE"))
- mMiddleHandle.setVisibility(View.VISIBLE);
- else
- mEndHandle.setVisibility(View.VISIBLE);
- }
-
- mViewLeft = 0.0f;
- mViewTop = 0.0f;
- mViewZoom = 0.0f;
- LayerView layerView = LOKitShell.getLayerView();
- if (layerView != null) {
- layerView.addLayer(TextSelection.this);
- }
- } catch(Exception e) {}
- }
- });
- } else if (event.equals("TextSelection:HideHandles")) {
- final JSONArray handles = message.getJSONArray("handles");
- LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() {
- public void run() {
- try {
- LayerView layerView = LOKitShell.getLayerView();
- if (layerView != null) {
- layerView.removeLayer(TextSelection.this);
- }
-
- for (int i=0; i < handles.length(); i++) {
- String handle = handles.getString(i);
- if (handle.equals("START"))
- mStartHandle.setVisibility(View.GONE);
- else if (handle.equals("MIDDLE"))
- mMiddleHandle.setVisibility(View.GONE);
- else
- mEndHandle.setVisibility(View.GONE);
- }
-
- } catch(Exception e) {}
- }
- });
- } else if (event.equals("TextSelection:PositionHandles")) {
- final JSONArray positions = message.getJSONArray("positions");
- LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() {
- public void run() {
- try {
- for (int i=0; i < positions.length(); i++) {
- JSONObject position = positions.getJSONObject(i);
- String handle = position.getString("handle");
- int left = position.getInt("left");
- int top = position.getInt("top");
-
- if (handle.equals("START"))
- mStartHandle.positionFromGecko(left, top);
- else if (handle.equals("MIDDLE"))
- mMiddleHandle.positionFromGecko(left, top);
- else
- mEndHandle.positionFromGecko(left, top);
- }
- } catch (Exception e) { }
- }
- });
- }
- } catch (Exception e) {
- Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
- }
- }
-
@Override
public void draw(final RenderContext context) {
// cache the relevant values from the context and bail out if they are the same. we do this
@@ -144,47 +68,49 @@ public class TextSelection extends Layer {
});
}
- public void showHandle(final String handleType) {
+ public void showHandle(final TextSelectionHandle.HandleType handleType) {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
- try {
- TextSelectionHandle handle;
- if (handleType.equals("START"))
- handle = mStartHandle;
- else if (handleType.equals("MIDDLE"))
- handle = mMiddleHandle;
- else
- handle = mEndHandle;
-
- handle.setVisibility(View.VISIBLE);
-
- mViewLeft = 0.0f;
- mViewTop = 0.0f;
- mViewZoom = 0.0f;
- LayerView layerView = LOKitShell.getLayerView();
- if (layerView != null) {
- layerView.addLayer(TextSelection.this);
- }
- } catch (Exception e) {
+ TextSelectionHandle handle = getHandle(handleType);
+
+ handle.setVisibility(View.VISIBLE);
+
+ mViewLeft = 0.0f;
+ mViewTop = 0.0f;
+ mViewZoom = 0.0f;
+ LayerView layerView = LOKitShell.getLayerView();
+ if (layerView != null) {
+ layerView.addLayer(TextSelection.this);
}
}
});
}
- public void positionHandle(final String handleType, final RectF position) {
+ private TextSelectionHandle getHandle(TextSelectionHandle.HandleType handleType) {
+ if (handleType == START) {
+ return mStartHandle;
+ } else if (handleType == MIDDLE) {
+ return mMiddleHandle;
+ } else {
+ return mEndHandle;
+ }
+ }
+
+ public void hideHandle(final TextSelectionHandle.HandleType handleType) {
+ LOKitShell.getMainHandler().post(new Runnable() {
+ public void run() {
+ TextSelectionHandle handle = getHandle(handleType);
+ handle.setVisibility(View.GONE);
+ }
+ });
+ }
+
+
+ public void positionHandle(final TextSelectionHandle.HandleType handleType, final RectF position) {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
- try {
- TextSelectionHandle handle;
- if (handleType.equals("START"))
- handle = mStartHandle;
- else if (handleType.equals("MIDDLE"))
- handle = mMiddleHandle;
- else
- handle = mEndHandle;
-
- handle.positionFromGecko((int) position.left, (int) position.top);
- } catch (Exception e) { }
+ TextSelectionHandle handle = getHandle(handleType);
+ handle.positionFromGecko((int) position.left, (int) position.top, false);
}
});
}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
index 92ca9d4..b554465 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
@@ -24,7 +24,7 @@ import android.widget.RelativeLayout;
public class TextSelectionHandle extends ImageView implements View.OnTouchListener {
private static final String LOGTAG = "GeckoTextSelectionHandle";
- private enum HandleType { START, MIDDLE, END };
+ public enum HandleType { START, MIDDLE, END };
private final HandleType mHandleType;
private final int mWidth;
@@ -33,12 +33,16 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
private int mLeft;
private int mTop;
+ private boolean mIsRTL;
private PointF mGeckoPoint;
private int mTouchStartX;
private int mTouchStartY;
private RelativeLayout.LayoutParams mLayoutParams;
+ private static final int IMAGE_LEVEL_LTR = 0;
+ private static final int IMAGE_LEVEL_RTL = 1;
+
public TextSelectionHandle(Context context, AttributeSet attrs) {
super(context, attrs);
setOnTouchListener(this);
@@ -53,6 +57,7 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
else
mHandleType = HandleType.END;
+ mIsRTL = false;
mGeckoPoint = new PointF(0.0f, 0.0f);
mWidth = getResources().getDimensionPixelSize(R.dimen.text_selection_handle_width);
@@ -99,13 +104,7 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
return;
}
// Send x coordinate on the right side of the start handle, left side of the end handle.
- float left = (float) mLeft;
- if (mHandleType.equals(HandleType.START))
- left += mWidth - mShadow;
- else if (mHandleType.equals(HandleType.MIDDLE))
- left += (float) ((mWidth - mShadow) / 2);
- else
- left += mShadow;
+ float left = (float) mLeft + adjustLeftForHandle();
PointF geckoPoint = new PointF(left, (float) mTop);
geckoPoint = layerView.getLayerClient().convertViewPointToLayerPoint(geckoPoint);
@@ -123,8 +122,7 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
setLayoutPosition();
}
- void positionFromGecko(int left, int top) {
- Log.i(LOGTAG, "positionFromGecko: " + left + " " + top);
+ void positionFromGecko(int left, int top, boolean rtl) {
LayerView layerView = LOKitShell.getLayerView();
if (layerView == null) {
Log.e(LOGTAG, "Can't position handle because layerView is null");
@@ -132,27 +130,34 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
}
mGeckoPoint = new PointF((float) left, (float) top);
+ if (mIsRTL != rtl) {
+ mIsRTL = rtl;
+ setImageLevel(mIsRTL ? IMAGE_LEVEL_RTL : IMAGE_LEVEL_LTR);
+ }
+
ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor);
}
void repositionWithViewport(float x, float y, float zoom) {
PointF viewPoint = new PointF((mGeckoPoint.x * zoom) - x,
- (mGeckoPoint.y * zoom) - y);
-
- mLeft = Math.round(viewPoint.x);
- if (mHandleType.equals(HandleType.START))
- mLeft -= mWidth - mShadow;
- else if (mHandleType.equals(HandleType.MIDDLE))
- mLeft -= (float) ((mWidth - mShadow) / 2);
- else
- mLeft -= mShadow;
+ (mGeckoPoint.y * zoom) - y);
+ mLeft = Math.round(viewPoint.x) - (int) adjustLeftForHandle();
mTop = Math.round(viewPoint.y);
setLayoutPosition();
}
+ private float adjustLeftForHandle() {
+ if (mHandleType.equals(HandleType.START))
+ return mIsRTL ? mShadow : mWidth - mShadow;
+ else if (mHandleType.equals(HandleType.MIDDLE))
+ return (float) ((mWidth - mShadow) / 2);
+ else
+ return mIsRTL ? mWidth - mShadow : mShadow;
+ }
+
private void setLayoutPosition() {
if (mLayoutParams == null) {
mLayoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
commit b24c0c24326a35e8d4cf23bff51cde5c640c62f7
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Jan 30 14:17:47 2015 +0900
android: make back button work again - return false in OnKeyDown
Change-Id: I8340e5f27475f38f8384d883ac0bb7fccf1135f1
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java
index a63b28d..6a5837b 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitInputConnectionHandler.java
@@ -20,7 +20,7 @@ public class LOKitInputConnectionHandler implements InputConnectionHandler {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
LOKitShell.sendKeyPressEvent(event);
- return true;
+ return false;
}
@Override
More information about the Libreoffice-commits
mailing list