• 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.util;
18 
19 import android.content.Context;
20 import android.view.accessibility.CaptioningManager;
21 import java.util.Locale;
22 
23 public class CaptionSettings {
24     public static final int OPTION_SYSTEM = 0;
25     public static final int OPTION_OFF = 1;
26     public static final int OPTION_ON = 2;
27 
28     private final CaptioningManager mCaptioningManager;
29     private int mOption = OPTION_SYSTEM;
30     private String mLanguage;
31     private String mTrackId;
32 
CaptionSettings(Context context)33     public CaptionSettings(Context context) {
34         mCaptioningManager =
35                 (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);
36     }
37 
getSystemLanguage()38     public final String getSystemLanguage() {
39         Locale l = mCaptioningManager.getLocale();
40         if (l != null) {
41             return l.getLanguage();
42         }
43         return null;
44     }
45 
getLanguage()46     public final String getLanguage() {
47         switch (mOption) {
48             case OPTION_SYSTEM:
49                 return getSystemLanguage();
50             case OPTION_OFF:
51                 return null;
52             case OPTION_ON:
53                 return mLanguage;
54         }
55         return null;
56     }
57 
isSystemSettingEnabled()58     public final boolean isSystemSettingEnabled() {
59         return mCaptioningManager.isEnabled();
60     }
61 
isEnabled()62     public final boolean isEnabled() {
63         switch (mOption) {
64             case OPTION_SYSTEM:
65                 return isSystemSettingEnabled();
66             case OPTION_OFF:
67                 return false;
68             case OPTION_ON:
69                 return true;
70         }
71         return false;
72     }
73 
getEnableOption()74     public int getEnableOption() {
75         return mOption;
76     }
77 
setEnableOption(int option)78     public void setEnableOption(int option) {
79         mOption = option;
80     }
81 
setLanguage(String language)82     public void setLanguage(String language) {
83         mLanguage = language;
84     }
85 
86     /** Returns the track ID to be used as an alternative key. */
getTrackId()87     public String getTrackId() {
88         return mTrackId;
89     }
90 
91     /** Sets the track ID to be used as an alternative key. */
setTrackId(String trackId)92     public void setTrackId(String trackId) {
93         mTrackId = trackId;
94     }
95 }
96