From f2ce877c1dde094ab599f0d3103145c9381ab260 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Fri, 5 Aug 2011 20:54:54 -0700 Subject: Fix bug #4584320 Single Line EditText not drawing correctly with spans applied (ICS) - use correct 0 index for computing advance thru the char buffer (the buffer is created from TextUtils.getChars()) - udpate unit tests Change-Id: Iaeb07658b79ecdf5e17395d55afb7c84965bb0fc --- tests/BiDiTests/res/layout/basic.xml | 56 +++++++++++++--------- tests/BiDiTests/res/values/strings.xml | 1 + .../src/com/android/bidi/BiDiTestBasic.java | 45 +++++++++++++++++ 3 files changed, 80 insertions(+), 22 deletions(-) (limited to 'tests/BiDiTests') diff --git a/tests/BiDiTests/res/layout/basic.xml b/tests/BiDiTests/res/layout/basic.xml index 18f193e..e8f67a6 100644 --- a/tests/BiDiTests/res/layout/basic.xml +++ b/tests/BiDiTests/res/layout/basic.xml @@ -46,6 +46,7 @@ android:layout_width="match_parent" android:textSize="32dip" android:textDirection="ltr" + android:text="@string/url" /> - - + + - + android:layout_height="match_parent" + android:layout_gravity="center_vertical" + android:orientation="vertical" + > + + + diff --git a/tests/BiDiTests/res/values/strings.xml b/tests/BiDiTests/res/values/strings.xml index f4ce0f7..fde0ecf 100644 --- a/tests/BiDiTests/res/values/strings.xml +++ b/tests/BiDiTests/res/values/strings.xml @@ -47,5 +47,6 @@ Left to right text" "والحق أن تترك ونص" "\u0644\u0627" + www.amazon.co.uk/gp/aw/h.html/275-8912818-8203452 diff --git a/tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java b/tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java index f0b7438..effac30 100644 --- a/tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java +++ b/tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java @@ -19,10 +19,14 @@ package com.android.bidi; import android.app.AlertDialog; import android.app.Fragment; import android.os.Bundle; +import android.text.Editable; +import android.text.Spannable; +import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.EditText; public class BiDiTestBasic extends Fragment { @@ -47,6 +51,8 @@ public class BiDiTestBasic extends Fragment { showDialog(); } }); + + useSpans(); } private void showDialog() { @@ -54,4 +60,43 @@ public class BiDiTestBasic extends Fragment { builder.setSingleChoiceItems(items, 0, null); builder.show(); } + + private void useSpans() { + EditText urlEdit = (EditText) currentView.findViewById(R.id.edittext_url); + Editable url = urlEdit.getText(); + if (url.length() < 1) { + return; + } + + String urlString = url.toString(); + int urlLength = urlString.length(); + String domainAndRegistry = "amazon.co.uk"; + + int startSchemeIndex = urlString.startsWith("https") ? 5 : 0; + int startDomainIndex = urlString.indexOf(domainAndRegistry); + if (startDomainIndex == -1) { + assert false; + return; + } + int stopIndex = startDomainIndex + domainAndRegistry.length(); + + if (startDomainIndex != 0) { + url.setSpan(new ForegroundColorSpan(0xfff00fff), + startSchemeIndex, + startDomainIndex, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + url.setSpan(new ForegroundColorSpan(0xff548aff), + startDomainIndex, + stopIndex, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + + if (stopIndex < urlString.length()) { + url.setSpan(new ForegroundColorSpan(0xfff00fff), + stopIndex, + urlLength, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + } } -- cgit v1.1