Android TV में ऐसी सेटिंग होती हैं जिनकी मदद से उपयोगकर्ता, कैप्शन की सेटिंग को एक जगह पर सेट कर सकता है. इससे, मीडिया ऐप्लिकेशन पर एक जैसा अनुभव मिलता है.
इन सेटिंग की मदद से, लोग कैप्शन चालू कर सकते हैं, अपनी पसंद की भाषा चुन सकते हैं, और अपनी ज़रूरत के हिसाब से कैप्शन की स्टाइल तय कर सकते हैं. उपयोगकर्ता यह भी तय कर सकते हैं कि उन्हें तीसरी कक्षा के छात्र-छात्राओं के पढ़ने के स्तर के हिसाब से, आसान कैप्शन चाहिए या नहीं. इसे "आसान रीडर" कहा जाता है.
इस गाइड में, सिस्टम की ओर से उपलब्ध कराई गई कैप्शन सेटिंग को अपने ऐप्लिकेशन में कैप्शन पर लागू करने का तरीका बताया गया है.
सेटिंग > सुलभता > कैप्शन में जाकर, कैप्शन के विकल्प देखें. इनमें, चुने गए कैप्शन की स्टाइल की झलक भी शामिल है:
CaptioningManager ऑब्जेक्ट पाएं
किसी गतिविधि से, Context से CaptioningManager सेवा पाएं:
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();