1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.usbtuner.cc; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 22 import com.android.usbtuner.data.Track.AtscCaptionTrack; 23 import com.android.usbtuner.layout.ScaledLayout; 24 25 /** 26 * Layout containing the safe title area that helps the closed captions look more prominent. 27 * This is required by CEA-708B. 28 */ 29 public class CaptionLayout extends ScaledLayout { 30 // The safe title area has 10% margins of the screen. 31 private static final float SAFE_TITLE_AREA_SCALE_START_X = 0.1f; 32 private static final float SAFE_TITLE_AREA_SCALE_END_X = 0.9f; 33 private static final float SAFE_TITLE_AREA_SCALE_START_Y = 0.1f; 34 private static final float SAFE_TITLE_AREA_SCALE_END_Y = 0.9f; 35 36 private final ScaledLayout mSafeTitleAreaLayout; 37 private AtscCaptionTrack mCaptionTrack; 38 CaptionLayout(Context context)39 public CaptionLayout(Context context) { 40 this(context, null); 41 } 42 CaptionLayout(Context context, AttributeSet attrs)43 public CaptionLayout(Context context, AttributeSet attrs) { 44 this(context, attrs, 0); 45 } 46 CaptionLayout(Context context, AttributeSet attrs, int defStyleAttr)47 public CaptionLayout(Context context, AttributeSet attrs, int defStyleAttr) { 48 super(context, attrs, defStyleAttr); 49 mSafeTitleAreaLayout = new ScaledLayout(context); 50 addView(mSafeTitleAreaLayout, new ScaledLayoutParams( 51 SAFE_TITLE_AREA_SCALE_START_X, SAFE_TITLE_AREA_SCALE_END_X, 52 SAFE_TITLE_AREA_SCALE_START_Y, SAFE_TITLE_AREA_SCALE_END_Y)); 53 } 54 addOrUpdateViewToSafeTitleArea(CaptionWindowLayout captionWindowLayout, ScaledLayoutParams scaledLayoutParams)55 public void addOrUpdateViewToSafeTitleArea(CaptionWindowLayout captionWindowLayout, 56 ScaledLayoutParams scaledLayoutParams) { 57 int index = mSafeTitleAreaLayout.indexOfChild(captionWindowLayout); 58 if (index < 0) { 59 mSafeTitleAreaLayout.addView(captionWindowLayout, scaledLayoutParams); 60 return; 61 } 62 mSafeTitleAreaLayout.updateViewLayout(captionWindowLayout, scaledLayoutParams); 63 } 64 removeViewFromSafeTitleArea(CaptionWindowLayout captionWindowLayout)65 public void removeViewFromSafeTitleArea(CaptionWindowLayout captionWindowLayout) { 66 mSafeTitleAreaLayout.removeView(captionWindowLayout); 67 } 68 setCaptionTrack(AtscCaptionTrack captionTrack)69 public void setCaptionTrack(AtscCaptionTrack captionTrack) { 70 mCaptionTrack = captionTrack; 71 } 72 getCaptionTrack()73 public AtscCaptionTrack getCaptionTrack() { 74 return mCaptionTrack; 75 } 76 } 77