diff options
Diffstat (limited to 'tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java')
-rw-r--r-- | tests/BiDiTests/src/com/android/bidi/BiDiTestBasic.java | 45 |
1 files changed, 45 insertions, 0 deletions
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); + } + } } |