/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.view.accessibility; import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.graphics.Color; import android.graphics.Typeface; import android.net.Uri; import android.os.Handler; import android.provider.Settings.Secure; import android.text.TextUtils; import java.util.ArrayList; import java.util.Locale; /** * Contains methods for accessing and monitoring preferred video captioning state and visual * properties. *
* To obtain a handle to the captioning manager, do the following: *
*
*
*/
public class CaptioningManager {
/** Default captioning enabled value. */
private static final int DEFAULT_ENABLED = 0;
/** Default style preset as an index into {@link CaptionStyle#PRESETS}. */
private static final int DEFAULT_PRESET = 0;
/** Default scaling value for caption fonts. */
private static final float DEFAULT_FONT_SCALE = 1;
private final ArrayListCaptioningManager captioningManager =
* (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);
*
*
*/
public final int edgeType;
/**
* The preferred edge color for video captions, if using an edge type
* other than {@link #EDGE_TYPE_NONE}.
*/
public final int edgeColor;
/**
* @hide
*/
public final String mRawTypeface;
private Typeface mParsedTypeface;
private CaptionStyle(int foregroundColor, int backgroundColor, int edgeType, int edgeColor,
String rawTypeface) {
this.foregroundColor = foregroundColor;
this.backgroundColor = backgroundColor;
this.edgeType = edgeType;
this.edgeColor = edgeColor;
mRawTypeface = rawTypeface;
}
/**
* @return the preferred {@link Typeface} for video captions, or null if
* not specified
*/
public Typeface getTypeface() {
if (mParsedTypeface == null && !TextUtils.isEmpty(mRawTypeface)) {
mParsedTypeface = Typeface.create(mRawTypeface, Typeface.NORMAL);
}
return mParsedTypeface;
}
/**
* @hide
*/
public static CaptionStyle getCustomStyle(ContentResolver cr) {
final CaptionStyle defStyle = CaptionStyle.DEFAULT_CUSTOM;
final int foregroundColor = Secure.getInt(
cr, Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, defStyle.foregroundColor);
final int backgroundColor = Secure.getInt(
cr, Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, defStyle.backgroundColor);
final int edgeType = Secure.getInt(
cr, Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE, defStyle.edgeType);
final int edgeColor = Secure.getInt(
cr, Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, defStyle.edgeColor);
String rawTypeface = Secure.getString(cr, Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE);
if (rawTypeface == null) {
rawTypeface = defStyle.mRawTypeface;
}
return new CaptionStyle(
foregroundColor, backgroundColor, edgeType, edgeColor, rawTypeface);
}
static {
WHITE_ON_BLACK = new CaptionStyle(
Color.WHITE, Color.BLACK, EDGE_TYPE_NONE, Color.BLACK, null);
BLACK_ON_WHITE = new CaptionStyle(
Color.BLACK, Color.WHITE, EDGE_TYPE_NONE, Color.BLACK, null);
YELLOW_ON_BLACK = new CaptionStyle(
Color.YELLOW, Color.BLACK, EDGE_TYPE_NONE, Color.BLACK, null);
YELLOW_ON_BLUE = new CaptionStyle(
Color.YELLOW, Color.BLUE, EDGE_TYPE_NONE, Color.BLACK, null);
PRESETS = new CaptionStyle[] {
WHITE_ON_BLACK, BLACK_ON_WHITE, YELLOW_ON_BLACK, YELLOW_ON_BLUE
};
DEFAULT_CUSTOM = WHITE_ON_BLACK;
}
}
/**
* Listener for changes in captioning properties, including enabled state
* and user style preferences.
*/
public static abstract class CaptioningChangeListener {
/**
* Called when the captioning enabled state changes.
*
* @param enabled the user's new preferred captioning enabled state
*/
public void onEnabledChanged(boolean enabled) {
}
/**
* Called when the captioning user style changes.
*
* @param userStyle the user's new preferred style
* @see CaptioningManager#getUserStyle()
*/
public void onUserStyleChanged(CaptionStyle userStyle) {
}
/**
* Called when the captioning locale changes.
*
* @param locale the preferred captioning locale
* @see CaptioningManager#getLocale()
*/
public void onLocaleChanged(Locale locale) {
}
/**
* Called when the captioning font scaling factor changes.
*
* @param fontScale the preferred font scaling factor
* @see CaptioningManager#getFontScale()
*/
public void onFontScaleChanged(float fontScale) {
}
}
}