1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.accessibility; 18 19 import android.content.Context; 20 import android.text.Html; 21 22 import androidx.annotation.NonNull; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 27 import com.google.common.annotations.VisibleForTesting; 28 29 /** Preference controller for footer in hearing device page. */ 30 public class HearingDeviceFooterPreferenceController extends 31 AccessibilityFooterPreferenceController { 32 private final HearingAidHelper mHelper; 33 HearingDeviceFooterPreferenceController( @onNull Context context, @NonNull String key)34 public HearingDeviceFooterPreferenceController( 35 @NonNull Context context, 36 @NonNull String key) { 37 super(context, key); 38 mHelper = new HearingAidHelper(context); 39 } 40 41 @VisibleForTesting HearingDeviceFooterPreferenceController( @onNull Context context, @NonNull String key, @NonNull HearingAidHelper hearingAidHelper)42 public HearingDeviceFooterPreferenceController( 43 @NonNull Context context, 44 @NonNull String key, 45 @NonNull HearingAidHelper hearingAidHelper) { 46 super(context, key); 47 mHelper = hearingAidHelper; 48 } 49 50 @Override getIntroductionTitle()51 protected String getIntroductionTitle() { 52 return mContext.getString(R.string.accessibility_hearing_device_about_title); 53 } 54 55 @Override getAvailabilityStatus()56 public int getAvailabilityStatus() { 57 return mHelper.isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 58 } 59 60 @Override displayPreference(@onNull PreferenceScreen screen)61 public void displayPreference(@NonNull PreferenceScreen screen) { 62 super.displayPreference(screen); 63 64 final AccessibilityFooterPreference footerPreference = 65 screen.findPreference(getPreferenceKey()); 66 final boolean isAshaProfileSupported = mHelper.isAshaProfileSupported(); 67 final boolean isHapClientProfileSupported = mHelper.isHapClientProfileSupported(); 68 final String summary; 69 final String summaryTts; 70 if (isAshaProfileSupported && isHapClientProfileSupported) { 71 summary = mContext.getString(R.string.accessibility_hearing_device_footer_summary); 72 summaryTts = mContext.getString( 73 R.string.accessibility_hearing_device_footer_summary_tts); 74 } else if (isAshaProfileSupported) { 75 summary = mContext.getString( 76 R.string.accessibility_hearing_device_footer_asha_only_summary); 77 summaryTts = mContext.getString( 78 R.string.accessibility_hearing_device_footer_asha_only_summary_tts); 79 } else if (isHapClientProfileSupported) { 80 summary = mContext.getString( 81 R.string.accessibility_hearing_device_footer_hap_only_summary); 82 summaryTts = mContext.getString( 83 R.string.accessibility_hearing_device_footer_hap_only_summary_tts); 84 } else { 85 return; 86 } 87 88 // We use html tag inside footer string, so it is better to load from html to have better 89 // html tag support. 90 final CharSequence title = Html.fromHtml( 91 summary, 92 Html.FROM_HTML_MODE_COMPACT, /* imageGetter= */ null, /* tagHandler= */ null); 93 footerPreference.setTitle(title); 94 95 // Need to update contentDescription string to announce "than" rather than ">" 96 final String contentDescription = getIntroductionTitle() + "\n\n" + summaryTts; 97 footerPreference.setContentDescription(contentDescription); 98 } 99 } 100