summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2011-08-08 10:58:13 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-08-08 10:58:13 -0700
commit253267256997b2bd5cf1c40e1302a4a1240d756f (patch)
treefab26b98488a4af268a5a94af95a3cc53b54fe48
parent4974bc1be68a77cf9709a8c50ef6de06ce8a3a0d (diff)
parentf2ce877c1dde094ab599f0d3103145c9381ab260 (diff)
downloadframeworks_base-253267256997b2bd5cf1c40e1302a4a1240d756f.zip
frameworks_base-253267256997b2bd5cf1c40e1302a4a1240d756f.tar.gz
frameworks_base-253267256997b2bd5cf1c40e1302a4a1240d756f.tar.bz2
Merge "Fix bug #4584320 Single Line EditText not drawing correctly with spans applied (ICS)"
-rw-r--r--graphics/java/android/graphics/Paint.java2
-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
4 files changed, 81 insertions, 23 deletions
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index 163bd4a..6562510 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -1602,7 +1602,7 @@ public class Paint {
int len = end - start;
char[] buf = TemporaryBuffer.obtain(contextLen);
TextUtils.getChars(text, start, end, buf, 0);
- float result = getTextRunAdvances(buf, start - contextStart, len,
+ float result = getTextRunAdvances(buf, 0, len,
0, contextLen, flags, advances, advancesIndex, reserved);
TemporaryBuffer.recycle(buf);
return result;
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);
+ }
+ }
}