summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2013-12-19 13:42:28 -0800
committerAlan Viverette <alanv@google.com>2013-12-19 13:42:28 -0800
commitce32ea7345f0157a595b1dd4306a9a65f444d7c2 (patch)
treee9e555991903f4a99e1da8536c074dba7e524d22 /core
parent1732f2639b036522410037d5264a978235f7139a (diff)
downloadframeworks_base-ce32ea7345f0157a595b1dd4306a9a65f444d7c2.zip
frameworks_base-ce32ea7345f0157a595b1dd4306a9a65f444d7c2.tar.gz
frameworks_base-ce32ea7345f0157a595b1dd4306a9a65f444d7c2.tar.bz2
Add APIs and implementation for additional caption edge types
Change-Id: I62d97a0b3e3b751d698a889eec80dc79fb908d7a
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/accessibility/CaptioningManager.java19
-rw-r--r--core/java/com/android/internal/widget/SubtitleView.java28
2 files changed, 40 insertions, 7 deletions
diff --git a/core/java/android/view/accessibility/CaptioningManager.java b/core/java/android/view/accessibility/CaptioningManager.java
index 02929ed..a0134d6 100644
--- a/core/java/android/view/accessibility/CaptioningManager.java
+++ b/core/java/android/view/accessibility/CaptioningManager.java
@@ -250,6 +250,9 @@ public class CaptioningManager {
* background colors, edge properties, and typeface.
*/
public static final class CaptionStyle {
+ /** Packed value for a color of 'none' and a cached opacity of 100%. */
+ private static final int COLOR_NONE_OPAQUE = 0x000000FF;
+
private static final CaptionStyle WHITE_ON_BLACK;
private static final CaptionStyle BLACK_ON_WHITE;
private static final CaptionStyle YELLOW_ON_BLACK;
@@ -271,6 +274,12 @@ public class CaptioningManager {
/** Edge type value specifying drop-shadowed character edges. */
public static final int EDGE_TYPE_DROP_SHADOW = 2;
+ /** Edge type value specifying raised bevel character edges. */
+ public static final int EDGE_TYPE_RAISED = 3;
+
+ /** Edge type value specifying depressed bevel character edges. */
+ public static final int EDGE_TYPE_DEPRESSED = 4;
+
/** The preferred foreground color for video captions. */
public final int foregroundColor;
@@ -283,6 +292,8 @@ public class CaptioningManager {
* <li>{@link #EDGE_TYPE_NONE}
* <li>{@link #EDGE_TYPE_OUTLINE}
* <li>{@link #EDGE_TYPE_DROP_SHADOW}
+ * <li>{@link #EDGE_TYPE_RAISED}
+ * <li>{@link #EDGE_TYPE_DEPRESSED}
* </ul>
*/
public final int edgeType;
@@ -352,13 +363,13 @@ public class CaptioningManager {
static {
WHITE_ON_BLACK = new CaptionStyle(Color.WHITE, Color.BLACK, EDGE_TYPE_NONE,
- Color.BLACK, Color.TRANSPARENT, null);
+ Color.BLACK, COLOR_NONE_OPAQUE, null);
BLACK_ON_WHITE = new CaptionStyle(Color.BLACK, Color.WHITE, EDGE_TYPE_NONE,
- Color.BLACK, Color.TRANSPARENT, null);
+ Color.BLACK, COLOR_NONE_OPAQUE, null);
YELLOW_ON_BLACK = new CaptionStyle(Color.YELLOW, Color.BLACK, EDGE_TYPE_NONE,
- Color.BLACK, Color.TRANSPARENT, null);
+ Color.BLACK, COLOR_NONE_OPAQUE, null);
YELLOW_ON_BLUE = new CaptionStyle(Color.YELLOW, Color.BLUE, EDGE_TYPE_NONE,
- Color.BLACK, Color.TRANSPARENT, null);
+ Color.BLACK, COLOR_NONE_OPAQUE, null);
PRESETS = new CaptionStyle[] {
WHITE_ON_BLACK, BLACK_ON_WHITE, YELLOW_ON_BLACK, YELLOW_ON_BLUE
diff --git a/core/java/com/android/internal/widget/SubtitleView.java b/core/java/com/android/internal/widget/SubtitleView.java
index 0b6790c..117463a 100644
--- a/core/java/com/android/internal/widget/SubtitleView.java
+++ b/core/java/com/android/internal/widget/SubtitleView.java
@@ -39,6 +39,12 @@ public class SubtitleView extends View {
// Ratio of inner padding to font size.
private static final float INNER_PADDING_RATIO = 0.125f;
+ /** Color used for the shadowed edge of a bevel. */
+ private static final int COLOR_BEVEL_DARK = 0x80000000;
+
+ /** Color used for the illuminated edge of a bevel. */
+ private static final int COLOR_BEVEL_LIGHT = 0x80FFFFFF;
+
// Styled dimensions.
private final float mCornerRadius;
private final float mOutlineWidth;
@@ -113,7 +119,6 @@ public class SubtitleView extends View {
// Set up density-dependent properties.
// TODO: Move these to a default style.
final Resources res = getContext().getResources();
- final DisplayMetrics m = res.getDisplayMetrics();
mCornerRadius = res.getDimensionPixelSize(com.android.internal.R.dimen.subtitle_corner_radius);
mOutlineWidth = res.getDimensionPixelSize(com.android.internal.R.dimen.subtitle_outline_width);
mShadowRadius = res.getDimensionPixelSize(com.android.internal.R.dimen.subtitle_shadow_radius);
@@ -312,7 +317,8 @@ public class SubtitleView extends View {
}
}
- if (mEdgeType == CaptionStyle.EDGE_TYPE_OUTLINE) {
+ final int edgeType = mEdgeType;
+ if (edgeType == CaptionStyle.EDGE_TYPE_OUTLINE) {
textPaint.setStrokeJoin(Join.ROUND);
textPaint.setStrokeWidth(mOutlineWidth);
textPaint.setColor(mEdgeColor);
@@ -321,8 +327,24 @@ public class SubtitleView extends View {
for (int i = 0; i < lineCount; i++) {
layout.drawText(c, i, i);
}
- } else if (mEdgeType == CaptionStyle.EDGE_TYPE_DROP_SHADOW) {
+ } else if (edgeType == CaptionStyle.EDGE_TYPE_DROP_SHADOW) {
textPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mEdgeColor);
+ } else if (edgeType == CaptionStyle.EDGE_TYPE_RAISED
+ || edgeType == CaptionStyle.EDGE_TYPE_DEPRESSED) {
+ final boolean raised = edgeType == CaptionStyle.EDGE_TYPE_RAISED;
+ final int colorUp = raised ? Color.WHITE : mEdgeColor;
+ final int colorDown = raised ? mEdgeColor : Color.WHITE;
+ final float offset = mShadowRadius / 2f;
+
+ textPaint.setColor(mForegroundColor);
+ textPaint.setStyle(Style.FILL);
+ textPaint.setShadowLayer(mShadowRadius, -offset, -offset, colorUp);
+
+ for (int i = 0; i < lineCount; i++) {
+ layout.drawText(c, i, i);
+ }
+
+ textPaint.setShadowLayer(mShadowRadius, offset, offset, colorDown);
}
textPaint.setColor(mForegroundColor);