Android TV تنظیماتی ارائه میدهد که به کاربر امکان میدهد اولویتهای زیرنویس ناشنوایان را بهصورت متمرکز تنظیم کند تا تجربهای منسجم در برنامههای رسانهای ایجاد شود.
این تنظیمات به کاربران امکان میدهد زیرنویس ناشنوایان را فعال کنند، زبان ترجیحی را انتخاب کنند، و سبک سفارشی زیرنویس ناشنوایان را براساس نیازهایشان تعریف کنند. کاربران همچنین میتوانند مشخص کنند که آیا زیرنویسهای سادهشده در سطح خواندن کلاس سوم را ترجیح میدهند، که به آن «Easy Reader» میگویند.
این راهنما نشان میدهد که چگونه تنظیمات زیرنویس ارائهشده توسط سیستم را دریافت و بر زیرنویسهای برنامه خود اعمال کنید.
گزینههای زیرنویس ناشنوایان، ازجمله پیشنمایش سبک زیرنویس ناشنوایان انتخابشده را در بخش تنظیمات > دسترسپذیری > زیرنویس ناشنوایان پیدا کنید:
دریافت CaptioningManager
از یک فعالیت، سرویس CaptioningManager را از Context دریافت کنید:
CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);
مدیریت تغییرات تنظیمات زیرنویس ناشنوایان
با پیادهسازی کلاس CaptioningChangeListener، تغییرات تنظیمات زیرنویس ناشنوایان را مدیریت کنید:
if (captioningManager != null) {
// Define a class to store the CaptionStyle details.
CurrentCaptionStyle currentCaptionStyle = new CurrentCaptionStyle();
// Define the listeners.
captioningManager.addCaptioningChangeListener(new CaptioningChangeListener() {
@Override
public void onEnabledChanged(boolean enabled) {
super.onEnabledChanged(enabled);
Log.d(TAG, "onEnabledChanged");
currentCaptionStyle.isEnabled = enabled;
}
@Override
public void onLocaleChanged(@Nullable Locale locale) {
super.onLocaleChanged(locale);
Log.d(TAG, "onLocaleChanged");
currentCaptionStyle.locale = locale;
if (locale == null) {
currentCaptionStyle.isEasyReaderEnabled = false;
} else {
currentCaptionStyle.isEasyReaderEnabled = locale.getVariant().contains("simple");
}
}
@Override
public void onFontScaleChanged(float fontScale) {
super.onFontScaleChanged(fontScale);
Log.d(TAG, "onFontScaleChanged");
currentCaptionStyle.fontScale = fontScale;
}
@Override
public void onUserStyleChanged(@NonNull CaptionStyle userStyle) {
super.onUserStyleChanged(userStyle);
Log.d(TAG, "onUserStyleChanged");
currentCaptionStyle.hasBackgroundColor = userStyle.hasBackgroundColor();
currentCaptionStyle.backgroundColor = userStyle.backgroundColor;
currentCaptionStyle.backgroundOpacity = userStyle.backgroundColor >>> 24;
currentCaptionStyle.hasForegroundColor = userStyle.hasForegroundColor();
currentCaptionStyle.foregroundColor = userStyle.foregroundColor;
currentCaptionStyle.foregroundOpacity = userStyle.foregroundColor >>> 24;
currentCaptionStyle.hasWindowColor = userStyle.hasWindowColor();
currentCaptionStyle.windowColor = userStyle.windowColor;
currentCaptionStyle.windowOpacity = userStyle.windowColor >>> 24;
currentCaptionStyle.hasEdgeColor = userStyle.hasEdgeColor();
currentCaptionStyle.edgeColor = userStyle.edgeColor;
currentCaptionStyle.hasEdgeType = userStyle.hasEdgeType();
currentCaptionStyle.edgeType = userStyle.edgeType;
currentCaptionStyle.typeFace = userStyle.getTypeface();
}
});
}
یا اینکه مستقیماً روش getUserStyle را فراخوانی کنید:
CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();