استخدام إعدادات شرح النظام

في 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();