FileDocCategorySizeDatePackage
CaptioningManager.javaAPI DocAndroid 5.1 API19956Thu Mar 12 22:22:10 GMT 2015android.view.accessibility

CaptioningManager

public class CaptioningManager extends Object
Contains methods for accessing and monitoring preferred video captioning state and visual properties.

To obtain a handle to the captioning manager, do the following:

CaptioningManager captioningManager =
(CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);

Fields Summary
private static final int
DEFAULT_ENABLED
Default captioning enabled value.
private static final int
DEFAULT_PRESET
Default style preset as an index into {@link CaptionStyle#PRESETS}.
private static final float
DEFAULT_FONT_SCALE
Default scaling value for caption fonts.
private final ArrayList
mListeners
private final android.os.Handler
mHandler
private final android.content.ContentResolver
mContentResolver
private final android.database.ContentObserver
mContentObserver
private final Runnable
mStyleChangedRunnable
Runnable posted when user style properties change. This is used to prevent unnecessary change notifications when multiple properties change in rapid succession.
Constructors Summary
public CaptioningManager(android.content.Context context)
Creates a new captioning manager for the specified context.

hide


                   
       
        mContentResolver = context.getContentResolver();
    
Methods Summary
public voidaddCaptioningChangeListener(android.view.accessibility.CaptioningManager$CaptioningChangeListener listener)
Adds a listener for changes in the user's preferred captioning enabled state and visual properties.

param
listener the listener to add

        synchronized (mListeners) {
            if (mListeners.isEmpty()) {
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_ENABLED);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_LOCALE);
                registerObserver(Secure.ACCESSIBILITY_CAPTIONING_PRESET);
            }

            mListeners.add(listener);
        }
    
public final floatgetFontScale()

return
the user's preferred font scaling factor for video captions, or 1 if not specified

        return Secure.getFloat(
                mContentResolver, Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE, DEFAULT_FONT_SCALE);
    
public final java.util.LocalegetLocale()

return
the locale for the user's preferred captioning language, or null if not specified

        final String rawLocale = getRawLocale();
        if (!TextUtils.isEmpty(rawLocale)) {
            final String[] splitLocale = rawLocale.split("_");
            switch (splitLocale.length) {
                case 3:
                    return new Locale(splitLocale[0], splitLocale[1], splitLocale[2]);
                case 2:
                    return new Locale(splitLocale[0], splitLocale[1]);
                case 1:
                    return new Locale(splitLocale[0]);
            }
        }

        return null;
    
public final java.lang.StringgetRawLocale()

return
the raw locale string for the user's preferred captioning language
hide

        return Secure.getString(mContentResolver, Secure.ACCESSIBILITY_CAPTIONING_LOCALE);
    
public intgetRawUserStyle()

return
the raw preset number, or the first preset if not specified
hide

        return Secure.getInt(
                mContentResolver, Secure.ACCESSIBILITY_CAPTIONING_PRESET, DEFAULT_PRESET);
    
public android.view.accessibility.CaptioningManager$CaptionStylegetUserStyle()

return
the user's preferred visual properties for captions as a {@link CaptionStyle}, or the default style if not specified

        final int preset = getRawUserStyle();
        if (preset == CaptionStyle.PRESET_CUSTOM) {
            return CaptionStyle.getCustomStyle(mContentResolver);
        }

        return CaptionStyle.PRESETS[preset];
    
public final booleanisEnabled()

return
the user's preferred captioning enabled state

        return Secure.getInt(
                mContentResolver, Secure.ACCESSIBILITY_CAPTIONING_ENABLED, DEFAULT_ENABLED) == 1;
    
private voidnotifyEnabledChanged()

        final boolean enabled = isEnabled();
        synchronized (mListeners) {
            for (CaptioningChangeListener listener : mListeners) {
                listener.onEnabledChanged(enabled);
            }
        }
    
private voidnotifyFontScaleChanged()

        final float fontScale = getFontScale();
        synchronized (mListeners) {
            for (CaptioningChangeListener listener : mListeners) {
                listener.onFontScaleChanged(fontScale);
            }
        }
    
private voidnotifyLocaleChanged()

        final Locale locale = getLocale();
        synchronized (mListeners) {
            for (CaptioningChangeListener listener : mListeners) {
                listener.onLocaleChanged(locale);
            }
        }
    
private voidnotifyUserStyleChanged()

        final CaptionStyle userStyle = getUserStyle();
        synchronized (mListeners) {
            for (CaptioningChangeListener listener : mListeners) {
                listener.onUserStyleChanged(userStyle);
            }
        }
    
private voidregisterObserver(java.lang.String key)

        mContentResolver.registerContentObserver(Secure.getUriFor(key), false, mContentObserver);
    
public voidremoveCaptioningChangeListener(android.view.accessibility.CaptioningManager$CaptioningChangeListener listener)
Removes a listener previously added using {@link #addCaptioningChangeListener}.

param
listener the listener to remove

        synchronized (mListeners) {
            mListeners.remove(listener);

            if (mListeners.isEmpty()) {
                mContentResolver.unregisterContentObserver(mContentObserver);
            }
        }