Show intro and footer string according to the device's supported status
Bug: 390078046 Bug: 386121967 Test: atest HearingAidHelperTest HearingDeviceFooterPreferenceControllerTest HearingDeviceIntroPreferenceControllerTest BluetoothDetailsHearingDeviceSettingsControllerTest Flag: EXEMPT bugfix Change-Id: I564cdb80cd14f4d2d8e882b64db939449c6936b7 Signed-off-by: Jie Wang <jie.x.wang@sony.com> Signed-off-by: Jason Hsu <jasonwshsu@google.com>
This commit is contained in:
@@ -24,12 +24,27 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
/** Preference controller for footer in hearing device page. */
|
||||
public class HearingDeviceFooterPreferenceController extends
|
||||
AccessibilityFooterPreferenceController {
|
||||
public HearingDeviceFooterPreferenceController(Context context,
|
||||
String key) {
|
||||
private final HearingAidHelper mHelper;
|
||||
|
||||
public HearingDeviceFooterPreferenceController(
|
||||
@NonNull Context context,
|
||||
@NonNull String key) {
|
||||
super(context, key);
|
||||
mHelper = new HearingAidHelper(context);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public HearingDeviceFooterPreferenceController(
|
||||
@NonNull Context context,
|
||||
@NonNull String key,
|
||||
@NonNull HearingAidHelper hearingAidHelper) {
|
||||
super(context, key);
|
||||
mHelper = hearingAidHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,22 +52,47 @@ public class HearingDeviceFooterPreferenceController extends
|
||||
return mContext.getString(R.string.accessibility_hearing_device_about_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mHelper.isHearingAidSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
final AccessibilityFooterPreference footerPreference =
|
||||
screen.findPreference(getPreferenceKey());
|
||||
final boolean isAshaProfileSupported = mHelper.isAshaProfileSupported();
|
||||
final boolean isHapClientProfileSupported = mHelper.isHapClientProfileSupported();
|
||||
final String summary;
|
||||
final String summaryTts;
|
||||
if (isAshaProfileSupported && isHapClientProfileSupported) {
|
||||
summary = mContext.getString(R.string.accessibility_hearing_device_footer_summary);
|
||||
summaryTts = mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_summary_tts);
|
||||
} else if (isAshaProfileSupported) {
|
||||
summary = mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_asha_only_summary);
|
||||
summaryTts = mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_asha_only_summary_tts);
|
||||
} else if (isHapClientProfileSupported) {
|
||||
summary = mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_hap_only_summary);
|
||||
summaryTts = mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_hap_only_summary_tts);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// We use html tag inside footer string, so it is better to load from html to have better
|
||||
// html tag support.
|
||||
final CharSequence title = Html.fromHtml(
|
||||
mContext.getString(R.string.accessibility_hearing_device_footer_summary),
|
||||
summary,
|
||||
Html.FROM_HTML_MODE_COMPACT, /* imageGetter= */ null, /* tagHandler= */ null);
|
||||
footerPreference.setTitle(title);
|
||||
|
||||
// Need to update contentDescription string to announce "than" rather than ">"
|
||||
final String summaryTts = mContext.getString(
|
||||
R.string.accessibility_hearing_device_footer_summary_tts);
|
||||
final String contentDescription = getIntroductionTitle() + "\n\n" + summaryTts;
|
||||
footerPreference.setContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user