Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d896225 authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Clear span array and set only 1 span when phone number changed

Doc https://goto.google.com/b25324025

Bug 25324025

Change-Id: I40f228efd704e956976d74b2fd8123bf8cc3f770
(cherry picked from commit 0761a0cdbef8447ef108111243279c6b5a91c2e3)
parent 8b9ef579
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -23,8 +23,10 @@ import android.os.Parcelable;
import android.provider.ContactsContract;
import android.text.Editable;
import android.text.InputType;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.TtsSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
@@ -270,6 +272,16 @@ public class TextFieldsEditorView extends LabeledEditorView {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    if (!ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(
                            getKind().mimeType) || !(s instanceof Spannable)) {
                        return;
                    }
                    final Spannable spannable = (Spannable) s;
                    final TtsSpan[] spans = spannable.getSpans(0, s.length(), TtsSpan.class);
                    for (int i = 0; i < spans.length; i++) {
                        spannable.removeSpan(spans[i]);
                    }
                    PhoneNumberUtilsCompat.addTtsSpan(spannable, 0, s.length());
                }
            });