सिस्टम कैप्शन की सेटिंग इस्तेमाल करें

Android TV में, लोगों के लिए ऐसी सेटिंग दी गई हैं जिनसे वे अपने हिसाब से कैप्शन की स्टाइल तय कर सकते हैं. इस गाइड में यह बताया गया है कि कोई ऐप्लिकेशन, सिस्टम से मिले ऐप्लिकेशन को कैसे डाउनलोड और लागू कर सकता है कैप्शन की शैली.

कैप्शन के विकल्प, सेटिंग > सिस्टम > सुलभता > कैप्शन:

ATV_Caption_Settings

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;
    }

    @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.backgroundOpcity = 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.windowOpcity = userStyle.windowColor >>> 24;
      currentCaptionStyle.hasEdgeColor = userStyle.hasEdgeColor();
      currentCaptionStyle.edgeColor = userStyle.edgeColor;
      currentCaptionStyle.hasEdgeType = userStyle.hasEdgeType();
      currentCaptionStyle.edgeType = userStyle.edgeType;
      currentCaptionStyle.typeFace = userStyle.getTypeface();
    }

  });

CaptionStyle सिस्टम पाने के लिए, getUserStyle() पर कॉल करें सीधे:

CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();