Loading graphics/java/android/graphics/Paint.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -1602,7 +1602,7 @@ public class Paint { int len = end - start; int len = end - start; char[] buf = TemporaryBuffer.obtain(contextLen); char[] buf = TemporaryBuffer.obtain(contextLen); TextUtils.getChars(text, start, end, buf, 0); 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); 0, contextLen, flags, advances, advancesIndex, reserved); TemporaryBuffer.recycle(buf); TemporaryBuffer.recycle(buf); return result; return result; Loading tests/BiDiTests/res/layout/basic.xml +34 −22 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ android:layout_width="match_parent" android:layout_width="match_parent" android:textSize="32dip" android:textSize="32dip" android:textDirection="ltr" android:textDirection="ltr" android:text="@string/url" /> /> <TextView android:id="@+id/textview_rtl" <TextView android:id="@+id/textview_rtl" Loading @@ -70,7 +71,16 @@ android:text="@string/button_alert_dialog_text" android:text="@string/button_alert_dialog_text" android:textSize="32dip" android:textSize="32dip" /> /> </LinearLayout> <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 <LinearLayout android:layout_width="600dip" android:layout_width="600dip" Loading Loading @@ -100,4 +110,6 @@ </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> </FrameLayout> </FrameLayout> tests/BiDiTests/res/values/strings.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -47,5 +47,6 @@ <string name="ltr">Left to right text"</string> <string name="ltr">Left to right text"</string> <string name="rtl">"والحق أن تترك ونص"</string> <string name="rtl">"والحق أن تترك ونص"</string> <string name="composing">"\u0644\u0627"</string> <string name="composing">"\u0644\u0627"</string> <string name="url">www.amazon.co.uk/gp/aw/h.html/275-8912818-8203452</string> </resources> </resources> tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java +45 −0 Original line number Original line Diff line number Diff line Loading @@ -19,10 +19,14 @@ package com.android.bidi; import android.app.AlertDialog; import android.app.AlertDialog; import android.app.Fragment; import android.app.Fragment; import android.os.Bundle; import android.os.Bundle; import android.text.Editable; import android.text.Spannable; import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; import android.widget.Button; import android.widget.Button; import android.widget.EditText; public class BiDiTestBasic extends Fragment { public class BiDiTestBasic extends Fragment { Loading @@ -47,6 +51,8 @@ public class BiDiTestBasic extends Fragment { showDialog(); showDialog(); } } }); }); useSpans(); } } private void showDialog() { private void showDialog() { Loading @@ -54,4 +60,43 @@ public class BiDiTestBasic extends Fragment { builder.setSingleChoiceItems(items, 0, null); builder.setSingleChoiceItems(items, 0, null); builder.show(); 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); } } } } Loading
graphics/java/android/graphics/Paint.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -1602,7 +1602,7 @@ public class Paint { int len = end - start; int len = end - start; char[] buf = TemporaryBuffer.obtain(contextLen); char[] buf = TemporaryBuffer.obtain(contextLen); TextUtils.getChars(text, start, end, buf, 0); 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); 0, contextLen, flags, advances, advancesIndex, reserved); TemporaryBuffer.recycle(buf); TemporaryBuffer.recycle(buf); return result; return result; Loading
tests/BiDiTests/res/layout/basic.xml +34 −22 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ android:layout_width="match_parent" android:layout_width="match_parent" android:textSize="32dip" android:textSize="32dip" android:textDirection="ltr" android:textDirection="ltr" android:text="@string/url" /> /> <TextView android:id="@+id/textview_rtl" <TextView android:id="@+id/textview_rtl" Loading @@ -70,7 +71,16 @@ android:text="@string/button_alert_dialog_text" android:text="@string/button_alert_dialog_text" android:textSize="32dip" android:textSize="32dip" /> /> </LinearLayout> <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 <LinearLayout android:layout_width="600dip" android:layout_width="600dip" Loading Loading @@ -100,4 +110,6 @@ </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> </FrameLayout> </FrameLayout>
tests/BiDiTests/res/values/strings.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -47,5 +47,6 @@ <string name="ltr">Left to right text"</string> <string name="ltr">Left to right text"</string> <string name="rtl">"والحق أن تترك ونص"</string> <string name="rtl">"والحق أن تترك ونص"</string> <string name="composing">"\u0644\u0627"</string> <string name="composing">"\u0644\u0627"</string> <string name="url">www.amazon.co.uk/gp/aw/h.html/275-8912818-8203452</string> </resources> </resources>
tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java +45 −0 Original line number Original line Diff line number Diff line Loading @@ -19,10 +19,14 @@ package com.android.bidi; import android.app.AlertDialog; import android.app.AlertDialog; import android.app.Fragment; import android.app.Fragment; import android.os.Bundle; import android.os.Bundle; import android.text.Editable; import android.text.Spannable; import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; import android.widget.Button; import android.widget.Button; import android.widget.EditText; public class BiDiTestBasic extends Fragment { public class BiDiTestBasic extends Fragment { Loading @@ -47,6 +51,8 @@ public class BiDiTestBasic extends Fragment { showDialog(); showDialog(); } } }); }); useSpans(); } } private void showDialog() { private void showDialog() { Loading @@ -54,4 +60,43 @@ public class BiDiTestBasic extends Fragment { builder.setSingleChoiceItems(items, 0, null); builder.setSingleChoiceItems(items, 0, null); builder.show(); 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); } } } }