시스템 자막 설정 채택

Android TV에는 사용자가 직접 자막 스타일을 정의할 수 있는 설정이 제공됩니다. 이 가이드에서는 앱이 시스템에서 제공한 값을 가져와 적용하는 방법을 보여줍니다. 자막 스타일을 선택합니다.

자막 옵션은 설정 > 시스템 > 접근성 > 설명:

ATV_캡션_설정

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