Loading res/xml/my_device_info.xml +2 −2 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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" Loading src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -158,7 +158,7 @@ public class PhoneNumberPreferenceController extends BasePreferenceController { } @VisibleForTesting Preference createNewPreference(Context context) { return new Preference(context); protected Preference createNewPreference(Context context) { return new PhoneNumberSummaryPreference(context); } } src/com/android/settings/deviceinfo/PhoneNumberSummaryPreference.java 0 → 100644 +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())); } } } src/com/android/settings/deviceinfo/PhoneNumberUtil.java 0 → 100644 +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)')'); } } src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java +4 −23 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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 Loading
res/xml/my_device_info.xml +2 −2 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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" Loading
src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -158,7 +158,7 @@ public class PhoneNumberPreferenceController extends BasePreferenceController { } @VisibleForTesting Preference createNewPreference(Context context) { return new Preference(context); protected Preference createNewPreference(Context context) { return new PhoneNumberSummaryPreference(context); } }
src/com/android/settings/deviceinfo/PhoneNumberSummaryPreference.java 0 → 100644 +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())); } } }
src/com/android/settings/deviceinfo/PhoneNumberUtil.java 0 → 100644 +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)')'); } }
src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java +4 −23 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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