summaryrefslogtreecommitdiffstats
path: root/core/java/android/text/Layout.java
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2011-08-31 19:46:15 -0700
committerFabrice Di Meglio <fdimeglio@google.com>2011-09-02 18:03:21 -0700
commit34d2eba560f83f4eb665cdc039cf02bf96c201da (patch)
tree7afe896e6af294db1a0294c0204f34a7d5519365 /core/java/android/text/Layout.java
parentfead8f976700906101714b3265e64e30c0a80180 (diff)
downloadframeworks_base-34d2eba560f83f4eb665cdc039cf02bf96c201da.zip
frameworks_base-34d2eba560f83f4eb665cdc039cf02bf96c201da.tar.gz
frameworks_base-34d2eba560f83f4eb665cdc039cf02bf96c201da.tar.bz2
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
Diffstat (limited to 'core/java/android/text/Layout.java')
-rw-r--r--core/java/android/text/Layout.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index 768071f..bdfe940 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);