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

Commit 7ce5352a authored by Walter Jang's avatar Walter Jang
Browse files

Apply TtsSpan to known phone numbers in contact interactions

The primary content description in ContactInteraction must be
made a Spannable so that the TtsSpan can be progated from the
Loader (where the ContactInteraction is constructed) up to the
ExpandingEntryCardView.

Bug 17322140

Change-Id: If668f27cab20822f3c80aab606089e6b6f2a96c0
parent 8a3fe528
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Events;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.format.Time;
import android.util.Log;
@@ -278,7 +279,7 @@ public class CalendarInteraction implements ContactInteraction {
    }

    @Override
    public String getContentDescription(Context context) {
    public Spannable getContentDescription(Context context) {
        // The default TalkBack is good
        return null;
    }
+8 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.contacts.interactions;

import com.android.contacts.R;
import com.android.contacts.common.util.BitmapUtil;
import com.android.contacts.common.util.ContactDisplayUtils;

import android.content.ContentValues;
import android.content.Context;
@@ -28,6 +29,7 @@ import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.text.BidiFormatter;
import android.text.Spannable;
import android.text.TextDirectionHeuristics;

/**
@@ -179,9 +181,12 @@ public class CallLogInteraction implements ContactInteraction {
    }

    @Override
    public String getContentDescription(Context context) {
        return context.getResources().getString(R.string.content_description_recent_call,
                getCallTypeString(context), getViewHeader(context), getViewFooter(context));
    public Spannable getContentDescription(Context context) {
        final String phoneNumber = getViewHeader(context);
        final String contentDescription = context.getResources().getString(
                R.string.content_description_recent_call,
                getCallTypeString(context), phoneNumber, getViewFooter(context));
        return ContactDisplayUtils.getTelephoneTtsSpannable(contentDescription, phoneNumber);
    }

    private String getCallTypeString(Context context) {
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.Spannable;

/**
 * Represents a default interaction between the phone's owner and a contact
@@ -32,7 +33,7 @@ public interface ContactInteraction {
    Drawable getIcon(Context context);
    Drawable getBodyIcon(Context context);
    Drawable getFooterIcon(Context context);
    String getContentDescription(Context context);
    Spannable getContentDescription(Context context);
    /** The resource id for the icon, if available. May be 0 if one is not available. */
    int getIconResourceId();
}
+8 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.contacts.interactions;

import com.android.contacts.R;
import com.android.contacts.common.util.ContactDisplayUtils;

import android.content.ContentValues;
import android.content.Context;
@@ -24,6 +25,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.Telephony.Sms;
import android.text.BidiFormatter;
import android.text.Spannable;
import android.text.TextDirectionHeuristics;

/**
@@ -159,9 +161,12 @@ public class SmsInteraction implements ContactInteraction {
    }

    @Override
    public String getContentDescription(Context context) {
        return context.getResources().getString(R.string.content_description_recent_sms,
                getViewHeader(context), getViewBody(context), getViewFooter(context));
    public Spannable getContentDescription(Context context) {
        final String phoneNumber = getViewBody(context);
        final String contentDescription = context.getResources().getString(
                R.string.content_description_recent_sms,
                getViewHeader(context), phoneNumber, getViewFooter(context));
        return ContactDisplayUtils.getTelephoneTtsSpannable(contentDescription, phoneNumber);
    }

    @Override
+4 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.CardView;
import android.text.Spannable;
import android.text.TextUtils;
import android.transition.ChangeBounds;
import android.transition.ChangeScroll;
@@ -73,7 +74,7 @@ public class ExpandingEntryCardView extends CardView {
        private final Drawable mSubHeaderIcon;
        private final String mText;
        private final Drawable mTextIcon;
        private final String mPrimaryContentDescription;
        private Spannable mPrimaryContentDescription;
        private final Intent mIntent;
        private final Drawable mAlternateIcon;
        private final Intent mAlternateIntent;
@@ -88,7 +89,7 @@ public class ExpandingEntryCardView extends CardView {

        public Entry(int id, Drawable mainIcon, String header, String subHeader,
                Drawable subHeaderIcon, String text, Drawable textIcon,
                String primaryContentDescription, Intent intent,
                Spannable primaryContentDescription, Intent intent,
                Drawable alternateIcon, Intent alternateIntent, String alternateContentDescription,
                boolean shouldApplyColor, boolean isEditable,
                EntryContextMenuInfo entryContextMenuInfo, Drawable thirdIcon, Intent thirdIntent,
@@ -138,7 +139,7 @@ public class ExpandingEntryCardView extends CardView {
            return mTextIcon;
        }

        String getPrimaryContentDescription() {
        Spannable getPrimaryContentDescription() {
            return mPrimaryContentDescription;
        }

Loading