From 34d2eba560f83f4eb665cdc039cf02bf96c201da Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Wed, 31 Aug 2011 19:46:15 -0700 Subject: Fix bug #5243493 TextView selection is not working correctly when there is some RTL run into it Part 2 - make selection handles aware of the run direction Change-Id: Idf41036de53d8968e7ae27eb87aea09e86bcd652 --- core/java/android/text/Layout.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'core/java/android/text/Layout.java') diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index 768071f5dc29..bdfe94048e5e 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -673,6 +673,35 @@ public abstract class Layout { return false; } + /** + * Returns true if the character at offset is right to left (RTL). + * @param offset the offset + * @return true if the character is RTL, false if it is LTR + */ + public boolean isRtlCharAt(int offset) { + int line = getLineForOffset(offset); + Directions dirs = getLineDirections(line); + if (dirs == DIRS_ALL_LEFT_TO_RIGHT) { + return false; + } + if (dirs == DIRS_ALL_RIGHT_TO_LEFT) { + return true; + } + int[] runs = dirs.mDirections; + int lineStart = getLineStart(line); + for (int i = 0; i < runs.length; i += 2) { + int start = lineStart + (runs[i] & RUN_LENGTH_MASK); + // No need to test the end as an offset after the last run should return the value + // corresponding of the last run + if (offset >= start) { + int level = (runs[i+1] >>> RUN_LEVEL_SHIFT) & RUN_LEVEL_MASK; + return ((level & 1) != 0); + } + } + // Should happen only if the offset is "out of bounds" + return false; + } + private boolean primaryIsTrailingPrevious(int offset) { int line = getLineForOffset(offset); int lineStart = getLineStart(line); -- cgit v1.2.3