summaryrefslogtreecommitdiffstats
path: root/tests/BiDiTests
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2011-08-05 20:54:54 -0700
committerFabrice Di Meglio <fdimeglio@google.com>2011-08-05 20:54:54 -0700
commitf2ce877c1dde094ab599f0d3103145c9381ab260 (patch)
treee8881d6fc76b1d7e3ed95ab40442a91f7c0c9290 /tests/BiDiTests
parentfd0b623c33393ba3144c5375380ea076469b67f9 (diff)
downloadframeworks_base-f2ce877c1dde094ab599f0d3103145c9381ab260.zip
frameworks_base-f2ce877c1dde094ab599f0d3103145c9381ab260.tar.gz
frameworks_base-f2ce877c1dde094ab599f0d3103145c9381ab260.tar.bz2
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
Diffstat (limited to 'tests/BiDiTests')
-rw-r--r--tests/BiDiTests/res/layout/basic.xml56
-rw-r--r--tests/BiDiTests/res/values/strings.xml1
-rw-r--r--tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java45
3 files changed, 80 insertions, 22 deletions
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"
/>
<TextView android:id="@+id/textview_rtl"
@@ -70,34 +71,45 @@
android:text="@string/button_alert_dialog_text"
android:textSize="32dip"
/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="600dip"
- android:layout_height="128dip"
- android:layout_gravity="center_vertical"
- android:orientation="horizontal"
- style="@android:style/Widget.Holo.Spinner"
- >
+ <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/edittext_url"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="text"
+ android:textSize="32dip"
+ android:scrollHorizontally="true"
+ android:ellipsize="end"
+ android:text="@string/url"
+ />
+
<LinearLayout
- android:layout_width="0dip"
- android:layout_weight="1"
- android:layout_height="match_parent"
+ android:layout_width="600dip"
+ android:layout_height="128dip"
android:layout_gravity="center_vertical"
- android:orientation="vertical"
+ android:orientation="horizontal"
+ style="@android:style/Widget.Holo.Spinner"
>
- <TextView
- android:id="@+id/spinner_line_1"
- android:layout_width="match_parent"
- android:layout_height="0dip"
+ <LinearLayout
+ android:layout_width="0dip"
android:layout_weight="1"
- android:textSize="16dip"
- android:singleLine="true"
- android:ellipsize="end"
- android:gravity="left|center_vertical"
- android:text="@string/button_text"
- />
+ android:layout_height="match_parent"
+ android:layout_gravity="center_vertical"
+ android:orientation="vertical"
+ >
+ <TextView
+ android:id="@+id/spinner_line_1"
+ android:layout_width="match_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+ android:textSize="16dip"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:gravity="left|center_vertical"
+ android:text="@string/button_text"
+ />
+ </LinearLayout>
</LinearLayout>
+
</LinearLayout>
</FrameLayout>
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 @@
<string name="ltr">Left to right text"</string>
<string name="rtl">"والحق أن تترك ونص"</string>
<string name="composing">"\u0644\u0627"</string>
+ <string name="url">www.amazon.co.uk/gp/aw/h.html/275-8912818-8203452</string>
</resources>
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);
+ }
+ }
}