• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.tv.tuner.cc;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import com.android.tv.tuner.data.nano.Track.AtscCaptionTrack;
22 import com.android.tv.tuner.layout.ScaledLayout;
23 
24 /**
25  * Layout containing the safe title area that helps the closed captions look more prominent. This is
26  * required by CEA-708B.
27  */
28 public class CaptionLayout extends ScaledLayout {
29     // The safe title area has 10% margins of the screen.
30     private static final float SAFE_TITLE_AREA_SCALE_START_X = 0.1f;
31     private static final float SAFE_TITLE_AREA_SCALE_END_X = 0.9f;
32     private static final float SAFE_TITLE_AREA_SCALE_START_Y = 0.1f;
33     private static final float SAFE_TITLE_AREA_SCALE_END_Y = 0.9f;
34 
35     private final ScaledLayout mSafeTitleAreaLayout;
36     private AtscCaptionTrack mCaptionTrack;
37 
CaptionLayout(Context context)38     public CaptionLayout(Context context) {
39         this(context, null);
40     }
41 
CaptionLayout(Context context, AttributeSet attrs)42     public CaptionLayout(Context context, AttributeSet attrs) {
43         this(context, attrs, 0);
44     }
45 
CaptionLayout(Context context, AttributeSet attrs, int defStyleAttr)46     public CaptionLayout(Context context, AttributeSet attrs, int defStyleAttr) {
47         super(context, attrs, defStyleAttr);
48         mSafeTitleAreaLayout = new ScaledLayout(context);
49         addView(
50                 mSafeTitleAreaLayout,
51                 new ScaledLayoutParams(
52                         SAFE_TITLE_AREA_SCALE_START_X, SAFE_TITLE_AREA_SCALE_END_X,
53                         SAFE_TITLE_AREA_SCALE_START_Y, SAFE_TITLE_AREA_SCALE_END_Y));
54     }
55 
addOrUpdateViewToSafeTitleArea( CaptionWindowLayout captionWindowLayout, ScaledLayoutParams scaledLayoutParams)56     public void addOrUpdateViewToSafeTitleArea(
57             CaptionWindowLayout captionWindowLayout, ScaledLayoutParams scaledLayoutParams) {
58         int index = mSafeTitleAreaLayout.indexOfChild(captionWindowLayout);
59         if (index < 0) {
60             mSafeTitleAreaLayout.addView(captionWindowLayout, scaledLayoutParams);
61             return;
62         }
63         mSafeTitleAreaLayout.updateViewLayout(captionWindowLayout, scaledLayoutParams);
64     }
65 
removeViewFromSafeTitleArea(CaptionWindowLayout captionWindowLayout)66     public void removeViewFromSafeTitleArea(CaptionWindowLayout captionWindowLayout) {
67         mSafeTitleAreaLayout.removeView(captionWindowLayout);
68     }
69 
setCaptionTrack(AtscCaptionTrack captionTrack)70     public void setCaptionTrack(AtscCaptionTrack captionTrack) {
71         mCaptionTrack = captionTrack;
72     }
73 
getCaptionTrack()74     public AtscCaptionTrack getCaptionTrack() {
75         return mCaptionTrack;
76     }
77 }
78