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

Commit d051e65d authored by Bonian Chen's avatar Bonian Chen
Browse files

[Settings] Support phone number talkback

Support phone number talkback in about phone UI pages.

Bug: 182923869
Test: local, junit
Change-Id: I159827070a954dee13230ff7cf6de81dbbaa7545
parent 4c450d6b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@
            settings:controller="com.android.settings.deviceinfo.BrandedAccountPreferenceController"/>

        <!-- Phone number -->
        <Preference
        <com.android.settings.deviceinfo.PhoneNumberSummaryPreference
            android:key="phone_number"
            android:order="3"
            android:title="@string/status_number"
@@ -113,7 +113,7 @@
            settings:controller="com.android.settings.deviceinfo.HardwareInfoPreferenceController"/>

        <!-- IMEI -->
        <Preference
        <com.android.settings.deviceinfo.PhoneNumberSummaryPreference
            android:key="imei_info"
            android:order="32"
            android:title="@string/status_imei"
+1 −1
Original line number Diff line number Diff line
@@ -159,6 +159,6 @@ public class PhoneNumberPreferenceController extends BasePreferenceController {

    @VisibleForTesting
    protected Preference createNewPreference(Context context) {
        return new Preference(context);
        return new PhoneNumberSummaryPreference(context);
    }
}
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settings.deviceinfo;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

/**
 * Preference which support phone number talkback in summary part.
 */
public class PhoneNumberSummaryPreference extends Preference {

    /**
     * Constructor
     * @param context
     */
    public PhoneNumberSummaryPreference(Context context) {
        this(context, null);
    }

    /**
     * Constructor
     * @param context
     * @param attrs
     */
    public PhoneNumberSummaryPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);

        // Expand text to support phone number talkback.
        TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
        if (summaryView != null) {
            summaryView.setText(PhoneNumberUtil.expandByTts(summaryView.getText()));
        }
    }
}
+65 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settings.deviceinfo;

import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.TtsSpan;

import java.util.Arrays;
import java.util.stream.IntStream;

/**
 * Helper class to detect format of phone number.
 */
public class PhoneNumberUtil {

    /**
     * Convert given text to support phone number talkback.
     * @param text given
     * @return converted text
     */
    public static CharSequence expandByTts(CharSequence text) {
        if ((text == null) || (text.length() <= 0)
            || (!isPhoneNumberDigits(text))) {
            return text;
        }
        Spannable spannable = new SpannableStringBuilder(text);
        TtsSpan span = new TtsSpan.DigitsBuilder(text.toString()).build();
        spannable.setSpan(span, 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannable;
    }

    /**
     * Check if given text may contains a phone id related numbers.
     * (ex: phone number, IMEI, ICCID)
     * @param text given
     * @return true when given text is a phone id related number.
     */
    private static boolean isPhoneNumberDigits(CharSequence text) {
        long textLength = (long)text.length();
        return (textLength == text.chars()
                .filter(c -> isPhoneNumberDigit(c)).count());
    }

    private static boolean isPhoneNumberDigit(int c) {
        return ((c >= (int)'0') && (c <= (int)'9'))
            || (c == (int)'-') || (c == (int)'+')
            || (c == (int)'(') || (c == (int)')');
    }
}
+4 −23
Original line number Diff line number Diff line
@@ -21,11 +21,6 @@ import android.content.res.Resources;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.TtsSpan;
import android.util.Log;

import androidx.annotation.NonNull;
@@ -53,19 +48,6 @@ public class ImeiInfoDialogController {
    @VisibleForTesting
    static final int ID_GSM_SETTINGS = R.id.gsm_settings;

    private static CharSequence getTextAsDigits(CharSequence text) {
        if (TextUtils.isEmpty(text)) {
            return "";
        }
        if (TextUtils.isDigitsOnly(text)) {
            final Spannable spannable = new SpannableStringBuilder(text);
            final TtsSpan span = new TtsSpan.DigitsBuilder(text.toString()).build();
            spannable.setSpan(span, 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            text = spannable;
        }
        return text;
    }

    private final ImeiInfoDialogFragment mDialog;
    private final TelephonyManager mTelephonyManager;
    private final SubscriptionInfo mSubscriptionInfo;
@@ -121,10 +103,9 @@ public class ImeiInfoDialogController {
        if ((mSubscriptionInfo != null && isCdmaLteEnabled()) ||
                    (mSubscriptionInfo == null && isSimPresent(mSlotId))) {
            // Show IMEI for LTE device
            mDialog.setText(ID_IMEI_VALUE,
                    getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
            mDialog.setText(ID_IMEI_VALUE, mTelephonyManager.getImei(mSlotId));
            mDialog.setText(ID_IMEI_SV_VALUE,
                    getTextAsDigits(mTelephonyManager.getDeviceSoftwareVersion(mSlotId)));
                    mTelephonyManager.getDeviceSoftwareVersion(mSlotId));
        } else {
            // device is not GSM/UMTS, do not display GSM/UMTS features
            mDialog.removeViewFromScreen(ID_GSM_SETTINGS);
@@ -132,9 +113,9 @@ public class ImeiInfoDialogController {
    }

    private void updateDialogForGsmPhone() {
        mDialog.setText(ID_IMEI_VALUE, getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
        mDialog.setText(ID_IMEI_VALUE, mTelephonyManager.getImei(mSlotId));
        mDialog.setText(ID_IMEI_SV_VALUE,
                getTextAsDigits(mTelephonyManager.getDeviceSoftwareVersion(mSlotId)));
                mTelephonyManager.getDeviceSoftwareVersion(mSlotId));
        // device is not CDMA, do not display CDMA features
        mDialog.removeViewFromScreen(ID_CDMA_SETTINGS);
    }
Loading