יישום ההגדרות של הצגת כתוביות במערכת

ב-Android TV יש הגדרות שמאפשרות למשתמשים להגדיר את העדפות הכתוביות באופן מרכזי, כדי ליצור חוויה עקבית באפליקציות מדיה.

ההגדרות האלה מאפשרות למשתמשים להפעיל כתוביות, לבחור שפה מועדפת ולהגדיר סגנון כתוביות מותאם אישית לפי הצרכים שלהם. המשתמשים יכולים גם לציין אם הם מעדיפים כתוביות פשוטות ברמת קריאה של כיתה ג', שנקראות 'קריאה קלה'.

במדריך הזה מוסבר איך לקבל ולהחיל את הגדרות הכתוביות שסופקו על ידי המערכת על הכתוביות באפליקציה.

אפשרויות הכתוביות, כולל תצוגה מקדימה של סגנון הכתוביות שנבחר, נמצאות בקטע הגדרות > נגישות > כתוביות:

תפריט הגדרות הכתוביות ב-Android TV.
איור 1. דף ההגדרות של הכתוביות.

קבלת 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();
    }

  });
}

אפשר גם להפעיל את ה-method‏ getUserStyle ישירות:

CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();