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

يوفر Android TV إعدادات تتيح للمستخدم ضبط الإعدادات المفضّلة للترجمة والشرح بشكل مركزي لإنشاء تجربة متسقة على مستوى تطبيقات الوسائط.

تتيح هذه الإعدادات للمستخدمين تفعيل ميزة "الترجمة والشرح" واختيار اللغة المفضّلة وتحديد نمط مخصّص للترجمة والشرح استنادًا إلى احتياجاتهم. ويمكن للمستخدمين أيضًا تحديد ما إذا كانوا يفضّلون ترجمة وشرحًا مبسطَين بمستوى قراءة الصف الثالث الابتدائي، والمعروف باسم "Easy Reader".

يوضّح هذا الدليل كيفية الحصول على إعدادات الترجمة والشرح التي يوفّرها النظام وتطبيقها على الترجمة والشرح في تطبيقك.

يمكنك العثور على خيارات الترجمة والشرح، بما في ذلك معاينة لنمط الترجمة والشرح المحدّد، ضمن الإعدادات > تسهيل الاستخدام > الترجمة والشرح:

قائمة إعدادات الترجمة والشرح على 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();
    }

  });
}

يمكنك بدلاً من ذلك استدعاء الطريقة getUserStyle مباشرةً:

CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();